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

📄 sfc_mnrequestoverplan_d.pas

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

Interface

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

Type
  TFrm_Sfc_MnRequestOverPlan_D = Class(TFrm_Base_Entry_Detail)
    Extedt_MoRequestqty: TExtEdit;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    lbl_ItemName: TLabel;
    Label4: TLabel;
    lbl_MoCtrlqty: TLabel;
    Label6: TLabel;
    lbl_MoRealqty: TLabel;
    Label8: TLabel;
    lbl_onhandInv: TLabel;
    Label12: TLabel;
    lbl_UomName: TLabel;
    edt_memo: TEdit;
    Label5: TLabel;
    Extedt_Batchno: TExtEdit;
    Label7: TLabel;
    Extedt_ItemCode: TLinkEdit;
    procedure FormCreate(Sender: TObject);
    procedure FloatCheck(Sender: TObject);
    procedure InOutItemCodeCheck(Sender: TObject);
    procedure Extedt_BatchnoExit(Sender: TObject);
    procedure Extedt_BatchnoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    tmp_Mono,tmp_MoLineno,tmp_Date,tmp_ItemCode,tmp_MoRequestid,oldmoRequestqty,whCode,WhPositionCode:string;
    tmp_ItemListid,tmp_Parentid,tmp_alterNative:string;
    tmp_BodymoRequestqty,tmp_MoCtrlqty,tmp_MoRequestqty,tmp_Bomqty,tmp_BomScrAp_Percent:real;
    { Private declarations }
  public
    procedure InitControls; Override;//根据AdoQry_Body当前值,初始化Form的控件
    procedure SaveBodyData; Override;//把Form的控件值写入缓存,要Post
    //设置在部分修改状态下,那些控件Enable=True
    procedure SetStatus(CurrentStatus:String;var EnableControls:String);Override;
    procedure SetFormParam(frmParam1,frmParam2,frmParam3,frmParam4,frmParam5,frmParam6:string);Override;
    { Public declarations }
  end;

var
  Frm_Sfc_MnRequestOverPlan_D: TFrm_Sfc_MnRequestOverPlan_D;

implementation

uses Sys_Global,Inv_Global;
{$R *.DFM}
procedure TFrm_Sfc_MnRequestOverPlan_D.InitControls;
begin
  inherited;

  with AdoQry_Body do
  begin
    if status='Add' then
    begin
      Extedt_ItemCode.text:='';
      Extedt_MoRequestqty.text:='0';
      lbl_ItemName.Caption:='';
      lbl_MoCtrlqty.Caption:='0';
      lbl_MoRealqty.Caption:='0';
      lbl_onhandInv.Caption:='0';
      lbl_UomName.Caption:='';
      edt_memo.text:='';
      Extedt_Batchno.text:='';
    end
    else
    begin
      Extedt_ItemCode.text:=fieldbyname('ItemCode').asstring;
      lbl_ItemName.Caption:=fieldbyname('ItemName').asstring;
      Extedt_MoRequestqty.text:=fieldbyname('moRequestqty').asstring;
      Extedt_Batchno.text:=fieldbyname('Batchno').asstring;
      if fieldbyname('moCtrlqty').asstring<>'' then
        lbl_MoCtrlqty.Caption:=fieldbyname('moCtrlqty').asstring
      else
        lbl_MoCtrlqty.Caption:='0';
      if fieldbyname('onhandInv').asstring<>'' then
        lbl_onhandInv.Caption:=fieldbyname('onhandInv').asstring
      else
        lbl_onhandInv.Caption:='0';

      lbl_MoRealqty.Caption:=fieldbyname('MoRealqty').asstring;
      edt_memo.text:=fieldbyname('BilllineremArk').asstring;
    end;

    if (status='AllEdit')   then //and (fieldbyname('moCtrlqty').asinteger<>0) then
      Extedt_ItemCode.ReadOnly :=True
    else
      Extedt_ItemCode.ReadOnly :=False;

    //tmp_Mono、tmPMoLineno、tmp_MoRequestid不能从fieldbyname(...)
    //中取,因为Grid可能为空
    tmp_ItemCode:=fieldbyname('ItemCode').asstring;
    oldmoRequestqty:=fieldbyname('moRequestqty').asstring;

     //替代件用
     tmp_alterNative:=fieldbyname('alterNative').asstring;
    if fieldbyname('alterNative').asstring='1' then
    begin
      tmp_Parentid:=fieldbyname('Parentid').asstring;
      tmp_ItemListid:=fieldbyname('ItemListid').asstring;
      tmp_alterNative:=fieldbyname('alterNative').asstring;
      tmp_Bomqty:=fieldbyname('Bomqty').asfloat;
      tmp_BomScrAp_Percent:=fieldbyname('BomScrAp_Percent').asfloat;
      tmp_MoRequestqty:=fieldbyname('moRequestqty').asfloat;
      First;
      locate('ItemListid',tmp_Parentid,[]);
      tmp_BodymoRequestqty:=fieldbyname('moRequestqty').asfloat;
      tmp_MoCtrlqty:=fieldbyname('moCtrlqty').asfloat;
      lbl_MoCtrlqty.Caption:=floattostr(tmp_MoCtrlqty);
      First;
      locate('ItemListid',tmp_ItemListid,[]);
    end;
  end;
end;

procedure TFrm_Sfc_MnRequestOverPlan_D.SaveBodyData;
var
  sqltext:string;
begin//把Form的控件值写入缓存,要Post
 inherited;
  with AdoQry_Body do
  begin
    if status='Add' then
    begin
      fieldbyname('UomName').AsString:=lbl_UomName.Caption;
      fieldbyname('MoRealqty').Asstring:='0';
    end;
    fieldbyname('ItemCode').AsString:=ExtEdt_ItemCode.Text;
    fieldbyname('tmpItemCode').AsString:=ExtEdt_ItemCode.Text;
    fieldbyname('ItemName').AsString:=lbl_ItemName.Caption;
    fieldbyname('mono').AsString:=tmp_Mono;
    fieldbyname('MoLineno').Asstring:=tmp_MoLineno;
    fieldbyname('moRequestqty').Asstring:=Extedt_MoRequestqty.Text;
    fieldbyname('onhandInv').asstring:=lbl_onhandInv.Caption;
    fieldbyname('BilllineremArk').asstring:=edt_memo.text;
    fieldbyname('Batchno').asstring:=Extedt_Batchno.text;
    Post;
    if fieldbyname('alterNative').asstring='1' then
    begin
      First;
      locate('ItemListid',tmp_Parentid,[]);
      edit;
      //替代虚项请领数量=替代虚项请领数量+(当前替代件请领数-旧请领数)/定额/损耗比
      fieldbyname('moRequestqty').asfloat:=fieldbyname('moRequestqty').asfloat+
         (strtofloat(Extedt_MoRequestqty.text)-tmp_MoRequestqty)/tmp_Bomqty/(1+tmp_BomScrAp_Percent/100);
      post;
      First;
      locate('ItemListid',tmp_ItemListid,[]);
    end;
  end;
end;

procedure TFrm_Sfc_MnRequestOverPlan_D.FormCreate(Sender: TObject);
begin
  inherited;
  SetFocus_Control:=Extedt_ItemCode;//设置新增时要聚焦的控件
end;

procedure TFrm_Sfc_MnRequestOverPlan_D.SetStatus(CurrentStatus:String;var EnableControls:String);
begin
  inherited;
end;

procedure TFrm_Sfc_MnRequestOverPlan_D.FloatCheck(Sender: TObject);
var
  saveplace:tBookmArk;
  I:integer;
begin
  inherited;
  if ActiveControl.Name='btn_Cancel' then
    exit;

  if (Trim(Extedt_MoRequestqty.text)='') or (Extedt_MoRequestqty.text='0') then
  begin
    if (oldmoRequestqty='0') or (oldmoRequestqty='') then
    begin
      DispInfo('请领数量不能为零或为空!',1);
      twincontrol(sender).setfocus;
      abort;
    end
    else
    begin
      if (BatchCtrl(AdoQry_tmp,Extedt_ItemCode.text)) and (Extedt_Batchno.text<>'') then
      begin
        Extedt_Batchno.text:='';
      end;
    end;

  end;

  if strtofloat(Extedt_MoRequestqty.text)>strtofloat(lbl_onhandInv.Caption) then
  begin
    DispInfo('请领数量不能大于现有可用库存!',1);
    twincontrol(sender).setfocus;
    abort;
  end;

  //不是替代件的冲销检验
  if tmp_alterNative<>'1' then
  begin
    if  (strtofloat(Extedt_MoRequestqty.text)<0) and
        ((-1)*strtofloat(Extedt_MoRequestqty.text)>
        (strtoint(lbl_MoRealqty.Caption)-
        strtofloat(lbl_MoCtrlqty.Caption)))
    then
    begin
      DispInfo('冲销的数量不能大于累计领料数量-限额数量!',1);
      abort;
    end;
  end
  else
  begin
    //替代件的冲销检验
    if  (strtofloat(Extedt_MoRequestqty.text)<0) and
        ((-1)*strtofloat(Extedt_MoRequestqty.text)>
        strtoint(lbl_MoRealqty.Caption)) then
    begin
      DispInfo('冲销的数量不能大于累计领料数量',1);
      abort;
    end;
  {  if  (strtofloat(Extedt_MoRequestqty.text)<0) and
        ((-1)*strtofloat(Extedt_MoRequestqty.text)>
        (strtoint(lbl_MoRealqty.Caption)-
        strtofloat(lbl_MoCtrlqty.Caption)))
        (tmp_MoCtrlqty-tmp_BodymoRequestqty)*tmp_Bomqty*(1+BomScrAp_Percent/100)
    then
    begin
      DispInfo('冲销的数量不能大于累计领料数量-限额数量!',1);
      abort;
    end;}
  end;

  saveplace:=AdoQry_Body.GetBookmArk;
  AdoQry_Body.EnableControls;
  AdoQry_Body.First;
  for I:=0 to AdoQry_Body.RecordCount-1 do
  begin
    if (strtofloat(Extedt_MoRequestqty.text)*AdoQry_Body.fieldbyname('moRequestqty').asfloat<0) and
     (AdoQry_Body.fieldbyname('ItemCode').asstring<>Trim(ExtEdt_ItemCode.text))
     then
     begin
        DispInfo('同一请领,不能出现正负数量混合的情况!',1);
       Extedt_MoRequestqty.setfocus;
       AdoQry_Body.GotoBookmArk(saveplace);
       AdoQry_Body.FreeBookmArk (saveplace);
       AdoQry_Body.EnableControls;
       abort;
     end;
     AdoQry_Body.next;
  end;
  AdoQry_Body.GotoBookmArk(saveplace);
  AdoQry_Body.FreeBookmArk (saveplace);
  AdoQry_Body.EnableControls;
end;

procedure TFrm_Sfc_MnRequestOverPlan_D.SetFormParam(frmParam1, frmParam2,
  frmParam3, frmParam4, frmParam5, frmParam6: string);
begin
  inherited;
  tmp_Mono:=frmParam1;
  tmp_MoLineno:=frmParam2;
  whCode:=frmParam3;
  WhPositionCode:=frmParam4;
  tmp_Date:=frmParam5;
end;

procedure TFrm_Sfc_MnRequestOverPlan_D.InOutItemCodeCheck(Sender: TObject);
var
  CurrentInvfields:string;
begin
  inherited;
  if ActiveControl.Name='btn_Cancel' then
    exit;
  if not DefaultWHCheck(AdoQry_tmp,whCode,Extedt_ItemCode.text) then
  begin
    twincontrol(sender).setfocus;
    abort;
  end;

  if status='Add' then
  begin
    //根据当前货位决定取CurrentInv中的那一个字段
    CurrentInvfields:=getInvfield(AdoQry_tmp,whCode,WhPositionCode,'CurrentInv');
    with AdoQry_Tmp do
    begin
      Close;
      SQL.clear;
      SQL.Add(
         'Select Count(*) as rCount '+
           'From mnItemList '+
           'Where ItemCode='''+TEdit(Sender).Text+''' and '+
              'mono='''+tmp_Mono+''' and '+
              'MoLineno='+tmp_MoLineno);
      Open;
      if fieldbyname('rCount').asinteger>0 then
      begin
        DispInfo('该物料已经存在,不允许增加或修改!',1);
        TWinControl(Sender).SetFocus;
        Abort;
      end
      else
      begin
        AdoQry_Body.First;
        if AdoQry_Body.locate('ItemCode',Extedt_ItemCode.text,[]) then
        begin
            DispInfo('该物料已经存在,不允许增加或修改!',1);
            TWinControl(Sender).SetFocus;
            Abort;
        end
        else
        begin
          //显示物料描述
          //显示计量单位
          Close;
          sql.clear;
          sql.Add('select UomName,Item.ItemName from Uom,Item where Item.ItemCode='''+Extedt_ItemCode.text+''' and Item.UomCode=Uom.UomCode ');
          open;
          lbl_UomName.Caption:=fieldbyname('UomName').asstring;
          lbl_ItemName.Caption:=fieldbyname('ItemName').asstring;

          //显示可用库存

          Close;
          sql.clear;
          sql.Add('select '+CurrentInvfields+ ' as onhandInv from CurrentInv where whCode='''+whCode+''' and WhPositionCode='''+WhPositionCode+''' and ItemCode='''+Extedt_ItemCode.text+'''');
          open;
          if not eof then
            lbl_onhandInv.Caption:=fieldbyname('onhandInv').asstring
          else
          lbl_onhandInv.Caption:='0';
          lbl_MoCtrlqty.Caption:='0';
          lbl_MoRealqty.Caption:='0';
        end;
      end;
    end;
  end;
end;

procedure TFrm_Sfc_MnRequestOverPlan_D.Extedt_BatchnoExit(Sender: TObject);
begin
  inherited;
  if ActiveControl.Name='btn_Cancel' then
    exit;
  if (not BatchCtrl(AdoQry_tmp,Extedt_ItemCode.text)) then
  begin
    if Trim(Extedt_Batchno.text)<>'' then
    begin
      DispInfo('该物料不受批次控制,不能录入批次号',1);
      twincontrol(sender).setfocus;
      abort;
    end
  end;


  if (BatchCtrl(AdoQry_tmp,Extedt_ItemCode.text)) and
     (Extedt_MoRequestqty.text<>'0')  then
  begin
    if (Extedt_Batchno.text='') then
    begin
      DispInfo('请录入批次号',1);
      twincontrol(sender).setfocus;
      abort;
    end
    else
    begin
      if not BatchNoCheck(AdoQry_tmp,Extedt_Batchno.text,Extedt_ItemCode.text,'',tmp_Date) then
      begin
        twincontrol(sender).setfocus;
        abort;
      end
      else
      begin
        if not BatchInvCheck(AdoQry_tmp,Extedt_Batchno.text,'C',WhCode,WhPositionCode,strtofloat(Extedt_MoRequestqty.text)) then
        begin
          twincontrol(sender).setfocus;
          abort;
        end;
      end;
    end;
  end
end;

procedure TFrm_Sfc_MnRequestOverPlan_D.Extedt_BatchnoKeyDown(
  Sender: TObject; var Key: Word; Shift: TShiftState);
begin
  inherited;
  if (key=vk_F9) then
  begin
    Extedt_Batchno.text:=BatchHint(AdoQry_tmp.Connection,Extedt_ItemCode.text,'',whCode,WhPositionCode);
  end;
end;

end.

⌨️ 快捷键说明

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