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

📄 sfc_backflushoutin_b.pas

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

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Entry_Body, Db, DBCtrls, StdCtrls, ActnList, AdODB, Grids, DBGridEh,
  ExtCtrls, ComCtrls, ToolWin, ExtPrintReport, ExtEdit, Mask, jpeg;

Type
  TFrm_Sfc_BackFlushOutIn_B = Class(TFrm_Base_Entry_Body)
    DBText1: TDBText;
    Label8: TLabel;
    Extpr: TExtPrintReport;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    cmbbx_WhCode: TComboBox;
    cmbbx_WhPositionCode: TComboBox;
    lbl_Dept: TLabel;
    medt_Date: TMaskEdit;
    lbl_Mono: TLabel;
    lbl_MoLineno: TLabel;
    lbl_Item: TLabel;
    Extedt_Billno: TExtEdit;
    Extedt_memo: TExtEdit;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    cmbbx_WhEmployee: TComboBox;
    Label7: TLabel;
    cmbbx_Shift: TComboBox;
    procedure Act_autoExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    procedure Act_ExcelExecute(Sender: TObject);
    procedure cmbbx_WhCodeChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure cmbbx_WhCodeExit(Sender: TObject);
    procedure Act_NewExecute(Sender: TObject);
    procedure Act_InsertLineExecute(Sender: TObject);
    procedure Act_ModifyExecute(Sender: TObject);
    procedure Act_DeleteLineExecute(Sender: TObject);
    procedure AdoQry_BodyAfterPost(DataSet: TDataSet);
    procedure AdoQry_BodyBeforePost(DataSet: TDataSet);
    procedure DateCheck(Sender: TObject);
    procedure cmbbx_WhPositionCodeExit(Sender: TObject);
    procedure CheckBox2Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
    procedure cmbbx_WhEmployeeExit(Sender: TObject);
  private
    IOType,oldmoRequestlineqty:real;
    BillTypeCode,oldWhPosition:string;
    Isinsert,IsAfterprint:boolean;
    procedure checkIOType;
    procedure checkcoCurrentqty;
    procedure InitCmbbx_WhPositionCode(whCode:string);
    procedure InitCmbbx_WhEmployee(whCode:string);
    procedure showdbgrid;
    procedure initprint;
    { Private declarations }
  public
    procedure SetStatus(CurrentStatus:String;var AnswerStatus,EnableControls:String); Override;//设置各种状态下那些控件Enable
    procedure InitControls; Override;//初始化Form上所有控件
    procedure SaveData; Override;

      { Public declarations }
  end;

var
  Frm_Sfc_BackFlushOutIn_B: TFrm_Sfc_BackFlushOutIn_B;

implementation

uses Sys_Global, Sfc_BackFlushOutIn_D,Inv_Global,
  Sfc_MnOut_NotSave_P, Sfc_BackFlushOutIn;
{$R *.DFM}

procedure TFrm_Sfc_BackFlushOutIn_B.Showdbgrid;
var
  sql_text,tmpfields,tmp_DeptCode,tmp_DeptCode1,tmp_WhEmployee:string;
  I:integer;
