📄 pdbyxt.pas
字号:
unit pdbyxt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, Grids, ExtCtrls, jpeg, DB, DBGrids;
type
TForm19 = class(TForm)
Panel2: TPanel;
Image1: TImage;
Label9: TLabel;
Label2: TLabel;
StringGrid1: TStringGrid;
Panel1: TPanel;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn7: TBitBtn;
BitBtn8: TBitBtn;
Label4: TLabel;
Edit4: TEdit;
Label7: TLabel;
Label1: TLabel;
Shape1: TShape;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Label8: TLabel;
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
Function isnull :Boolean ;//检查项目列表最后一行是否为空
Procedure ClearString;
Function JCxmlb: Boolean;
procedure BitBtn7Click(Sender: TObject);
procedure BitBtn3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit4KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DBGrid1DblClick(Sender: TObject);
Procedure ClearStringEnd;
procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form19: TForm19;
x,y: Integer;
Ss:Boolean = False ;//判断当焦点在StringGrid1上时是否按回车键
s1: Boolean = False;//在StringGrid1的OnSetEditText事件中是否执行相关代码,其作用是防止连续出现对话框
s2: Boolean = False; //在StringGrid1的OnSetEditText事件中是否执行相关代码,其作用是防止删除行时,统计的数量金额错误
implementation
uses datamodal,ckglxt;
{$R *.dfm}
procedure TForm19.FormShow(Sender: TObject);
begin
BitBtn7.OnClick(Sender);
Label8.Caption := czy ;
end;
procedure TForm19.FormCreate(Sender: TObject);
begin
StringGrid1.Cells[0,0]:=' 商品编号';
StringGrid1.Cells[1,0]:=' 商品名称';
StringGrid1.Cells[2,0]:=' 数量';
StringGrid1.Cells[3,0]:=' 金额';
StringGrid1.Cells[4,0]:=' 操作员';
StringGrid1.Cells[5,0]:=' 经手人';
StringGrid1.Cells[6,0]:=' 日期';
end;
procedure TForm19.BitBtn3Click(Sender: TObject);
begin
label7.Caption := FormatDateTime('yyyy-mm-dd',Now());
Edit4.SetFocus;
end;
procedure TForm19.BitBtn4Click(Sender: TObject);
var
i: Integer;
begin
if Trim(Edit4.Text)='' then
begin
Application.MessageBox('经手人不能为空。','提示',64);
Edit4.SetFocus;
Exit;
end;
if JCxmlb = True then
begin
Data.ADOConnection1.BeginTrans;
Try
For i := 1 to StringGrid1.RowCount-1 do
begin
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('Update 库存表 set 库存数量 = 库存数量 + :a ,库存金额 = 库存金额 + :c where 商品编号 = :b');
Parameters.ParamByName('a').Value := StrToInt(StringGrid1.Cells[2,i]);
Parameters.ParamByName('c').Value := StrToFloat(StringGrid1.Cells[3,i]);
parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[0,i]);
ExecSQL;
end;
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('insert 报溢表 values (:a,:b,:c,:d,:e,:f,default)');
Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,StringGrid1.RowCount-1]);
Parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[1,StringGrid1.RowCount-1]);
Parameters.ParamByName('c').Value := StrToInt(StringGrid1.Cells[2,StringGrid1.RowCount-1]);
Parameters.ParamByName('d').Value := StrToFloat(StringGrid1.Cells[3,StringGrid1.RowCount-1]);
Parameters.ParamByName('e').Value := Trim(Label8.Caption);
Parameters.ParamByName('f').Value := Trim(StringGrid1.Cells[5,StringGrid1.RowCount-1]);
ExecSQL;
end;
end;
Data.ADOConnection1.CommitTrans;
Application.MessageBox('报溢处理成功。','提示',64);
BitBtn7.OnClick(Sender);
except
Data.ADOConnection1.RollbackTrans;
Application.MessageBox('系统出错。','提示',64);
Close;
end;
end
else
Application.MessageBox('项目列表有误。','提示',64);
end;
function TForm19.isnull: Boolean;
var
a: integer;
begin
isnull := False;
for a:= 0 to StringGrid1.ColCount -1 do
if Trim(StringGrid1.Cells[a,StringGrid1.RowCount-1])=''then
begin
isnull := True;
break;
end ;
end;
procedure TForm19.BitBtn7Click(Sender: TObject);
var
a,b: integer;
begin
Edit4.Clear;
Label7.Caption := '';
For a := 1 to StringGrid1.RowCount-1 do
For b := 0 to StringGrid1.ColCount-1 do
StringGrid1.Cells[b,a]:= '';
StringGrid1.RowCount := 2;
DataSource1.DataSet := Nil;
DBGrid1.Visible := False;
BitBtn3.SetFocus;
end;
procedure TForm19.BitBtn3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Trim(Edit4.Text)<>'' then
if (key = VK_ReTurn)and(BitBtn3.Enabled = True)then
BitBtn3.SetFocus;
end;
procedure TForm19.Edit4KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Trim(Label7.Caption)='' then
begin
Application.MessageBox('请添加报损时间。','提示',64);
BitBtn3.SetFocus;
Exit;
end;
if Trim(Edit4.Text)<>'' then
if Key = VK_Return then
begin
StringGrid1.Cells[4,1]:= Label8.Caption;
StringGrid1.Cells[5,1]:= Edit4.Text;
StringGrid1.Cells[6,1]:= Label7.Caption;
StringGrid1.SetFocus;
StringGrid1.Col := 1;
end;
end;
procedure TForm19.DBGrid1DblClick(Sender: TObject);
begin
StringGrid1.Cells[0,x]:= Data.ADOQuery1.FieldByName('商品编号').Value;
StringGrid1.Cells[1,x]:= Data.ADOQuery1.FieldByName('商品名称').Value;
DataSource1.DataSet := nil;
DBGrid1.Visible := False;
StringGrid1.SetFocus;
StringGrid1.Col := 2;
end;
procedure TForm19.DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = Vk_Return then
DBGrid1.OnDblClick(Sender);
end;
procedure TForm19.StringGrid1KeyPress(Sender: TObject; var Key: Char);
var
mm: Boolean;
begin
if y = 2 then
begin
mm := (Key <#8)or(Key >#8)and(Key<#48)or(Key>#57);
if mm then
Key := #0;
end;
end;
procedure TForm19.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
y := ACol;
x := ARow;
if (ACol = 1)and( Trim(StringGrid1.Cells[0,x])='')or(ACol = 2)and(Trim(StringGrid1.Cells[0,x])<>'') then
StringGrid1.Options := StringGrid1.Options +[goEditing]
else
StringGrid1.Options := StringGrid1.Options -[goEditing];
end;
procedure TForm19.StringGrid1SetEditText(Sender: TObject; ACol,
ARow: Integer; const Value: String);
var
Jg: Real;
a1: Integer;
begin
Jg := 0.0;
if (Trim(StringGrid1.Cells[0,x])<>'')and(Trim(StringGrid1.Cells[1,x])<>'')then
if Trim(StringGrid1.Cells[2,x])<>'' then
begin
with Data.ADOQuery4 do
begin
Close;
SQL.Clear;
SQL.Add('select * from 商品基础信息表 where 商品编号 =:a');
Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,x]);
Open;
end;
Jg:= Data.ADOQuery4.FieldByName('进价').Value;
StringGrid1.Cells[3,x]:= FloatToStr(StrToInt(StringGrid1.Cells[2,x])* Jg);
Exit;
end
else
begin
StringGrid1.Cells[3,x]:='';
Exit;
end;
if (ss = False)and(s1 = False) then
begin
if ACol = 1 then
begin
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select 商品编号 Into #qq from 库存表 where 商品名称 Like :b ');
SQL.Add('Select * from 商品基础信息表 where 商品编号 in ( select 商品编号 from #qq)');
Parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[1,x]) + '%';
Open;
end;
if Data.ADOQuery1.RecordCount>0 then
begin
DataSource1.DataSet := Data.ADOQuery1;
DBGrid1.Visible := True;
end
else
begin
S1 := True;
DataSource1.DataSet := nil;
DBGrid1.Visible := False;
Application.MessageBox('库中没有此商品。','提示',64);
For a1 := 0 to 3 do
StringGrid1.Cells[a1,x]:='';
StringGrid1.SetFocus;
StringGrid1.Col := 2;
StringGrid1.Col := 1;
end;
end ;
end;
end;
procedure TForm19.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
R,L: Integer;
begin
S1 := False;
s2 := False;
ss := False;
if key = VK_Delete then
begin
if StringGrid1.RowCount>2 then
begin
If Application.MessageBox('确实要删除该条记录吗?','提示',MB_YESNO )= ID_Yes then
begin
ClearString;
if x <> StringGrid1.RowCount-1 then
begin
For r := x+1 to StringGrid1.RowCount-1 do
For l := 0 to StringGrid1.ColCount-1 do
StringGrid1.Cells[l,r-1]:= StringGrid1.Cells[l,r];
end;
ClearStringEnd;
StringGrid1.RowCount := StringGrid1.RowCount-1;
s2 := True;
Exit;
end;
end
else if StringGrid1.RowCount = 2 then
begin
If Application.MessageBox('确实要删除该条记录吗?','提示',MB_YESNO )= ID_Yes then
begin
ClearString;
StringGrid1.SetFocus;
StringGrid1.Col := 2;
StringGrid1.Col := 1;
end;
end;
end;
if (key = Vk_Next)and(DBGrid1.Visible = True)then
begin
DBGrid1.SetFocus;
Exit;
end;
if (Key = VK_Down)and(IsNull = False)and(x = StringGrid1.RowCount-1) then
begin
StringGrid1.RowCount := StringGrid1.RowCount+1;
StringGrid1.Cells[4,StringGrid1.RowCount-1]:= StringGrid1.Cells[4,StringGrid1.RowCount-2];
StringGrid1.Cells[5,StringGrid1.RowCount-1]:= StringGrid1.Cells[5,StringGrid1.RowCount-2];
StringGrid1.Cells[6,StringGrid1.RowCount-1]:= StringGrid1.Cells[6,StringGrid1.RowCount-2];
StringGrid1.Col := 1;
Exit;
end;
if key = vk_ReTurn then
if Trim(StringGrid1.Cells[0,x])='' then
begin
Ss := True;
DataSource1.DataSet := nil;
DBGrid1.Visible := False;
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select 商品编号 into #ss from 库存表 where 商品名称 = :a');
SQL.Add('select * from 商品基础信息表 where 商品编号 In (select * from #ss)');
Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[1,x]);
Open;
end;
if Data.ADOQuery1.RecordCount>1 then
begin
DataSource1.DataSet := Data.ADOQuery1;
DBGrid1.Visible := True;
DBGrid1.SetFocus;
end
else if Data.ADOQuery1.RecordCount = 1 then
begin
StringGrid1.Cells[0,x]:= Data.ADOQuery1.FieldByName('商品编号').Value;
StringGrid1.Cells[1,x]:= Data.ADOQuery1.FieldByName('商品名称').Value;
StringGrid1.SetFocus;
StringGrid1.Col := 2;
DBGrid1.visible := False;
end
else
begin
Application.MessageBox('该商品在库中不存在。','提示',64);
ClearString;
if StringGrid1.RowCount>2 then
StringGrid1.RowCount := StringGrid1.RowCount-1;
end;
end;
if Key = Vk_Shift then
if JCxmlb = True then
BitBtn4.SetFocus;
end;
procedure TForm19.ClearString;
var
i: Integer;
begin
For i := 0 to 3 do
StringGrid1.Cells[i,x]:= '';
end;
procedure TForm19.ClearStringEnd;
var
mm: Integer;
begin
For mm:= 0 to 3 do
StringGrid1.Cells[mm,StringGrid1.RowCount-1]:= '';
end;
function TForm19.JCxmlb: Boolean;
var
a,b: Integer;
begin
JCxmlb := True;
For a := 1 to StringGrid1.RowCount-1 do
For b := 0 to StringGrid1.ColCount-1 do
if Trim(StringGrid1.Cells[b,a])=''then
begin
JCxmlb := False;
Break;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -