⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pm_enter_newpo.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
unit Pm_Enter_NewPo;

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_NewPo = Class(TFrm_Base_Entry_Body)
    Label1: TLabel;
    Label2: TLabel;
    Edt_PoNo: TEdit;
    MEdt_PoDate: TMaskEdit;
    Label4: TLabel;
    Label5: TLabel;
    Cmbx_PoType: TComboBox;
    Label6: TLabel;
    Label7: TLabel;
    Edt_CurrencyCode: TEdit;
    Label9: TLabel;
    Edt_Potax: TEdit;
    Label11: TLabel;
    Edt_PoRemArk: TEdit;
    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;
    Edt_BuyerName: TEdit;
    Edt_VendorName: TEdit;
    Label16: TLabel;
    Edt_zbr: TLabel;
    Edt_EmployeeCode: TLinkEdit;
    Edt_CurrencyName: TEdit;
    Label10: TLabel;
    lbl_ordinal: TLabel;
    Label12: TLabel;
    edt_rno: TEdit;
    AdoQry_BodyPORealInQty: TFloatField;
    AdoQry_BodyPOInQty: TFloatField;
    AdoQry_Bodypolinecheck: TIntegerField;
    Edt_VendorCode: TLinkEdit;
    procedure FormCreate(Sender: TObject);
    procedure Act_SaveExecute(Sender: TObject);
    procedure EmployeeCodeCheck(Sender: TObject);
    procedure Act_DeleteLineExecute(Sender: TObject);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    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 FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure Edt_EmployeeCodeExit(Sender: TObject);
    procedure Edt_VendorCodeExit(Sender: TObject);
  private
    StrinGlist:TStrinGlist;
    POReferencedPrice:Integer;//是否参考价
    CurrentPcNo:String;//当前采购价格单号
    CurrentFormStatus:String;//当前窗体状态
    Function SavePoHistory(Status:String):Boolean;//保存历史记录
    Function SavePoLineHistory(Status:String):Boolean;//保存历史记录
    Function SavePoLineHistory1(Status:String;TmpQry:TAdoQuery):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_NewPo: TFrm_Pm_Enter_NewPo;

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_NewPo.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)+''''+','
            +QuotedStr(CurrentPcNo)+','
            +''''+IntToStr(Cmbx_PoType.ItemIndex)+''''+','
            +''''+Medt_PoDate.Text+''''+','
            +''''+Trim(Edt_PoTax.Text)+''''+','
            +''''+Trim(Edt_CurrencyCode.Text)+''''+','
            +''''+Trim(Edt_EmployeeCode.Text)+''''+','
            +''''+'0'+''''+','
            +''''+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_NewPo.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') 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_NewPo.SetStatus(CurrentStatus:String;var AnswerStatus,EnableControls:String);
begin
  Inherited;
  if Currentstatus='Add' then
  begin
    AnswerStatus:='Add';
    EnableControls:=' MEdt_PoDate,Edt_VendorCode,edt_rno,Cmbx_PoType,Edt_EmployeeCode,Edt_PoRemArk,';
  end;
  If Pos('Edit',Currentstatus)>0 then
  begin
    AnswerStatus:='PArtEdit';
    EnableControls:='MEdt_PoDate,Edt_EmployeeCode,edt_rno,Edt_PoRemArk,';
  end;
end;

procedure TFrm_Pm_Enter_NewPo.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;
  if Status='PArtEdit'then
    Act_DeleteLine.Enabled := True;

  PriceFields:='PoNoTaxPrice,PONoTaxAmount,PoTaxPrice,PoTaxAmount,';
  Application.ProcessMessages;
  With AdoQry_Head do
  begin
    if Status<>'Add' then
    begin
      Act_InsertLine.Enabled := True;
      if Status='ReadOnly'  then 
      Act_InsertLine.Enabled := False;
      Edt_PoNo.Text:=fieldbyname('PoNo').asstring;
      MEdt_PoDate.Text:=Formatdatetime('yyyy.mm.dd',fieldbyname('PoDate').AsDatetime);
      CurrentPcNo := fieldbyname('PcNo').AsString;
      edt_rno.Text:=fieldbyname('referenceno').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_CurrencyName.Text:=fieldbyname('CurrencyName').AsString;      
      Edt_Potax.Text:=IntToStr(fieldbyname('POTaxRate_Percent').AsInteger);
      Edt_PoReMArk.Text:=fieldbyname('PoReMArk').AsString;
      lbl_ordinal.Caption:=inttostr(fieldbyname('Vendorordinal').asinteger);
      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
      Act_InsertLine.Enabled := True;
      Edt_PoNo.Text:='';
      MEdt_Podate.Text:=Formatdatetime('yyyy.mm.dd',date);
      CurrentPcNo := '';
      edt_rno.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:='';
      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_rno.Enabled:=True;
  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_NewPo.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.DisableControls;
  AdoQry_Body.First;
  I:=1;
  While Not AdoQry_Body.Eof Do
  begin
    SqlText := ' Select Case when PcLine.FormalPricePass=1 then PcLine.PcTaxPrice_Formal '
              +'             else PcLine.PcTaxPrice   '
              +'        end as PcTaxPrice, '
              +'        Case When PcLine.FormalPricePass=1 then PcLine.PcNoTaxPrice_Formal '
              +'             else PcLine.PcNoTaxPrice '
              +'        end as PcNoTaxPrice, '
              +'        Case When PcLine.FormalPricePass=1 then 0 '
              +'             else  1 end as PcReferencedPrice '
            +' From PcLine '
            +' Where (ItemCode='''+Trim(AdoQry_Body.fieldbyname('ItemCode').AsString)+''''
            +' )And (PcNo='+QuotedStr(CurrentPcNo)+')'
            +' 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;
        AdoQry_Body.EnableControls;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -