unit24.pas

来自「停车厂管理系统 麻雀虽小 但是五脏齐全」· PAS 代码 · 共 231 行

PAS
231
字号
unit Unit24;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, DBCtrls, Mask, Buttons, StdCtrls, DB, ADODB;

type
  Tkhwh = class(TForm)
    Label37: TLabel;
    ComboBox1: TComboBox;
    Label38: TLabel;
    Edit4: TEdit;
    find: TButton;
    change: TBitBtn;
    Label31: TLabel;
    Label32: TLabel;
    Label33: TLabel;
    Label34: TLabel;
    Label35: TLabel;
    Label36: TLabel;
    DBGrid8: TDBGrid;
    adot_customers: TADOTable;
    DataSource1: TDataSource;
    DBEdit6: TEdit;
    DBEdit9: TEdit;
    DBEdit8: TEdit;
    DBEdit7: TEdit;
    DBEdit10: TEdit;
    DBComboBox2: TComboBox;
    Label1: TLabel;
    Edit1: TEdit;
    procedure changeClick(Sender: TObject);
    procedure findClick(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormResize(Sender: TObject);
    procedure DBEdit6KeyPress(Sender: TObject; var Key: Char);
    procedure DBEdit8KeyPress(Sender: TObject; var Key: Char);
    procedure DBGrid8CellClick(Column: TColumn);
    procedure FormActivate(Sender: TObject);
    procedure DBGrid8DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  khwh: Tkhwh;
  FormOldWid:Integer;

implementation

uses Unit11, Unit4;

{$R *.dfm}

procedure clearface();
begin
  with khwh do
  begin
     edit1.Clear;
     edit4.SetFocus;
     edit4.Clear;
     dbedit6.Clear;
     dbedit6.Enabled:=false;//用户ID不能修改
     dbedit7.Clear;
     dbedit8.Clear;
     dbedit9.Clear;
     dbedit10.Clear;
     change.Enabled:=false;
  end;
end;

procedure Tkhwh.changeClick(Sender: TObject);
begin
  adot_customers.Open;
  adot_customers.Edit;
  if trim(edit1.Text)='' then
    begin
      showmessage('身份证号不能为空!');
      edit1.SetFocus;
    end
  else if trim(dbedit7.Text)='' then
    begin
      showmessage('用户姓名不能为空!');
      dbedit7.SetFocus;
    end
  else if trim(dbedit9.Text)='' then
    begin
      showmessage('联系电话不能为空!');
      dbedit9.SetFocus;
    end
  else
    begin
      adot_customers.FieldByName('shfenid').Value:=trim(edit1.Text);
      adot_customers.FieldByName('usename').Value:=trim(dbedit7.Text);
      adot_customers.FieldByName('tele').Value:=trim(dbedit9.Text);
      if trim(dbedit8.Text)<>'' then
      adot_customers.FieldByName('age').Value:=trim(dbedit8.Text);
      if trim(dbedit10.Text)<>'' then
      adot_customers.FieldByName('address').Value:=trim(dbedit10.Text);
      if trim(dbcombobox2.Text)<>'' then
      adot_customers.FieldByName('sex').Value:=trim(dbcombobox2.Text);
      adot_customers.Post;
      clearface();
      showmessage('客户信息修改成功');
    end;
end;

procedure Tkhwh.findClick(Sender: TObject);
begin
     adot_customers.Open;
     if not adot_customers.Locate(combobox1.Hint,edit4.Text,[loCaseInsensitive])  then
     begin
     showmessage('对不起,没找到您要查询的用户信息。');
     clearface();
     end
     else
     begin
       if adot_customers.FieldByName('shfenid').Value<>null then
         edit1.Text:=trim(adot_customers.FieldByName('shfenid').Value);
       if adot_customers.FieldByName('useid').Value<>null then
        dbedit6.Text:=trim(adot_customers.FieldByName('useid').Value);
       if adot_customers.FieldByName('usename').Value<>null then
        dbedit7.Text:=trim(adot_customers.FieldByName('usename').Value);
       if adot_customers.FieldByName('age').Value<>null then
        dbedit8.Text:=trim(inttostr(adot_customers.FieldByName('age').Value));
       if adot_customers.FieldByName('tele').Value<>null then
        dbedit9.Text:=trim(adot_customers.FieldByName('tele').Value);
       if adot_customers.FieldByName('address').Value<>null then
        dbedit10.Text:=trim(adot_customers.FieldByName('address').Value);
       if adot_customers.FieldByName('sex').Value<>null then
        dbcombobox2.Text:=adot_customers.FieldByName('sex').Value;
        change.Enabled:=true;
        edit4.Clear;
     end;
end;

procedure Tkhwh.ComboBox1Change(Sender: TObject);
begin
    if combobox1.ItemIndex=0 then
       combobox1.Hint:='useid'
    else if combobox1.ItemIndex=1 then
       combobox1.Hint:='cardid'
    else if combobox1.ItemIndex=2 then
       combobox1.Hint:='usename'
    else if combobox1.ItemIndex=3 then
       combobox1.Hint:='tele';
end;

procedure Tkhwh.FormShow(Sender: TObject);
begin
     FormOldWid:=self.Width;
end;

procedure Tkhwh.FormClose(Sender: TObject; var Action: TCloseAction);
begin
adot_customers.Close;
khwh:=nil;
Action:=caFree;
end;

procedure Tkhwh.FormResize(Sender: TObject);
begin
    if FormOldWid>0 then
    begin
     ScaleBy(self.Width,FormOldWid);
     FormOldWid:=self.Width;
    end ;
end;

procedure Tkhwh.DBEdit6KeyPress(Sender: TObject; var Key: Char);
begin
    if not(key in['0'..'9','a'..'z',#008]) then
    begin
      key:=#0;
     end
end;

procedure Tkhwh.DBEdit8KeyPress(Sender: TObject; var Key: Char);
begin
    if not(key in['0'..'9',#008]) then
    begin
      key:=#0;
     end
end;

procedure Tkhwh.DBGrid8CellClick(Column: TColumn);
begin
     if  not adot_customers.IsEmpty then
       begin
       if adot_customers.FieldByName('shfenid').Value<>null then
         edit1.Text:=trim(adot_customers.FieldByName('shfenid').Value);
       if adot_customers.FieldByName('useid').Value<>null then
        dbedit6.Text:=trim(adot_customers.FieldByName('useid').Value);
       if adot_customers.FieldByName('usename').Value<>null then
        dbedit7.Text:=trim(adot_customers.FieldByName('usename').Value);
       if adot_customers.FieldByName('age').Value<>null then
        dbedit8.Text:=trim(inttostr(adot_customers.FieldByName('age').Value));
       if adot_customers.FieldByName('tele').Value<>null then
        dbedit9.Text:=trim(adot_customers.FieldByName('tele').Value);
       if adot_customers.FieldByName('address').Value<>null then
        dbedit10.Text:=trim(adot_customers.FieldByName('address').Value);
       if adot_customers.FieldByName('sex').Value<>null then
        dbcombobox2.Text:=adot_customers.FieldByName('sex').Value;
        change.Enabled:=true;
        edit4.Clear;
        end;
end;

procedure Tkhwh.FormActivate(Sender: TObject);
begin
     adot_customers.Open;
     clearface();
end;

procedure Tkhwh.DBGrid8DblClick(Sender: TObject);
begin
  if history=nil then
  Application.CreateForm(Thistory,history);
   history.Show;
   history.Edit1.text:=adot_customers.Fields[1].Value;
   history.BitBtn1.Click;
end;

end.

⌨️ 快捷键说明

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