< SQL SERVER 2000 案例教程>>,冶金工业出版社,这本书的代码
源代码在线查看: unit7.~pas
unit Unit7;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ComCtrls;
type
Tsettimeform = class(TForm)
Label1: TLabel;
Label5: TLabel;
Label9: TLabel;
Label13: TLabel;
settime: TBitBtn;
cancel: TBitBtn;
amstart: TDateTimePicker;
amend: TDateTimePicker;
pmstart: TDateTimePicker;
pmend: TDateTimePicker;
procedure settimeClick(Sender: TObject);
procedure cancelClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
settimeform: Tsettimeform;
implementation
{$R *.dfm}
Uses Unit2,Unit3;
procedure Tsettimeform.settimeClick(Sender: TObject);
var index:integer;
begin
with mydata.Query2 do //使用Query2执行SQL操作
begin
close;
with sql do
begin
clear;
//获取上下班时间表中的所有数据
add('select * from 上下班时间表');
end;
open;
if findlast() then //如果表中有记录,则执行更新语句,否则执行插入语句
begin
//获取记录号
index:=FieldByName('记录号').AsInteger;
close;
with sql do
begin
clear;
//设置更新表的SQL语句
add('update 上下班时间表 set 上午上班时间=:amstart,上午下班时间=:amend,下午上班时间=:pmstart,下午下班时间=:pmend where 记录号=:index');
ParamByName('index').AsInteger:=index;
ParamByName('amstart').AsString:=timetostr(amstart.Time);
ParamByName('amend').AsString:=timetostr(amend.Time);
ParamByName('pmstart').AsString:=timetostr(pmstart.Time);
ParamByName('pmend').AsString:=timetostr(pmend.Time);
end;
execsql;
end else
begin
close;
with sql do
begin
clear;
//设置插入记录的SQL语句
add('insert into 上下班时间表 values(:index,:amstart,:amend,:pmstart,:pmend)');
ParamByName('index').AsInteger:=1;
ParamByName('amstart').AsString:=timetostr(amstart.Time);
ParamByName('amend').AsString:=timetostr(amend.Time);
ParamByName('pmstart').AsString:=timetostr(pmstart.Time);
ParamByName('pmend').AsString:=timetostr(pmend.Time);
end;
execsql;
end;
close;
end;
//更新主界面显示的数据
main.oninit1();
close;
end;
procedure Tsettimeform.cancelClick(Sender: TObject);
begin
close;
end;
end.