pm_enter_newfreepo.pas
来自「一个MRPII系统源代码版本」· PAS 代码 · 共 752 行 · 第 1/2 页
PAS
752 行
unit Pm_Enter_NewFreePo;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Entry_Body, Db, ActnList, AdODB, Grids, DBGridEh, ExtCtrls,
ComCtrls, ToolWin, Mask, StdCtrls, ExtPrintReport, DBCtrls, linkedit, jpeg;
Type
TFrm_Pm_Enter_NewFreePo = Class(TFrm_Base_Entry_Body)
AdoQry_BodyPONO: TStringField;
AdoQry_BodyPOLINENo: TIntegerField;
AdoQry_BodyItemCode: TStringField;
AdoQry_BodyPOLineDATE: TDateTimeField;
AdoQry_BodyPOQTY: TFloatField;
AdoQry_BodyPONoFinishQty: TFloatField;
AdoQry_BodyPOREFERENCEDPRICE: TIntegerField;
AdoQry_BodyPOLINESTATUS: TIntegerField;
AdoQry_BodyPoNoTaxPrice: TFloatField;
AdoQry_BodyPONoTaxAmount: TBCDField;
AdoQry_BodyPoTaxPrice: TFloatField;
AdoQry_BodyPoTaxAmount: TBCDField;
AdoQry_BodyPOStArtWorkDate: TDateTimeField;
AdoQry_BodyItemName: TStringField;
AdoQry_BodyUomName: TStringField;
AdoQry_Temp: TAdoQuery;
Label13: TLabel;
Lbl_ItemFlag: TLabel;
Label15: TLabel;
DBText1: TDBText;
Label8: TLabel;
DBText2: TDBText;
Label16: TLabel;
Edt_zbr: TLabel;
Label1: TLabel;
Edt_PoNo: TEdit;
Label2: TLabel;
MEdt_PoDate: TMaskEdit;
Label3: TLabel;
Edt_PcNo: TLinkEdit;
Label9: TLabel;
Edt_Potax: TEdit;
Label5: TLabel;
Cmbx_PoType: TComboBox;
Edt_CurrencyName: TEdit;
Edt_CurrencyCode: TEdit;
Label7: TLabel;
Edt_BuyerName: TEdit;
Edt_EmployeeCode: TLinkEdit;
Label6: TLabel;
Label4: TLabel;
Edt_VendorCode: TEdit;
Edt_VendorName: TEdit;
Label11: TLabel;
Edt_PoRemArk: TEdit;
procedure FormCreate(Sender: TObject);
procedure Act_SaveExecute(Sender: TObject);
procedure Act_PrintExecute(Sender: TObject);
procedure Act_PreviewExecute(Sender: TObject);
procedure Edt_PcNoKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
procedure Edt_PcNoExit(Sender: TObject);
procedure DataSourceDataChange(Sender: TObject; Field: TField);
procedure Act_ExcelExecute(Sender: TObject);
procedure Act_InsertLineExecute(Sender: TObject);
procedure Act_ModifyExecute(Sender: TObject);
procedure Act_DeleteLineExecute(Sender: TObject);
procedure Vw_BuyerCodeCheck(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
POReferencedPrice:Integer;//是否参考价
CurrentPcNo:String;//当前采购价格单号
CurrentFormStatus:String;//当前窗体状态
Function SavePoHistory(Status:String):Boolean;//保存历史记录
Function SavePoLineHistory(Status:String):Boolean;//保存历史记录
{ Private declarations }
public
procedure SetStatus(CurrentStatus:String;var AnswerStatus,EnableControls:String); Override;
procedure InitControls; Override;
procedure SaveData; Override;
{ Public declarations }
end;
var
Frm_Pm_Enter_NewFreePo: TFrm_Pm_Enter_NewFreePo;
implementation
uses Sys_Global, Pm_Enter_Po_D, Pm_Enter_Po_P, Mrp_Global;
{$R *.DFM}
function checksymbol(Source:string;disptext:string):boolean; //检查输入中是否有单引号
var
i:integer;
s:string;
begin
s:=Trim(Source);
for i:=1 to length(s) do
if s[i]='''' then
begin
DispInfo(disptext+'中不能使用单引号!',1);
Result:=False;
exit;
end;
Result:=True;
end;
Function TFrm_Pm_Enter_NewFreePo.SavePoHistory(Status:String):Boolean;
var
SqlText:String;
begin
Try
SqlText:='Insert PoHistory '
+' (PoNo,VendorCode,PcNO,POType,PODate,'
+' POTaxRate_Percent,CurrencyCode,EmployeeCode, PoSpecial,PORemArk,PoChgEmployeeCode,PoChgTime,PoChgType)'
+' Values('
+''''+Trim(Edt_PoNo.Text)+''''+','
+''''+Trim(Edt_VendorCode.Text)+''''+','
+''''+Trim(Edt_PcNo.Text)+''''+','
+''''+IntToStr(Cmbx_PoType.ItemIndex)+''''+','
+''''+Medt_PoDate.Text+''''+','
+''''+Trim(Edt_PoTax.Text)+''''+','
+''''+Trim(Edt_CurrencyCode.Text)+''''+','
+''''+Trim(Edt_EmployeeCode.Text)+''''+','
+''''+'1'+''''+','
+''''+Trim(Edt_PoReMArk.Text)+''''+','
+''''+UserCode+''''+','
+'GetDate(),';
IF Status='Add' Then
SqlText:=SqlText+''''+'增加'+''''+')'
Else
SqlText:=SqlText+''''+'修改'+''''+')';
AdoQry_Tmp.Close;
AdoQry_Tmp.Sql.Text:=Sqltext;
AdoQry_Tmp.ExecsQl;
Result:=True;
Except
Result:=False;
end;
end;
Function TFrm_Pm_Enter_NewFreePo.SavePoLineHistory(Status:String):Boolean;
var
SqlText:String;
begin
Try
SqlText:='Insert PoLineHistory '
+' (PoNo,PoLineNo,ItemCode,POLineDate,PoStArtWorkDate,POQty,POTaxPrice,POTaxAmount,PONoTaxPrice,'
+' PONoTaxAmount,PONoFinishQty,POReferencedPrice,POLineStatus,PolChgEmployeeCode,PolChgTime,PolChgType)'
+'Values('
+''''+Trim(Edt_PoNo.Text)+''''+','
+''''+IntToStr(AdoQry_Body.fieldbyname('PoLineNo').AsInteger)+''''+','
+''''+AdoQry_Body.fieldbyname('ItemCode').AsString+''''+','
+''''+DatetimeToStr(AdoQry_Body.fieldbyname('PoLineDate').AsDateTime)+''''+','
+''''+DatetimeToStr(AdoQry_Body.fieldbyname('PoStArtWorkDate').AsDateTime)+''''+','
+''''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+''''+','
+''''+FloatToStr(AdoQry_Body.fieldbyname('POTaxPrice').AsFloat)+''''+','
+''''+FloatToStr(AdoQry_Body.fieldbyname('POTaxAmount').AsFloat)+''''+','
+''''+FloatToStr(AdoQry_Body.fieldbyname('PONoTaxPrice').AsFloat)+''''+','
+''''+FloatToStr(AdoQry_Body.fieldbyname('PONoTaxAmount').AsFloat)+''''+','
+''''+FloatToStr(AdoQry_Body.fieldbyname('PONoFinishQty').AsFloat)+''''+','
+''''+IntToStr(AdoQry_Body.fieldbyname('POReferencedPrice').AsInteger)+''''+','
+''''+IntToStr(AdoQry_Body.fieldbyname('POLineStatus').AsInteger)+''''+','
+''''+UserCode+''''+','
+'GetDate(),';
IF (Status='Add') Or (Status='Edit1') Then
SqlText:=SqlText+''''+'增加'+''')';
If (status='Delete') Then
SqlText:=SqlText+''''+'删除'+''')';
If (status='Edit') Then
SqlText:=SqlText+''''+'修改'+''')';
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:=SqlText;
AdoQry_Tmp.ExecSQL;
Result:=True;
Except
Result:=False;
end;
end;
procedure TFrm_Pm_Enter_NewFreePo.SetStatus(CurrentStatus:String;var AnswerStatus,EnableControls:String);
begin
Inherited;
if Currentstatus='Add' then
begin
AnswerStatus:='Add';
EnableControls:='MEdt_PoDate,Edt_PcNo,Cmbx_PoType,Edt_EmployeeCode,Edt_PoRemArk,';
end;
If Pos('Edit',CurrentStatus)>0 Then
begin
AnswerStatus:='PArtEdit';
EnableControls:='MEdt_PoDate,Edt_EmployeeCode,Edt_PoRemArk,';
end;
end;
procedure TFrm_Pm_Enter_NewFreePo.InitControls;
var
SqlText:string;
begin
Edt_zbr.Caption:='';
If Status<>'Add' then
begin
CurrentFormStatus:='PArtEdit';
SetFocus_Control:=MEdt_PoDate;
end //状态为修改时
Else
begin
CurrentFormStatus:='Add';
SetFocus_Control:=MEdt_PoDate;
end;
IF Status='Query' Then
begin
Caption:='独立采购订单明细';
Pnl_Title.Caption:='独立采购订单明细';
end;
inherited;
PriceFields:='PoNoTaxPrice,PONoTaxAmount,PoTaxPrice,PoTaxAmount,';
Application.ProcessMessages;
With AdoQry_Head do
begin
if Status<>'Add' then
begin
Edt_PoNo.Text:=fieldbyname('PoNo').asstring;
MEdt_PoDate.Text:=Formatdatetime('yyyy.mm.dd',fieldbyname('PoDate').asdatetime);
Edt_PcNo.Text:=fieldbyname('PcNo').AsString;
Edt_VendorCode.Text:=fieldbyname('VendorCode').AsString;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select VendorName From Vendor Where VendorCode='''+fieldbyname('VendorCode').AsString+'''';
AdoQry_Tmp.Open;
If Not AdoQry_Tmp.Eof Then
Edt_VendorName.Text:=AdoQry_Tmp.fieldbyname('VendorName').AsString;
Cmbx_PoType.ItemIndex:=fieldbyname('PoType').AsInteger;
Edt_EmployeeCode.Text:=fieldbyname('EmployeeCode').AsString;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select EmployeeName From Employee Where EmployeeCode='''+fieldbyname('EmployeeCode').AsString+'''';
AdoQry_Tmp.Open;
If Not AdoQry_Tmp.Eof Then
Edt_BuyerName.Text:=AdoQry_Tmp.fieldbyname('EmployeeName').AsString;
Edt_CurrencyCode.Text:=fieldbyname('CurrencyCode').AsString;
Edt_Potax.Text:=IntToStr(fieldbyname('POTaxRate_Percent').AsInteger);
Edt_PoReMArk.Text:=fieldbyname('PoReMArk').AsString;
CurrentPcNo:=fieldbyname('PcNo').AsString;
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select EmployeeCode+'' ''+EmployeeName as zbr From Employee Where EmployeeCode='''+fieldbyname('CreateEmpolyeeCode').AsString+'''';
AdoQry_Tmp.Open;
If Not AdoQry_Tmp.Eof Then
Edt_zbr.Caption := AdoQry_Tmp.fieldbyname('zbr').Asstring;
end
Else
begin
Edt_PoNo.Text:='';
MEdt_Podate.Text:=Formatdatetime('yyyy.mm.dd',date);
Edt_PcNo.Text:='';
Edt_VendorCode.Text:='';
Edt_VendorName.Text:='';
Cmbx_PoType.ItemIndex:=0;
Edt_EmployeeCode.Text:='';
Edt_BuyerName.Text:='';
Edt_CurrencyCode.Text:='';
Edt_Potax.Text:='0';
Edt_PoReMArk.Text:='';
CurrentPcNo:='';
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:='Select EmployeeCode+'' ''+EmployeeName as zbr From Employee Where EmployeeCode='''+UserCode+'''';
AdoQry_Tmp.Open;
If Not AdoQry_Tmp.Eof Then
Edt_zbr.Caption := AdoQry_Tmp.fieldbyname('zbr').Asstring;
end;
end; // 初始化控件内容
AdoQry_Body.Close;
if UpperCase(Status)=UpperCase('Add') then
SqlText:='Select Top 0 PoLine.*,Item.ItemCode,ItemName,Uom.UomName '
+' From PoLine '
+' Join Item On PoLine.ItemCode=Item.ItemCode '
+' Join Uom On Item.UomCode=Uom.UomCode '
+' Order By PoLineNo '
else
SqlText:='Select PoLine.*,Item.ItemCode,ItemName,Uom.UomName '
+' From PoLine '
+' Join Item On PoLine.ItemCode=Item.ItemCode '
+' And PoLine.PoNo='+''''+Trim(AdoQry_Head.fieldbyname('Pono').AsString)+''''
+' Join Uom On Item.UomCode=Uom.UomCode '
+' Order By PoLineNo ';
AdoQry_Body.Close;
AdoQry_Body.SQL.Text:=SqlText;
AdoQry_Body.Open;
Edt_Pono.Enabled:=False;
Edt_VendorCode.Enabled:=False;
Edt_Potax.Enabled:=False;
Edt_CurrencyCode.Enabled:=False;
Edt_CurrencyName.Enabled:=False;
Edt_BuyerName.Enabled:=False;
Edt_VendorName.Enabled:=False;
end;
procedure TFrm_Pm_Enter_NewFreePo.SaveData;
var
SqlText,CurrencyName,VendorName,EmployeeName,PoNo:String;
I:Integer;
begin
inherited;
IF (AdoQry_Body.RecordCount=0) And (status='Add') Then
begin
DispInfo('没有行数据,不能保存!',1);
Abort;
end;
AdoQry_Body.First;
I:=1;
While Not AdoQry_Body.Eof Do
begin
SqlText:=' Select PcLine.PcTaxPrice,PcLine.PcNoTaxPrice,PcLine.PcReferencedPrice '
+' From PcLine '
+' Where (ItemCode='''+Trim(AdoQry_Body.fieldbyname('ItemCode').AsString)+''''
+' )And (PcNo='''+Trim(Edt_PcNo.Text)+''')'
+' And (PcLine.PclineStatus=1)';
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:=SqlText;
AdoQry_Tmp.Open;
If AdoQry_Tmp.Eof Then
begin
If DispInfo('第'+IntToStr(I)+'行物料代码在相应的采购合同中找不到或不在批准状态,是否删除?',2)='y' Then
begin
AdoQry_Body.Delete;
Continue;
end
Else
Abort;
end//在采购合同中不存在时的处理
Else
begin
SqlText:=' Select PcLine.PcTaxPrice,PcLine.PcNoTaxPrice,PcLine.PcReferencedPrice '
+' From PcLine '
+' Where ('''+DateTimeToStr(AdoQry_Body.fieldbyname('PoLineDate').AsDateTime) +''' >=PcStArtDate '
+' And '''+DateTimeToStr(AdoQry_Body.fieldbyname('PoLineDate').AsDateTime) +'''<=PcendDate) '
+' And (('''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+'''>=PcStArtQty '
+' And '''+FloatToStr(AdoQry_Body.fieldbyname('PoQty').AsFloat)+'''<PcendQty)'
+' Or (PcStArtQty=0 And PcendQty=0)) '
+' And (ItemCode='''+Trim(AdoQry_Body.fieldbyname('ItemCode').AsString)+''''
+' )And (PcNo='''+Trim(Edt_PcNo.Text)+''')'
+' And (PcLine.PcLineStatus=1)';
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:=SqlText;
AdoQry_Tmp.Open;
With AdoQry_Body Do
begin
Edit;
fieldbyname('POREFERENCEDPRICE').AsInteger:=AdoQry_Tmp.fieldbyname('PcREFERENCEDPRICE').AsInteger;
fieldbyname('PoNoTaxPrice').AsFloat:=AdoQry_Tmp.fieldbyname('PcNoTaxPrice').AsFloat;
fieldbyname('PONoTaxAmount').AsFloat:=AdoQry_Tmp.fieldbyname('PcNoTaxPrice').AsFloat*fieldbyname('PoQty').AsFloat;
fieldbyname('PoTaxPrice').AsFloat:=AdoQry_Tmp.fieldbyname('PcTaxPrice').AsFloat;
fieldbyname('PoTaxAmount').AsFloat:=AdoQry_Tmp.fieldbyname('PcTaxPrice').AsFloat*fieldbyname('PoQty').AsFloat;
Post;
end;
end;//存在时的处理
If (AdoQry_Body.fieldbyname('PoQty').AsFloat<=0)
And (Status='Add') Then
begin
DispInfo('第'+IntToStr(AdoQry_Body.RecNo)+'行数据有错,请修改!',1);
Abort;
end;
AdoQry_Body.Next;
I:=I+1;
end; //校验数据
IF (AdoQry_Body.RecordCount=0) And (status='Add') Then
begin
DispInfo('没有行数据,不能保存!',1);
Abort;
end;
DbConnect.beginTrans;
Try
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?