📄 inv_whpmove_b.pas
字号:
unit Inv_WhPMove_B;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Entry_Body, Db, ActnList, AdODB, Grids, DBGridEh, ExtCtrls,
ComCtrls, ToolWin, StdCtrls, Mask, ExtEdit, DBCtrls, ExtPrintReport, jpeg;
Type
TFrm_Inv_WhPMove_B = Class(TFrm_Base_Entry_Body)
Label1: TLabel;
CmBx_Warehouse: TComboBox;
Label4: TLabel;
Label7: TLabel;
Edt_BillNo: TEdit;
Label8: TLabel;
MEdt_BillDate: TMaskEdit;
Label3: TLabel;
Label5: TLabel;
CmBx_WhPosition: TComboBox;
Edt_RemArk: TEdit;
CmBx_OWhPosition: TComboBox;
procedure FormCreate(Sender: TObject);
procedure CmBx_WarehouseChange(Sender: TObject);
procedure CmBx_OWhPositionChange(Sender: TObject);
procedure CmBx_OWhPositionExit(Sender: TObject);
procedure MEdt_BillDateExit(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Act_PreviewExecute(Sender: TObject);
procedure Act_PrintExecute(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure SetStatus(CurrentStatus:String;var AnswerStatus,
EnableControls:String); Override;
procedure InitControls; Override;
procedure SaveHeadData; Override;
procedure SaveData; Override;
end;
var
Frm_Inv_WhPMove_B: TFrm_Inv_WhPMove_B;
implementation
uses Sys_Global,Inv_WhPMove_D,Inv_Global;
{$R *.DFM}
{ TFrm_Inv_SaleMaterial_B }
procedure TFrm_Inv_WhPMove_B.InitControls;
var
Bill_ID:String;
begin
inherited;
InitUsableWHCmBx(AdoQry_Tmp,UserCode,CmBx_Warehouse,False);
//取得单据ID
if Status<>'Add' then
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select InvBillId From InvOutBill'
+' Where InvBillNo='''+AdoQry_Head.fieldbyname('InvBillNo').AsString+''''
+' And WHCode='''+AdoQry_Head.fieldbyname('WHCode').AsString+'''';
AdoQry_Tmp.Open;
Bill_ID:=AdoQry_Tmp.fieldbyname('InvBillId').AsString;
end
else
Bill_ID:='-1';
//设置表体AdoQry_Body 当前SQL语句(注意要能与表头关联)
AdoQry_Body.Close;
AdoQry_Body.SQL.Text:='Select InvOutBillLine.POLineNo'
+',InvOutBillLine.ItemCode'
+',Item.ItemName'
+',Uom.UomName'
+',InvOutBillLine.InvBillQty'
+',InvOutBillLine.BatchNo'
+',InvOutBillLine.BillLineRemArk'
+' From InvOutBillLine'
+' Join Item On InvOutBillLine.ItemCode=Item.ItemCode'
+' Join Uom On Item.UomCode=Uom.UomCode'
+' Where InvOutBillLine.InvBillId='+Bill_ID+'';
AdoQry_Body.Open;
AdoQry_Body.Sort:='POLineNo';
with AdoQry_Head do
begin//把根据表头当前数据初始化,表头控件
InitCmBxText(CmBx_Warehouse,fieldbyname('WHCode').AsString);
CmBx_Warehouse.OnChange(CmBx_Warehouse);
if Status<>'Add' then
Edt_BillNo.Text:=fieldbyname('InvBillNo').AsString
else
Edt_BillNo.Text:='';
if Status<>'Add' then
MEdt_BillDate.Text:=fieldbyname('InvBillDate').AsString
else
MEdt_BillDate.Text:=FormatDateTime('yyyy.mm.dd',Now);
if Status<>'Add' then
Edt_RemArk.Text:=fieldbyname('InvBillRemArk').AsString
else
Edt_RemArk.Text:='';
end;
end;
procedure TFrm_Inv_WhPMove_B.SaveData;
var
Bill_No,Bill_Id,DispStr,Tempstr:String;
Bill_LineNo:Integer;
NeedChangePrice:Boolean;
begin
inherited;
DispStr:=' 单据保存失败,请稍后再试 ';
DBConnect.beginTrans;
try
if(Status='Add')then
begin
if AdoQry_Body.RecordCount=0 then
begin
DispStr:=' 新增的单据没有记录,不允许保存 ';
Abort;
end;
Bill_No:=GetNo(DBConnect,AdoQry_Head.fieldbyname('WHCode').AsString+
'C'+FormatDateTime('yymm',AdoQry_Head.fieldbyname('InvBillDate').
AsDateTime),'InvBill');
AdoQry_Head.fieldbyname('InvBillNo').AsString:=Bill_No;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Insert InvOutBill'+
'(InvBillNo,WHCode,InvBillDate,InvBillMonth,BillTypeCode,'+
'EmployeeCode,WH_EmployeeCode,OWhPositionCode,WhPositionCode,InvBillRemArk)'+
'Values('
+''''+Bill_No+''''
+','''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
+','''+AdoQry_Head.fieldbyname('InvBillDate').AsString+''''
+','''+FormatDateTime('yyyy.mm',AdoQry_Head.fieldbyname('InvBillDate').
AsDateTime)+''''
+','''+Param1+''''
+','''+UserCode+''''
+','''+UserCode+''''
+','''+AdoQry_Head.fieldbyname('OWhPositionCode').AsString+''''
+','''+AdoQry_Head.fieldbyname('WhPositionCode').AsString+''''
+','''+AdoQry_Head.fieldbyname('InvBillRemArk').AsString+''''
+')';
AdoQry_Tmp.ExecSQL;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select @@identity as Bill_Id';
AdoQry_Tmp.Open;
Bill_Id:=AdoQry_Tmp.fieldbyname('Bill_Id').AsString;
end;
ChangeInvStatus(AdoQry_Tmp,AdoQry_Head.fieldbyname('WHCode').AsString,
FormatDateTime('yy.mm',AdoQry_Head.fieldbyname('InvBillDate').AsDateTime));
NeedChangePrice:=NeedChangeAveragePrice(AdoQry_Tmp,FormatDateTime('yyyy.mm',
AdoQry_Head.fieldbyname('InvBillDate').AsDateTime));
AdoQry_Body.DisableControls ;
AdoQry_Body.First;
Bill_LineNo:=1;
while(not AdoQry_Body.Eof)do
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Insert InvOutBillLine'+
'(InvBillId,InvBillLineNo,ItemCode,InvBillQty,BillLineRemArk,BatchNo)'+
'Values('
+''''+Bill_Id+''''
+','+IntToStr(Bill_LineNo)+''
+','''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''
+','+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+','''+AdoQry_Body.fieldbyname('BillLineRemArk').AsString+''''
+','''+AdoQry_Body.fieldbyname('BatchNo').AsString+''''
+')';
AdoQry_Tmp.ExecSQL;
Tempstr:=UpdateInv(AdoQry_Tmp,AdoQry_Head.fieldbyname('WHCode').AsString,
AdoQry_Head.fieldbyname('WhPositionCode').AsString,
AdoQry_Body.fieldbyname('ItemCode').AsString,
'(-('+AdoQry_Body.fieldbyname('InvBillQty').AsString+'))',
NeedChangePrice,True);
if Tempstr<>'' then
begin
DispStr:=Tempstr;
Abort;
end;
if AdoQry_Body.fieldbyname('BatchNo').AsString<>'' then
begin
if not BatchInvCheck(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
'C',AdoQry_Head.fieldbyname('WHCode').AsString,
AdoQry_Head.fieldbyname('WhPositionCode').AsString,
AdoQry_Body.fieldbyname('InvBillQty').AsFloat)then
Abort;
ChangeBatchInv(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
'C',MEdt_BillDate.Text,AdoQry_Head.fieldbyname('WHCode').AsString,
AdoQry_Head.fieldbyname('WhPositionCode').AsString,
AdoQry_Body.fieldbyname('InvBillQty').AsFloat);
end;
AdoQry_Body.Next;
Bill_LineNo:=Bill_LineNo+1;
end;
if(Status='Add')then
begin
if AdoQry_Body.RecordCount=0 then
begin
DispStr:=' 新增的单据没有记录,不允许保存 ';
Abort;
end;
Bill_No:=GetNo(DBConnect,AdoQry_Head.fieldbyname('WHCode').AsString+
'R'+FormatDateTime('yymm',AdoQry_Head.fieldbyname('InvBillDate').
AsDateTime),'InvBill');
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Insert InvInBill'+
'(InvBillNo,WHCode,InvBillDate,InvBillMonth,BillTypeCode,'+
'EmployeeCode,WH_EmployeeCode,OWhPositionCode,WhPositionCode,InvBillRemArk)'+
'Values('
+''''+Bill_No+''''
+','''+AdoQry_Head.fieldbyname('WHCode').AsString+''''
+','''+AdoQry_Head.fieldbyname('InvBillDate').AsString+''''
+','''+FormatDateTime('yyyy.mm',AdoQry_Head.fieldbyname('InvBillDate').
AsDateTime)+''''
+','''+Param1+''''
+','''+UserCode+''''
+','''+UserCode+''''
+','''+AdoQry_Head.fieldbyname('WhPositionCode').AsString+''''
+','''+AdoQry_Head.fieldbyname('OWhPositionCode').AsString+''''
+','''+AdoQry_Head.fieldbyname('InvBillRemArk').AsString+''''
+')';
AdoQry_Tmp.ExecSQL;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select @@identity as Bill_Id';
AdoQry_Tmp.Open;
Bill_Id:=AdoQry_Tmp.fieldbyname('Bill_Id').AsString;
end;
AdoQry_Body.First;
Bill_LineNo:=1;
while(not AdoQry_Body.Eof)do
begin
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Insert InvInBillLine'+
'(InvBillId,InvBillLineNo,ItemCode,InvBillQty,BillLineRemArk,BatchNo)'+
'Values('
+''''+Bill_Id+''''
+','+IntToStr(Bill_LineNo)+''
+','''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''
+','+AdoQry_Body.fieldbyname('InvBillQty').AsString+''
+','''+AdoQry_Body.fieldbyname('BillLineRemArk').AsString+''''
+','''+AdoQry_Body.fieldbyname('BatchNo').AsString+''''
+')';
AdoQry_Tmp.ExecSQL;
Tempstr:=UpdateInv(AdoQry_Tmp,AdoQry_Head.fieldbyname('WHCode').AsString,
AdoQry_Head.fieldbyname('OWhPositionCode').AsString,
AdoQry_Body.fieldbyname('ItemCode').AsString,
'('+AdoQry_Body.fieldbyname('InvBillQty').AsString+')',
NeedChangePrice,True);
if Tempstr<>'' then
begin
DispStr:=Tempstr;
Abort;
end;
if AdoQry_Body.fieldbyname('BatchNo').AsString<>'' then
begin
if not BatchInvCheck(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
'R',AdoQry_Head.fieldbyname('WHCode').AsString,
AdoQry_Head.fieldbyname('OWhPositionCode').AsString,
AdoQry_Body.fieldbyname('InvBillQty').AsFloat)then
Abort;
ChangeBatchInv(AdoQry_Tmp,AdoQry_Body.fieldbyname('BatchNo').AsString,
'R',MEdt_BillDate.Text,AdoQry_Head.fieldbyname('WHCode').AsString,
AdoQry_Head.fieldbyname('OWhPositionCode').AsString,
AdoQry_Body.fieldbyname('InvBillQty').AsFloat);
end;
AdoQry_Body.Next;
Bill_LineNo:=Bill_LineNo+1;
end;
DBConnect.CommitTrans;
AdoQry_Body.EnableControls ;
except
DBConnect.RollBackTrans;
DispInfo(DispStr,3);
AdoQry_Body.EnableControls ;
Abort;
end;
end;
procedure TFrm_Inv_WhPMove_B.SaveHeadData;
begin//把表头控件写入缓存,没Post
inherited;
with AdoQry_Head do
begin//把根据表头当前数据初始化,表头控件
fieldbyname('WHCode').AsString:=GetCode(CmBx_Warehouse.Text);
fieldbyname('WHName').AsString:=GetName(CmBx_Warehouse.Text);
fieldbyname('WhPositionCode').AsString:=GetCode(CmBx_WhPosition.Text);
fieldbyname('WhPositionName').AsString:=GetName(CmBx_WhPosition.Text);
fieldbyname('OWhPositionCode').AsString:=GetCode(CmBx_OWhPosition.Text);
fieldbyname('OWhPositionName').AsString:=GetName(CmBx_OWhPosition.Text);
fieldbyname('InvBillDate').AsString:=MEdt_BillDate.Text;
fieldbyname('InvBillRemArk').AsString:=Edt_ReMArk.Text;
end;
end;
procedure TFrm_Inv_WhPMove_B.SetStatus(CurrentStatus: String;
var AnswerStatus, EnableControls: String);
begin
inherited;
if(CurrentStatus='Edit')then
begin
AnswerStatus:='ReadOnly';
EnableControls:='';
end
else if (CurrentStatus='Add') then
begin
AnswerStatus:='Add';
EnableControls:='Edt_RemArk,';
end;
end;
procedure TFrm_Inv_WhPMove_B.FormCreate(Sender: TObject);
begin
inherited;
Frm_Entry_Detail:=TFrm_Inv_WhPMove_D.Create(Self);
SetFocus_Control:=CmBx_Warehouse;
end;
procedure TFrm_Inv_WhPMove_B.CmBx_WarehouseChange(Sender: TObject);
begin
inherited;
AllChange(Sender);
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select WhPosition.WhPositionCode'
+'+'' ''+WhPosition.WhPositionName As WhPositionCodeName'
+' From WhPosition'
+' Where WhPosition.WHCode='''+GetCode(CmBx_Warehouse.Text)+''''
+' And WhPosition.WhPositionType<>1';
AdoQry_Tmp.Open;
AdoQry_Tmp.First;
CmBx_WhPosition.clear;
CmBx_OWhPosition.clear;
while not AdoQry_Tmp.Eof do
begin
CmBx_WhPosition.Items.Add(AdoQry_Tmp.fieldbyname('WhPositionCodeName').AsString);
CmBx_OWhPosition.Items.Add(AdoQry_Tmp.fieldbyname('WhPositionCodeName').AsString);
AdoQry_Tmp.Next;
end;
InitCmBxText(CmBx_WhPosition,AdoQry_Head.fieldbyname('WhPositionCode').AsString);
InitCmBxText(CmBx_OWhPosition,AdoQry_Head.fieldbyname('OWhPositionCode').AsString);
end;
procedure TFrm_Inv_WhPMove_B.CmBx_OWhPositionChange(Sender: TObject);
begin
inherited;
AllChange(Sender);
end;
procedure TFrm_Inv_WhPMove_B.CmBx_OWhPositionExit(Sender: TObject);
begin
inherited;
if ActiveControl.Name='ToolButton4' then
Abort;
if CmBx_OWhPosition.Text=CmBx_WhPosition.Text then
begin
DispInfo('移入货位不能与移出货位相同!',3);
TWinControl(Sender).SetFocus;
Abort;
end;
end;
procedure TFrm_Inv_WhPMove_B.MEdt_BillDateExit(Sender: TObject);
begin
inherited;
DateCheck(Sender);
if WHClsPeriodCheck(AdoQry_Tmp,GetCode(CmBx_Warehouse.Text),
Copy(TEdit(Sender).Text,1,7))=False then
begin
TWinControl(Sender).SetFocus;
Abort;
end;
end;
procedure TFrm_Inv_WhPMove_B.FormActivate(Sender: TObject);
begin
inherited;
//ToolButton4.left:=TlBtn_Print.left+ToolButton4.Width;
Act_Excel.Enabled :=False;
Act_Excel.Visible :=False;
end;
procedure TFrm_Inv_WhPMove_B.Act_PreviewExecute(Sender: TObject);
begin
//inherited;
BillPrint(DBConnect,GetCode(CmBx_Warehouse.text),Edt_BillNo.text,Param1,ModuleCode,True,False,True,'');
end;
procedure TFrm_Inv_WhPMove_B.Act_PrintExecute(Sender: TObject);
begin
//inherited;
BillPrint(DBConnect,GetCode(CmBx_Warehouse.text),Edt_BillNo.text,Param1,ModuleCode,False,False,True,'');
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -