f_yhgl.pas
上传用户:lcqxtx
上传日期:2013-02-15
资源大小:530k
文件大小:6k
- unit f_yhgl;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ComCtrls, StdCtrls, Buttons, Grids, DBGrids, DB, ADODB;
- type
- Tw_yhgl = class(TForm)
- gb_1: TGroupBox;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- e_bh: TEdit;
- c_xb: TComboBox;
- e_password: TEdit;
- e_user: TEdit;
- gb_2: TGroupBox;
- b_xz: TBitBtn;
- b_xg: TBitBtn;
- b_gb: TBitBtn;
- b_qx: TBitBtn;
- b_bc: TBitBtn;
- b_sc: TBitBtn;
- stb: TStatusBar;
- e_yhzw: TEdit;
- Label5: TLabel;
- DBGrid1: TDBGrid;
- ado_yhgl: TADOQuery;
- ado_yhgluser_id: TIntegerField;
- ado_yhgluser_name: TStringField;
- ado_yhgluser_job: TStringField;
- ado_yhgluser_power: TStringField;
- ado_yhgluser_password: TStringField;
- datas_yhgl: TDataSource;
- procedure FormShow(Sender: TObject);
- procedure b_xzClick(Sender: TObject);
- procedure b_qxClick(Sender: TObject);
- procedure b_scClick(Sender: TObject);
- procedure b_bcClick(Sender: TObject);
- procedure b_xgClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure b_gbClick(Sender: TObject);
- procedure DBGrid1CellClick(Column: TColumn);
- procedure FormClose(Sender: TObject; var Action: TCloseAction);
- private
- { Private declarations }
- public
- { Public declarations }
- procedure s_save;
- procedure s_show;
- procedure s_clear(bb:boolean);
- end;
- var
- w_yhgl: Tw_yhgl;
- bsf:string;
- implementation
- uses data_1, f_main;
- {$R *.dfm}
- procedure tw_yhgl.s_save;
- begin
- ado_yhgl.Edit ;
- ado_yhgl.FieldByName('user_id').AsString :=trim(e_bh.Text);
- ado_yhgl.FieldByName('user_name').AsString :=trim(e_user.Text);
- ado_yhgl.FieldByName('user_password').AsString:=trim(e_password.Text);
- ado_yhgl.FieldByName('user_power').AsString:=trim(c_xb.text);
- ado_yhgl.FieldByName('user_job').AsString:=trim(e_yhzw.text);
- ado_yhgl.Post;
- end;
- procedure tw_yhgl.s_show;
- begin
- ado_yhgl.Close;
- ado_yhgl.SQL.Clear;
- ado_yhgl.SQL.Add('select * from username');
- ado_yhgl.Open;
- end;
- procedure tw_yhgl.s_clear(bb:boolean);
- var
- i:integer;
- begin
- e_bh.text:='';
- e_user.Text:='';
- e_bh.Text:='';
- e_password.Text:='';
- c_xb.Text :='';
- e_yhzw.text:='';
- b_xz.Enabled:=true;
- b_xg.Enabled :=true;
- b_sc.Enabled :=true;
- b_bc.Enabled :=false;
- b_qx.Enabled :=false;
- b_gb.Enabled :=true;
- for i:=0 to gb_1.ControlCount-1 do
- begin
- if (gb_1.Controls[i].ClassType=tedit) or (gb_1.Controls[i].ClassType=tcombobox) then
- begin
- if bb=false then
- gb_1.Controls[i].Enabled :=false
- else
- gb_1.Controls[i].Enabled :=true;
- end;
- end;
- end;
- procedure Tw_yhgl.FormShow(Sender: TObject);
- var
- ss:boolean;
- begin
- ss:=false;
- s_clear(ss);
- end;
- procedure Tw_yhgl.b_xzClick(Sender: TObject);
- var
- ss:boolean;
- begin
- if bsf='xz' then
- ss:=true;
- s_clear(ss);
- e_bh.Text:='';
- e_user.Text:='';
- e_password.Text:='';
- c_xb.Text:='';
- e_yhzw.text:='';
- e_bh.SetFocus ;
- b_xz.Enabled :=false;
- b_xg.Enabled :=false;
- b_bc.Enabled :=true;
- b_sc.Enabled :=false;
- b_qx.Enabled :=true;
- b_gb.Enabled :=false;
- end;
- procedure Tw_yhgl.b_qxClick(Sender: TObject);
- var
- bb:boolean;
- begin
- bb:=false;
- s_clear(bb);
- end;
- procedure Tw_yhgl.b_scClick(Sender: TObject);
- var
- bb:boolean;
- begin
- if trim(e_bh.Text )<>'' then
- begin
- if MessageDlg('记录是否删除 ?',mtConfirmation, [mbYes, mbNo], 0) = mrYes then
- begin
- data1.ado_yhgl.Delete;
- s_show;
- bb:=false;
- s_clear(bb);
- end
- else
- exit;
- end
- else
- showmessage('请输入删除值!');
- exit;
- end;
- procedure Tw_yhgl.b_bcClick(Sender: TObject);
- var
- bb:boolean;
- begin
- if trim(e_bh.Text)='' then
- begin
- showmessage('请输入用户编号!');
- exit;
- end;
- if bsf<>'xg' then
- begin
- ado_yhgl.Close;
- ado_yhgl.SQL.clear;
- ado_yhgl.SQL.Add('select * from username where user_id='+char(39)+trim(e_bh.Text)+char(39));
- ado_yhgl.Open;
- end;
- if ado_yhgl.RecordCount <0 then
- begin
- showmessage('请输入值');
- exit;
- end;
- if trim(e_user.Text)='' then
- begin
- showmessage('请输入用户姓名');
- exit;
- end;
- if trim(e_password.Text )='' then
- begin
- showmessage('请输入用户密码');
- exit;
- end;
- if trim(c_xb.Text)='' then
- begin
- showmessage('请选择用户权限!');
- exit;
- end;
- if trim(e_yhzw.Text)='' then
- begin
- showmessage('请输入用户职务!');
- exit;
- end;
- if MessageDlg('记录是否保存吗 ?',mtConfirmation, [mbYes, mbNo], 0) = mrYes then
- begin
- s_save;
- s_show;
- bb:=false;
- s_clear(bb);
- end
- else
- s_show;
- exit;
- end;
- procedure Tw_yhgl.b_xgClick(Sender: TObject);
- var
- i:integer;
- begin
- if trim(e_bh.text)<>'' then begin
- bsf:='xg';
- for i:=0 to gb_1.ControlCount-1 do
- if (gb_1.Controls[i].ClassType=tedit) or(gb_1.Controls[i].ClassType=tcombobox) then
- gb_1.Controls[i].Enabled :=true;
- b_xz.Enabled :=false;
- b_bc.Enabled :=true;
- b_sc.Enabled :=false;
- b_qx.Enabled :=true;
- b_gb.Enabled :=false;
- b_xg.Enabled :=false;
- end
- else
- showmessage('请输入修改值');
- exit;
- end;
- procedure Tw_yhgl.FormCreate(Sender: TObject);
- begin
- w_main.Enabled:=FALSE;
- end;
- procedure Tw_yhgl.b_gbClick(Sender: TObject);
- begin
- close;
- w_main.Enabled:=true;
- end;
- procedure Tw_yhgl.DBGrid1CellClick(Column: TColumn);
- begin
- if data1.ado_yhgl.RecordCount>0 then
- begin
- e_bh.Text:=trim(ado_yhgl.fieldbyname('user_id').AsString );
- e_user.Text:=trim(ado_yhgl.fieldbyname('user_name').AsString );
- e_password.Text:=trim(ado_yhgl.fieldbyname('user_password').AsString);
- c_xb.Text:=trim(ado_yhgl.fieldbyname('user_power').AsString );
- e_yhzw.Text:=trim(ado_yhgl.fieldbyname('user_job').AsString );
- end;
- end;
- procedure Tw_yhgl.FormClose(Sender: TObject; var Action: TCloseAction);
- begin
- w_main.Enabled:=true;
- end;
- end.