?? a1.pas
字號:
unit a1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, ExtCtrls, StdCtrls, DBGrids, IniFiles;
type
Tfa1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Label11: TLabel;
Label1: TLabel;
Button1: TButton;
Button2: TButton;
dg_view: TDBGrid;
StringGrid1: TStringGrid;
Label2: TLabel;
lbl_hj: TLabel;
lbl_no: TLabel;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormShow(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure dg_viewKeyPress(Sender: TObject; var Key: Char);
procedure dg_viewDblClick(Sender: TObject);
procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
x,y : integer;
{ Private declarations }
public
flag : char;
{ Public declarations }
end;
var
fa1: Tfa1;
implementation
uses dm,vks;
{$R *.dfm}
procedure Tfa1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action := cafree;
end;
procedure Tfa1.FormShow(Sender: TObject);
var
i,p : integer;
myini : TIniFile;
begin
myini := TIniFile.Create(pchar(extractfilepath(application.ExeName))+'inc\set.ini');
p := myini.ReadInteger('config','length',0);
if p=0 then
begin
p:=25;
myini.WriteInteger('config','length',p);
end;
myini.Free;
StringGrid1.RowCount := p+1;
StringGrid1.ColCount := 10;
for i:=1 to p do
begin
StringGrid1.Cells[0,i] := IntToStr(i);
StringGrid1.RowHeights[i] := 20;
end;
StringGrid1.Cells[0,0] := 'NO';
StringGrid1.ColWidths[0] := 20;
StringGrid1.Cells[1,0] := '商品簡稱';
StringGrid1.Cells[2,0] := '商品編號';
StringGrid1.Cells[3,0] := '商品名稱';
StringGrid1.ColWidths[3] := 200;
StringGrid1.Cells[4,0] := '單位';
StringGrid1.ColWidths[4] := 40;
StringGrid1.Cells[5,0] := '數量';
StringGrid1.ColWidths[5] := 40;
StringGrid1.Cells[6,0] := '單價';
StringGrid1.Cells[7,0] := '合計金額';
StringGrid1.Cells[8,0] := '商品說明';
StringGrid1.ColWidths[8] := 150;
StringGrid1.Cells[9,0] := '進貨說明';
StringGrid1.ColWidths[9] := 200;
StringGrid1.SetFocus;
end;
procedure Tfa1.Button2Click(Sender: TObject);
begin
close;
end;
procedure Tfa1.Button1Click(Sender: TObject);
var
i:integer;
str : string;
begin
if length(StringGrid1.Cells[1,1])=0 then
begin
if flag='A' then vks.info(1022) else vks.info(1023);
exit;
end;
if flag='A' then str:='入庫' else str:='出庫';
if vks.box('確定將這些商品進行'+str+'嗎?',str+'確認提示窗口') then
begin
with fdm.q do
begin
close;
sql.Text := 'insert into [dan]([no],hj,[type]) values('''+lbl_no.Caption+''','+lbl_hj.Caption+','''+flag+''');';
try
execsql;
except
vks.info(1008);
exit;
end;
for i:=1 to 50 do
begin
if length(StringGrid1.Cells[2,i])<>0 then
begin
close;
sql.Clear;
sql.text := 'insert into dandetail(gid,[no],num,inprc,je,[memo],memo2) values(';
sql.Text := sql.Text+StringGrid1.Cells[2,i]+','''+lbl_no.Caption+''','+StringGrid1.Cells[5,i]+',';
sql.Text := sql.Text+StringGrid1.Cells[6,i]+','+StringGrid1.Cells[7,i];
sql.Text := sql.Text+','''+StringGrid1.Cells[8,i]+''','''+StringGrid1.Cells[9,i]+''')';
try
execsql;
except
vks.info(1008);
exit;
end;
end;
end;
if flag='A' then vks.info(1101) else vks.info(1102);
self.close;
end;
end;
end;
procedure Tfa1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
var
h:integer;
z:real;
begin
x := StringGrid1.Row;
y := StringGrid1.Col;
if key=#13 then
begin
if StringGrid1.Col<9 then StringGrid1.Col := StringGrid1.Col + 1
else
if StringGrid1.Row<>50 then
begin
StringGrid1.Row := StringGrid1.Row +1;
StringGrid1.Col := 1;
end;
if y=1 then
begin
if Length(StringGrid1.Cells[y,x])<>0 then
begin
if StringGrid1.Cells[1,x]='*' then
begin
fdm.qrk.close;
fdm.qrk.sql.text := 'select * from goodslist3 where flag=0';
fdm.qrk.Open;
dg_view.Visible := true;
dg_view.SetFocus;
end
else
begin
fdm.qrk.close;
fdm.qrk.sql.text := 'select * from goodslist3 where flag=0 and sname like ''%'+StringGrid1.Cells[1,x]+'%''';
fdm.qrk.Open;
dg_view.Visible := true;
dg_view.SetFocus;
end;
end;
end;
if y=5 then
begin
if length(StringGrid1.Cells[2,x])<>0 then
begin
StringGrid1.Cells[7,x] := FloatToStr(fdm.qrk.FieldByName('inprc').asfloat*strtoint(StringGrid1.Cells[5,x]));
end;
end;
if y=7 then
begin
z :=0;
for h:=1 to 50 do
begin
if length(StringGrid1.Cells[7,h])<>0 then
z:= StrToFloat(StringGrid1.Cells[7,h])+z
else
break;
end;
lbl_hj.Caption := floattostr(z);
end
else
begin
if length(StringGrid1.Cells[2,x-1])=0 then
begin
key:=#0;
end
else
begin
if y=2 then key:=#0;
if y=3 then key:=#0;
if y=4 then key:=#0;
if y=6 then key:=#0;
if y=7 then key:=#0;
if y=8 then key:=#0;
if y=5 then
begin
if key=#8 then key:=#8
else if (key<'0')or(key>'9') then key:=#0;
end;
end;
end;
end;
end;
procedure Tfa1.dg_viewKeyPress(Sender: TObject; var Key: Char);
begin
if key=#27 then
begin
dg_view.Visible := false;
StringGrid1.SetFocus;
StringGrid1.Col := 1;
exit;
end;
if key=#13 then
if fdm.qrk.RecordCount<>0 then
begin
StringGrid1.Cells[1,x] := dg_view.Fields[0].AsString;
StringGrid1.Cells[2,x] := dg_view.Fields[1].AsString;
StringGrid1.Cells[3,x] := dg_view.Fields[2].AsString;
StringGrid1.Cells[4,x] := dg_view.Fields[3].AsString;
StringGrid1.Cells[5,x] := '1';
StringGrid1.Cells[6,x] := dg_view.Fields[4].AsString;
StringGrid1.Cells[7,x] := dg_view.Fields[4].AsString;
if dg_view.Fields[5].AsString<>'' then
StringGrid1.Cells[8,x] := dg_view.Fields[5].AsString;
dg_view.Visible := false;
StringGrid1.Col :=5;
StringGrid1.SetFocus;
end
else
begin
dg_view.Visible := false;
StringGrid1.SetFocus;
StringGrid1.Col := 1;
exit;
end;
end;
procedure Tfa1.dg_viewDblClick(Sender: TObject);
begin
if fdm.qrk.RecordCount<>0 then
begin
StringGrid1.Cells[1,x] := dg_view.Fields[0].AsString;
StringGrid1.Cells[2,x] := dg_view.Fields[1].AsString;
StringGrid1.Cells[3,x] := dg_view.Fields[2].AsString;
StringGrid1.Cells[4,x] := dg_view.Fields[3].AsString;
StringGrid1.Cells[5,x] := '1';
StringGrid1.Cells[6,x] := dg_view.Fields[4].AsString;
StringGrid1.Cells[7,x] := dg_view.Fields[4].AsString;
if dg_view.Fields[5].AsString<>'' then
StringGrid1.Cells[8,x] := dg_view.Fields[5].AsString;
dg_view.Visible := false;
StringGrid1.Col :=5;
StringGrid1.SetFocus;
end
else
begin
dg_view.Visible := false;
StringGrid1.SetFocus;
StringGrid1.Col := 1;
exit;
end;
end;
procedure Tfa1.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
x := StringGrid1.Row;
y := StringGrid1.Col;
if key=$2D then
begin
if length(StringGrid1.Cells[2,x-1])<>0 then
begin
fdm.qrk.close;
fdm.qrk.sql.text := 'select * from goodslist3 where flag=0';
fdm.qrk.Open;
dg_view.Visible := true;
dg_view.SetFocus;
end;
end;
if key=$25 then
begin
if StringGrid1.Col<9 then StringGrid1.Col := StringGrid1.Col - 1;
abort;
end;
if key=$27 then
begin
if StringGrid1.Col<9 then StringGrid1.Col := StringGrid1.Col + 1;
abort;
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -