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

📄 pm_pc_entry_d.pas

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

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Entry_Detail, Db, AdODB, ExtCtrls, StdCtrls, Mask, ExtEdit, linkedit;

Type
  TFrm_Pm_Pc_Entry_D = Class(TFrm_Base_Entry_Detail)
    Label1: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Lbl_ItemName: TLabel;
    MEdt_PcStArtDate: TMaskEdit;
    MEdt_PcendDate: TMaskEdit;
    Edt_PcStArtQty: TEdit;
    Edt_PcendQty: TEdit;
    Edt_PcTaxPrice: TEdit;
    Edt_PcNoTaxPrice: TEdit;
    CmBx_PcPriceType: TComboBox;
    Label11: TLabel;
    Label12: TLabel;
    ExtEdt_ItemCode: TLinkEdit;
    Edt_ItemName: TEdit;
    Lbl_UomName: TEdit;
    Lbl_PcLineStatus: TEdit;
    Label2: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Edt_PcTaxPrice_Formal: TEdit;
    Edt_PcNoTaxPrice_Formal: TEdit;
    procedure Edt_PcendQtyExit(Sender: TObject);
    procedure ItemCodeCheck(Sender: TObject);
    procedure ItemHint(Sender: TObject; var Key: Word; Shift: TShiftState);
    procedure Edt_PcTaxPriceExit(Sender: TObject);
    procedure Edt_PcNoTaxPriceExit(Sender: TObject);
    procedure MEdt_PcendDateExit(Sender: TObject);
    procedure Edt_PcStArtQtyExit(Sender: TObject);
    procedure btn_okClick(Sender: TObject);
    procedure ExtEdt_ItemCodeButtonClick(Sender: TObject);
    procedure Edt_PcTaxPrice_FormalExit(Sender: TObject);
    procedure Edt_PcNoTaxPrice_FormalExit(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    VendorCode:string;
    IsPriceRequestPass : Integer; //0:  不需要 1:需要
    procedure InitControls; Override;
    procedure SaveBodyData; Override;
    procedure SetStatus(CurrentStatus:String;var EnableControls:String); Override;
    function  ExistsPC(VendorCode,ItemCode,sdate,edate:string;sqty,eqty:double):boolean;
  end;

var
  Frm_Pm_Pc_Entry_D: TFrm_Pm_Pc_Entry_D;

implementation

uses Sys_Global;

{$R *.DFM}

function  TFrm_Pm_Pc_Entry_D.ExistsPC(VendorCode,ItemCode,sdate,edate:string;sqty,eqty:double):boolean;
var sqltext:string;
begin
  Result:=False;
  sqltext:='exec sp_Pcexists '+ QuotedStr(AdoQry_Body.fieldbyname('PcNo').AsString)+','
                                +IntToStr(AdoQry_Body.fieldbyname('PcLineId').AsInteger)+','
                                +IIFValue(status='Add','0','1')+','
                                +quotedstr(VendorCode)+','
                                +quotedstr(ItemCode)+','
                                +quotedstr(sdate)+','
                                +quotedstr(edate)+','
                                +floattostr(sqty)+','
                                +floattostr(eqty);
  Executesql(AdoQry_tmp,sqltext,0)          ;
  if AdoQry_tmp.RecordCount>0 then 
   begin
     Result:=True;
     exit;
   end;
  if status<>'Add' then exit;
  AdoQry_Body.First;
  while not AdoQry_Body.Eof do
  begin
   if    (        (AdoQry_Body.fieldbyname('pcstArtdate').asstring<=sdate)
               and (AdoQry_Body.fieldbyname('pcenddate').asstring<=sdate)  
           )
        or (       (AdoQry_Body.fieldbyname('pcstArtdate').asstring>=edate)
               and (AdoQry_Body.fieldbyname('pcenddate').asstring>=edate)  
           ) 
     and  (AdoQry_Body.fieldbyname('ItemCode').asstring=Trim(Extedt_ItemCode.text)  ) then
     begin
       AdoQry_Body.Next;
       continue;
     end;     
  if   (AdoQry_Body.fieldbyname('pcstArtqty').asfloat=0) and (AdoQry_Body.fieldbyname('pcendqty').asfloat=0) 
     and  (AdoQry_Body.fieldbyname('ItemCode').asstring=Trim(Extedt_ItemCode.text)  ) then
     begin
       AdoQry_Body.Next;
       continue;
     end;
                   
  if not  ( (             (AdoQry_Body.fieldbyname('pcstArtqty').asfloat<=sqty)
                     and (AdoQry_Body.fieldbyname('pcendqty').asfloat<=sqty)  )
            or  ( (AdoQry_Body.fieldbyname('pcstArtqty').asfloat>=eqty)
                       and (AdoQry_Body.fieldbyname('pcendqty').asfloat>=eqty)  )
             )
      and (AdoQry_Body.fieldbyname('ItemCode').asstring=Trim(Extedt_ItemCode.text)  )
    then
    begin
      Result:=True;
      break;
      exit;
    end;
    AdoQry_Body.Next;
  end;
end;


procedure TFrm_Pm_Pc_Entry_D.InitControls;
begin
  inherited;
  ExecuteSql(AdoQry_Tmp,'Select * from PmParam '
                       +' where PmParamCode=''ISPriceRequestPass''',0);
  IsPriceRequestPass := AdoQry_Tmp.fieldbyname('PmParamValueN').AsInteger;                       
  with AdoQry_Body do
  begin
    ExtEdt_ItemCode.Text:=fieldbyname('ItemCode').AsString;
    Lbl_ItemName.Caption:=fieldbyname('ItemName').AsString;
    Edt_ItemName.Text :=fieldbyname('ItemName').AsString;
    Lbl_UomName.Text :=fieldbyname('UomName').AsString;
    if (Status='Add') then
    begin
      MEdt_PcStArtDate.Text := fieldbyname('PcStArtDate').AsString;
      If Trim(fieldbyname('PcStArtDate').AsString) = '' then
      MEdt_PcStArtDate.Text:=FormatDateTime('yyyy.mm.dd',Now);
      MEdt_PcendDate.Text := fieldbyname('PcendDate').AsString;
      If Trim(fieldbyname('PcendDate').AsString) = '' then 
      MEdt_PcendDate.Text:=FormatDateTime('yyyy.mm.dd',Now);
      CmBx_PcPriceType.ItemIndex:=0;
//      CmBx_PcReferencedPrice.ItemIndex:=0;
      Edt_PcTaxPrice.Text:='0';
      Edt_PcNoTaxPrice.Text:='0';
      Edt_PcTaxPrice_Formal.Text := '0';
      Edt_PcNoTaxPrice_Formal.Text := '0';
      Edt_PcStArtQty.Text:=IntToStr(fieldbyname('PcStArtQty').AsInteger);
      Edt_PcendQty.Text:=IntToStr(fieldbyname('PcendQty').AsInteger);
    end
    else
    begin
      MEdt_PcStArtDate.Text:=FormatDateTime('yyyy.mm.dd',fieldbyname('PcStArtDate').AsDateTime);
      MEdt_PcendDate.Text:=FormatDateTime('yyyy.mm.dd',fieldbyname('PcendDate').AsDateTime);
      CmBx_PcPriceType.ItemIndex:=fieldbyname('PcPriceType').AsInteger;
//      CmBx_PcReferencedPrice.ItemIndex:=fieldbyname('PCReferencedPrice').AsInteger;
      Edt_PcTaxPrice.Text:=fieldbyname('PcTaxPrice').AsString;
      Edt_PcNoTaxPrice.Text:=fieldbyname('PcNoTaxPrice').AsString;
      Edt_PcTaxPrice_Formal.Text:=FloatToStr(fieldbyname('PcTaxPrice_Formal').AsFloat);
      Edt_PcNoTaxPrice_Formal.Text:=FloatToStr(fieldbyname('PcNoTaxPrice_Formal').AsFloat);
      Edt_PcStArtQty.Text:=IntToStr(fieldbyname('PcStArtQty').AsInteger);
      Edt_PcendQty.Text:=IntToStr(fieldbyname('PcendQty').AsInteger);
      if fieldbyname('PcLineStatus').AsString='1' then
        Lbl_PcLineStatus.Text:='已批准'
      else
        Lbl_PcLineStatus.Text:='未批准';
    end;
    if Status='Add' then
      Lbl_PcLineStatus.Text:='未批准';
  end;
end;

procedure TFrm_Pm_Pc_Entry_D.SaveBodyData;
begin//把Form的控件值写入缓存,要Post
  inherited;
  with AdoQry_Body do
  begin
    fieldbyname('ItemCode').AsString:=ExtEdt_ItemCode.Text;
    fieldbyname('ItemName').AsString:=Edt_ItemName.Text;
    fieldbyname('UomName').AsString:=Lbl_UomName.text;
    fieldbyname('PcStArtDate').AsString:=MEdt_PcStArtDate.Text;
    fieldbyname('PcendDate').AsString:=MEdt_PcendDate.Text;
    fieldbyname('PcStArtQty').AsString:=Edt_PcStArtQty.Text;
    fieldbyname('PcendQty').AsString:=Edt_PcendQty.Text;
    fieldbyname('PcTaxPrice').AsString:=Edt_PcTaxPrice.Text;
    fieldbyname('PcNoTaxPrice').AsString:=Edt_PcNoTaxPrice.Text;
    fieldbyname('PcTaxPrice_Formal').AsString := Edt_PcTaxPrice_Formal.Text;
    fieldbyname('PcNoTaxPrice_Formal').AsString := Edt_PcNoTaxPrice_Formal.Text;    
    fieldbyname('PcPriceType').AsInteger:=CmBx_PcPriceType.ItemIndex;
//    fieldbyname('PCReferencedPrice').AsInteger:=CmBx_PcReferencedPrice.ItemIndex;
    if Status='Add' then
    begin
      fieldbyname('PcLineStatus').AsString:=IIFString(IsPriceRequestPass=0,'1','0');
      fieldbyname('ReferencePricePass').AsInteger := IIFInteger((IsPriceRequestPass=0) and (StrToFloat(Edt_PcNoTaxPrice.Text)>0),1,0);
      fieldbyname('FormalPricePass').AsInteger := IIFInteger((IsPriceRequestPass=0) and (StrToFloat(Edt_PcNoTaxPrice_Formal.Text)>0),1,0);
    end
    else 
    begin
      If IsPriceRequestPass = 0 then 
      begin
        fieldbyname('PcLineStatus').AsString:=IIFString((StrToFloat(Edt_PcNoTaxPrice.Text)>0) or (StrToFloat(Edt_PcNoTaxPrice_Formal.Text)>0),'1','0');
        fieldbyname('ReferencePricePass').AsInteger := IIFInteger( (StrToFloat(Edt_PcNoTaxPrice.Text)>0),1,fieldbyname('ReferencePricePass').AsInteger);
        fieldbyname('FormalPricePass').AsInteger := IIFInteger((StrToFloat(Edt_PcNoTaxPrice_Formal.Text)>0),1,fieldbyname('FormalPricePass').AsInteger);
      end;      
    end;
    Post;
  end;
end;

procedure TFrm_Pm_Pc_Entry_D.Edt_PcendQtyExit(Sender: TObject);
begin
  inherited;
  if(ActiveControl.Name='btn_Cancel')then
    Abort;
  FloatCheck(Sender);
  if (StrToFloat(Edt_PcStArtQty.Text)>=StrToFloat(Edt_PcendQty.Text))
    and(not((StrToFloat(Edt_PcStArtQty.Text)=0)and(StrToFloat(Edt_PcendQty.Text)=0))) then
  begin
    DispInfo('起始数量不能大于等于终止数量',3);
    TWinControl(Sender).SetFocus;
    Abort;
  end;
end;

procedure TFrm_Pm_Pc_Entry_D.ItemCodeCheck(Sender: TObject);
var
  SqlText:string;
begin
  if(ActiveControl.Name='btn_Cancel')then
    Abort;
  SqlText:=' Select * from Item '
           +' where ItemUsable=1 And ItemCode='''+Trim(ExtEdt_ItemCode.Text)+''''
           +'   and PmCode in (1,2,3) ';
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.Text :=SqlText;
  AdoQry_Tmp.Open;
  if  AdoQry_Tmp.Eof then
  begin
    DispInfo('该物料无效,不能输入!',3);
    TwinControl(sender).setfocus;
    Abort;
  end
  else
    Edt_ItemName.Text :=  AdoQry_Tmp.fieldbyname('ItemName').AsString;

  CommonCodeCheck(Sender,AdoQry_Tmp,'ItemName','物料名称','ItemCode',
    '物料代码','Item','PmCode In (1,2,3)');
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:='Select Item.PmCode,Uom.UomName'
    +' From Item Join Uom On Item.UomCode=Uom.UomCode'
    +' Where Item.ItemCode='''+TExtEdit(Sender).Text+'''';
  AdoQry_Tmp.Open;
  Lbl_UomName.Text:=AdoQry_Tmp.fieldbyname('UomName').AsString;
  if AdoQry_Tmp.fieldbyname('PmCode').AsString='1' then
    CmBx_PcPriceType.ItemIndex:=0
  else
    CmBx_PcPriceType.ItemIndex:=1;
end;

procedure TFrm_Pm_Pc_Entry_D.ItemHint(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if(Key=120)then
  begin
    CommonHint(Sender,AdoQry_Tmp,'ItemName','物料名称','ItemCode',
      '物料代码','Item','PmCode In (1,2,3) and ItemUsable=1 ');
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.Text:='Select Item.PmCode,Uom.UomName'
      +' From Item Join Uom On Item.UomCode=Uom.UomCode'
      +' Where Item.ItemCode='''+TExtEdit(Sender).Text+'''';
    AdoQry_Tmp.Open;
    Lbl_UomName.Text:=AdoQry_Tmp.fieldbyname('UomName').AsString;
    if AdoQry_Tmp.fieldbyname('PmCode').AsString='1' then
      CmBx_PcPriceType.ItemIndex:=0
    else
      CmBx_PcPriceType.ItemIndex:=1;
  end;
end;

procedure TFrm_Pm_Pc_Entry_D.Edt_PcTaxPriceExit(Sender: TObject);
begin
  inherited;
  FloatCheck(Sender);
  if Changed then
  begin
    try
      Edt_PcNoTaxPrice.Text:=FormatFloat('0.000000',(StrToFloat(Edt_PcTaxPrice.Text)/(1+
        AdoQry_Head.fieldbyname('PCTaxRate_Percent').AsFloat/100)));
    except
    end;
  end;
end;

procedure TFrm_Pm_Pc_Entry_D.Edt_PcNoTaxPriceExit(Sender: TObject);
begin
  inherited;
  FloatCheck(Sender);
  if Changed then
  begin
    try
      Edt_PcTaxPrice.Text:=FloatToStr((StrToFloat(Edt_PcNoTaxPrice.Text)*
        (1+AdoQry_Head.fieldbyname('PCTaxRate_Percent').AsFloat/100)));
    except
    end;
  end;
end;

procedure TFrm_Pm_Pc_Entry_D.SetStatus(CurrentStatus: String;
  var EnableControls: String);
begin
  inherited;
  ExtendCaption:=False;
  if (CurrentStatus='AllEdit') and (IsPriceRequestPass=1) then
  begin
    if (AdoQry_Body.fieldbyname('FormalPricePass').AsInteger=0)
      or (AdoQry_Body.fieldbyname('ReferencePricePass').AsInteger=0)  then
    begin
      EnableControls:=IifString((AdoQry_Body.fieldbyname('FormalPricePass').AsInteger=1)
                                or (AdoQry_Body.fieldbyname('ReferencePricePass').AsInteger=1),
                                '',
                                'ExtEdt_ItemCode,MEdt_PcStArtDate,MEdt_PcendDate'
                                +',Edt_PcStArtQty,Edt_PcendQty,')
                     +IifString( (AdoQry_Body.fieldbyname('FormalPricePass').AsInteger=0)
                                and (Param1='0'),
                                'Edt_PcTaxPrice_Formal,Edt_PcNoTaxPrice_Formal,',
                                '')
                     +IifString((AdoQry_Body.fieldbyname('ReferencePricePass').AsInteger=0)

⌨️ 快捷键说明

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