if form5.Tag=1 then begin adoquery1.SQL.Add('select * from Purchase where 采购单编号=:cgdbh'); adoquery1.Parameters.ParamByName('cgdbh').Value:=edit1.Text; adoquery1.Open; if adoquery1.RecordCount> 0 then begin showmessage('采购单编号已存在,请重新输入'); edit1.Text:=''; edit1.SetFocus; exit; end;
end; if form5.Tag=2 then begin str:=edit1.Text; adoquery1.Close; adoquery1.SQL.Clear; adoquery1.SQL.Add('update Purchase set 采购单编号=:cgdbh,商品编号=:spbh,' +'进货价=:jhj,进货数量=:jhsl,进货日期=:jhrq' +' where 采购单编号=:oldcgdbh'); adoquery1.Parameters.ParamByName('oldcgdbh').Value:=str;
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, ExtCtrls;type
TForm4 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Bevel1: TBevel;
Button1: TButton;
Button2: TButton;
ADOQuery1: TADOQuery;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form4: TForm4;implementationuses PurchaseInfo, DataModule;{$R *.dfm}procedure TForm4.Button2Click(Sender: TObject);
begin
form4.Close;
end;procedure TForm4.Button1Click(Sender: TObject);
var
str:string;
begin
if edit1.Text='' then
begin
showmessage('请输入采购单编号');
edit1.SetFocus;
exit;
end;
if edit2.Text='' then
begin
showmessage('请输入商品编号');
edit1.SetFocus;
exit;
end;
if edit3.Text='' then
begin
showmessage('请输入进货价');
edit1.SetFocus;
exit;
end;
if edit4.Text='' then
begin
showmessage('请输入进货数量');
edit1.SetFocus;
exit;
end;
if edit5.Text='' then
begin
showmessage('请输入进货日期');
edit1.SetFocus;
exit;
end;
adoquery1.Close;
adoquery1.SQL.Clear;
if form5.Tag=1 then
begin
adoquery1.SQL.Add('select * from Purchase where 采购单编号=:cgdbh');
adoquery1.Parameters.ParamByName('cgdbh').Value:=edit1.Text;
adoquery1.Open;
if adoquery1.RecordCount>0 then
begin
showmessage('采购单编号已存在,请重新输入');
edit1.Text:='';
edit1.SetFocus;
exit;
end;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('insert into Purchase');
adoquery1.SQL.Add('values(:cgdbh,:spbh,:jhj,:jhsl,:jhrq)');
end;
if form5.Tag=2 then
begin
str:=edit1.Text;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('update Purchase set 采购单编号=:cgdbh,商品编号=:spbh,'
+'进货价=:jhj,进货数量=:jhsl,进货日期=:jhrq'
+' where 采购单编号=:oldcgdbh');
adoquery1.Parameters.ParamByName('oldcgdbh').Value:=str;
end;
form5.ADOQuery1.Close;
adoquery1.Parameters.ParamByName('cgdbh').Value:=edit1.Text;
adoquery1.Parameters.ParamByName('spbh').Value:=edit2.Text;
adoquery1.Parameters.ParamByName('jhj').Value:=edit3.Text;
adoquery1.Parameters.ParamByName('jhsl').Value:=edit4.Text;
adoquery1.Parameters.ParamByName('jhrq').Value:=edit5.Text;
adoquery1.ExecSQL;
form5.ADOQuery1.Open;
close;
end;
这是代码
begin
adoquery1.SQL.Add('select * from Purchase where 采购单编号=:cgdbh');
adoquery1.Parameters.ParamByName('cgdbh').Value:=edit1.Text;
adoquery1.Open;
if adoquery1.RecordCount> 0 then
begin
showmessage('采购单编号已存在,请重新输入');
edit1.Text:='';
edit1.SetFocus;
exit;
end;
end;
if form5.Tag=2 then
begin
str:=edit1.Text;
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.SQL.Add('update Purchase set 采购单编号=:cgdbh,商品编号=:spbh,'
+'进货价=:jhj,进货数量=:jhsl,进货日期=:jhrq'
+' where 采购单编号=:oldcgdbh');
adoquery1.Parameters.ParamByName('oldcgdbh').Value:=str;
adoquery1.Parameters.ParamByName('cgdbh').Value:=edit1.Text;
adoquery1.Parameters.ParamByName('spbh').Value:=edit2.Text;
adoquery1.Parameters.ParamByName('jhj').Value:=edit3.Text;
adoquery1.Parameters.ParamByName('jhsl').Value:=edit4.Text;
adoquery1.Parameters.ParamByName('jhrq').Value:=edit5.Text;
adoquery1.ExecSQL;
end;
没重新操作都要执行
adoquery1.Close;
adoquery1.SQL.Clear;
adoquery1.Parameters.Clear;