⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ygda.pas

📁 一个基于数据的药品行业管理系统,较全面,可供学习数据的开发人员参考消息
💻 PAS
📖 第 1 页 / 共 2 页
字号:
t6.Enabled:=true;
groupbox1.Enabled:=false;
end;
procedure Tfrmyg.t7Click(Sender: TObject);
begin
frmygcx:=tfrmygcx.create(application);
frmygcx.showmodal;
end;
procedure Tfrmyg.addbm;
begin
   if bmsave=1 then
   begin
   if edit5.text='' then
   begin
   messagedlg('部门编号不能为空',mtinformation,[mbok],1);
   edit5.SetFocus;
   edit5.Color:=clskyblue;
   exit;
   end;
   if edit7.text='' then
   begin
   messagedlg('部门名称号不能为空',mtinformation,[mbok],1);
   edit7.SetFocus;
   edit7.Color:=clskyblue;
   exit;
   end;
   with data do
   begin
   aq1.Connection:=adoc1;
   aq1.Close;
   aq1.SQL.Clear;
   aq1.SQL.Add('insert into bm (bmbh,bmmc) '+
              ' values (:bmbh,:bmmc)');
   aq1.Parameters.ParamByName('bmbh').Value:=trim(edit5.text);
   aq1.Parameters.ParamByName('bmmc').Value:=trim(edit7.text);
   aq1.ExecSQL;
   end;
   bmsave:=0;
   end;
   end;
procedure Tfrmyg.Edit5KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
with data do
begin
aq1.Connection:=adoc1;
aq1.Close;
aq1.SQL.Clear;
aq1.SQL.add('select bmbh from bm where bmbh=:ygbh');
aq1.Parameters.ParamByName('ygbh').Value:=trim(edit5.Text);
aq1.Open;
if aq1.Recordset.RecordCount>0 then
begin
showmessage('该部门编号已存在');
edit5.SetFocus;
edit5.SelectAll;
edit5.Color:=clskyblue;
exit;
end;
end;
edit5.Color:=clwindow;
edit7.SetFocus;
edit7.Color:=clskyblue;
end;
end;
procedure Tfrmyg.Edit7KeyPress(Sender: TObject; var Key: Char);
begin
if key=#13 then
begin
edit7.Color:=clwindow;
t4.Click;
toolbutton1.Click;
end;
end;
procedure Tfrmyg.ToolButton1Click(Sender: TObject);
begin
treeviewflesh;
end;
//增加员工
procedure Tfrmyg.addyg;
begin
if ygsave=1 then
   begin
   if edit1.text='' then
   begin
   messagedlg('员工编号不能为空',mtinformation,[mbok],1);
   edit1.SetFocus;
   edit1.Color:=clskyblue;
   exit;
   end;
   if edit1.text='' then
   begin
   messagedlg('员工编号不能为空',mtinformation,[mbok],1);
   edit1.SetFocus;
   edit1.Color:=clskyblue;
   exit;
   end;
   if edit2.text='' then
   begin
   messagedlg('员工名称不能为空',mtinformation,[mbok],1);
   edit2.SetFocus;
   edit2.Color:=clskyblue;
   exit;
   end;
   if edit3.text='' then
   begin
   messagedlg('联系人不能为空',mtinformation,[mbok],1);
   edit3.SetFocus;
   edit3.Color:=clskyblue;
   exit;
   end;
   //位编辑
   if editflag=0 then
   begin
   screen.Cursor:=crHourGlass;
   with data do
   begin
   aq1.Connection:=adoc1;
   aq1.Close;
   aq1.SQL.Clear;
   aq1.SQL.Add('insert into ygzl (bmbh,ygbh,ygmc,phone,dz,zw) '+
              ' values (:bmbh,:ygbh,:ygmc,:phone,:dz,:zw)');
   aq1.Parameters.ParamByName('bmbh').Value:=trim(edit5.text);
   aq1.Parameters.ParamByName('ygbh').Value:=trim(edit1.text);
   aq1.Parameters.ParamByName('ygmc').Value:=trim(edit2.text);
   aq1.Parameters.ParamByName('phone').Value:=trim(edit3.text);
   aq1.Parameters.ParamByName('dz').Value:=trim(edit4.text);
   aq1.Parameters.ParamByName('zw').Value:=trim(edit6.text);
   try
   if messagedlg('确定增加此员工吗?',mtinformation,[mbyes,mbno],0)=mrno then exit;
   aq1.ExecSQL;
   messagedlg('此员工已入库',mtinformation,[mbyes],1);
   editflag:=0;
   treeviewflesh;
   screen.Cursor:=crDefault
   except
   showmessage('插入数据出错');
   screen.Cursor:=crDefault;
   end;
   end;
   end;
   if editflag=1 then
   begin
   with data do
   begin
   aq1.Connection:=adoc1;
   aq1.Close;
   aq1.SQL.Clear;
   aq1.SQL.Add('update ygzl set ygmc=:ygmc,'+
   ' phone=:phone,dz=:dz,zw=:zw '+
   ' where ygbh=:ygbh and bmbh=:bmbh');
    aq1.Parameters.ParamByName('bmbh').Value:=trim(edit5.text);
   aq1.Parameters.ParamByName('ygbh').Value:=trim(edit1.text);
   aq1.Parameters.ParamByName('ygmc').Value:=trim(edit2.text);
   aq1.Parameters.ParamByName('dz').Value:=trim(edit4.text);
   aq1.Parameters.ParamByName('phone').Value:=trim(edit3.text);
   aq1.Parameters.ParamByName('zw').Value:=trim(edit6.text);
   try
   if messagedlg('确定修改此员工内容吗?',mtinformation,[mbyes,mbno],0)=mrno then exit;
   aq1.ExecSQL;
   messagedlg('此员工修改成功',mtinformation,[mbyes],1);
   editflag:=0;
  treeviewflesh;
   screen.Cursor:=crDefault
   except
   showmessage('修改数据出错');
   screen.Cursor:=crDefault;
   end;
   end;
   end;
   end;
