?? ywgl_bjrkform.~pas
字號:
unit ywgl_BJRKFORM;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DBCtrls, DBGrids, Grids, DB, ADODB, ExtCtrls;
type
Tywgl_BJRK = class(TForm)
GroupBox1: TGroupBox;
Label1: TLabel;
Label2: TLabel;
ADOQuery3: TADOQuery;
DataSource3: TDataSource;
StringGrid1: TStringGrid;
Label3: TLabel;
GroupBox2: TGroupBox;
Button2: TButton;
Button1: TButton;
Button3: TButton;
Button4: TButton;
Label4: TLabel;
Label5: TLabel;
Bevel1: TBevel;
DataSource1: TDataSource;
ADOQuery1: TADOQuery;
DBLookupComboBox1: TDBLookupComboBox;
DBLookupComboBox2: TDBLookupComboBox;
ADOQuery2: TADOQuery;
DataSource2: TDataSource;
DBGrid1: TDBGrid;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
ADOQuery4: TADOQuery;
Label10: TLabel;
Label11: TLabel;
procedure menuyp(sc:string);
procedure FormCreate(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure StringGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DBGrid1KeyPress(Sender: TObject; var Key: Char);
procedure Button1Click(Sender: TObject);
procedure DBLookupComboBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DBLookupComboBox2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
ywgl_BJRK: Tywgl_BJRK;
si:integer;
sql1:string;
i, j,k:integer;
implementation
{$R *.dfm}
PROCEDURE Tywgl_BJRK.menuyp(sc:string);//準備并顯示列表窗體
begin
sql1:='select top 12 * from 備件庫存 where 編號 like '+''''+sc+'%'+''''+' or '+' 物品名稱 like'+''''+sc+'%'+'''';//查詢鍵盤輸入相似的語句
ADOQuery3.SQL.Clear;//準備查詢
ADOQuery3.SQL.Add(sql1);//設置查詢語句
ADOQuery3.Active:=true;//開始查詢
if ADOquery3.FieldByName('編號').AsString<>'' then //將查詢到的結果附給列表
begin
// dbgrid1.Top:=SG1.Top;
// dbgrid1.Left:=SG1.Left+100;
dbgrid1.Visible:=true;
End
// else if dbgrid1.Visible=true then dbgrid1.Visible:=false;
end; //列表窗體準備完畢
procedure Tywgl_BJRK.FormShow(Sender: TObject);
begin
Button1.SetFocus ;
end;
procedure Tywgl_BJRK.FormCreate(Sender: TObject);
begin
stringgrid1.ColWidths[0]:=19;
stringgrid1.ColWidths[1]:=70;
stringgrid1.ColWidths[2]:=70;
stringgrid1.ColWidths[3]:=60;
stringgrid1.ColWidths[4]:=60;
stringgrid1.ColWidths[5]:=50;
stringgrid1.ColWidths[6]:=40;
stringgrid1.ColWidths[7]:=50;
stringgrid1.ColWidths[8]:=90;
stringgrid1.ColWidths[9]:=150;
stringgrid1.cells[1,0]:='名稱';
stringgrid1.cells[2,0]:='編碼';
stringgrid1.cells[3,0]:='型號';
stringgrid1.cells[4,0]:='規格';
stringgrid1.cells[5,0]:='數量';
stringgrid1.cells[6,0]:='單位';
stringgrid1.cells[7,0]:='單價';
stringgrid1.cells[8,0]:='金額';
stringgrid1.cells[9,0]:='備注';
for si:=1 to 50 do begin
stringgrid1.cells[0,si]:=inttostr(si);
end;
stringgrid1.Col:=1;
label7.caption:=datetimetostr(date);
end;
procedure tywgl_BJRK.StringGrid1KeyUp(Sender: TObject; var Key: Word;Shift: TShiftState);
type
tkeyset=set of 0..255;
Var
keyset:tkeyset;
begin
keyset:=[48..57,65..90,96..105,8];
If (StringGrid1.Col > 1) Then
begin
dbgrid1.Visible:=FALSE;
exit;
END ;
If (StringGrid1.Col = 1) Then begin
if StringGrid1.Cells[1,StringGrid1.Row]<>'' then
menuyp(StringGrid1.Cells[1,StringGrid1.row])
else dbgrid1.Visible:=false;
end ;
end;
procedure tywgl_BJRK.StringGrid1KeyPress(Sender: TObject;var Key: Char);
begin
if (key=#13) AND (StringGrid1.Col=9) then begin
StringGrid1.ROW:=StringGrid1.ROW+1;
StringGrid1.Col:=1;
END ;
if (key=#13) AND (StringGrid1.Col<9)AND (StringGrid1.Col>1) then begin
StringGrid1.Col:=StringGrid1.Col+1;
END ;
IF (StringGrid1.Cells[7,StringGrid1.Row]<>'')AND (StringGrid1.Cells[5,StringGrid1.Row]<>'') THEN BEGIN
StringGrid1.Cells[8,StringGrid1.Row]:= FLOATTOSTR(STRTOFLOAT(StringGrid1.Cells[7,StringGrid1.Row])*STRTOFLOAT(StringGrid1.Cells[5,StringGrid1.Row]));
END;
end;
procedure tywgl_BJRK.StringGrid1KeyDown(Sender: TObject;
var Key: Word; Shift: TShiftState);
begin
If (StringGrid1.Col = 1) And (Dbgrid1.Visible = True) Then
begin
If (Key = 39) Then
begin
dbgrid1.SetFocus ;
END;
If (Key = 40) Then
begin
StringGrid1.ROW:=StringGrid1.ROW-1;
dbgrid1.SetFocus ;
END;
If Key = 13 Then
begin
StringGrid1.Cells[1,StringGrid1.Row]:=ADOQUERY3.FieldByname('物品名稱').Asstring;
StringGrid1.Cells[2,StringGrid1.Row]:=ADOQUERY3.FieldByname('編號').Asstring;
StringGrid1.Cells[3,StringGrid1.Row]:=ADOQUERY3.FieldByname('型號').Asstring;
StringGrid1.Cells[4,StringGrid1.Row]:=ADOQUERY3.FieldByname('規格').Asstring;
StringGrid1.Cells[6,StringGrid1.Row]:=ADOQUERY3.Fieldbyname('單位').Asstring;
StringGrid1.Cells[5,StringGrid1.Row]:='';
StringGrid1.Cells[8,StringGrid1.Row]:='';
StringGrid1.Cells[9,StringGrid1.Row]:='';
Dbgrid1.Visible:=false;
StringGrid1.Col:=4;
stringgrid1.SetFocus;
END;
END;
end;
procedure Tywgl_BJRK.Button1Click(Sender: TObject); //添加備件
begin
j:=1;
for j:=1 to 50 do
begin
for i:=1 to 9 do
begin
StringGrid1.Cells[i,j]:='';
end;
end;
DBLookupComboBox1.SetFocus ;
Button1.Enabled:=FALSE;
Button2.Enabled:=TRUE;
Button3.Enabled:=TRUE;
Button4.Enabled:=FALSE;
end;
procedure Tywgl_BJRK.DBLookupComboBox1KeyDown(Sender: TObject;var Key: Word; Shift: TShiftState);
begin
If Key = 13 Then
DBLookupComboBox2.SetFocus ;
end;
procedure Tywgl_BJRK.DBLookupComboBox2KeyDown(Sender: TObject;var Key: Word; Shift: TShiftState);
begin
If Key = 13 Then begin
stringgrid1.Col:=1;
stringgrid1.Row:=1;
stringgrid1.SetFocus ;
END;
end;
procedure Tywgl_BJRK.DBGrid1KeyPress(Sender: TObject; var Key: Char); //選擇備件
begin
if key<>#27 then begin
if key=#13 then begin
StringGrid1.Cells[1,StringGrid1.Row]:=ADOQUERY3.FieldByname('物品名稱').Asstring;
StringGrid1.Cells[2,StringGrid1.Row]:=ADOQUERY3.FieldByname('編號').Asstring;
StringGrid1.Cells[3,StringGrid1.Row]:=ADOQUERY3.FieldByname('型號').Asstring;
StringGrid1.Cells[4,StringGrid1.Row]:=ADOQUERY3.FieldByname('規格').Asstring;
StringGrid1.Cells[6,StringGrid1.Row]:=ADOQUERY3.Fieldbyname('單位').Asstring;
StringGrid1.Cells[7,StringGrid1.Row]:=ADOQUERY3.Fieldbyname('平均單價').Asstring;
StringGrid1.Cells[5,StringGrid1.Row]:='';
StringGrid1.Cells[8,StringGrid1.Row]:='';
StringGrid1.Cells[9,StringGrid1.Row]:='';
Dbgrid1.Visible:=false;
StringGrid1.Col:=5;
stringgrid1.SetFocus;
exit;
end;
key:=#0;
end else begin
dbgrid1.Visible:=false;
stringgrid1.Cells[1,StringGrid1.Row]:='';
stringgrid1.Cells[2,StringGrid1.Row]:='';
stringgrid1.Cells[3,StringGrid1.Row]:='';
stringgrid1.Cells[4,StringGrid1.Row]:='';
stringgrid1.Cells[5,StringGrid1.Row]:='';
stringgrid1.Cells[6,StringGrid1.Row]:='';
stringgrid1.Cells[7,StringGrid1.Row]:='';
stringgrid1.Cells[8,StringGrid1.Row]:='';
end;
end;
procedure Tywgl_BJRK.Button2Click(Sender: TObject); //保存備件入庫
begin
for i:=1 to 50 DO
begin
if stringgrid1.Cells[1,i]<>''then
begin
sql1:='select * from 備件庫存 where 編號 = '+''''+StringGrid1.Cells[2,i]+'''';
ADOQuery3.SQL.Clear;//準備查詢
ADOQuery3.SQL.Add(sql1);//設置查詢語句
ADOQuery3.Active:=true;//開始查詢
if ADOQuery3.FieldByName('物品名稱').asstring<>'' then begin
ADOQuery3.Edit;
ADOQuery3.FieldByName('數量').AsInteger:=ADOQuery3.FieldByName('數量').ASINTEGER+strtoint(StringGrid1.Cells[5,i]);
ADOQuery3.FieldByName('庫存金額').AsCurrency:=ADOQuery3.FieldByName('庫存金額').ASFLOAT+strtoint(StringGrid1.Cells[8,i]);
ADOQuery3.Post ;
adoquery4.Insert;
adoquery4.FieldByName('日期').ASDATETIME:=STRTODATETIME(LABEL7.CAPTION);
adoquery4.FieldByName('經手人').ASSTRING:=DBLookupComboBox2.Text;
adoquery4.FieldByName('備件來歷').ASSTRING:=DBLookupComboBox1.Text;
adoquery4.FieldByName('物品名稱').ASSTRING:=stringgrid1.Cells[1,i];
adoquery4.FieldByName('型號').ASSTRING:=stringgrid1.Cells[3,i];
adoquery4.FieldByName('規格').ASSTRING:=stringgrid1.Cells[4,i];
adoquery4.FieldByName('入庫數量').ASinteger:=strtoint(stringgrid1.Cells[5,i]);
adoquery4.FieldByName('單位').ASSTRING:=stringgrid1.Cells[6,i];
adoquery4.FieldByName('入庫單價').ASfloat:=strtofloat(stringgrid1.Cells[7,i]);
adoquery4.FieldByName('金額').ASfloat:=strtofloat(stringgrid1.Cells[8,i]);
adoquery4.FieldByName('詳細說明').ASSTRING:=stringgrid1.Cells[9,i];
adoquery4.Post;
Button1.Enabled:=TRUE;
Button4.Enabled:=TRUE;
Button2.Enabled:=FALSE;
Button3.Enabled:=FALSE;
end;
end;
end;
end;
procedure Tywgl_BJRK.StringGrid1Click(Sender: TObject);
begin
If (StringGrid1.Col > 4) And (StringGrid1.Col < 9) Then begin
label11.caption:='0';
j:=1;
for j:=1 to 50 do
begin
if (StringGrid1.Cells[1,j] <>'')and (StringGrid1.Cells[8,j]<>'') then
begin
label10.Caption:=INTTOSTR(J);
label11.Caption:=floattostr(strtofloat(label11.Caption)+strtofloat(StringGrid1.Cells[8,j]));
end;
end;
end;
end;
procedure Tywgl_BJRK.Button3Click(Sender: TObject); //取消備件入庫
begin
j:=1;
for j:=1 to 50 do
begin
for i:=1 to 9 do
begin
StringGrid1.Cells[i,j]:='';
end;
end;
label11.Caption:='';
label10.Caption:='';
DBLookupComboBox1.SetFocus ;
Button1.Enabled:=TRUE;
Button2.Enabled:=FALSE;
Button3.Enabled:=FALSE;
Button4.Enabled:=TRUE;
end;
procedure Tywgl_BJRK.Button4Click(Sender: TObject); //退出
begin
close;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -