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

Delphi控件源码

开发平台:

Delphi

  1. unit am_dzbjs;
  2. interface
  3. uses
  4.   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5.   Dialogs, Buttons, ExtCtrls, StdCtrls, DB, Mask, DBCtrls, DBCtrlsEh;
  6. type
  7.   Tam_dzbj = class(TForm)
  8.     Image1: TImage;
  9.     Label1: TLabel;
  10.     Panel1: TPanel;
  11.     SpeedButton1: TSpeedButton;
  12.     SpeedButton2: TSpeedButton;
  13.     Label2: TLabel;
  14.     DBEdit1: TDBEdit;
  15.     Label3: TLabel;
  16.     DBEdit2: TDBEdit;
  17.     Label4: TLabel;
  18.     DBEdit3: TDBEdit;
  19.     Label5: TLabel;
  20.     Label6: TLabel;
  21.     DBEdit5: TDBEdit;
  22.     Label7: TLabel;
  23.     DBEdit6: TDBEdit;
  24.     Label8: TLabel;
  25.     Label9: TLabel;
  26.     DBEdit8: TDBEdit;
  27.     Label10: TLabel;
  28.     Label11: TLabel;
  29.     Label12: TLabel;
  30.     Label13: TLabel;
  31.     zjlb: TDBLookupComboBox;
  32.     jyjb: TDBLookupComboBox;
  33.     DBDateTimeEditEh1: TDBDateTimeEditEh;
  34.     DataSource1: TDataSource;
  35.     Label14: TLabel;
  36.     Label15: TLabel;
  37.     MaskEdit1: TMaskEdit;
  38.     procedure FormKeyPress(Sender: TObject; var Key: Char);
  39.     procedure SpeedButton2Click(Sender: TObject);
  40.     procedure SpeedButton1Click(Sender: TObject);
  41.     procedure DBEdit6Exit(Sender: TObject);
  42.     procedure DBEdit8Exit(Sender: TObject);
  43.     procedure FormShow(Sender: TObject);
  44.     procedure DBEdit4KeyPress(Sender: TObject; var Key: Char);
  45.     procedure FormClose(Sender: TObject; var Action: TCloseAction);
  46.     procedure FormCreate(Sender: TObject);
  47.     procedure DBEdit8KeyPress(Sender: TObject; var Key: Char);
  48.   private
  49.     { Private declarations }
  50.   public
  51.     { Public declarations }
  52.   end;
  53. var
  54.   am_dzbj: Tam_dzbj;
  55. implementation
  56. uses DMs,am_dzs, mainfrms;
  57. {$R *.dfm}
  58. procedure Tam_dzbj.FormKeyPress(Sender: TObject; var Key: Char);
  59. begin
  60.  if key=#13 then
  61.    begin
  62.      key:=#0;
  63.      perform(WM_NEXTDLGCTL,0,0);
  64.    END;
  65. end;
  66. procedure Tam_dzbj.SpeedButton2Click(Sender: TObject);
  67. begin
  68.  close;
  69. end;
  70. procedure Tam_dzbj.SpeedButton1Click(Sender: TObject);
  71. var i:integer;
  72. begin
  73.    if dbedit1.Text='' then
  74.    begin
  75.     application.MessageBox('读者代码不能为空!','提示',mb_ok+mb_iconinformation);
  76.     exit;
  77.    end;
  78.    if dbedit2.Text='' then
  79.    begin
  80.     application.MessageBox('读者姓名不能为空!','提示',mb_ok+mb_iconinformation);
  81.     exit;
  82.    end;
  83.    if zjlb.Text='' then
  84.    begin
  85.     application.MessageBox('证件类别不能为空!','提示',mb_ok+mb_iconinformation);
  86.     zjlb.SetFocus;
  87.     exit;
  88.    end;
  89.    if jyjb.Text='' then
  90.    begin
  91.     application.MessageBox('借阅级别不能为空!','提示',mb_ok+mb_iconinformation);
  92.     jyjb.SetFocus;
  93.     exit;
  94.    end;
  95.    //-----------------------------------------
  96.    dm.am_dz.Edit;
  97.    dm.am_dz.FieldByName('dz_djsj').AsString:=DBDateTimeEditEh1.Text;
  98.    dm.am_dz.FieldByName('dz_lxdh').AsString:=maskedit1.Text;
  99.    Dm.am_dz.ApplyUpdates(0);
  100.    i:=Dm.am_dz.ApplyUpdates(0);  
  101.    if i=0 then
  102.    begin
  103.       application.MessageBox('数据保存成功','提示',mb_ok+mb_iconinformation);
  104.       dm.am_dz.Close;
  105.       dm.am_dz.CommandText:='select * from am_dz';
  106.       dm.am_dz.Open;
  107.       //刷新视图
  108.       dm.V_DZ.Close;
  109.       dm.V_DZ.CommandText:='select * from V_DZ';
  110.       dm.V_DZ.Open;
  111.       close;
  112.    end
  113.    else
  114.    begin
  115.      application.MessageBox('数据保存失败','提示',mb_ok+mb_iconinformation);
  116.      exit;
  117.    end;  
  118. end;
  119. procedure Tam_dzbj.DBEdit6Exit(Sender: TObject);
  120. var
  121.   Email,s:string;
  122.   Etpos:integer;
  123. begin
  124.   Email:=dbEdit6.Text;
  125.   etpos:=pos('@',Email);
  126.   if etpos>1 then
  127.   begin
  128.      s:=copy(email,etpos+1,length(email));
  129.      if (pos('.',s)>1)and(pos('.',s)<length(s)) then
  130.      begin
  131.      end
  132.      else
  133.      begin
  134.         application.MessageBox('电子邮件格式不对!','提示',mb_ok+mb_iconinformation);
  135.         dbedit6.SetFocus;
  136.      end
  137.  end
  138.  else
  139.  begin
  140.         application.MessageBox('电子邮件格式不对!','提示',mb_ok+mb_iconinformation);
  141.         dbedit6.SetFocus;
  142.  end;
  143. end;
  144. procedure Tam_dzbj.DBEdit8Exit(Sender: TObject);
  145. begin
  146.  if trim(zjlb.Text)='身份证' then
  147.  begin
  148.     if length(dbedit8.Text)<>0 then
  149.      if (length(dbedit8.Text)=15) or(length(dbedit8.Text)=18) then
  150.      begin
  151.          try
  152.            strtofloat(dbedit8.Text)
  153.          except
  154.            application.MessageBox('身份证号码不对!','提示',mb_ok+mb_iconinformation);
  155.            dbedit8.SetFocus;
  156.            exit;
  157.          end
  158.      end
  159.      else
  160.      begin
  161.         application.MessageBox('身份证号码必须为15或18位!','提示',mb_ok+mb_iconinformation);
  162.         dbedit8.SetFocus;
  163.         exit;
  164.      end;
  165.   //---------------------
  166.  end;
  167. end;
  168. procedure Tam_dzbj.FormShow(Sender: TObject);
  169. begin
  170.   dbdatetimeediteh1.Value:=now;
  171. end;
  172. procedure Tam_dzbj.DBEdit4KeyPress(Sender: TObject; var Key: Char);
  173. //var Epos:integer;
  174. begin
  175.   {if not (Key in ['0'..'9','-'] ) then
  176.    begin
  177.     Key:=#0;
  178.     application.MessageBox('请输入正确的电话格式:','提示',mb_ok+mb_iconinformation);
  179.    end
  180.    else
  181.    if length(trim(dbedit4.Text))=4 then
  182.    begin
  183.       dbedit4.Text:=dbedit4.Text+'-';
  184.    end;}
  185. end;
  186. procedure Tam_dzbj.FormClose(Sender: TObject; var Action: TCloseAction);
  187. begin
  188.   action:=cafree;
  189.   am_dzbj:=Nil;
  190. end;
  191. procedure Tam_dzbj.FormCreate(Sender: TObject);
  192. begin
  193.   Dm.am_dz.Active:=true;
  194.   dm.am_jygz.Active:=true;
  195.   DM.sz_zjlb.Active:=true;
  196.   dm.V_DZ.Close;
  197.   dm.V_DZ.CommandText:='select * from v_dz';
  198.   dm.V_DZ.Open;
  199. end;
  200. procedure Tam_dzbj.DBEdit8KeyPress(Sender: TObject; var Key: Char);
  201. begin
  202.  mainfrm.DbInputNum(DbEdit8,key);
  203. end;
  204. end.