📄 fjhd.pas
字号:
unit Fjhd;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Fbase, StdCtrls, Buttons, Grids, ExtCtrls, ComCtrls, DB, ADODB;
type
TF_jhd = class(TF_base)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
StringGrid1: TStringGrid;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
SpeedButton3: TSpeedButton;
Label6: TLabel;
Edit6: TEdit;
Label7: TLabel;
Panel1: TPanel;
DateTimePicker1: TDateTimePicker;
ADOQuery1: TADOQuery;
procedure SpeedButton3Click(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure StringGrid1SelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
procedure StringGrid1KeyPress(Sender: TObject; var Key: Char);
procedure getspbh(sender:Tobject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
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_jhd: TF_jhd;
spbh:string;
strdbrows:integer;
implementation
uses Fkcspxz,Fghdw,Fjsr,Fdm,Fzct;
{$R *.dfm}
procedure TF_jhd.getspbh(sender:Tobject); //得到进货单编号
begin
adoquery1.Last;
if adoquery1.RecordCount=0 then
spbh:=formatdatetime('yyyymmdd',datetimepicker1.Date)+'JH'+formatfloat('0000000',1)
else
spbh:=formatdatetime('yyyymmdd',datetimepicker1.Date)+'JH'+formatfloat('0000000',strtoint(copy(adoquery1.Fields[1].asstring,11,7))+1);
end;
procedure TF_jhd.SpeedButton3Click(Sender: TObject);
begin
inherited;
Application.CreateForm(TF_kcspxz, F_kcspxz);
F_kcspxz.ShowModal;
F_kcspxz.Free;
end;
procedure TF_jhd.FormShow(Sender: TObject);
begin
inherited;
F_zct.wf:=1;
DateTimePicker1.Date:=now();
with F_jhd.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_warehouse_main');
Open;
end;
F_jhd.getspbh(sender);
Edit2.Text:=spbh;
end;
procedure TF_jhd.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_jhd.SpeedButton1Click(Sender: TObject);
begin
inherited;
Application.CreateForm(TF_ghdw, F_ghdw);
F_ghdw.ShowModal;
F_ghdw.Free;
end;
procedure TF_jhd.SpeedButton2Click(Sender: TObject);
begin
inherited;
Application.CreateForm(TF_jsr, F_jsr);
F_jsr.ShowModal;
F_jsr.Free;
end;
procedure TF_jhd.StringGrid1Click(Sender: TObject);
var
xh:integer;
begin
inherited;
for xh:=1 to F_jhd.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_jhd.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
inherited;
if not (key in ['0'..'9','.',#8]) then key:=#0;
end;
procedure TF_jhd.BitBtn1Click(Sender: TObject);
var
gcol,grow,xhjc:integer;
ave:string; //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_warehouse_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('fullpayment').AsFloat:=strtofloat(panel1.Caption);
FieldByName('payment').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Edit6.Text)]));
post;
end;
with Adoquery1 do //将信息保存到进货明细表
begin
Close;
SQl.Clear;
SQl.Add('select * from tb_warehouse_detailed');
open;
For grow:=1 to strdbrows do //strdbrows记录当前表单的记录个数
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 adoquery1 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('reducegathering').AsFloat:=strtofloat(panel1.Caption);
FieldByName('balance').AsFloat:=strtofloat(Edit6.Text)-strtofloat(panel1.Caption);
post;
end;
For grow:=1 to strdbrows do
begin
with adoquery1 do
begin
with stringgrid1 do
begin
Close;
SQL.Clear;
SQL.Add('select * from tb_stock where fullnamed='+''''+Trim(Cells[2,grow])+'''');
Open;
edit;
if (fieldbyname('averageprice').AsFloat=0) then
ave:=format('%10.4f',[(strtofloat(Cells[7,grow]) * strtofloat(Cells[8,grow]))/(strtofloat(Cells[7,grow]))])
else
ave:=format('%10.4f',[(strtofloat(Cells[7,grow]) * strtofloat(Cells[8,grow])+fieldbyname('averageprice').AsFloat*fieldbyname('qty').AsFloat)/(strtofloat(Cells[7,grow])+fieldbyname('qty').AsFloat)]);
Edit;
fieldbyname('qty').AsFloat:=fieldbyname('qty').AsFloat+strtofloat(Cells[7,grow]);
fieldbyname('price').AsFloat:=strtofloat(format('%10.4f',[strtofloat(Cells[8,grow])]));
fieldbyname('averageprice').AsFloat:=strtofloat(ave);
UpdateRecord;
post;
end;
end;
end;
//保存往来单位表中的 累计应收 累计应付字段
with Adoquery1 do
begin
Close;
SQl.Clear;
SQl.Add('select * from tb_units where fullname='+''''+Trim(Edit3.Text)+'''');
open;
Edit;
FieldByName('payment').AsFloat:=strtofloat(format('%10.4f',[FieldByName('payment').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_warehouse_main');
Open;
end;
bitbtn2.OnClick(sender); //调用取消按钮清空记录
F_jhd.getspbh(sender); //得到下一单据编号
Edit2.Text:=spbh; //显示编号值
end;
procedure TF_jhd.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_jhd.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
inherited;
F_zct.wf:=0;
end;
procedure TF_jhd.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_jhd.Edit3KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if key=13 then speedbutton1.Click;
end;
procedure TF_jhd.Edit4KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
inherited;
if key=13 then speedbutton2.Click;
end;
procedure TF_jhd.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 + -