xt_yhzs.pas
上传用户:szruida
上传日期:2007-06-01
资源大小:6518k
文件大小:5k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. unit xt_yhzs;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, StdCtrls, Buttons, DBCtrls, DB, Grids, DBGridEh, ExtCtrls, Mask,
  6.   DBCtrlsEh, DBLookupEh, DBClient;
  7. type
  8.   Txt_fpyhz = class(TForm)
  9.     GroupBox1: TGroupBox;
  10.     Label37: TLabel;
  11.     Label5: TLabel;
  12.     SpeedButton19: TSpeedButton;
  13.     SpeedButton21: TSpeedButton;
  14.     SpeedButton22: TSpeedButton;
  15.     SpeedButton23: TSpeedButton;
  16.     Refresh: TSpeedButton;
  17.     SpeedButton25: TSpeedButton;
  18.     Panel6: TPanel;
  19.     DBGridEh6: TDBGridEh;
  20.     DataSource1: TDataSource;
  21.     Label1: TLabel;
  22.     Label2: TLabel;
  23.     DBLookupComboboxEh1: TDBLookupComboboxEh;
  24.     DBLookupComboboxEh2: TDBLookupComboboxEh;
  25.     Ds_user: TDataSource;
  26.     Ds_Yhz: TDataSource;
  27.     Ds_UandG: TDataSource;
  28.     ClientDataSet1: TClientDataSet;
  29.     procedure FormCreate(Sender: TObject);
  30.     procedure SpeedButton25Click(Sender: TObject);
  31.     procedure SpeedButton19Click(Sender: TObject);
  32.     procedure SpeedButton21Click(Sender: TObject);
  33.     procedure SpeedButton22Click(Sender: TObject);
  34.     procedure SpeedButton23Click(Sender: TObject);
  35.     procedure RefreshClick(Sender: TObject);
  36.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  37.   private
  38.     { Private declarations }
  39.   public
  40.     { Public declarations }
  41.   end;
  42. var
  43.   xt_fpyhz: Txt_fpyhz;
  44. implementation
  45. uses dms,U_public,ljszs;
  46. {$R *.dfm}
  47. procedure Txt_fpyhz.FormCreate(Sender: TObject);
  48. begin
  49.   dm.xt_yhz.Active:=true;
  50.   dm.xt_user.active:=true;
  51.   dm.xt_uandg.Active:=true;
  52.   dm.V_UandG.Active:=true;
  53. end;
  54. procedure Txt_fpyhz.SpeedButton25Click(Sender: TObject);
  55. begin
  56.  close;
  57. end;
  58. procedure Txt_fpyhz.SpeedButton19Click(Sender: TObject);
  59. begin
  60.  dm.xt_UandG.Append;//增加
  61.  DbLookUpComboboxeh1.Color:=clwindow;
  62.  DbLookUpComboboxeh2.Color:=clwindow;
  63.  DbLookUpComboboxeh1.Enabled:=true;
  64.  DbLookUpComboboxeh2.Enabled:=true;
  65. end;
  66. procedure Txt_fpyhz.SpeedButton21Click(Sender: TObject);
  67. var s_xh:string;
  68. begin
  69.   s_xh:=dm.V_UandG.fieldbyname('ug_xh').AsString;
  70.   dm.xt_UandG.Close;
  71.   dm.xt_UandG.CommandText:='select * from xt_UandG where ug_xh='+''''+s_xh+''''+'';
  72.   dm.xt_UandG.Open;
  73.   dm.xt_uandg.Edit;//修改数据
  74.   DbLookUpComboboxeh1.Color:=clwindow;
  75.  DbLookUpComboboxeh2.Color:=clwindow;
  76.  DbLookUpComboboxeh1.Enabled:=true;
  77.  DbLookUpComboboxeh2.Enabled:=true;
  78. end;
  79. procedure Txt_fpyhz.SpeedButton22Click(Sender: TObject);
  80. var s_xh:string;
  81. begin
  82.  s_xh:=dm.V_UandG.fieldbyname('ug_xh').AsString;
  83.  if dm.V_UandG.RecordCount=0 then
  84.   begin
  85.     application.MessageBox('当前表中没有数据,'+#13#10+'不能删除','警告',mb_ok+mb_iconinformation);
  86.     exit;
  87.   end
  88.  else
  89.   begin//删除选中的书并且更新表和视图
  90.     if application.MessageBox('您确定要删除吗?','警告',mb_ok+mb_iconinformation)=Idok then
  91.      begin
  92.       dm.xt_UandG.Close;
  93.       dm.xt_UandG.CommandText:='delete xt_UandG where ug_xh='+''''+s_xh+''''+'';
  94.       dm.xt_UandG.Execute;
  95.       dm.xt_UandG.Close;
  96.       dm.xt_uandg.CommandText:='select * from xt_uandG';
  97.       dm.xt_uandg.open;
  98.       dm.V_UandG.Close;
  99.       dm.V_UandG.CommandText:='select * from v_UandG';
  100.       dm.V_UandG.Open;
  101.      end;
  102.   end;
  103. end;
  104. procedure Txt_fpyhz.SpeedButton23Click(Sender: TObject);
  105. var N:integer;
  106.     s:string;
  107. begin
  108.  if DbLookupComboboxeh1.Text='' then
  109.   begin
  110.     application.MessageBox('用户名称不能为空','提示',mb_ok+mb_iconinformation);
  111.     exit;
  112.   end;
  113.  if DbLookupComboboxeh2.Text='' then
  114.   begin
  115.     application.MessageBox('用户组名称不能为空','提示',mb_ok+mb_iconinformation);
  116.     exit;
  117.   end;
  118.  //数据有效性验证
  119.  s:=DbLookUpComboboxeh1.KeyValue;
  120.  ClientdataSet1.Close;
  121.  Clientdataset1.CommandText:='select * from xt_UandG where User_dm='+''''+s+''''+'';
  122.  Clientdataset1.Open;
  123.  if clientdataset1.RecordCount<>0 then
  124.    begin
  125.     application.MessageBox('当前表中已有该用户存在,'+#13#10+'请选择其他用户','提示',mb_ok+mb_iconinformation);
  126.     exit;
  127.    end; 
  128.  N:=dm.xt_UandG.ApplyUpdates(0);
  129.  if N=0 then
  130.   begin
  131.     application.MessageBox('数据保存成功','提示',mb_ok+mb_iconinformation);
  132.     dm.xt_UandG.Close;
  133.     dm.xt_uandg.CommandText:='select * from xt_UandG';
  134.     dm.xt_UandG.open;
  135.     dm.v_uandg.Close;
  136.     dm.V_UandG.CommandText:='select * from v_UandG';
  137.     dm.V_UandG.Open;
  138.   end
  139.  else
  140.   begin
  141.     application.MessageBox('数据保存失败','提示',mb_ok+mb_iconinformation);
  142.   end;
  143. end;
  144. procedure Txt_fpyhz.RefreshClick(Sender: TObject);
  145. begin
  146.  dm.V_UandG.Close;
  147.  dm.v_Uandg.CommandText:='select * from v_UandG';
  148.  dm.V_UandG.Open;//刷新
  149. end;
  150. procedure Txt_fpyhz.FormClose(Sender: TObject; var Action: TCloseAction);
  151. begin
  152.   dm.xt_UandG.Active:=false;
  153.   dm.V_UandG.Active:=false;
  154.   dm.xt_user.Active:=false;
  155.   dm.xt_yhz.Active:=false;  
  156. end;
  157. end.