📄 untinstock.~pas
字号:
unit untInStock;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, DB,ADODB ,DateUtils;
type
TfrmInStock = class(TForm)
Panel1: TPanel;
Bevel1: TBevel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
edtGoodsCode: TEdit;
edtInPrice: TEdit;
edtQtyInStock: TEdit;
edtGoodsName: TEdit;
edtUnit: TEdit;
edtPrice: TEdit;
edtSafeStock: TEdit;
edtQtyBuyMin: TEdit;
btnOK: TBitBtn;
btnCancel: TBitBtn;
uspTmp: TADOStoredProc;
procedure btnOKClick(Sender: Tobject);
procedure edtGoodsCodeExit(Sender:Tobject);
private
function CheckAllRecords:Boolean;
function SaveAllRecords:Boolean;
{ Private declarations }
public
function Execute:Boolean;
{ Public declarations }
end;
var
frmInStock: TfrmInStock;
implementation
uses untGoodsOrderDat;
function TfrmInStock.Execute:Boolean;
begin
edtGoodsCode.Text:='';
edtInPrice.Text:='';
edtQtyInStock.Text:='';
edtGoodsName.Text :='';
edtUnit.Text:='';
edtPrice.Text:='';
edtSafeStock.Text:='';
edtQtyBuyMin.Text:='';
Result:=ShowModal=mrOK;
end;
{$R *.DFM}
function StrToFloatDef(const S: string ;Default:Extended):Extended;
var
nErrNo: Integer;
begin
Val(S,Result,nErrNo);
if nErrNo<> 0 then Result :=Default;
end;
function TfrmInStock.SaveAllRecords:Boolean;
var
sGoodsCode: string;
begin
Result := False;
with datGoodsOrder do begin
conGoodsOrder.BeginTrans;
try
qryInStock.SQL.Text :='select * from Instock where 1=0';
qryInStock.LockType :=ltBatchOptimistic;
qryInStock.CursorType :=ctKeyset;
qryInStock.Open;
qryGoods.SQL.Text :='select * from Goods';
qryGoods.LockType :=ltBatchOptimistic;
qryGoods.CursorType :=ctKeyset;
qryGoods.Open;
sGoodsCode :=Trim(edtGoodsCode.Text);
qryInStock.Append;
qryInStock.FieldByName('DateInStock').AsDateTime :=Today;
qryInStock.FieldByName('GoodsCode').AsString :=sGoodsCode;
qryInStock.FieldByName('QtyInStock').AsCurrency :=StrToFloatDef(edtQtyInStock.Text,0.0);
qryInStock.FieldByName('Price').AsCurrency:=StrTofloatDef(edtInPrice.Text,0.0);
qryInStock.Post;
if qryGoods.Locate('GoodsCode',sGoodsCode,[]) then
qryGoods.Edit
else begin
qryGoods.Append;
qryGoods.FieldByName('GoodsCode').AsString :=sGoodsCode;
end;
qryGoods.FieldByName('GoodsName').AsString :=Trim(edtGoodsName.Text);
qryGoods.FieldByName('Unit').AsString :=Trim(edtUnit.Text);
qryGoods.FieldByName('Price').AsCurrency :=StrToFloatDef(edtPrice.Text,0.0);
qryGoods.FieldByName('SafeStock').AsCurrency :=StrToFloatDef(edtSafeStock.Text,0.0);
qryGoods.FieldByName('QtyBuyMin').AsCurrency :=StrtoFloatDef(edtSafeStock.Text,0.0);
qryGoods.Post;
qryInStock.UpdateBatch;
qryGoods.UpdateBatch;
conGoodsOrder.CommitTrans;
Result := True;
except
conGoodsOrder.RollbackTrans;
MessageDlg('保存数据失败!',mtError,[mbOK],0);
Close;
end;
end;
end;
function TfrmInStock.CheckAllRecords:Boolean;
begin
Result :=True;
if Trim(edtGoodsCode.Text) ='' then begin
Result := False;
Exit;
end;
if StrToFloatDef(edtInPrice.Text,0.0)< 0.01 then begin
Result :=False;
Exit;
end;
if StrToFloatDef(edtQtyInStock.Text,0.0)<0.01 then begin
Result :=False;
Exit;
end;
if Trim(edtGoodsName.Text) = '' then begin
Result := False;
Exit;
end;
if Trim(edtUnit.Text) ='' then begin
Result :=False;
Exit;
end;
if StrToFloatDef(edtPrice.Text,0.0) <0.01 then begin
Result :=False;
Exit;
end;
if trim(edtSafeStock.text) = '' then begin
Result := False;
Exit;
end;
if StrToFloatDef(edtQtyBuyMin.Text,0.0)< 0.01 then begin
Result :=False;
Exit;
end;
end;
procedure TfrmInStock.edtGoodsCodeExit(Sender:Tobject);
var
sGoodsCode:string;
begin
sGoodsCode:=Trim(edtGoodsCode.Text);
uspTmp.Parameters.Clear;
uspTmp.ProcedureName :='usp_GetGoodsInfo';
uspTmp.Parameters.CreateParameter('GoodsCode',ftString,pdInput,10,sGoodsCode);
uspTmp.Parameters.CreateParameter('GoodsName',ftString,pdOutput,20,'');
uspTmp.Parameters.CreateParameter('Find',ftSmallInt,pdOutput,0,0);
uspTmp.Parameters.CreateParameter('Unit',ftString,pdOutput,20,'');
uspTmp.Parameters.CreateParameter('Price',ftCurrency,pdOutput,0,0);
uspTmp.Parameters.CreateParameter('SafeStock',ftCurrency,pdOutput,0,0);
uspTmp.Parameters.CreateParameter('QtyBuyMin',ftCurrency,pdOutput,0,0);
uspTmp.ExecProc;
if
uspTmp.Parameters.ParamByname('Find').Value=1 then begin
edtGoodsName.Text := uspTmp.Parameters.ParamByname('GoodsName').Value;
edtUnit.Text :=uspTmp.Parameters.ParamByname('Unit').Value;
edtPrice.Text :=uspTmp.Parameters.ParamByname('Price').Value;
edtSafeStock.Text :=uspTmp.Parameters.ParamByName('SafeStock').Value;
edtQtyBuyMin.Text :=uspTmp.Parameters.ParamByname('QtyBuyMin').Value;
end;
end;
procedure TfrmInStock.btnOKClick(Sender: Tobject);
begin
if CheckAllRecords
then
SaveAllRecords;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -