📄 cgth.~pas
字号:
if Data.Query1.RecordCount>0 then
begin
Grid1.Columns.Clear;
For ColNum := 0 to 2 do
begin
Column1 := Grid1.Columns.Add;
Column1.Title.Alignment := taCenter;
Column1.Title.Font.Color := clRed;
Case ColNum of
0: begin
Column1.FieldName := 'spdm';
Column1.Title.Caption := '商品代码';
end;
1: begin
Column1.FieldName := 'spmc';
Column1.Title.Caption := '商品名称';
end;
2: begin
Column1.FieldName := 'jbdw';
Column1.Title.Caption := '基本单位';
end;
end;
end;
DataSource1.DataSet := Data.Query1;
if Grid1.Visible = False then
begin
CellRect := bg.CellRect(Col,Row);
CellRect.Left := CellRect.Left+bg.Left;
CellRect.Right := CellRect.Right+ bg.Left;
CellRect.Top := bg.Top+ CellRect.Top;
Grid1.Left := CellRect.Right+1;
Grid1.Top := CellRect.Top;
Grid1.Visible := True;
end;
end;
Grid1.Tag := 2;
end
{ DONE : 按商品名称查找商品信息 }
else if (Col = spmc)and(kc= false)and(Trim(bg.Cells[spdm,Row])='') then
begin
With Data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from t_spjcxx where spmc like :a and cs = :c and spdm in(select distinct spdm from t_sprkjl where kcmc = :b)');
ParamByName('a').AsString := Trim(bg.Cells[spmc,Row])+'%';
paramByName('b').AsString := Trim(bg.Cells[kcmc,Row]);
ParamByName('c').AsString := Trim(cs.Text);
Open;
end;
if Data.Query1.RecordCount>0 then
begin
Grid1.Columns.Clear;
For ColNum := 0 to 2 do
begin
Column1 := Grid1.Columns.Add;
Column1.Title.Alignment := taCenter;
Column1.Title.Font.Color := clRed;
Case ColNum of
0: begin
Column1.FieldName := 'spdm';
Column1.Title.Caption := '商品代码';
end;
1: begin
Column1.FieldName := 'spmc';
Column1.Title.Caption := '商品名称';
end;
2: begin
Column1.FieldName := 'jbdw';
Column1.Title.Caption := '基本单位';
end;
end;
end;
DataSource1.DataSet := Data.Query1;
if Grid1.Visible = False then
begin
CellRect := bg.CellRect(Col,Row);
CellRect.Left := CellRect.Left+bg.Left;
CellRect.Right := CellRect.Right+ bg.Left;
CellRect.Top := bg.Top+ CellRect.Top;
Grid1.Left := CellRect.Right+1;
Grid1.Top := CellRect.Top;
Grid1.Visible := True;
end;
end;
Grid1.Tag := 2;
end;
end;
function Tf_cgth.CalculateCB(spdm: String): Real;
var
sum: Integer;
money: Real;
begin
Result := 0;
with Data.Query2 do
begin
Close;
SQL.Clear;
SQL.Add('select Sum(sl)as num,Sum(je)as Je from t_sprkjl where spdm = :a');
ParamByName('a').AsString := Trim(spdm);
Open;
end;
if Data.Query2.Fields[0].Value<>Null then
begin
Sum := Data.Query2.Fields[0].AsInteger;
money := Data.Query2.Fields[1].AsFloat;
Result := Money/sum;
end;
end;
function Tf_cgth.GroupPrice: real;
var
r: Integer;
Sum: Real;
begin
Sum := 0.0;
For r:=1 to bg.RowCount-1 do
if Trim(bg.Cells[je,r])<>'' then
Sum := Sum + StrToFloat(bg.Cells[je,r]);
Result := Sum;
end;
procedure Tf_cgth.Grid1DblClick(Sender: TObject);
begin
Case Grid1.Tag of
1: begin
bg.Cells[kcmc,Row]:= Trim(Data.Query1.FieldByName('kcmc').AsString);
bg.Cells[kclb,Row]:= Trim(Data.Query1.FieldByName('kclb').AsString);
if Row = 1 then
bg.Cells[zk,Row]:= '1.0';
bg.SetFocus;
bg.Col := bg.Col+1;
end;
2: begin
bg.Cells[spdm,Row]:= Trim(Data.Query1.FieldByName('spdm').AsString);
bg.Cells[spmc,Row]:= Trim(Data.Query1.FieldByName('spmc').AsString);
bg.Cells[jbdw,Row]:= Trim(Data.Query1.FieldByName('jbdw').AsString);
bg.Cells[cbj,Row]:= Format('%8.4f',[CalculateCB(Trim(Data.Query1.FieldByName('spdm').AsString))]);
bg.SetFocus;
bg.Col := bg.Col+1;
end;
end;
Grid1.Visible := False;
end;
procedure Tf_cgth.Grid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = vk_Return then
Grid1.OnDblClick(Sender);
end;
procedure Tf_cgth.Grid1Exit(Sender: TObject);
begin
Grid1.Visible := False;
end;
procedure Tf_cgth.bgKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
Rect1: TRect;
col1,row1: integer;
begin
kc:= False;
if (Key = vk_shift)and(Grid1.Visible = True) then //显示网格
begin
Grid1.SetFocus;
Exit;
end;
if Key = vk_Delete then //删除当前记录
begin
if Application.MessageBox('确实要删除当前记录吗?','提示',mb_YesNo)=ID_Yes then
begin
ClearCurrentRow;
if bg.RowCount>2 then
begin
if Row<>bg.RowCount-1 then
begin
For row1 := Row+1to (bg.RowCount-1) do
For col1:=0 to bg.ColCount-1 do
bg.Cells[col1,row1-1]:= bg.Cells[col1,row1];
end;
ClearEndRow;
bg.RowCount := bg.RowCount-1;
end
else
bg.Cells[zk,Row]:= '1.0';
thxj.Text := Format('%8.4f',[GroupPrice]);
bg.SetFocus;
bg.Col := kcmc;
end;
end;
if (Key= vk_insert)and(CurrentIsNull = False)and(Row = bg.RowCount-1) then //添加新行
begin
bg.RowCount := bg.RowCount+1;
bg.Row:= Bg.Row+1;
bg.Cells[zk,Row]:='1.0';
bg.Col:=kcmc;
exit;
end;
if Key = vk_Return then //查询定位计算数据
begin
if Grid1.Visible = True then
Grid1.Visible := False;
if (Col = bzq)and(Trim(bg.Cells[jbdw,Row])<>'') then
begin
bzqlb.Clear;
with Data.Query2 do
begin
Close;
SQL.Clear;
SQL.Add('select bzq from t_sprkjl where spdm = :a and kcmc = :b');
ParamByName('a').AsString := Trim(bg.Cells[spdm,Row]);
ParamByName('b').AsString := Trim(bg.Cells[kcmc,Row]);
Open;
end;
while Not Data.Query2.Eof do
begin
bzqlb.Items.Add(DateTimeToStr(Data.Query2.FieldByName('bzq').AsDateTime));
Data.Query2.Next;
end;
Rect1 := bg.CellRect(bzq,Row);
Rect1.Left := Rect1.Left+bg.Left;
Rect1.Right :=Rect1.Right+bg.Left;
Rect1.Top := bg.Top+ Rect1.Top;
bzqlb.Left := Rect1.Left;
bzqlb.Top := Rect1.Top+1;
bzqlb.Visible := True;
bzqlb.SetFocus;
bzqlb.ItemIndex := 0;
Exit;
end;
if Trim(bg.Cells[kcmc,Row])='' then
Exit;
if (Col = Kcmc)and(Trim(bg.Cells[Kcmc,Row])<>'') then //不在列表中选择,直接输入库存信息时,判断库存信息是否存在
begin
With Data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from t_kcjcxx where kcdm = :a or kcmc = :a');
ParamByName('a').AsString := Trim(bg.Cells[Kcmc,Row]);
Open;
end;
if Data.Query1.RecordCount>0 then
begin
bg.Cells[kcmc,Row]:= Trim(Data.Query1.Fields[1].AsString);
bg.Cells[kclb,Row]:= Trim(Data.Query1.Fields[2].AsString);
if Row = 1 then
bg.Cells[zk,Row]:='1.0';
bg.SetFocus;
bg.Col := bg.Col+1;
end
else
begin
kc := True;
bg.Cells[kcmc,Row]:='';
end;
end
else if (Col = spdm)and(Trim(bg.Cells[spdm,Row])<>'')and(Trim(bg.Cells[kcmc,Row])<>'') then
begin
With Data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from t_spjcxx where spdm in(select distinct spdm from t_sprkjl where spdm =:a and kcmc = :b)and cs = :c');
ParamByName('a').AsString := Trim(bg.Cells[spdm,Row]);
ParamByName('b').AsString := Trim(bg.Cells[kcmc,Row]);
ParamByName('c').AsString := Trim(cs.Text);
Open;
end;
if Data.Query1.RecordCount>0 then
begin
bg.Cells[spdm,Row]:= Trim(Data.Query1.Fields[0].AsString);
bg.Cells[spmc,Row]:= Trim(Data.Query1.Fields[1].AsString);
bg.Cells[jbdw,Row]:= Trim(Data.Query1.FieldByName('jbdw').AsString);
bg.Cells[cbj,Row]:= FloatToStr(CalculateCB(Trim(Data.Query1.FieldByName('spdm').AsString)));
bg.SetFocus;
bg.Col := bg.Col+1;
end
else
begin
kc := True;
bg.Cells[spdm,Row]:='';
bg.Cells[spmc,Row]:='';
bg.Cells[jbdw,Row]:='';
end;
end
else if (Col = spmc)and(Trim(bg.Cells[spmc,Row])<>'')and(Trim(bg.Cells[spdm,Row])='')and(Trim(bg.Cells[Kcmc,Row])<>'') then
begin
With Data.Query1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from t_spjcxx where spmc = :a and spdm in(select distinct spdm from t_sprkjl where kcmc = :b)and cs=:c ');
ParamByName('a').AsString := Trim(bg.Cells[spmc,Row]);
ParamByName('b').AsString := Trim(bg.Cells[kcmc,Row]);
ParamByName('c').AsString := Trim(cs.Text);
Open;
end;
if Data.Query1.RecordCount>0 then
begin
bg.Cells[spdm,Row]:= Trim(Data.Query1.Fields[0].AsString);
bg.Cells[spmc,Row]:= Trim(Data.Query1.Fields[1].AsString);
bg.Cells[jbdw,Row]:= Trim(Data.Query1.FieldByName('jbdw').AsString);
bg.Cells[cbj,Row]:= FloatToStr(CalculateCB(Trim(Data.Query1.FieldByName('spdm').AsString)));
bg.SetFocus;
bg.Col := bg.Col+1;
end
else
begin
kc := True;
bg.Cells[spdm,Row]:='';
bg.Cells[spmc,Row]:='';
bg.Cells[jbdw,Row]:='';
end;
end
else
begin
bg.SetFocus;
if bg.Col<bg.ColCount-1 then
bg.Col := bg.Col+1;
end;
end;
end;
procedure Tf_cgth.ClearCurrentRow;
var
i: Integer;
begin
For i:=0 to bg.ColCount-1 do
bg.Cells[i,Row]:= '';
end;
procedure Tf_cgth.ClearEndRow;
var
i: Integer;
begin
For i:=0 to bg.ColCount-1 do
bg.Cells[i,bg.RowCount-1]:= '';
end;
function Tf_cgth.CurrentIsNull: Boolean;
var
a: Integer;
begin
Result := False;
For a:= 0 to bg.ColCount -1 do
begin
if Trim(bg.Cells[a,Row])='' then
begin
Result := True;
Break;
end;
end;
end;
procedure Tf_cgth.bzqlbDblClick(Sender: TObject);
begin
bg.Cells[bzq,Row]:= bzqlb.Items[bzqlb.itemIndex];
bzqlb.Visible := False;
bg.SetFocus;
end;
procedure Tf_cgth.bzqlbKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if Key = Vk_Return then
bzqlb.OnDblClick(Sender);
end;
procedure Tf_cgth.csExit(Sender: TObject);
begin
if Trim(cs.Text)<>'' then
begin
with Data.Query2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from t_cszl where csmc = :a');
ParamByName('a').AsString := Trim(cs.Text);
Open;
end;
if Data.Query2.RecordCount <1 then
cs.Clear;
end;
end;
procedure Tf_cgth.thzrChange(Sender: TObject);
begin
if Trim(thzr.Text)<>'' then
begin
if StrToFloat(thzr.Text)>StrToFloat(thxj.Text) then
begin
Application.MessageBox('退货折让不能大于退货小计.','提示',64);
thzr.Text := '0.0';
end
else
begin
thxj.Text := Format('%8.4f',[Groupprice]);
thxj.Text := Format('%8.4f',[StrToFloat(thxj.Text)-StrToFloat(thzr.Text)]);
end;
end
else
thzr.Text := '0.0';
end;
procedure Tf_cgth.thzrKeyPress(Sender: TObject; var Key: Char);
var
i: Boolean;
begin
i := (Key<#8)or(Key>#8)and(Key<#46)or(Key>#46)and(Key<#48)or(Key>#57);
if i then
Key := #0;
end;
procedure Tf_cgth.thzrEnter(Sender: TObject);
begin
thzr.SelectAll;
end;
function Tf_cgth.EditIsNull: Boolean;
var
i: Integer;
begin
Result := False;
For i := 0 to ControlCount-1 do
begin
if Controls[i] is TEdit then
begin
if Trim(TEdit(Controls[i]).Text)='' then
begin
Result := True;
Exit;
end;
end;
end;
For i :=0 to Panel2.ControlCount-1 do
begin
if Controls[i] is TEdit then
if Trim(TEdit(Controls[i]).Text)='' then
begin
Result := True;
Break;
end;
end;
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -