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

📄 pm_fakepc_d.pas

📁 一个MRPII系统源代码版本
💻 PAS
字号:
unit Pm_FakePc_D;

Interface

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

Type
  TFrm_Pm_FakePc_D = Class(TFrm_Base_Entry_Detail)
    Label1: TLabel;
    lbl_ItemName: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    lbl_UomName: TLabel;
    Extedt_ItemCode: TExtEdit;
    Extedt_Price: TExtEdit;
    Extedt_Amount: TExtEdit;
    Extedt_memo: TExtEdit;
    Label2: TLabel;
    Label8: TLabel;
    Extedt_qty: TExtEdit;
    medt_Date: TMaskEdit;
    procedure Extedt_PriceExit(Sender: TObject);
    procedure Extedt_AmountExit(Sender: TObject);
    procedure Extedt_qtyExit(Sender: TObject);
    procedure Extedt_ItemCodeExit(Sender: TObject);
    procedure Extedt_ItemCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    pcno,FakePcno,pcPriceType,hastax:string;
    { Private declarations }
  public
    { Public declarations }
    procedure InitControls;Override;
    procedure SetStatus(CurrentStatus:String;var EnableControls:String); Override;
    procedure SetFormParam(FrmParam1,FrmParam2,FrmParam3,FrmParam4,
      FrmParam5,FrmParam6:String);Override;
    procedure SaveBodyData;Override;
  end;

var
  Frm_Pm_FakePc_D: TFrm_Pm_FakePc_D;

implementation

{$R *.DFM}
uses Sys_Global, Sys_Hint;

procedure TFrm_Pm_FakePc_D.InitControls;
begin//根据AdoQry_Body当前值,初始化Form的控件
  inherited;
  with AdoQry_Body do
  begin
    if status='Add' then
    begin
      Extedt_ItemCode.text:='';
      lbl_ItemName.Caption:='';
      lbl_UomName.Caption:='';
      Extedt_qty.text:='0';
      Extedt_Price.text:='0';
      Extedt_Amount.text:='0';
      medt_Date.text:=LoginDate;
      Extedt_memo.text:='';
    end
    else
    begin
      Extedt_ItemCode.text:=fieldbyname('ItemCode').asstring;
      lbl_ItemName.Caption:=fieldbyname('ItemName').asstring;
      lbl_UomName.Caption:=fieldbyname('UomName').asstring;
      Extedt_qty.text:=fieldbyname('qty').asstring;
      Extedt_Price.text:=fieldbyname('Price').asstring;
      Extedt_Amount.text:=fieldbyname('Amount').asstring;
      medt_Date.text:=fieldbyname('Finishdate').asstring;
      Extedt_memo.text:=fieldbyname('remArk').asstring;
    end;
  end;
end;

procedure TFrm_Pm_FakePc_D.SaveBodyData;
begin//把Form的控件值写入缓存,要Post
  inherited;
  with AdoQry_Body do
  begin
    if status='Add' then
      fieldbyname('pclineno').asinteger:=recordCount+1;
    fieldbyname('ItemCode').AsString:=ExtEdt_ItemCode.Text;
    fieldbyname('ItemName').AsString:=Lbl_ItemName.Caption;
    fieldbyname('UomName').AsString:=lbl_UomName.Caption;
    fieldbyname('qty').AsString:=ExtEdt_qty.Text;
    fieldbyname('Price').asstring:=Extedt_Price.text;
    fieldbyname('Amount').asstring:=Extedt_Amount.text;
    fieldbyname('Finishdate').asstring:=medt_Date.text;
    fieldbyname('remArk').AsString:=ExtEdt_memo.Text;
    fieldbyname('FakePcno').text:=FakePcno;
    Post;
  end;
end;

procedure TFrm_Pm_FakePc_D.SetStatus(CurrentStatus:String;var EnableControls:String);
begin
  inherited;
  if CurrentStatus='Add' then
  begin
    if AdoQry_Body.RecordCount>20 then
    begin
      EnableControls:='None';
      DispInfo('本单据最多只允许输入二十条记录',1);
    end;
    SetFocus_Control:=ExtEdt_ItemCode;
  end
  else if CurrentStatus='AllEdit' then
    begin
      EnableControls:='Extedt_ItemCode,Extedt_qty,Extedt_Price,Extedt_Amount,medt_Date,Extedt_memo,'
    end
  else
    EnableControls:='None';
end;

procedure TFrm_Pm_FakePc_D.SetFormParam(FrmParam1,FrmParam2,FrmParam3,FrmParam4,
      FrmParam5,FrmParam6:String);
begin
  inherited;
  pcno:=FrmParam1;
  FakePcno:=FrmParam4;
  pcPriceType:=FrmParam3;
  hastax:=FrmParam5;
end;

procedure TFrm_Pm_FakePc_D.Extedt_PriceExit(Sender: TObject);
begin
  inherited;
  if activecontrol.Name='btn_Cancel' then
     exit;
  floatcheck(sender);
  if (strtofloat(Extedt_Price.text)<=0) then
  begin
    DispInfo('单价必须大于零!',1);
    twincontrol(sender).setfocus;
    abort;
  end;
  Extedt_Amount.text:=floattostr(strtofloat(Extedt_qty.text)*strtofloat(Extedt_Price.text))
end;

procedure TFrm_Pm_FakePc_D.Extedt_AmountExit(Sender: TObject);
begin
  inherited;
  if activecontrol.Name='btn_Cancel' then
     exit;
  floatcheck(sender);
  if strtofloat(Extedt_Amount.text)<=0 then
  begin
    DispInfo('金额必须大于零!',1);
    twincontrol(sender).setfocus;
    abort;
  end;
end;

procedure TFrm_Pm_FakePc_D.Extedt_qtyExit(Sender: TObject);
var
  tmp_StArtqty,tmp_Endqty:real;