edit1.Clear;
edit2.Clear;
edit3.Clear;
edit4.Clear;
edit6.Clear;
end;
procedure Tfrmyg.TreeView1Change(Sender: TObject; Node: TTreeNode);
begin
if node.Level=2 then
  begin
    showdata(node.Text);
  end;
end;

procedure Tfrmyg.showdata(str:string);
var i:integer;
begin
with data do
   begin
     aq1.Connection:=adoc1;
     aq1.Close;
     aq1.SQL.Clear;
     aq1.SQL.add(' select a.bmbh,a.bmmc,b.ygbh,b.ygmc,b.dz,b.zw,b.phone from bm a,ygzl b');
     aq1.SQL.add(' where a.bmbh=b.bmbh and b.ygmc=:ygmc');
     aq1.Parameters.ParamByName('ygmc').Value:=str;
     aq1.Open;
  if aq1.Recordset.RecordCount=0 then  exit;
     edit5.text:=aq1.Fields.Fieldbyname('bmbh').Value;
     edit7.text:=aq1.Fields.Fieldbyname('bmmc').Value;
     edit1.Text:=aq1.Fields.Fieldbyname('ygbh').Value;
     edit2.Text:=aq1.Fields.Fieldbyname('ygmc').Value;
     edit3.Text:=aq1.Fields.Fieldbyname('phone').Value;
     edit4.Text:=aq1.Fields.Fieldbyname('dz').Value;
     edit6.Text:=aq1.Fields.Fieldbyname('zw').Value;
     stgid1.RowCount:=aq1.Recordset.RecordCount+1;
     StatusBar1.Panels[1].Text:=inttostr(aq1.Recordset.RecordCount);
     stgid1.Font.Color:=clblack;
  while not aq1.Eof do
  begin
  for i:=1 to stgid1.RowCount do
  begin
     stgid1.Cells[0,i]:=aq1.Fields.fieldbyname('ygbh').Value;
     stgid1.Cells[1,i]:=aq1.Fields.fieldbyname('ygmc').Value;
     stgid1.Cells[2,i]:=aq1.Fields.fieldbyname('phone').Value;
     stgid1.Cells[3,i]:=aq1.Fields.fieldbyname('dz').Value;
     stgid1.Cells[4,i]:=aq1.Fields.fieldbyname('zw').Value;
     aq1.Next;
  end;
  end;
  end;
