📄 rkglxt.~pas
字号:
unit rkglxt;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, ExtCtrls, Grids, jpeg, TeeProcs, TeEngine,
Chart, DB, DBGrids;
type
TForm12 = class(TForm)
Panel2: TPanel;
Image1: TImage;
StringGrid1: TStringGrid;
Panel4: TPanel;
Edit8: TEdit;
ComboBox2: TComboBox;
Panel1: TPanel;
BitBtn3: TBitBtn;
Label13: TLabel;
Label9: TLabel;
Label8: TLabel;
Label7: TLabel;
Label12: TLabel;
Label6: TLabel;
Label3: TLabel;
Label11: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
BitBtn4: TBitBtn;
BitBtn7: TBitBtn;
BitBtn8: TBitBtn;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Edit1: TEdit;
ListBox1: TListBox;
Label4: TLabel;
Label5: TLabel;
Edit4: TEdit;
Edit2: TEdit;
Label2: TLabel;
Label1: TLabel;
Label14: TLabel;
Shape3: TShape;
Shape4: TShape;
Label10: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure Edit7KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
Function JCxmlb : Boolean;//检查项目列表是否有误
procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure BitBtn4Click(Sender: TObject);
procedure Edit8Exit(Sender: TObject);
procedure Clear;//窗体初始化
procedure BitBtn7Click(Sender: TObject);
procedure BitBtn3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BitBtn3MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Edit8KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit4KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: String);
procedure DBGrid1DblClick(Sender: TObject);
procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
Function SumPrice : Real;//合计金额
Function Kinds: Integer;//记录商品种类
Function SumSL : Integer;//合计数量
Procedure ClearString; //清空StringGrid当前行数据
Procedure ClearStringEnd;//清空StringGrid最后一行数据
procedure SelectSPXX; //查询商品信息
Function FirstIsNull: Boolean;// 判断StringGrid1首行是否有空项
Function EndIsNull: Boolean; // 判断StringGrid1最后一行是否有空项
Function CurrentIsCf : Boolean;//判断当前行是否重复
Function IsNull:Boolean;
procedure Edit1Exit(Sender: TObject);
procedure Edit1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ComboBox2KeyPress(Sender: TObject; var Key: Char);
procedure Edit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure ListBox1DblClick(Sender: TObject);
procedure ListBox1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form12: TForm12;
x,y: Integer;
Ss:Boolean = False ;//判断当焦点在StringGrid1上时是否按回车键
s1: Boolean = False;//在StringGrid1的OnSetEditText事件中是否执行相关代码,其作用是防止连续出现对话框
implementation
uses ckglxt,datamodal,spxx;
{$R *.dfm}
procedure TForm12.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]:=' 供应商全称';
StringGrid1.Cells[7,0]:=' 入库票号';
StringGrid1.Cells[8,0]:=' 入库日期';
Label14.Caption := FormatDateTime('yyyy-mm-dd',Now());
end;
procedure TForm12.FormShow(Sender: TObject);
begin
ListBox1.Clear;
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select Distinct 供应商全称 from 供应商基础信息表');
Open;
end;
while not Data.ADOQuery1.Eof do
begin
ListBox1.Items.Add(Data.ADOQuery1.FieldByName('供应商全称').AsString);
Data.ADOQuery1.Next;
end;
ComboBox2.ItemIndex := 0;
Clear;
BitBtn3.SetFocus;
end;
procedure TForm12.BitBtn3Click(Sender: TObject);
var
s,m: String;
i: integer;
begin
Label14.Caption := FormatDateTime('yyyy-mm-dd',Now());
s:= 'PH'+ FormatDateTime('yyyymmdd',Now());
With Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select max(入库票号) as ss From 入库票号表 ');
Open;
end;
If Data.ADOQuery1.FieldByName('ss').Value = null then
s := s + '001'
else
begin
m:= Trim(Data.ADOQuery1.FieldByName('ss').Value) ;
i:= StrToInt(Trim(Copy(m,11,8))) ;
if i<9 then
s:= s + '00'+ InttoStr(i +1)
else if i<99 then
s:= s + '0'+ InttoStr(i +1)
else
s:= s +InttoStr(i +1);
end;
Label10.Caption := s;
if Trim(Edit4.Text)='' then
Edit4.SetFocus
else
Edit2.SetFocus;
end;
procedure TForm12.Edit7KeyPress(Sender: TObject; var Key: Char);
var
a: Boolean;
begin
a := (Key <#8)or(Key >#8)and(Key<#46)or(Key>#46)and(Key<#48)or(Key>#57);
if a then
Key := #0;
end;
procedure TForm12.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 TForm12.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;
function TForm12.JCxmlb: Boolean;
var
a,b: integer;
begin
ReSult := 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;
procedure TForm12.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
R,L: Integer;
cp: String;// 记录当前行的价格
cl: String;//记录当前行的数量
begin
S1 := False;
ss := False;
cp := '';
cl:= '';
if key = VK_Delete then
begin
if StringGrid1.RowCount>2 then
begin
If Application.MessageBox('确实要删除该条记录吗?','提示',MB_YESNO )= ID_Yes then
begin
if IsNull = False then
begin
cl := StringGrid1.Cells[2,x];
cp := StringGrid1.Cells[3,x];
if CurrentIsCf = False then
Label15.Caption := IntToStr(StrToInt(Label15.Caption)-1);
end;
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;
if Trim(cl)<>'' then
Label16.Caption := IntToStr(StrToInt(Label16.Caption)- StrToInt(cl));
if Trim(cp)<>'' then
Label17.Caption := FloatToStr(StrToFloat(Label17.Caption)-StrToFloat(cp));
StringGrid1.SetFocus;
StringGrid1.Col := 2;
StringGrid1.Col := 1;
Exit;
end;
end
else if StringGrid1.RowCount = 2 then
begin
If Application.MessageBox('确实要删除该条记录吗?','提示',MB_YESNO )= ID_Yes then
begin
ClearString;
Label15.Caption := '0';
Label16.Caption :='0';
Label17.Caption := '0.0';
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[5,StringGrid1.RowCount-1]:= StringGrid1.Cells[5,StringGrid1.RowCount-2];
StringGrid1.Cells[6,StringGrid1.RowCount-1]:= StringGrid1.Cells[6,StringGrid1.RowCount-2];
StringGrid1.Cells[4,StringGrid1.RowCount-1]:= '1.0';
StringGrid1.Cells[7,StringGrid1.RowCount-1]:= StringGrid1.Cells[7,StringGrid1.RowCount-2];
StringGrid1.Cells[8,StringGrid1.RowCount-1]:= StringGrid1.Cells[8,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;
SelectSPXX;
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;
end
else
begin
Application.MessageBox('该商品不存在。','提示',64);
ClearString;
if StringGrid1.RowCount>2 then
StringGrid1.RowCount := StringGrid1.RowCount-1;
end;
end;
if (Key = VK_Shift)and(Jcxmlb = True)then
Edit1.SetFocus;
end;
procedure TForm12.BitBtn4Click(Sender: TObject);
var
rowsum,row: integer;
Spjg: Real;//记录商品进价
begin
Spjg := 0.0;
for row := 0 to StringGrid1.Colcount-1 do
begin
if StringGrid1.Cells[row,Stringgrid1.RowCount-1]='' then
if StringGrid1.RowCount >2 then
StringGrid1.RowCount := StringGrid1.RowCount -1;
end;
if (Trim(Edit1.Text) = '')or(Trim(Edit4.Text)='')or(Trim(ComboBox2.Text)='') then
begin
Application.MessageBox('项目列表不能为空。','提示',0+64);
Exit;
end;
if JCxmlb = True then
begin
Data.ADOConnection1.BeginTrans;
Try
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('insert 入库票号表 values (:a,:b,:c,:d,:g,:h,:i,:j,:k)');
parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[7,1]);
parameters.ParamByName('b').Value := StrToInt(Trim(Label15.Caption));
parameters.ParamByName('c').Value := StrToInt(Trim(Label16.Caption));
parameters.ParamByName('d').Value := StrToFloat(Trim(Label17.Caption));
parameters.ParamByName('g').Value := Trim(ComboBox2.Text);
parameters.ParamByName('h').Value := StrToFloat(Edit1.Text);
parameters.ParamByName('i').Value := StrToDateTime(Trim(StringGrid1.Cells[8,1]));
parameters.ParamByName('j').Value := Trim(Edit4.Text);
with Data.ADOQuery2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from 操作员信息表 where 操作员姓名 = :a');
Parameters.ParamByName('a').Value := Trim(czy);
Open;
end;
parameters.ParamByName('k').Value := Data.ADOQuery2.FieldByName('操作员编号').Value;
ExecSQL;
end;
For Rowsum := 1 to StringGrid1.RowCount-1 do
begin
with Data.ADOQuery2 do
begin
Close;
SQL.Clear;
SQL.Add('insert 入库表 values (:a,:b,:ee,:c,:d,:e,:f,:aa,:g)');
parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,Rowsum]);
parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[1,Rowsum]);
parameters.ParamByName('ee').Value := Trim(StringGrid1.Cells[5,Rowsum]);
parameters.ParamByName('c').Value := Trim(StringGrid1.Cells[6,Rowsum]);
parameters.ParamByName('d').Value := StrToDateTime(Trim(StringGrid1.Cells[8,1]));
parameters.ParamByName('e').Value := StrToInt(Trim(StringGrid1.Cells[2,Rowsum]));
parameters.ParamByName('f').Value := StrToFloat(Trim(StringGrid1.Cells[3,Rowsum]));
parameters.ParamByName('aa').Value := StrToFloat(Trim(StringGrid1.Cells[4,Rowsum]));
parameters.ParamByName('g').Value := Trim(StringGrid1.Cells[7,Rowsum]);
ExecSQL;
end;
end;
For Rowsum := 1 to StringGrid1.RowCount-1 do
begin
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from 库存表 where 商品编号 = :a');
parameters.ParamByName('a').Value := StringGrid1.Cells[0,rowsum];
Open;
end;
with Data.ADOQuery4 do
begin
Close;
SQL.Clear;
SQL.Add('select * from 商品基础信息表 where 商品编号 =:a');
Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[0,Rowsum]);
Open;
end;
Spjg := Data.ADOQuery4.FieldByName('进价').Value;
if Data.ADOQuery1.RecordCount <1 then
begin
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('insert 库存表 values(:a,:ss,:b,:c,:d)');
Parameters.ParamByName('a').Value := StringGrid1.Cells[0,rowsum];
Parameters.ParamByName('ss').Value:= StringGrid1.Cells[1,rowsum];
Parameters.ParamByName('b').Value := StrToInt(StringGrid1.Cells[2,rowsum]);
Parameters.ParamByName('c').Value := StrToFloat(StringGrid1.Cells[2,rowsum])*Spjg;
Parameters.ParamByName('d').Value := -1;//-1表示未进行过盘点
ExecSQL;
end;
end
else
begin
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('update 库存表 set 库存数量 = 库存数量 + :a,库存金额 =库存金额 +:b where 商品编号 = :c ');
Parameters.ParamByName('a').Value := StrToInt(StringGrid1.Cells[2,rowsum]);
Parameters.ParamByName('b').Value := StrToFloat(StringGrid1.Cells[2,rowsum])*Spjg;
Parameters.ParamByName('c').Value := Trim(StringGrid1.Cells[0,rowsum]);
ExecSQL;
end;
end;
end;
For RowSum :=1 to StringGrid1.RowCount-1 do
begin
with Data.ADOQuery2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from 供应商结款表 where 供应商编号 =:a');
Parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[5,Rowsum]);
Open;
end;
if Data.ADOQuery2.RecordCount < 1 then
begin
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('insert 供应商结款表 values (:a,:b,:c,:d,:e,default)');
parameters.ParamByName('a').Value := Trim(StringGrid1.Cells[5,Rowsum]) ;
parameters.ParamByName('b').Value := Trim(StringGrid1.Cells[6,Rowsum]) ;
parameters.ParamByName('c').Value := StrToFloat(Label17.Caption) ;
parameters.ParamByName('d').Value := StrToFloat(Label17.Caption)- StrToFloat(Edit1.Text) ;
parameters.ParamByName('e').Value := StrToFloat(Edit1.Text) ;
ExecSQL;
end;
end
else
begin
with Data.ADOQuery1 do
begin
Close;
SQL.Clear;
SQL.Add('update 供应商结款表 set 金额小计 = 金额小计 + :d , 付款合计 = 付款合计 + :a ,欠款记账 = 欠款记账 + :b,结款时间 = Default where 供应商编号 = :c');
parameters.ParamByName('d').Value := StrToFloat(Label17.Caption) ;
parameters.ParamByName('a').Value := StrToFloat(Edit1.Text) ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -