unit csszgl;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, Grids, DBGrids, DB, ComCtrls, StdCtrls, Buttons, DBTables;type TForm_csszgl = class(TForm) Bevel1: TBevel; DataSource1: TDataSource; DBGrid1: TDBGrid; StatusBar1: TStatusBar; BitBtn1: TBitBtn; BitBtn2: TBitBtn; BitBtn3: TBitBtn; BitBtn4: TBitBtn; Bevel2: TBevel; Label1: TLabel; Label2: TLabel; Label3: TLabel; Label4: TLabel; Label5: TLabel; Edit1: TEdit; Edit2: TEdit; Edit3: TEdit; DateTimePicker1: TDateTimePicker; DateTimePicker2: TDateTimePicker; Query1: TQuery; Query2: TQuery; Query1zlmc: TStringField; Query1zldm: TStringField; Query1yxqsrq: TDateTimeField; Query1yxjzrq: TDateTimeField; Query1czrq: TDateTimeField; Query1sm: TStringField; procedure BitBtn4Click(Sender: TObject); procedure BitBtn1Click(Sender: TObject); procedure BitBtn2Click(Sender: TObject); procedure BitBtn3Click(Sender: TObject); procedure DBGrid1DblClick(Sender: TObject); procedure FormActivate(Sender: TObject); procedure getXx; private { Private declarations } public { Public declarations } end;var Form_csszgl: TForm_csszgl;implementationuses jg;{$R *.dfm}procedure TForm_csszgl.BitBtn4Click(Sender: TObject); begin if (BitBtn4.Caption='增加返回') then begin //改变标题 BitBtn1.Caption:='增加'; BitBtn4.Caption:='返回'; BitBtn2.Enabled:=true; BitBtn3.Enabled:=true; Edit2.ReadOnly:=true; Edit1.ReadOnly:=true; end else if (BitBtn4.Caption='修改返回') then begin //改变标题 BitBtn2.Caption:='修改'; BitBtn4.Caption:='返回'; BitBtn1.Enabled:=true; BitBtn3.Enabled:=true; Edit2.ReadOnly:=true; Edit1.ReadOnly:=true; end else if (BitBtn4.Caption='删除返回') then begin //改变标题 BitBtn3.Caption:='删除'; BitBtn4.Caption:='返回'; BitBtn1.Enabled:=true; BitBtn2.Enabled:=true; Edit2.ReadOnly:=true; Edit1.ReadOnly:=true; end else begin close; end; end; Edit2.Text:='10001' else Edit2.Text:=inttostr(query2.FieldByName('zldm').Asinteger+1); if (DateTimePicker1.DateTime>DateTimePicker1.DateTime) then begin Form_jg.Label1.Left:=37; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='对不起,有效起始时间不能大于截止时间!'; Form_jg.showmodal; exit; end; query2.SQL.Clear; query2.SQL.Add('insert into zlcsb values('''+Edit1.Text+''','''+Edit2.Text+''',convert(datetime,'''+datetostr(DateTimePicker1.date)+'''),convert(datetime,'''+datetostr(DateTimePicker2.date)+'''),getdate(),'''+Edit3.Text+''')'); //inputbox('','',query2.SQL.Text); query2.Execsql; getXx; Form_jg.Label1.Left:=100; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='增加完毕!'; Form_jg.showmodal; end; end;procedure TForm_csszgl.BitBtn2Click(Sender: TObject); begin if (BitBtn2.Caption='修改') then begin //改变标题 BitBtn2.Caption:='修改确定'; BitBtn4.Caption:='修改返回'; BitBtn1.Enabled:=false; BitBtn3.Enabled:=false; Edit2.ReadOnly:=true; Edit1.ReadOnly:=true; end else begin //修改记录 if (DateTimePicker1.DateTime>DateTimePicker1.DateTime) then begin Form_jg.Label1.Left:=37; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='对不起,有效起始时间不能大于截止时间!'; Form_jg.showmodal; exit; end; query2.SQL.Clear; query2.SQL.Add('update zlcsb set yxqsrq=convert(datetime,'''+datetostr(DateTimePicker1.date)+'''),yxjzrq=convert(datetime,'''+datetostr(DateTimePicker2.date)+'''),czrq=getdate(),sm='''+Edit3.Text+''' where zldm='''+Edit2.Text+''' '); //inputbox('','',query2.SQL.Text); query2.Execsql; getXx; Form_jg.Label1.Left:=100; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='修改完毕!'; Form_jg.showmodal; end; end;procedure TForm_csszgl.BitBtn3Click(Sender: TObject); begin if (BitBtn3.Caption='删除') then begin //改变标题 BitBtn3.Caption:='删除确定'; BitBtn4.Caption:='删除返回'; BitBtn2.Enabled:=false; BitBtn1.Enabled:=false; Edit2.ReadOnly:=true; Edit1.ReadOnly:=true; end else begin //删除记录 query2.SQL.Clear; query2.SQL.Add('delete zlcsb where zldm='''+Edit2.Text+''' '); query2.Execsql; getXx; Form_jg.Label1.Left:=100; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='删除完毕!'; Form_jg.showmodal; end; end;procedure TForm_csszgl.DBGrid1DblClick(Sender: TObject); begin edit1.Text:=query1.FieldByName('zlmc').AsString; edit2.Text:=query1.FieldByName('zldm').AsString; edit3.Text:=query1.FieldByName('sm').AsString; DateTimePicker1.Date:=query1.FieldByName('yxqsrq').AsDateTime; DateTimePicker2.Date:=query1.FieldByName('yxjzrq').AsDateTime; end;procedure TForm_csszgl.FormActivate(Sender: TObject); begin getXx; end;procedure TForm_csszgl.getXx; begin query1.SQL.Clear; query1.SQL.Add('select * from xxsjk..zlcsb'); query1.open; end;end.
procedure TForm_csszgl.BitBtn1Click(Sender: TObject); begin if (BitBtn1.Caption='增加') then begin //改变标题 BitBtn1.Caption:='增加确定'; BitBtn4.Caption:='增加返回'; BitBtn2.Enabled:=false; BitBtn3.Enabled:=false; Edit2.ReadOnly:=true; Edit1.ReadOnly:=false; end else begin //增加记录 if (Edit1.text='') then begin Form_jg.Label1.Left:=37; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='对不起,你还没有填写商品的名称。'; //Form_jg.Label2.Caption:='如果有特殊需要,请和开发员联系!'; Form_jg.showmodal; exit; end; query2.SQL.Clear; query2.SQL.Add('select count(zlmc) as sl from xxsjk..zlcsb where zlmc='''+Edit1.Text+''''); query2.Open; if (query2.FieldByName('sl').Asinteger>0) then begin Form_jg.Label1.Left:=37; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='对不起,数据库中已经存在改信息。'; //Form_jg.Label2.Caption:='如果有特殊需要,请和开发员联系!'; Form_jg.showmodal; exit; end; query2.SQL.Clear; query2.SQL.Add('select max(zldm) as zldm from xxsjk..zlcsb '); //inputbox('','',query2.SQL.Text); query2.Open; if (query2.FieldByName('zldm').AsString='') then
Edit2.Text:='10001' else Edit2.Text:=inttostr(query2.FieldByName('zldm').Asinteger+1); if (DateTimePicker1.DateTime>DateTimePicker1.DateTime) then begin Form_jg.Label1.Left:=37; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='对不起,有效起始时间不能大于截止时间!'; Form_jg.showmodal; exit; end; query2.SQL.Clear; query2.SQL.Add('insert into zlcsb values('''+Edit1.Text+''','''+Edit2.Text+''',convert(datetime,'''+datetostr(DateTimePicker1.date)+'''),convert(datetime,'''+datetostr(DateTimePicker2.date)+'''),getdate(),'''+Edit3.Text+''')'); //inputbox('','',query2.SQL.Text); query2.Execsql; getXx; Form_jg.Label1.Left:=100; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='增加完毕!'; Form_jg.showmodal; end; end;procedure TForm_csszgl.BitBtn2Click(Sender: TObject); begin if (BitBtn2.Caption='修改') then begin //改变标题 BitBtn2.Caption:='修改确定'; BitBtn4.Caption:='修改返回'; BitBtn1.Enabled:=false; BitBtn3.Enabled:=false; Edit2.ReadOnly:=true; Edit1.ReadOnly:=true; end else begin //修改记录 if (DateTimePicker1.DateTime>DateTimePicker1.DateTime) then begin Form_jg.Label1.Left:=37; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='对不起,有效起始时间不能大于截止时间!'; Form_jg.showmodal; exit; end; query2.SQL.Clear; query2.SQL.Add('update zlcsb set yxqsrq=convert(datetime,'''+datetostr(DateTimePicker1.date)+'''),yxjzrq=convert(datetime,'''+datetostr(DateTimePicker2.date)+'''),czrq=getdate(),sm='''+Edit3.Text+''' where zldm='''+Edit2.Text+''' '); //inputbox('','',query2.SQL.Text); query2.Execsql; getXx; Form_jg.Label1.Left:=100; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='修改完毕!'; Form_jg.showmodal; end; end;procedure TForm_csszgl.BitBtn3Click(Sender: TObject); begin if (BitBtn3.Caption='删除') then begin //改变标题 BitBtn3.Caption:='删除确定'; BitBtn4.Caption:='删除返回'; BitBtn2.Enabled:=false; BitBtn1.Enabled:=false; Edit2.ReadOnly:=true; Edit1.ReadOnly:=true; end else begin //删除记录 query2.SQL.Clear; query2.SQL.Add('delete zlcsb where zldm='''+Edit2.Text+''' '); query2.Execsql; getXx; Form_jg.Label1.Left:=100; Form_jg.Label1.top:=25; Form_jg.Label1.Caption:='删除完毕!'; Form_jg.showmodal; end; end;procedure TForm_csszgl.DBGrid1DblClick(Sender: TObject); begin edit1.Text:=query1.FieldByName('zlmc').AsString; edit2.Text:=query1.FieldByName('zldm').AsString; edit3.Text:=query1.FieldByName('sm').AsString; DateTimePicker1.Date:=query1.FieldByName('yxqsrq').AsDateTime; DateTimePicker2.Date:=query1.FieldByName('yxjzrq').AsDateTime; end;procedure TForm_csszgl.FormActivate(Sender: TObject); begin getXx; end;procedure TForm_csszgl.getXx; begin query1.SQL.Clear; query1.SQL.Add('select * from xxsjk..zlcsb'); query1.open; end;end.
hammer_shi(@活着真累$$$FBS@)好努力,再给你+点U 最简练的莫过于 查询 query2.SQL.Clear; query2.SQL.Add('select count(zlmc) as sl from xxsjk..zlcsb ); query2.Open; 修改 query2.SQL.Clear; query2.SQL.Add('update b set a=b'); query2.Open; 插入 query2.SQL.Clear; query2.SQL.Add('insert b select * from a'); query2.Open;:) 不是抢分,只是觉得楼主看看书的好,要不上面给了那么多代码,你也看不懂。
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, Grids, DBGrids, DB, ComCtrls, StdCtrls, Buttons,
DBTables;type
TForm_csszgl = class(TForm)
Bevel1: TBevel;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
StatusBar1: TStatusBar;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
Bevel2: TBevel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
DateTimePicker1: TDateTimePicker;
DateTimePicker2: TDateTimePicker;
Query1: TQuery;
Query2: TQuery;
Query1zlmc: TStringField;
Query1zldm: TStringField;
Query1yxqsrq: TDateTimeField;
Query1yxjzrq: TDateTimeField;
Query1czrq: TDateTimeField;
Query1sm: TStringField;
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure DBGrid1DblClick(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure getXx;
private
{ Private declarations }
public
{ Public declarations }
end;var
Form_csszgl: TForm_csszgl;implementationuses jg;{$R *.dfm}procedure TForm_csszgl.BitBtn4Click(Sender: TObject);
begin
if (BitBtn4.Caption='增加返回') then
begin
//改变标题
BitBtn1.Caption:='增加';
BitBtn4.Caption:='返回';
BitBtn2.Enabled:=true;
BitBtn3.Enabled:=true;
Edit2.ReadOnly:=true;
Edit1.ReadOnly:=true;
end
else if (BitBtn4.Caption='修改返回') then
begin
//改变标题
BitBtn2.Caption:='修改';
BitBtn4.Caption:='返回';
BitBtn1.Enabled:=true;
BitBtn3.Enabled:=true;
Edit2.ReadOnly:=true;
Edit1.ReadOnly:=true;
end
else if (BitBtn4.Caption='删除返回') then
begin
//改变标题
BitBtn3.Caption:='删除';
BitBtn4.Caption:='返回';
BitBtn1.Enabled:=true;
BitBtn2.Enabled:=true;
Edit2.ReadOnly:=true;
Edit1.ReadOnly:=true;
end
else
begin
close;
end;
end; Edit2.Text:='10001'
else
Edit2.Text:=inttostr(query2.FieldByName('zldm').Asinteger+1); if (DateTimePicker1.DateTime>DateTimePicker1.DateTime) then
begin
Form_jg.Label1.Left:=37;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='对不起,有效起始时间不能大于截止时间!';
Form_jg.showmodal;
exit;
end; query2.SQL.Clear;
query2.SQL.Add('insert into zlcsb values('''+Edit1.Text+''','''+Edit2.Text+''',convert(datetime,'''+datetostr(DateTimePicker1.date)+'''),convert(datetime,'''+datetostr(DateTimePicker2.date)+'''),getdate(),'''+Edit3.Text+''')');
//inputbox('','',query2.SQL.Text);
query2.Execsql;
getXx; Form_jg.Label1.Left:=100;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='增加完毕!';
Form_jg.showmodal;
end;
end;procedure TForm_csszgl.BitBtn2Click(Sender: TObject);
begin
if (BitBtn2.Caption='修改') then
begin
//改变标题
BitBtn2.Caption:='修改确定';
BitBtn4.Caption:='修改返回';
BitBtn1.Enabled:=false;
BitBtn3.Enabled:=false;
Edit2.ReadOnly:=true;
Edit1.ReadOnly:=true;
end
else
begin
//修改记录
if (DateTimePicker1.DateTime>DateTimePicker1.DateTime) then
begin
Form_jg.Label1.Left:=37;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='对不起,有效起始时间不能大于截止时间!';
Form_jg.showmodal;
exit;
end; query2.SQL.Clear;
query2.SQL.Add('update zlcsb set yxqsrq=convert(datetime,'''+datetostr(DateTimePicker1.date)+'''),yxjzrq=convert(datetime,'''+datetostr(DateTimePicker2.date)+'''),czrq=getdate(),sm='''+Edit3.Text+''' where zldm='''+Edit2.Text+''' ');
//inputbox('','',query2.SQL.Text);
query2.Execsql;
getXx; Form_jg.Label1.Left:=100;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='修改完毕!';
Form_jg.showmodal;
end;
end;procedure TForm_csszgl.BitBtn3Click(Sender: TObject);
begin
if (BitBtn3.Caption='删除') then
begin
//改变标题
BitBtn3.Caption:='删除确定';
BitBtn4.Caption:='删除返回';
BitBtn2.Enabled:=false;
BitBtn1.Enabled:=false;
Edit2.ReadOnly:=true;
Edit1.ReadOnly:=true;
end
else
begin
//删除记录
query2.SQL.Clear;
query2.SQL.Add('delete zlcsb where zldm='''+Edit2.Text+''' ');
query2.Execsql;
getXx; Form_jg.Label1.Left:=100;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='删除完毕!';
Form_jg.showmodal;
end;
end;procedure TForm_csszgl.DBGrid1DblClick(Sender: TObject);
begin
edit1.Text:=query1.FieldByName('zlmc').AsString;
edit2.Text:=query1.FieldByName('zldm').AsString;
edit3.Text:=query1.FieldByName('sm').AsString;
DateTimePicker1.Date:=query1.FieldByName('yxqsrq').AsDateTime;
DateTimePicker2.Date:=query1.FieldByName('yxjzrq').AsDateTime;
end;procedure TForm_csszgl.FormActivate(Sender: TObject);
begin
getXx;
end;procedure TForm_csszgl.getXx;
begin
query1.SQL.Clear;
query1.SQL.Add('select * from xxsjk..zlcsb');
query1.open;
end;end.
begin
if (BitBtn1.Caption='增加') then
begin
//改变标题
BitBtn1.Caption:='增加确定';
BitBtn4.Caption:='增加返回';
BitBtn2.Enabled:=false;
BitBtn3.Enabled:=false;
Edit2.ReadOnly:=true;
Edit1.ReadOnly:=false;
end
else
begin
//增加记录
if (Edit1.text='') then
begin
Form_jg.Label1.Left:=37;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='对不起,你还没有填写商品的名称。';
//Form_jg.Label2.Caption:='如果有特殊需要,请和开发员联系!';
Form_jg.showmodal;
exit;
end;
query2.SQL.Clear;
query2.SQL.Add('select count(zlmc) as sl from xxsjk..zlcsb where zlmc='''+Edit1.Text+'''');
query2.Open;
if (query2.FieldByName('sl').Asinteger>0) then
begin
Form_jg.Label1.Left:=37;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='对不起,数据库中已经存在改信息。';
//Form_jg.Label2.Caption:='如果有特殊需要,请和开发员联系!';
Form_jg.showmodal;
exit;
end; query2.SQL.Clear;
query2.SQL.Add('select max(zldm) as zldm from xxsjk..zlcsb ');
//inputbox('','',query2.SQL.Text);
query2.Open;
if (query2.FieldByName('zldm').AsString='') then
else
Edit2.Text:=inttostr(query2.FieldByName('zldm').Asinteger+1); if (DateTimePicker1.DateTime>DateTimePicker1.DateTime) then
begin
Form_jg.Label1.Left:=37;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='对不起,有效起始时间不能大于截止时间!';
Form_jg.showmodal;
exit;
end; query2.SQL.Clear;
query2.SQL.Add('insert into zlcsb values('''+Edit1.Text+''','''+Edit2.Text+''',convert(datetime,'''+datetostr(DateTimePicker1.date)+'''),convert(datetime,'''+datetostr(DateTimePicker2.date)+'''),getdate(),'''+Edit3.Text+''')');
//inputbox('','',query2.SQL.Text);
query2.Execsql;
getXx; Form_jg.Label1.Left:=100;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='增加完毕!';
Form_jg.showmodal;
end;
end;procedure TForm_csszgl.BitBtn2Click(Sender: TObject);
begin
if (BitBtn2.Caption='修改') then
begin
//改变标题
BitBtn2.Caption:='修改确定';
BitBtn4.Caption:='修改返回';
BitBtn1.Enabled:=false;
BitBtn3.Enabled:=false;
Edit2.ReadOnly:=true;
Edit1.ReadOnly:=true;
end
else
begin
//修改记录
if (DateTimePicker1.DateTime>DateTimePicker1.DateTime) then
begin
Form_jg.Label1.Left:=37;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='对不起,有效起始时间不能大于截止时间!';
Form_jg.showmodal;
exit;
end; query2.SQL.Clear;
query2.SQL.Add('update zlcsb set yxqsrq=convert(datetime,'''+datetostr(DateTimePicker1.date)+'''),yxjzrq=convert(datetime,'''+datetostr(DateTimePicker2.date)+'''),czrq=getdate(),sm='''+Edit3.Text+''' where zldm='''+Edit2.Text+''' ');
//inputbox('','',query2.SQL.Text);
query2.Execsql;
getXx; Form_jg.Label1.Left:=100;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='修改完毕!';
Form_jg.showmodal;
end;
end;procedure TForm_csszgl.BitBtn3Click(Sender: TObject);
begin
if (BitBtn3.Caption='删除') then
begin
//改变标题
BitBtn3.Caption:='删除确定';
BitBtn4.Caption:='删除返回';
BitBtn2.Enabled:=false;
BitBtn1.Enabled:=false;
Edit2.ReadOnly:=true;
Edit1.ReadOnly:=true;
end
else
begin
//删除记录
query2.SQL.Clear;
query2.SQL.Add('delete zlcsb where zldm='''+Edit2.Text+''' ');
query2.Execsql;
getXx; Form_jg.Label1.Left:=100;
Form_jg.Label1.top:=25;
Form_jg.Label1.Caption:='删除完毕!';
Form_jg.showmodal;
end;
end;procedure TForm_csszgl.DBGrid1DblClick(Sender: TObject);
begin
edit1.Text:=query1.FieldByName('zlmc').AsString;
edit2.Text:=query1.FieldByName('zldm').AsString;
edit3.Text:=query1.FieldByName('sm').AsString;
DateTimePicker1.Date:=query1.FieldByName('yxqsrq').AsDateTime;
DateTimePicker2.Date:=query1.FieldByName('yxjzrq').AsDateTime;
end;procedure TForm_csszgl.FormActivate(Sender: TObject);
begin
getXx;
end;procedure TForm_csszgl.getXx;
begin
query1.SQL.Clear;
query1.SQL.Add('select * from xxsjk..zlcsb');
query1.open;
end;end.
最简练的莫过于
查询
query2.SQL.Clear;
query2.SQL.Add('select count(zlmc) as sl from xxsjk..zlcsb );
query2.Open;
修改
query2.SQL.Clear;
query2.SQL.Add('update b set a=b');
query2.Open;
插入
query2.SQL.Clear;
query2.SQL.Add('insert b select * from a');
query2.Open;:)
不是抢分,只是觉得楼主看看书的好,要不上面给了那么多代码,你也看不懂。
再在odbc中配置一个xxcj的
就可以运行了!
发送完毕!
但是太多了,我看不懂,打开还会报错,我只要简单的,在form上一个确定buton就可以了,然后就可以把得到ADO集合,和插入数据。