begin
  tmpfields:=getInvfield(AdoQry_tmp,getCode(cmbbx_WhCode.text),getCode(cmbbx_WhPositionCode.text),'CurrentInv');

  if checkbox2.Checked=True then
  begin
     tmp_DeptCode:=' and  (m.DeptCode in ('''+getCode(lbl_Dept.Caption)+''','''+copy(getCode(lbl_Dept.Caption),1,length(getCode(lbl_Dept.Caption))-2)+''')) ';
     tmp_DeptCode1:=' and  (DeptCode in ('''+getCode(lbl_Dept.Caption)+''','''+copy(getCode(lbl_Dept.Caption),1,length(getCode(lbl_Dept.Caption))-2)+''')) '
  end
  else
  begin
     tmp_DeptCode:='';
     tmp_DeptCode1:='';
  end;

  if cmbbx_WhEmployee.text<>'' then
    tmp_WhEmployee:='   and i.wh_EmployeeCode='''+getCode(cmbbx_WhEmployee.text)+''''
  else
    tmp_WhEmployee:='';

  //如果显示库存不为零
  if checkbox1.checked=True then
  begin
    sql_text:='select m.mono,'+
             'm.MoLineno,'+
             'm.ItemCode,'+
             'i.ItemName,'+
             'u.UomName,'+
             'e.EmployeeName,'+
             'm.alterNative,'+
             'm.ItemListid,'+
             'm.Parentid,'+
             'm.ite_ItemCode,'+
             'm.BilllineremArk,'+
             'm.BilllineremArk as Batchno,'+
             'm.moCtrlqty,'+
             'm.BFRealQty,'+
             'm.moRequestqty, '+
             'c.'+tmpfields+' as onhandInv '+
         'from mnItemList m '+
         '  join Item i '+
         '    on m.ItemCode=i.ItemCode '+
              tmp_WhEmployee+
         '  join Uom u '+
         '    on i.UomCode=u.UomCode '+
         ' left join Employee e '+
         '      on i.wh_EmployeeCode=e.EmployeeCode '+
         '  join CurrentInv c '+
         '    on m.ItemCode=c.ItemCode '+
         '    and c.whCode='''+getCode(cmbbx_WhCode.text)+''''+
         '    and c.WhPositionCode='''+getCode(cmbbx_WhPositionCode.text)+''''+
         '    and c.'+tmpfields+'>0 '+
         ' where m.mono='''+lbl_Mono.Caption+''' '+
         '   and m.MoLineno='+lbl_MoLineno.Caption+
         '   and m.moCtrlqty>m.BFRealQty '+
         '   and m.ItemCode=c.ItemCode '+
             tmp_DeptCode+
         '   and (i.whCode='''+getCode(cmbbx_WhCode.text)+''' or '+
         '       c.'+tmpfields+'>0) '+
         ' Order by m.ItemCode ';
  end
  else
  begin
    sql_text:=
      'select m.mono,'+
           'm.MoLineno,'+
           'm.ItemCode,'+
           'i.ItemName,'+
           'u.UomName,'+
           'e.EmployeeName,'+
           'm.alterNative,'+
           'm.ItemListid,'+
           'm.Parentid,'+
           'm.ite_ItemCode,'+
           'm.BilllineremArk,'+
           'm.BilllineremArk as Batchno,'+
           'm.moCtrlqty,'+
           'm.BFRealQty,'+
           'm.moRequestqty,'+
           'c.'+tmpfields+' as onhandInv '+
       'from mnItemList m'+
       ' join Item i '+
       '      on m.ItemCode=i.ItemCode '+
       tmp_WhEmployee+
       ' left join Uom u '+
       '      on i.UomCode=u.UomCode '+
       ' left join Employee e '+
       '   on i.wh_EmployeeCode=e.EmployeeCode '+
       ' left join CurrentInv c '+
       '      on m.ItemCode=c.ItemCode '+
       '     and c.whCode='''+getCode(cmbbx_WhCode.text)+''''+
       '     and c.WhPositionCode='''+getCode(cmbbx_WhPositionCode.text)+''''+
       ' where m.mono='''+lbl_Mono.Caption+''' '+
       '   and m.MoLineno='+lbl_MoLineno.Caption+
       '   and m.moCtrlqty>m.BFRealQty '+
       '   and (i.whCode='''+getCode(cmbbx_WhCode.text)+''' or '+
       '       c.'+tmpfields+'>0) '+
       ' Order by m.ItemCode ';
  end;

  try
    with AdoQry_Body do
    begin
      Close;
      sql.clear;
      sql.Add(sql_text);
      Open;
      First;
      for I:=0 to recordCount-1 do
      begin
        edit;
        fieldbyname('Batchno').asstring:='';
      end;
      First;
    end

  except
    begin
      DispInfo('连接失败,请重试!',3);
    end;
  end;
end;

procedure TFrm_Sfc_BackFlushOutIn_B.InitCmbbx_WhEmployee(whCode:string);
begin
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select distinct i.wh_EmployeeCode,e.EmployeeName '+
            '  from Item i,Employee e '+
            '  where whCode='''+whCode+''''+
            '    and i.wh_EmployeeCode is not null '+
            '    and i.wh_EmployeeCode=e.EmployeeCode '+
            ' Order by i.wh_EmployeeCode');
    open;
    cmbbx_WhEmployee.clear;
    cmbbx_WhEmployee.Items.Add('');
    if not Eof then
    begin
      First;
      while not Eof do
      begin
        cmbbx_WhEmployee.Items.Add(fieldbyname('wh_EmployeeCode').asstring+' '+fieldbyname('EmployeeName').asstring);
        Next;
      end;
      cmbbx_WhEmployee.Itemindex:=0;
    end;
  end;
end;


procedure TFrm_Sfc_BackFlushOutIn_B.InitCmbbx_WhPositionCode(whCode:string);
begin
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select WhPositionCode,WhPositionName '+
              ' from WhPosition  '+
              ' where whCode='''+whCode+''''+
              ' and WhPositionType<>1 '+
              ' and BackFlushWhP=0 ');
    open;
    cmbbx_WhPositionCode.clear;
    if not Eof then
    begin
      First;
      while not Eof do
      begin
        cmbbx_WhPositionCode.Items.Add(fieldbyname('WhPositionCode').asstring+' '+fieldbyname('WhPositionName').asstring);
        Next;
      end;
      cmbbx_WhPositionCode.Itemindex:=0;
    end;
  end;
end;


procedure TFrm_Sfc_BackFlushOutIn_B.InitControls;
var
  tmpfields:string;
begin//初始化Form上的控件
  inherited;
  //单据类型
  Isinsert:=False;  //由于在插入记录时基类会触发本onEXIT事件,为了避免这一件事件执行,所以加入本变量控制
  if (showflag=True) and (status<>'Add') then
    exit;
  checkbox1.Checked:=False;
  checkbox2.checked:=False;
  BillTypeCode:=Param2;
  lbl_Mono.Caption:=AdoQry_Head.fieldbyname('mono').asstring;
  lbl_MoLineno.Caption:=AdoQry_Head.fieldbyname('MoLineno').asstring;
  lbl_Item.Caption:=AdoQry_Head.fieldbyname('ItemCode').asstring+' '+Frm_Sfc_BackFlushOutIn.AdoQry_Head.fieldbyname('ItemName').asstring;
  cmbbx_Shift.text:=Frm_Sfc_BackFlushOutIn.tmp_MoRequestshift;
  lbl_Dept.Caption:=Frm_Sfc_BackFlushOutIn.tmp_DeptCode;
  medt_Date.text:=LoginDate;
  oldWhPosition:='#@%^';
  initUsablewhcmbx(AdoQry_tmp,userCode,cmbbx_WhCode,False);
  InitShiftCmBx(AdoQry_tmp,cmbbx_Shift,True);
  cmbbx_WhCodeexit(cmbbx_WhCode);
  tmpfields:=getInvfield(AdoQry_tmp,getCode(cmbbx_WhCode.text),getCode(cmbbx_WhPositionCode.text),'CurrentInv');

  IOType:=0;

  if status='ReadOnly' then
  begin
    cmbbx_WhCode.Enabled:=False;
    cmbbx_WhPositionCode.Enabled:=False;
    medt_Date.Enabled:=False;
    Act_Save.Enabled :=False;
    Act_auto.Enabled :=False;
  end
  else
  begin
    Act_auto.Enabled :=True;
    act_Save.Enabled :=True;
    Extedt_Billno.text:='';
  end;
  InitCmBxText(cmbbx_Shift,Frm_Sfc_BackFlushOutIn.tmp_MoRequestshift);
end;

procedure TFrm_Sfc_BackFlushOutIn_B.SetStatus(CurrentStatus:String;var AnswerStatus,
  EnableControls:String);
begin//指明当前状态,定义Enable=True的控件
  inherited;
  if CurrentStatus='Add' then
     EnableControls:=''
  else
  begin
     if CurrentStatus='Edit' then
     EnableControls:='cmbbx_WhCode,cmbbx_WhPositionCode,cmbbx_WhEmployee,';
  end;
end;

procedure TFrm_Sfc_BackFlushOutIn_B.checkIOType;
begin
  if IoType<>0 then
  if AdoQry_Body.fieldbyname('moRequestqty').asfloat*IoType<0 then
  begin
    DispInfo('同一请领,不能出现正负数量混合的情况!',1);
    abort;
  end;
end;

procedure TFrm_Sfc_BackFlushOutIn_B.checkcoCurrentqty;
var
  tmp_MoRequestqty,tmp_onhandInv:real;
begin
  tmp_MoRequestqty:=AdoQry_Body.fieldbyname('moRequestqty').asfloat;
  tmp_onhandInv:=AdoQry_Body.fieldbyname('onhandInv').asfloat;
  if AdoQry_Body.fieldbyname('moRequestqty').asstring='' then
  begin
    DispInfo('当前数量不能为空!',1);
    abort;
  end;
  if tmp_MoRequestqty>tmp_onhandInv then
  begin
    DispInfo('当前可用库存是:'+AdoQry_Body.fieldbyname('onhandInv').asstring,1);
    abort;
  end;
end;

procedure TFrm_Sfc_BackFlushOutIn_B.Act_autoExecute(Sender: TObject);
var
  M:integer;
  tmp_onhandInv,tmp_MoCtrlqty,tmp_BFRealQty,tmp_MoRequestqty:real;
begin
  inherited;
  with AdoQry_Body do
  begin
    AdoQry_Body.First;
    for M:=0 to recordCount-1 do
    begin
      tmp_onhandInv:=fieldbyname('onhandInv').asfloat;
      tmp_MoCtrlqty:=fieldbyname('moCtrlqty').asfloat;
      tmp_BFRealQty:=fieldbyname('BFRealQty').asfloat;
      tmp_MoRequestqty:=fieldbyname('moRequestqty').asfloat;
      if tmp_onhandInv>
         (tmp_MoCtrlqty-
          tmp_BFRealQty)
      then
      begin
        edit;
        fieldbyname('moRequestqty').asfloat:=
             fieldbyname('moCtrlqty').asfloat-
             fieldbyname('BFRealQty').asfloat
      end
      else
      begin
        edit;
        fieldbyname('moRequestqty').asfloat:=
             fieldbyname('onhandInv').asfloat;
      end;
      AdoQry_Body.next;
    end;
  end;
end;

procedure TFrm_Sfc_BackFlushOutIn_B.FormCreate(Sender: TObject);
begin
  inherited;
  IsAfterprint:=False;
  Frm_Entry_Detail:=TFrm_Sfc_BackFlushOutIn_D.Create(Self);//设置弹出Detail
  SetFocus_Control:=cmbbx_WhCode;
end;


procedure TFrm_Sfc_BackFlushOutIn_B.Act_PreviewExecute(Sender: TObject);
begin
  //  inherited;
  if Trim(Extedt_Billno.text)<>'' then
     BillPrint(AdoQry_Tmp.Connection,GetCode(cmbbx_WhCode.Text),Extedt_Billno.Text,Param2,ModuleCode,True,False,True,'')
  else
   begin
    Application.CreateForm(TFrm_Sfc_MnOut_NotSave_P,Frm_Sfc_MnOut_NotSave_P);
    Frm_Sfc_MnOut_NotSave_P.SetFormParam('',getCode(cmbbx_WhCode.text),Param2,'Preview',ModuleCode,'');
    initprint;
    Frm_Sfc_MnOut_NotSave_P.SetDBConnect(AdoQry_tmp.Connection);
    Frm_Sfc_MnOut_NotSave_P.release;
   end;
end;

procedure TFrm_Sfc_BackFlushOutIn_B.Act_PrintExecute(Sender: TObject);
begin
  IsAfterprint:=True;
  if Trim(Extedt_Billno.text)<>'' then
    BillPrint(AdoQry_Tmp.Connection,GetCode(cmbbx_WhCode.Text),Extedt_Billno.Text,Param2,ModuleCode,False,False,True,'')
  else
  begin
    Application.CreateForm(TFrm_Sfc_MnOut_NotSave_P,Frm_Sfc_MnOut_NotSave_P);
    Frm_Sfc_MnOut_NotSave_P.SetFormParam('',getCode(cmbbx_WhCode.text),Param2,'Print',ModuleCode,'');
    initprint;
    Frm_Sfc_MnOut_NotSave_P.SetDBConnect(AdoQry_tmp.Connection);
    Frm_Sfc_MnOut_NotSave_P.release;
   end;
   IsAfterprint:=False;
end;

procedure TFrm_Sfc_BackFlushOutIn_B.Act_ExcelExecute(Sender: TObject);

⌨️ 快捷键说明

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