📄 fjhthd.pas
字号:
unit Fjhthd;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Fbase, DB, ADODB, StdCtrls, Buttons, ExtCtrls, Grids, ComCtrls;
type
TF_jhthd = class(TF_base)
Label1: TLabel;
DateTimePicker1: TDateTimePicker;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
SpeedButton1: TSpeedButton;
Label4: TLabel;
Edit4: TEdit;
SpeedButton2: TSpeedButton;
Edit5: TEdit;
Label5: TLabel;
SpeedButton3: TSpeedButton;
StringGrid1: TStringGrid;
Label6: TLabel;
Panel1: TPanel;
Label7: TLabel;
Edit6: TEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton3Click(Sender: TObject);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure getspbh(sender:Tobject);
procedure FormShow(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure StringGrid1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure StringGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edit4KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
F_jhthd: TF_jhthd;
spbh:string;
strdbrows:integer;
implementation
uses Fghdw,Fjsr,Fkcspxz,Fdm,Fzct, Fjhd;
{$R *.dfm}
procedure TF_jhthd.getspbh(sender:Tobject); //得到进货退货单编号
begin
adoquery1.Last;
if adoquery1.RecordCount=0 then
spbh:=formatdatetime('yyyymmdd',datetimepicker1.Date)+'JHTH'+formatfloat('0000000',1)
else
spbh:=formatdatetime('yyyymmdd',datetimepicker1.Date)+'JHTH'+formatfloat('0000000',strtoint(copy(adoquery1.Fields[1].asstring,13,7))+1);
end;
procedure TF_jhthd.SpeedButton1Click(Sender: TObject);
begin
inherited;
Application.CreateForm(TF_ghdw, F_ghdw);
F_ghdw.ShowModal;
F_ghdw.Free;
end;
procedure TF_jhthd.SpeedButton2Click(Sender: TObject);
begin
inherited;
Application.CreateForm(TF_jsr, F_jsr);
F_jsr.ShowModal;
F_jsr.Free;
end;
procedure TF_jhthd.SpeedButton3Click(Sender: TObject);
begin
inherited;
Application.CreateForm(TF_kcspxz, F_kcspxz);
F_kcspxz.ShowModal;
F_kcspxz.Free;
end;
procedure TF_jhthd.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
inherited;
if not (key in ['0'..'9','.',#8]) then key:=#0;
end;
procedure TF_jhthd.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
inherited;
F_zct.wf:=0;
end;
procedure TF_jhthd.FormShow(Sender: TObject);
begin
inherited;
F_zct.wf:=2;
DateTimePicker1.Date:=now();
with StringGrid1 do
begin
Cells[1,0]:='商品编号';
Cells[2,0]:='商品全称';
Cells[3,0]:='商品型号';
Cells[4,0]:='商品规格';
Cells[5,0]:='单位';
Cells[6,0]:='产地';
Cells[7,0]:='数量';
Cells[8,0]:='退货价';
Cells[9,0]:='金额';
end;
with adoquery1 do
begin
close;
SQl.Clear;
SQl.Add('select * from tb_rewarehouse_main');
Open;
end;
getspbh(sender);
Edit2.Text:=spbh;
end;
procedure TF_jhthd.StringGrid1SelectCell(Sender: TObject; ACol,
ARow: Integer; var CanSelect: Boolean);
begin
inherited;
if (Acol=7) or (Acol=8) then
stringgrid1.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect,goEditing]
else
stringgrid1.Options:=[goFixedVertLine,goFixedHorzLine,goVertLine,goHorzLine,goRangeSelect];
end;
procedure TF_jhthd.StringGrid1Click(Sender: TObject);
var
xh:integer;
begin
inherited;
for xh:=1 to StringGrid1.RowCount do //统计每行金额
begin
if (Trim(StringGrid1.Cells[1,xh])<>'') and (Trim(StringGrid1.Cells[7,xh])<>'') and (Trim(StringGrid1.Cells[8,xh])<>'')then
begin
StringGrid1.Cells[9,xh]:=format('%10.4f',[strtofloat(StringGrid1.Cells[7,xh]) * strtofloat(StringGrid1.Cells[8,xh])]);
end;
end;
end;
procedure TF_jhthd.BitBtn2Click(Sender: TObject);
var
grow,gcol:integer;
begin
inherited;
Edit3.Clear;
Edit4.Clear;
Edit5.Clear;
Edit6.Clear;
Panel1.Caption:='';
for grow:=1 to stringgrid1.RowCount do
begin
for gcol:=1 to stringgrid1.ColCount do
begin
stringgrid1.Cells[gcol,grow]:='';
end;
end;
end;
procedure TF_jhthd.BitBtn1Click(Sender: TObject);
var
gcol,grow,xhjc:integer; //age加权平均价
begin
inherited;
if (Trim(Edit3.Text)='') or (Trim(Edit4.Text)='') or (Trim(Edit6.Text)='') or (stringgrid1.Cells[9,1]='') then
begin
Application.MessageBox('请输入完整信息','提示',mb_ok);
Exit;
end;
for xhjc:=1 to strdbrows do
begin
if (stringgrid1.Cells[7,xhjc]='') or (strtofloat(stringgrid1.Cells[8,xhjc])<=0) then
begin
Application.MessageBox('请输入商品数量或金额','提示',mb_ok);
Exit;
end;
end;
try
F_dm.ADOConnection1.BeginTrans;
with Adoquery1 do //保存主表信息
begin
Close;
SQl.Clear;
SQl.Add('select * from tb_rewarehouse_main');
open;
insert;
FieldByName('billdate').AsDateTime:=strtodate(formatdatetime('yyyy-mm-dd',datetimepicker1.Date));
FieldByName('billcode').AsString:=Trim(Edit2.Text);
FieldByName('units').AsString:=Trim(Edit3.Text);
FieldByName('handle').AsString:=Trim(Edit4.Text);
FieldByName('summary').AsString:=Trim(Edit5.Text);
FieldByName('fullgathering').AsFloat:=strtofloat(panel1.Caption);
FieldByName('gathering').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Edit6.Text)]));
post;
end;
with Adoquery1 do //保存明细表信息
begin
Close;
SQl.Clear;
SQl.Add('select * from tb_rewarehouse_detailed');
open;
For grow:=1 to strdbrows do //当前表单的记录个数
begin
insert;
FieldByName('billdate').AsDateTime:=strtodate(formatdatetime('yyyy-mm-dd',datetimepicker1.Date));
FieldByName('billcode').AsString:=Trim(Edit2.Text);
for gcol:=1 to 9 do
begin
Fields[gcol].AsVariant:=stringgrid1.Cells[gcol,grow];
end;
post;
end;
end;
with adoquery2 do //保存往来账明细表
begin
close;
SQL.Clear;
SQL.Add('select * from tb_currentaccount');
Open;
insert;
FieldByName('billdate').AsDateTime:=strtodate(formatdatetime('yyyy-mm-dd',datetimepicker1.Date));
FieldByName('billcode').AsString:=Trim(Edit2.Text);
FieldByName('units').AsString:=Trim(Edit3.Text);
FieldByName('addgathering').AsFloat:=strtofloat(panel1.Caption);
FieldByName('balance').AsFloat:=strtofloat(format('%10.4f',[strtofloat(panel1.Caption)-strtofloat(Edit6.Text)]));
post;
end;
For grow:=1 to strdbrows do
begin
with adoquery2 do
begin
Close;
SQL.Clear;
SQL.Add('select * from tb_stock where fullnamed='+''''+Trim(stringgrid1.Cells[2,grow])+'''');
Open;
Edit;
fieldbyname('qty').AsFloat:=fieldbyname('qty').AsFloat-strtofloat(stringgrid1.Cells[7,grow]);
UpdateRecord;
post;
end;
end;
//保存入往来单位表中的 累计应收 累计应付字段
with Adoquery2 do
begin
Close;
SQl.Clear;
SQl.Add('select * from tb_units where fullname='+''''+Trim(Edit3.Text)+'''');
open;
Edit;
//供货单位累计应收= 累计应收+应付-实付
FieldByName('gathering').AsFloat:=strtofloat(format('%10.4f',[FieldByName('gathering').AsFloat+strtofloat(panel1.Caption)-strtofloat(Edit6.Text)]));
updaterecord;
post;
end;
F_dm.ADOConnection1.CommitTrans;
Application.MessageBox('保存成功','提示',mb_ok);
except
F_dm.ADOConnection1.RollbackTrans;
Application.MessageBox('保存不成功','提示',mb_ok);
end;
with Adoquery1 do //打开主表
begin
Close;
SQl.Clear;
SQl.Add('select * from tb_rewarehouse_main');
Open;
end;
bitbtn2.OnClick(sender); //取消按钮清空记录
F_jhthd.getspbh(sender); //得到下一单据编号
Edit2.Text:=spbh; //全局变量编号值
end;
procedure TF_jhthd.StringGrid1KeyUp(Sender: TObject; var Key: Word;
Shift: TShiftState);
var
xh:integer;
ss:real;
begin
inherited;
ss:=0;
stringgrid1.OnClick(sender);
for xh:=1 to StringGrid1.RowCount do
begin
if (Trim(StringGrid1.Cells[1,xh])<>'') and (Trim(StringGrid1.Cells[7,xh])<>'') and (Trim(StringGrid1.Cells[8,xh])<>'')then
begin
ss:=ss+ strtofloat(StringGrid1.Cells[9,xh]);
strdbrows:=xh;
end;
end;
panel1.Caption:=format('%10.4f',[ss]);
end;
procedure TF_jhthd.Edit3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if key=13 then speedbutton1.Click;
end;
procedure TF_jhthd.Edit4KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if key=13 then speedbutton2.Click;
end;
procedure TF_jhthd.StringGrid1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if key=13 then speedbutton3.Click;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -