📄 spckgl.pas
字号:
unit spckgl;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, jpeg, Grids, Buttons, DBGrids, DB;
type
TForm35 = class(TForm)
Image1: TImage;
Label9: TLabel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Shape3: TShape;
Shape1: TShape;
Label5: TLabel;
Edit2: TEdit;
StringGrid1: TStringGrid;
Panel1: TPanel;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn7: TBitBtn;
BitBtn8: TBitBtn;
Panel4: TPanel;
Label7: TLabel;
Label12: TLabel;
Label6: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
ComboBox2: TComboBox;
Label10: TLabel;
Label14: TLabel;
Label4: TLabel;
Label8: TLabel;
Shape2: TShape;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
procedure FormShow(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
Function JCxmlb: Boolean;
Function Sumprice: Real;
Function SumSL: Integer;
Function Kinds: Integer;
Function IsNull: Boolean;
Function CurrentIsCF: Boolean;
Procedure Clear;
Procedure ClearStringEnd;
Procedure ClearStrings;
Procedure SelectSPxx;
Function GroupSL(SPbh: String): Integer;
procedure BitBtn3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure BitBtn3MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Edit2KeyDown(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);
procedure DBGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure DBGrid1DblClick(Sender: TObject);
procedure BitBtn7Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form35: TForm35;
x,y: Integer;
Ss:Boolean = False ;//判断当焦点在StringGrid1上时是否按回车键
s1: Boolean = False;//在StringGrid1的OnSetEditText事件中是否执行相关代码,其作用是防止连续出现对话框
implementation
uses DataModal,ckglxt;
{$R *.dfm}
procedure TForm35.FormShow(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]:=' 提货日期';
Label14.Caption := FormatDateTime('yyyy-mm-dd',Now());
Label8.Caption := czy;
end;
procedure TForm35.BitBtn3Click(Sender: TObject);
var
s,m: String;
i: integer;
begin
Clear;
Edit2.SetFocus;
Label14.Caption := FormatDateTime('yyyy-mm-dd',Now());
s:= 'TH'+ 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;
end;
procedure TForm35.BitBtn3MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
TBitBtn(Sender).Font.Color := clRed;
end;
procedure TForm35.BitBtn3MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
TBitBtn(Sender).Font.Color := clBlue;
end;
procedure TForm35.Edit2KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Trim(Label10.Caption)='') or(Trim(Label14.Caption)='') then
begin
Application.MessageBox('提货票号或提货时间不能为空。','提示',64);
BitBtn3.SetFocus;
Exit;
end;
if (Key = Vk_ReTurn)and(Trim(Edit2.Text)<>'') then
begin
StringGrid1.Cells[4,1]:= Edit2.Text;
StringGrid1.Cells[5,1]:= Label10.Caption;
StringGrid1.Cells[6,1]:= Label14.Caption;
Edit2.ReadOnly := True;
StringGrid1.SetFocus;
StringGrid1.Col := 1;
end;
end;
procedure TForm35.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 TForm35.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 TForm35.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);
if jcxmlb = True then
begin
Label17.Caption := FloatToStr(SumPrice);
Label16.Caption := IntToStr(SumSL);
Label15.Caption := IntToStr(Kinds);
end;
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 * from 商品基础信息表 where 商品名称 like :b ');
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
DataSource1.DataSet := nil;
DBGrid1.Visible := False;
S1 := True;
Application.MessageBox('库中没有此商品。','提示',64 );
For a1 := 0 to 3 do
StringGrid1.Cells[a1,x]:= '';
StringGrid1.SetFocus;
StringGrid1.Col := 1;
end;
end;
end ;
end;
function TForm35.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;
function TForm35.Sumprice: Real;
var
nn: Integer;
sum: Real;
begin
sum := 0.0;
For nn := 1 to StringGrid1.RowCount-1 do
sum := Sum + StrToFloat(StringGrid1.Cells[3,nn]);
ReSult := Sum;
end;
function TForm35.SumSL: Integer;
var
nn: Integer;
sum: Integer;
begin
sum := 0;
For nn := 1 to StringGrid1.RowCount-1 do
sum := Sum + StrToInt(StringGrid1.Cells[2,nn]);
ReSult := Sum;
end;
function TForm35.Kinds: Integer;
var
i,m,mm: Integer;
Iscf: Boolean; //判断当前记录是否与之前的记录重复
begin
mm:= 0;
Iscf := False;
Result := StringGrid1.RowCount-1;
For m := 1 to StringGrid1.RowCount-1 do
For i := m+1 to StringGrid1.RowCount-1 do
begin
Iscf := False;
if m >1 then
For mm := 1 to m-1 do
if Trim(StringGrid1.Cells[0,m])= Trim(StringGrid1.Cells[0,mm])then
begin
Iscf := True;
Break;
end;
if Iscf = True then
Continue;
if Trim(StringGrid1.Cells[0,m])=Trim(StringGrid1.Cells[0,i])then
ReSult := Result -1;
end;
end;
procedure TForm35.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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -