UnitProdList.pas
资源名称:东之源.rar [点击查看]
上传用户:zexin0769
上传日期:2010-01-19
资源大小:443k
文件大小:6k
源码类别:
百货/超市行业
开发平台:
Delphi
- unit UnitProdList;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, Grids, DBGrids, DB, ADODB, ExtCtrls, StdCtrls, Mask, DBCtrls;
- type
- TFrameProdList = class(TFrame)
- Image1: TImage;
- ADOQuery1: TADOQuery;
- DataSource1: TDataSource;
- DBGrid1: TDBGrid;
- GroupBox1: TGroupBox;
- Image2: TImage;
- Image3: TImage;
- Image4: TImage;
- Label1: TLabel;
- DBEdit1: TDBEdit;
- Label2: TLabel;
- DBEdit2: TDBEdit;
- DBEdit3: TDBEdit;
- Label3: TLabel;
- DBEdit4: TDBEdit;
- Label4: TLabel;
- DBEdit5: TDBEdit;
- Label5: TLabel;
- Image5: TImage;
- Image6: TImage;
- GroupBox2: TGroupBox;
- Label6: TLabel;
- Edit1: TEdit;
- Image7: TImage;
- Label7: TLabel;
- procedure Image2Click(Sender: TObject);
- procedure Image5Click(Sender: TObject);
- procedure Image3Click(Sender: TObject);
- procedure Image4Click(Sender: TObject);
- procedure Image6Click(Sender: TObject);
- procedure Image7Click(Sender: TObject);
- procedure Edit1KeyPress(Sender: TObject; var Key: Char);
- function IsAllNum(s:string):bool;
- procedure Label7Click(Sender: TObject);
- procedure DBEdit1KeyPress(Sender: TObject; var Key: Char);
- procedure DBEdit2KeyPress(Sender: TObject; var Key: Char);
- procedure DBEdit3KeyPress(Sender: TObject; var Key: Char);
- procedure DBEdit4KeyPress(Sender: TObject; var Key: Char);
- procedure DBEdit5KeyPress(Sender: TObject; var Key: Char);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- implementation
- {$R *.dfm}
- procedure TFrameProdList.Image2Click(Sender: TObject);
- begin
- {添加商品}
- Image2.Enabled := False;
- Image3.Enabled := False;
- Image4.Enabled := False;
- DBEdit1.Color := clWhite;
- DBEdit2.Color := clWhite;
- DBEdit3.Color := clWhite;
- DBEdit4.Color := clWhite;
- DBEdit5.Color := clWhite;
- DBEdit1.Enabled := True;
- DBEdit2.Enabled := True;
- DBEdit3.Enabled := True;
- DBEdit4.Enabled := True;
- DBEdit5.Enabled := True;
- Image5.Visible := True;
- Image6.Visible := True;
- DBEdit1.SetFocus;
- ADOQuery1.Append;
- end;
- procedure TFrameProdList.Image5Click(Sender: TObject);
- begin
- {提交数据}
- if (DBEdit1.Text<>'') and (DBEdit2.Text<>'') and (DBEdit3.Text<>'') and (DBEdit4.Text<>'') and (DBEdit5.Text<>'') then
- ADOQuery1.Post
- else
- if messagebox(handle,'您的输入不正确(空值),放弃输入?','检查输入',mb_iconquestion+mb_yesno)=IDyes then
- ADOQuery1.Cancel
- else
- exit;
- Image2.Enabled := True;
- Image3.Enabled := True;
- Image4.Enabled := True;
- DBEdit1.Color := $00FFF0DC;
- DBEdit2.Color := $00FFF0DC;
- DBEdit3.Color := $00FFF0DC;
- DBEdit4.Color := $00FFF0DC;
- DBEdit5.Color := $00FFF0DC;
- DBEdit1.Enabled := False;
- DBEdit2.Enabled := False;
- DBEdit3.Enabled := False;
- DBEdit4.Enabled := False;
- DBEdit5.Enabled := False;
- Image5.Visible := False;
- Image6.Visible := False;
- end;
- procedure TFrameProdList.Image3Click(Sender: TObject);
- begin
- if messagebox(handle,'删除的商品不能被恢复,是否删除?','确认删除',mb_iconquestion+mb_yesno)=IDyes then ADOQuery1.Delete;
- end;
- procedure TFrameProdList.Image4Click(Sender: TObject);
- begin
- {修改用户}
- Image2.Enabled := False;
- Image3.Enabled := False;
- Image4.Enabled := False;
- DBEdit1.Color := clWhite;
- DBEdit2.Color := clWhite;
- DBEdit3.Color := clWhite;
- DBEdit4.Color := clWhite;
- DBEdit5.Color := clWhite;
- DBEdit1.Enabled := True;
- DBEdit2.Enabled := True;
- DBEdit3.Enabled := True;
- DBEdit4.Enabled := True;
- DBEdit5.Enabled := True;
- Image5.Visible := True;
- Image6.Visible := True;
- DBEdit1.SetFocus;
- ADOQuery1.Edit;
- end;
- procedure TFrameProdList.Image6Click(Sender: TObject);
- begin
- {放弃提交}
- ADOQuery1.Cancel;
- Image2.Enabled := True;
- Image3.Enabled := True;
- Image4.Enabled := True;
- DBEdit1.Color := $00FFF0DC;
- DBEdit2.Color := $00FFF0DC;
- DBEdit3.Color := $00FFF0DC;
- DBEdit4.Color := $00FFF0DC;
- DBEdit5.Color := $00FFF0DC;
- DBEdit1.Enabled := False;
- DBEdit2.Enabled := False;
- DBEdit3.Enabled := False;
- DBEdit4.Enabled := False;
- DBEdit5.Enabled := False;
- Image5.Visible := False;
- Image6.Visible := False;
- end;
- procedure TFrameProdList.Image7Click(Sender: TObject);
- var
- sqlstr:string;
- begin
- if Edit1.Text<>'' then
- begin
- sqlstr := 'select * from t_prod where prod_name like "%' + Edit1.Text + '%"';
- if IsAllNum(Edit1.Text) then sqlstr := sqlstr + ' or prod_id=' + Edit1.Text;
- ADOQuery1.Close;
- ADOQuery1.SQL.Clear;
- ADOQuery1.SQL.Add(sqlstr);
- ADOQuery1.Open;
- end
- else
- messagebox(handle,'请输入查询条件!','检查输入',mb_iconwarning+mb_ok)
- end;
- procedure TFrameProdList.Edit1KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then Image7Click(self);
- end;
- function TFrameProdList.IsAllNum(s:string):bool;
- var
- i:integer;
- begin
- for i := 1 To Length(s) do
- if (s[i] < '0') or (s[i] > '9') then
- begin
- IsAllNum := False;
- Exit;
- end;
- IsAllNum := True;
- end;
- procedure TFrameProdList.Label7Click(Sender: TObject);
- var
- sqlstr: string;
- begin
- sqlstr := 'select * from t_prod';
- ADOQuery1.Close;
- ADOQuery1.SQL.Clear;
- ADOQuery1.SQL.Add(sqlstr);
- ADOQuery1.Open;
- end;
- procedure TFrameProdList.DBEdit1KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then DBEdit2.SetFocus;
- end;
- procedure TFrameProdList.DBEdit2KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then DBEdit3.SetFocus;
- end;
- procedure TFrameProdList.DBEdit3KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then DBEdit4.SetFocus;
- end;
- procedure TFrameProdList.DBEdit4KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then DBEdit5.SetFocus;
- end;
- procedure TFrameProdList.DBEdit5KeyPress(Sender: TObject; var Key: Char);
- begin
- if key=#13 then Image5Click(Self);
- end;
- end.