end;
//以目录树显示部门信息
procedure Tfrmyg.treeviewflesh;
var node,node1,node2:ttreenode;
begin
 treeview1.Items.Clear;
 node:=treeview1.Items.Add(nil,'部门');
 node.SelectedIndex:=0;
 node.ImageIndex:=0;
 with data do
 begin
   aq1.Connection:=adoc1;
   aq1.Close;
   aq1.SQL.Clear;
   aq1.SQL.Add('select * from bm');
   aq1.Open;
 if aq1.Recordset.RecordCount=0 then exit;
   edit5.Text:=aq1.Fields.Fieldbyname('bmbh').value;
   edit7.Text:=aq1.Fields.Fieldbyname('bmmc').value;
 while not aq1.Eof do
 begin
   node1:=treeview1.Items.AddChild(node,aq1.Fields.Fieldbyname('bmmc').Value);
   node1.SelectedIndex:=1;
   node1.ImageIndex:=0;
   aq2.connection:=adoc1;
   aq2.Close;
   aq2.SQL.Clear;
   aq2.SQL.add('select a.bmbh,a.bmmc,b.ygbh,b.ygmc from bm a,ygzl b');
   aq2.SQL.Add(' where a.bmbh=b.bmbh and a.bmmc=:bmmc');
   aq2.Parameters.ParamByName('bmmc').Value:=aq1.Fields.Fieldbyname('bmmc').Value;
   aq2.Open;
 if aq2.Recordset.RecordCount>0 then
 begin
 while not aq2.Eof do
 begin
   node2:=treeview1.Items.AddChild(node1,aq2.Fields.Fieldbyname('ygmc').Value);
   node2.ImageIndex:=0;
   node2.SelectedIndex:=1;
   aq2.Next;
 end;
 end;
   aq1.Next;
 end;
 end;
 treeview1.Items.Item[0].Selected:=true;
end;

procedure Tfrmyg.TreeView1Expanding(Sender: TObject; Node: TTreeNode;
  var AllowExpansion: Boolean);
var i:integer;
begin
if node.Level=1 then
   begin
   bmsave:=0;
   ygsave:=1;
   edit7.Text:=treeview1.Selected.Text;
   for i:=1 to stgid1.RowCount do
   stgid1.Rows[i].Clear;
   with data do
   begin
     aq1.Connection:=adoc1;
     aq1.Close;
     aq1.SQL.Clear;
     aq1.SQL.Add('select * from bm where bmmc=:bmmc');
     aq1.Parameters.ParamByName('bmmc').Value:=trim(edit7.Text);
     aq1.Open;
  if aq1.Recordset.RecordCount=0 then exit;
     edit5.Text:=aq1.Fields.Fieldbyname('bmbh').Value;
     aq1.Close;
     aq1.SQL.Clear;
     aq1.SQL.add(' select a.bmbh,b.ygbh,b.ygmc,b.dz,b.zw,b.phone from bm a,ygzl b');
     aq1.SQL.add(' where a.bmbh=b.bmbh and a.bmbh=:bmbh');
     aq1.Parameters.ParamByName('bmbh').Value:=trim(edit5.text);
     aq1.Open;
  if aq1.Recordset.RecordCount>0 then
     begin
     aq1.First;
     edit1.Text:=aq1.Fields.Fieldbyname('ygbh').Value;
     edit2.Text:=aq1.Fields.Fieldbyname('ygmc').Value;
     edit3.Text:=aq1.Fields.Fieldbyname('phone').Value;
     edit4.Text:=aq1.Fields.Fieldbyname('dz').Value;
     edit6.Text:=aq1.Fields.Fieldbyname('zw').Value;
     stgid1.RowCount:=aq1.Recordset.RecordCount+1;
     StatusBar1.Panels[1].Text:=inttostr(aq1.Recordset.RecordCount);
     stgid1.Font.Color:=clblack;
   while not aq1.Eof do
   begin
   for i:=1 to stgid1.RowCount-1 do
   begin
     stgid1.Cells[0,i]:=aq1.Fields.fieldbyname('ygbh').Value;
     stgid1.Cells[1,i]:=aq1.Fields.fieldbyname('ygmc').Value;
     stgid1.Cells[2,i]:=aq1.Fields.fieldbyname('phone').Value;
     stgid1.Cells[3,i]:=aq1.Fields.fieldbyname('dz').Value;
     stgid1.Cells[4,i]:=aq1.Fields.fieldbyname('zw').Value;
     aq1.Next;
   end;
   end;
   end;
   end;
   end;
