Z
zhb16519
Unregistered / Unconfirmed
GUEST, unregistred user!
要做个药品管理方面的,4个表,库存表,出库表,入库表,药品信息表,现在的问题是假如更新了入库表,那么库存表和信息表也要跟着更新,俺这个菜鸟不知道咋办了,请高手指点!下面是俺的入库界面的代码:
unit rk;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Buttons, Mask, Grids, DBGrids;
type
TrkForm = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
ComboBox1: TComboBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
MaskEdit1: TMaskEdit;
MaskEdit2: TMaskEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
ADOConnection1: TADOConnection;
DBGrid1: TDBGrid;
ADOTable1: TADOTable;
DataSource1: TDataSource;
GroupBox2: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
Label8: TLabel;
procedure BitBtn3Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure ADOTable1AfterScroll(DataSet: TDataSet);
procedure RadioButton1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure initiate;
procedure savetotable;
procedure loadfromtable;
end;
var
rkForm: TrkForm;
new_id:boolean;
implementation
uses main;
{$R *.dfm}
procedure TrkForm.BitBtn3Click(Sender: TObject);
begin
close;
end;
procedure TrkForm.FormActivate(Sender: TObject);
begin
dbgrid1.DataSource:=datasource1;
datasource1.DataSet:=adotable1;
adotable1.Connection:=adoconnection1;
adotable1.TableName:='rk';
adotable1.active:=true;
dbgrid1.ReadOnly:=true;
radiobutton2.Checked:=true;
if not adotable1.Eof then
loadfromtable
else
radiobutton3.Enabled:=false;
new_id:=false;
end;
procedure TrkForm.initiate;
begin
edit1.text:='';
edit2.text:='';
edit3.text:='';
edit4.text:='';
edit5.text:='';
edit6.text:='';
edit7.text:='';
edit8.text:='';
edit9.Text:='';
combobox1.text:='';
maskedit1.text:='';
maskedit2.text:=datetostr(Date());
edit1.SetFocus;
end;
procedure TrkForm.savetotable;
begin
adotable1.FieldByName('库存地址').asstring:=combobox1.text;
adotable1.FieldByName('药品名称').asstring:=edit1.text;
adotable1.FieldByName('规格').asstring:=edit2.text;
adotable1.FieldByName('批号').AsString:=edit3.text;
adotable1.FieldByName('生产厂家').asstring:=edit4.text;
adotable1.FieldByName('供应商').asstring:=edit5.text;
adotable1.FieldByName('备注').asstring:=edit6.text;
adotable1.FieldByName('入库数量').asstring:=edit7.text;
adotable1.FieldByName('单价').AsString:=edit8.text;
adotable1.FieldByName('入库操作员').asstring:=edit9.text;
adotable1.FieldByName('有效期').AsDateTime:=Strtodate(MaskEdit1.text);
adotable1.FieldByName('修改时间').AsDateTime:=date();
end;
procedure TrkForm.loadfromtable;
begin
combobox1.text:=adotable1.FieldByName('库存地址').asstring ;
edit1.text:= adotable1.FieldByName('药品名称').asstring;
edit2.text:=adotable1.FieldByName('规格').asstring;
edit3.text:=adotable1.FieldByName('批号').AsString;
edit4.text:=adotable1.FieldByName('生产厂家').asstring;
edit5.text:=adotable1.FieldByName('供应商').AsString;
edit6.text:=adotable1.FieldByName('备注').asstring;
edit7.text:=adotable1.FieldByName('入库数量').asstring;
edit8.text:=adotable1.FieldByName('单价').AsString;
edit9.text:=adotable1.FieldByName('入库操作员').asstring;
MaskEdit1.text:=datetostr(adotable1.FieldByName('有效期').AsDateTime);
MaskEdit2.text:=datetostr(adotable1.FieldByName('入库日期').AsDateTime);
end;
procedure TrkForm.ADOTable1AfterScroll(DataSet: TDataSet);
begin
if not radiobutton1.Checked then
loadfromtable;
end;
procedure TrkForm.RadioButton1Click(Sender: TObject);
begin
initiate;
edit1.SetFocus;
end;
procedure TrkForm.BitBtn1Click(Sender: TObject);
begin
if radiobutton1.Checked then
begin
adotable1.Append;
adotable1.edit;
savetotable;
adotable1.post;
end
else if radiobutton2.Checked then
begin
adotable1.edit;
savetotable;
adotable1.Post;
end
else
begin
adotable1.Delete;
adotable1.first;
end;
if adotable1.eof then
radiobutton3.Enabled:=false
else
radiobutton3.Enabled:=true;
if radiobutton1.checked then
initiate
else
loadfromtable;
end;
procedure TrkForm.RadioButton2Click(Sender: TObject);
begin
loadfromtable;
end;
end.
unit rk;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls, Buttons, Mask, Grids, DBGrids;
type
TrkForm = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
ComboBox1: TComboBox;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
MaskEdit1: TMaskEdit;
MaskEdit2: TMaskEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
ADOConnection1: TADOConnection;
DBGrid1: TDBGrid;
ADOTable1: TADOTable;
DataSource1: TDataSource;
GroupBox2: TGroupBox;
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
RadioButton3: TRadioButton;
Label8: TLabel;
procedure BitBtn3Click(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure ADOTable1AfterScroll(DataSet: TDataSet);
procedure RadioButton1Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure initiate;
procedure savetotable;
procedure loadfromtable;
end;
var
rkForm: TrkForm;
new_id:boolean;
implementation
uses main;
{$R *.dfm}
procedure TrkForm.BitBtn3Click(Sender: TObject);
begin
close;
end;
procedure TrkForm.FormActivate(Sender: TObject);
begin
dbgrid1.DataSource:=datasource1;
datasource1.DataSet:=adotable1;
adotable1.Connection:=adoconnection1;
adotable1.TableName:='rk';
adotable1.active:=true;
dbgrid1.ReadOnly:=true;
radiobutton2.Checked:=true;
if not adotable1.Eof then
loadfromtable
else
radiobutton3.Enabled:=false;
new_id:=false;
end;
procedure TrkForm.initiate;
begin
edit1.text:='';
edit2.text:='';
edit3.text:='';
edit4.text:='';
edit5.text:='';
edit6.text:='';
edit7.text:='';
edit8.text:='';
edit9.Text:='';
combobox1.text:='';
maskedit1.text:='';
maskedit2.text:=datetostr(Date());
edit1.SetFocus;
end;
procedure TrkForm.savetotable;
begin
adotable1.FieldByName('库存地址').asstring:=combobox1.text;
adotable1.FieldByName('药品名称').asstring:=edit1.text;
adotable1.FieldByName('规格').asstring:=edit2.text;
adotable1.FieldByName('批号').AsString:=edit3.text;
adotable1.FieldByName('生产厂家').asstring:=edit4.text;
adotable1.FieldByName('供应商').asstring:=edit5.text;
adotable1.FieldByName('备注').asstring:=edit6.text;
adotable1.FieldByName('入库数量').asstring:=edit7.text;
adotable1.FieldByName('单价').AsString:=edit8.text;
adotable1.FieldByName('入库操作员').asstring:=edit9.text;
adotable1.FieldByName('有效期').AsDateTime:=Strtodate(MaskEdit1.text);
adotable1.FieldByName('修改时间').AsDateTime:=date();
end;
procedure TrkForm.loadfromtable;
begin
combobox1.text:=adotable1.FieldByName('库存地址').asstring ;
edit1.text:= adotable1.FieldByName('药品名称').asstring;
edit2.text:=adotable1.FieldByName('规格').asstring;
edit3.text:=adotable1.FieldByName('批号').AsString;
edit4.text:=adotable1.FieldByName('生产厂家').asstring;
edit5.text:=adotable1.FieldByName('供应商').AsString;
edit6.text:=adotable1.FieldByName('备注').asstring;
edit7.text:=adotable1.FieldByName('入库数量').asstring;
edit8.text:=adotable1.FieldByName('单价').AsString;
edit9.text:=adotable1.FieldByName('入库操作员').asstring;
MaskEdit1.text:=datetostr(adotable1.FieldByName('有效期').AsDateTime);
MaskEdit2.text:=datetostr(adotable1.FieldByName('入库日期').AsDateTime);
end;
procedure TrkForm.ADOTable1AfterScroll(DataSet: TDataSet);
begin
if not radiobutton1.Checked then
loadfromtable;
end;
procedure TrkForm.RadioButton1Click(Sender: TObject);
begin
initiate;
edit1.SetFocus;
end;
procedure TrkForm.BitBtn1Click(Sender: TObject);
begin
if radiobutton1.Checked then
begin
adotable1.Append;
adotable1.edit;
savetotable;
adotable1.post;
end
else if radiobutton2.Checked then
begin
adotable1.edit;
savetotable;
adotable1.Post;
end
else
begin
adotable1.Delete;
adotable1.first;
end;
if adotable1.eof then
radiobutton3.Enabled:=false
else
radiobutton3.Enabled:=true;
if radiobutton1.checked then
initiate
else
loadfromtable;
end;
procedure TrkForm.RadioButton2Click(Sender: TObject);
begin
loadfromtable;
end;
end.