begin
  inherited;
  if activecontrol.Name='btn_Cancel' then
     exit;
  //数字有效性检验
  floatcheck(sender);
  //数量必须大于零的检验
  if strtofloat(Extedt_qty.text)<=0 then
  begin
    DispInfo('数量必须大于零!',1);
    twincontrol(sender).setfocus;
    abort;
  end;
  //如果系统合同号不为空,则从PCLINE中取PCSTArTQTY,PCendQTY,
  //PCSTArTQTY,PCendQTY都不为零,表示录入数量不受限制,否则
  //录入的数量就受到这两个数量的约束。
  //如果系统合同号为空,则数量不受约束
  if pcno<>'' then
  begin
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.text:=
        'select pcstArtqty,pcendqty '+
         ' from pcline '+
         ' where pcno='''+pcno+''''+
         '   and ItemCode='''+Extedt_ItemCode.text+''''+
         '   and pcPriceType='+pcPriceType;
      open;
      tmp_StArtqty:=fieldbyname('pcstArtqty').asfloat;
      tmp_Endqty:=fieldbyname('pcendqty').asfloat;
    end;
    if (tmp_StArtqty=0) and  (tmp_Endqty=0) then
    begin
    end
    else
    begin
      if (strtofloat(Trim(Extedt_qty.text))<tmp_StArtqty) or
         (strtofloat(Trim(Extedt_qty.text))>tmp_Endqty) then
      begin
        DispInfo('数量必须介于系统数量'+floattostr(tmp_StArtqty)+'与'+floattostr(tmp_Endqty)+'之间!',1);
        twincontrol(sender).setfocus;
        abort;
      end;
    end;
  end;
  //数量确定后,如果有单价,则计算金额
  if Extedt_Price.text<>'' then
     Extedt_Amount.text:=floattostr(strtofloat(Extedt_qty.text)*strtofloat(Extedt_Price.text))
end;

procedure TFrm_Pm_FakePc_D.Extedt_ItemCodeExit(Sender: TObject);
begin
  inherited;
  if(ActiveControl.Name='btn_Cancel')then
    Abort;
  //不允许物料代码为空
  if Extedt_ItemCode.text='' then
  begin
    DispInfo('物料代码不能为空!',1);
    twincontrol(sender).setfocus;
    abort;
  end;
  //不允许物料代码重复
  if status='Add' then
  begin
    AdoQry_Body.First;
    if AdoQry_Body.locate('ItemCode',Extedt_ItemCode.text,[]) then
    begin
      DispInfo('该物料已经存在,不允许增加或修改!',1);
      TWinControl(Sender).SetFocus;
      Abort;
    end;
  end
  else
  begin
    //修改时的检验
    if Extedt_ItemCode.text<>AdoQry_Body.fieldbyname('ItemCode').asstring then
    begin
      AdoQry_Body.First;
      if AdoQry_Body.locate('ItemCode',Extedt_ItemCode.text,[]) then
      begin
        DispInfo('该物料已经存在,不允许增加或修改!',1);
        TWinControl(Sender).SetFocus;
        Abort;
      end
    end;
  end;
  //这是基类的一个参数,用于控制ONEXIT事件发生,如果物料代码没有改变,则数量,单价,金额就不会改变
  if not Changed then
  exit;
  //物料代码定后,如果系统合同号存在,检验合同中是否存该物料,如不存在,不允许录入
  //否则,从PCLINE中取出单价,数量,及完成日期显示
  if pcno<>'' then
  begin
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.text:=
        'select pcline.ItemCode,'+
               'pcline.pctaxPrice,'+
               'pcline.pcnotaxPrice,'+
               'pcline.pcstArtdate,'+
               'pcline.pcenddate,'+
               'pcline.pcstArtqty,'+
               'pcline.pcendqty,'+
               'pcline.pcPriceType, '+
               'Item.ItemName,'+
               'Uom.UomName '+
         ' from pcline '+
         '  join Item on pcline.ItemCode=Item.ItemCode '+
         '  join Uom on Item.UomCode=Uom.UomCode '+
         ' where pcline.pcno='''+pcno+''''+
         '   and pcline.ItemCode='''+Extedt_ItemCode.text+''''+
         '   and pcline.pcPriceType='+pcPriceType;
      open;
      if recordCount<1 then
      begin
        DispInfo('系统合同中不存在该物料或合同类型不正确!',1);
        twincontrol(sender).setfocus;
        abort;
      end;
      medt_Date.text:=fieldbyname('pcenddate').asstring;
      Extedt_qty.text:=fieldbyname('pcendqty').asstring;
      if hastax='是' then
      begin
        Extedt_Price.text:=fieldbyname('pctaxPrice').asstring;
        Extedt_Amount.text:=floattostr(fieldbyname('pcendqty').asfloat*fieldbyname('pctaxPrice').asfloat)
      end
      else
      begin
        Extedt_Price.text:=fieldbyname('pcnotaxPrice').asstring;
        Extedt_Amount.text:=floattostr(fieldbyname('pcendqty').asfloat*fieldbyname('pcnotaxPrice').asfloat)
      end;
      lbl_ItemName.Caption:=fieldbyname('ItemName').asstring;
      lbl_UomName.Caption:=fieldbyname('UomName').asstring;
    end;
  end
  else
  begin
    //如果系统合同号不存在,则从物料主文件中取出名称,单位显示。
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.text:=
        ' select i.ItemCode,i.ItemName,u.UomName '+
        '  from Item i,Uom u '+
        '  where i.ItemCode='''+Extedt_ItemCode.text+''''+
        '    and i.ItemUsable=1 '+
        '    and i.UomCode=u.UomCode ';
      open;
      if recordCount<1 then
      begin
        DispInfo('该物料不存在!',1);
        twincontrol(sender).setfocus;
        abort;
      end;
      lbl_ItemName.Caption:=fieldbyname('ItemName').asstring;
      lbl_UomName.Caption:=fieldbyname('UomName').asstring;
    end;
  end;
end;

procedure TFrm_Pm_FakePc_D.Extedt_ItemCodeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  if Key=120 then
  begin
    if pcno<>'' then
    begin
      Frm_Sys_Hint:=TFrm_Sys_Hint.Create(nil);
      Frm_Sys_Hint.InitForm(DBConnect,
         ' select pcline.ItemCode as ''物料代码'''
         +',Item.ItemName as ''物料描述'''
         +',pcline.pclineid as ''行号'''
         +' from pcline '+
         '  join Item on pcline.ItemCode=Item.ItemCode '+
         '  where pcline.pcno='''+pcno+''''+
         '    and pcline.pcPriceType='+pcPriceType+
         '  Order by pcline.pclineid ');
      if Frm_Sys_Hint.ShowModal=mrOk then
      begin
        TEdit(Sender).Text:=Frm_Sys_Hint.GetValueByFieldIndex(0);
        lbl_ItemName.Caption:=Frm_Sys_Hint.GetValueByFieldIndex(1);
      end;
      Frm_Sys_Hint.Release;
    end
    else
    begin
      inoutItemHint(sender,key,Shift);
    end;
  end;
end;

end.

⌨️ 快捷键说明

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