end;

procedure Tfrmyg.TreeView1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var i:integer;
begin
if treeview1.Selected.Level=2 then
   showdata(treeview1.Selected.Text);
if treeview1.Selected.Level=1 then
   begin
   with data do
   begin
     aq1.Connection:=adoc1;
     aq1.Close;
     aq1.SQL.Clear;
     aq1.SQL.add(' select bmbh,bmmc from bm ');
     aq1.SQL.add(' where bmmc=:bmmc');
     aq1.Parameters.ParamByName('bmmc').Value:=trim(treeview1.Selected.Text);
     aq1.Open;
  //判断部门是否存在
  if aq1.Recordset.RecordCount>0 then
  begin
     for i:=1 to stgid1.RowCount do
     stgid1.Rows[i].Clear;
     edit5.text:=aq1.Fields.Fieldbyname('bmbh').Value;
     edit7.text:=aq1.Fields.Fieldbyname('bmmc').Value;
     StatusBar1.Panels[1].Text:=inttostr(aq1.Recordset.RecordCount);
     bmsave:=0;
     ygsave:=1;
     aq1.Close;
     aq1.SQL.Clear;
     aq1.SQL.add(' select a.bmbh,b.ygbh,b.ygmc,b.dz,b.zw,b.phone from bm a,ygzl b');
     aq1.SQL.add(' where a.bmbh=b.bmbh and a.bmbh=:bmbh');
     aq1.Parameters.ParamByName('bmbh').Value:=trim(edit5.text);
     aq1.Open;
  if aq1.Recordset.RecordCount>0 then
  begin
     aq1.First;
     edit1.Text:=aq1.Fields.Fieldbyname('ygbh').Value;
     edit2.Text:=aq1.Fields.Fieldbyname('ygmc').Value;
     edit3.Text:=aq1.Fields.Fieldbyname('phone').Value;
     edit4.Text:=aq1.Fields.Fieldbyname('dz').Value;
     edit6.Text:=aq1.Fields.Fieldbyname('zw').Value;
     stgid1.RowCount:=aq1.Recordset.RecordCount+1;
     StatusBar1.Panels[1].Text:=inttostr(aq1.Recordset.RecordCount);
     stgid1.Font.Color:=clblack;
   while not aq1.Eof do
   begin
   for i:=1 to stgid1.RowCount-1 do
   begin
     stgid1.Cells[0,i]:=aq1.Fields.fieldbyname('ygbh').Value;
     stgid1.Cells[1,i]:=aq1.Fields.fieldbyname('ygmc').Value;
     stgid1.Cells[2,i]:=aq1.Fields.fieldbyname('phone').Value;
     stgid1.Cells[3,i]:=aq1.Fields.fieldbyname('dz').Value;
     stgid1.Cells[4,i]:=aq1.Fields.fieldbyname('zw').Value;
     aq1.Next;
   end;
   end;
   end;
   end;
   end;
   end;
   end;


end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -