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

📄 sfc_mnin_b.pas

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

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Inner, Menus, ExtPrintReport, Db, ActnList, AdODB, Grids, DBGridEh,dbGrids,
  StdCtrls, ExtCtrls, ComCtrls, ToolWin, Base_Outer, DBCtrls, Mask,math,
  jpeg;

Type
  TFrm_Sfc_MnIn_B = Class(TFrm_Base_Outer)
    AdoQry_MainMoLineNo: TIntegerField;
    AdoQry_MainItemCode: TStringField;
    AdoQry_MainItemName: TStringField;
    AdoQry_MainMoQty: TFloatField;
    AdoQry_MainMoLineDate: TDateTimeField;
    AdoQry_MainMoNoFinishQty: TFloatField;
    AdoQry_MainMoRealInQty: TFloatField;
    AdoQry_MainMoInQty: TFloatField;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Lbl_MoNo: TLabel;
    DBText1: TDBText;
    Cmbx_WhCode: TComboBox;
    Label5: TLabel;
    Label6: TLabel;
    Cmbx_Position: TComboBox;
    Label7: TLabel;
    Edt_BillNo: TEdit;
    MEdt_Date: TMaskEdit;
    Label8: TLabel;
    Label9: TLabel;
    Edt_Memo: TEdit;
    Lbl_Dept: TLabel;
    AdoQry_MaInBillLineRemArk: TStringField;
    Label10: TLabel;
    cmbx_WhEmployee: TComboBox;
    AdoQry_Mainwh_EmployeeCode: TStringField;
    Cmbox_Shift: TComboBox;
    AdoQry_MainBackFlush: TIntegerField;
    AdoQry_MainIScheck: TIntegerField;
    procedure AdoQry_MainBeforePost(DataSet: TDataSet);
    procedure AdoQry_MainAfterInsert(DataSet: TDataSet);
    procedure Cmbx_WhCodeChange(Sender: TObject);
    procedure Act_SaveExecute(Sender: TObject);
    procedure Cmbx_WhCodeExit(Sender: TObject);
    procedure Cmbx_PositionExit(Sender: TObject);
    procedure DateCheck(Sender: TObject);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Act_QuitExecute(Sender: TObject);
    procedure Edt_MemoChange(Sender: TObject);
    procedure MEdt_DateChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Act_autoExecute(Sender: TObject);
    procedure Act_OrderExecute(Sender: TObject);
    procedure cmbx_WhEmployeeChange(Sender: TObject);
    procedure DBGridEhGetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
  private
    OldSignValue :Double;
    //当原始单据无正数也无负数时,使用该标志来记录上一个值,看是否同号
    FDeptCode,FMoNo,FShift,HasNegative:string;
    BillTypeCode :String;
    FMOSpecial   :Boolean;  //标志是否是独立订单
    Overqtydeny_Percent:string;//标志正常百分比
    function InitwhposIfSpec:integer;//初始化独立订单货位
    function CheckAllSame:boolean;//检验所有拟入数量是否同号
    procedure FindItemIndex(Shift:string);
    procedure refreshall;//根据仓库、货位的改变更新grid中的数据
    procedure InitCmbx_Position(WhCode:String);
    procedure InitCmbX_WhEmployee(WhCode:String);
    { Private declarations }
  public
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
    procedure SetFormParam(FrmParam1,FrmParam2,FrmParam3,FrmParam4,FrmParam5,FrmParam6:String);OverRide;
    { Public declarations }
  end;

var
  Frm_Sfc_MnIn_B: TFrm_Sfc_MnIn_B;

implementation
uses Sys_Global,Inv_Global,Sfc_MnIn;
{$R *.DFM}

{ TFrm_Sfc_MnIn }

procedure TFrm_Sfc_MnIn_B.InitForm(AdOConnection: TAdOConnection;
  ReadOnly: Boolean);
begin
  AdoQry_Main.Connection:=AdOConnection;
  AdoQry_Tmp.Connection:=AdOConnection;
  //置DBGRIDEH为编辑状态
  with DBGridEh do
  begin
    options:=options+[dgEditing]-[dgRowselect];
  end;
  AdoQry_Tmp.EnableBCD:=False;
  AdoQry_Main.EnableBCD:=False;
  Tlbtn_Order.Action:=Act_Save;
  inherited;
  //act_Save.Enabled:=False;
  OldSignValue:=0;
  Lbl_MoNo.Caption:=FMONo;
  mEdt_Date.Text:=formatdatetime('yyyy.mm.dd',Date());
  //Lbl_MoFinishShift.Caption:=FShift;
  CmBx_WhCode.clear;
  with AdoQry_tmp do
  begin
    Close;
//    sql.text:= 'select WhCode+'' ''+WhName CodeName from Warehouse where PriceType=1 ';
    sql.text:= 'select WhCode+'' ''+WhName CodeName from Warehouse ';
    open;
    while not Eof do
    begin
      cmbx_WhCode.Items.Add(fieldbyname('CodeName').asstring);
      Next;
    end;
{    Close;
    sql.text:='select MORemArk '+
              '  from mo '+
              ' where mono='''+FMONo+'''';
    open;}
    //Edt_Memo.Text:=Frm_Sfc_MnIn.AdoQry_Main.fieldbyname('MORemArk').asstring;

    Close;
    sql.text:='select MrpParamValueN '+
               ' from MrpParam '+
               'where MrpParamCode=''Overqtydeny_Percent''';
    open;
    Overqtydeny_Percent:=fieldbyname('MrpParamValueN').asstring;
  end;
  cmbx_WhCode.ItemIndex:=0;
  InitCmbx_Position(GetCode(Cmbx_WhCode.Text));
  Cmbx_Position.ItemIndex:=InitwhposIfSpec;
  InitCmbX_WhEmployee(GetCode(Cmbx_WhCode.Text));
  CmbX_WhEmployee.ItemIndex:=0;
  Lbl_Dept.Caption:=FDeptCode;
  //act_Save.Enabled:=False;
  refreshall;
  InitShiftCmBx(AdoQry_Tmp,Cmbox_Shift,True);
  FindItemIndex(FShift);
end;

procedure TFrm_Sfc_MnIn_B.InitCmbx_Position(WhCode:String);
begin
  Cmbx_Position.clear;
  With AdoQry_Tmp do
  begin
    Close;
    Sql.clear;
//    If (not FMOSpecial) then
    Sql.Add(' select WhPositionCode,WhPositionName '+
                      ' from WhPosition '+
                      '  where WHCode='''+WhCode+''''+
                      '    and WhPositionType<>1 '+
                      '    and BackFlushWhP=0 '+
                      '  Order by WhPositionCode ');
//    Else
//      Sql.Add(' select WhPositionCode,WhPositionName '+
//                        ' from WhPosition '+
//                        '  where WHCode='''+WhCode+''''+
//                        '  and  WhPositionType=2 '+
//                        '  Order by WhPositionCode ');
    Open;
    if not Eof then
    begin
      First;
      while not Eof do
      begin
        Cmbx_Position.Items.Add(fieldbyname('WhPositionCode').AsString+' '+fieldbyname('WhPositionName').asstring);
        Next;
      end;
    end;
  end;
  cmbx_Position.Itemindex:=0;
end;


procedure TFrm_Sfc_MnIn_B.AdoQry_MainBeforePost(DataSet: TDataSet);
var
  old,new:real;
begin
  inherited;
  if AdoQry_Main.fieldbyname('MoInQty').asstring='' then
  begin
    AdoQry_Main.fieldbyname('MoInQty').asstring:='0';
    abort;
  end;
  //有效性库存数量检查
  if not InvQtyCheck(False,
                     AdoQry_Main,AdoQry_Tmp,
                     getCode(Cmbx_WhCode.text),
                     getCode(Cmbx_Position.text),
                     AdoQry_Main.fieldbyname('ItemCode').asstring,
                     'MoInQty',AdoQry_Main.fieldbyname('MoInQty').AsFloat,True)then Abort;

  If AdoQry_Main.fieldbyname('BackFlush').asinteger=0 then
  begin
    old:=AdoQry_Main.fieldbyname('MoInQty').AsFloat;
    new:=round(AdoQry_Main.fieldbyname('MOQty').AsFloat*(1.0+strtofloat(Overqtydeny_Percent)/100))-
        AdoQry_Main.fieldbyname('MoRealInQty').AsFloat;
    If (Old>New) and
       (AdoQry_Main.fieldbyname('MoInQty').asfloat>0)
    then
    begin
      DispInfo('本次拟入数量不能超过实际未结量!',1);
      AdoQry_Main.Cancel;
      Abort;
    end;
    old:=AdoQry_Main.fieldbyname('MoRealInQty').asfloat;
    new:=round(AdoQry_Main.fieldbyname('MoQty').asfloat*(1+strtofloat(Overqtydeny_Percent)/100));
    if (old>new) and (AdoQry_Main.fieldbyname('MoInQty').asfloat<0)
    then
    begin
      DispInfo('请先使用“超订单入库”进行冲销!',1);
      AdoQry_Main.Cancel;
      Abort;
    end;
  end
  else
  begin
    old:=AdoQry_Main.fieldbyname('MoRealInQty').asfloat+
         AdoQry_Main.fieldbyname('MoInQty').asfloat;
    new:=AdoQry_Main.fieldbyname('MoQty').asfloat;
    if old>new then
    begin
      DispInfo('拉式领料的生产订单行'+chr(13)+chr(10)
              +'          累计入库量'+chr(13)+chr(10)
              +'不允许超过约定交货量!',1);
      abort;
    end;
  end;
  old:=abs(AdoQry_Main.fieldbyname('MoInQty').asfloat);
  new:= AdoQry_Main.fieldbyname('MoRealInQty').asfloat;
  if (old>new) and
  (AdoQry_Main.fieldbyname('MoInQty').asfloat<0) then
  begin
    DispInfo('冲销的入库数量不能大于累计实入量!',1);
    AdoQry_Main.Cancel;
    Abort;
  end;
  if (AdoQry_Main.fieldbyname('IScheck').asinteger=1) and
     (AdoQry_Main.fieldbyname('MoInQty').asfloat>0) then
     begin
       DispInfo('该物料是必检产品,本次拟入量不能大于0!',1);
       abort;
     end;

  //act_Save.Enabled:=True;
end;

procedure TFrm_Sfc_MnIn_B.AdoQry_MainAfterInsert(DataSet: TDataSet);
begin
  inherited;
  AdoQry_Main.Cancel;
end;

procedure TFrm_Sfc_MnIn_B.SetFormParam(FrmParam1, FrmParam2, FrmParam3,
  FrmParam4, FrmParam5, FrmParam6: String);
begin
  FMoNo:=FrmParam1;
  FDeptCode:=FrmParam2;
  FShift:=FrmParam3;
  HasNegative:=FrmParam4;
  BillTypeCode:=FrmParam5;
  IF FrmParam6='1'  then
    FMOSpecial:=True
  Else
    FMOSpecial:=False;
end;

procedure TFrm_Sfc_MnIn_B.Cmbx_WhCodeChange(Sender: TObject);
begin
  inherited;
  InitCmbx_Position(GetCode(Cmbx_WhCode.Text));
  Cmbx_Position.ItemIndex:=InitwhposIfSpec;
  Initcmbx_WhEmployee(GetCode(Cmbx_WhCode.Text));
  refreshall;
end;

procedure TFrm_Sfc_MnIn_B.Act_SaveExecute(Sender: TObject);
var FlagFloat :Double;
   i,m,Loop,IsZero: integer;  //循环控制变量
   BeforeSaveError :Boolean;
   Billno,Billid :String;
begin
  inherited;
  BeforeSaveError:=True;;
  Cmbx_WhCodeExit(Cmbx_WhCode);
  Cmbx_PositionExit(Cmbx_Position);
  DateCheck(Medt_Date);
  MEdt_DateChange(Medt_Date);
  if AdoQry_Main.RecordCount<1  then
  begin
    DispInfo('没有记录,不允许保存!',1);
    abort;
  end;
  if AdoQry_Main.state<>dsBrowse then
    AdoQry_Main.post;

  AdoQry_Main.DisableControls;
  AdoQry_Main.First;
  FlagFloat:=0;
  if not CheckAllSame then
  begin
    DispInfo('所有单据行不能正负异号!',1);
    AdoQry_Main.EnableControls;
    DBGridEh.SetFocus;
    abort;
  end;
  AdoQry_Main.EnableControls;
  
  //检查每一项拟入量是否全为零
  IsZero:=0;
  with AdoQry_Main do
  begin
    First;
    while not Eof do
    begin
      if fieldbyname('MoInQty').asinteger=0 then
        IsZero:=IsZero+1;
      next;
    end;
    if IsZero=RecordCount then
      begin
        DispInfo('所有单据行拟入量为零!'+#13#10+'不能保存!',1);
        Exit;
      end;
  end;

  with AdoQry_Tmp do
  begin
    Close;
    sql.text:='select Billlines '+
              '  from BillType  '+
              ' where BillTypeCode='''+Param2+'''';
    open;
    Loop:=fieldbyname('Billlines').asinteger;
  end;
  AdoQry_Main.Connection.beginTrans;
  try
    BeforeSaveError:=False;
    Billno:=getno(AdoQry_Main.Connection,
                  getCode(Cmbx_WhCode.Text)+'R'+Formatdatetime('yymm',StrToDate(Medt_Date.Text)),
                  'InvBill');

   With AdoQry_Tmp do
   begin
     Close;
     Sql.clear;
     AdoQry_tmp.sql.Add('insert InvInBill'+
                         '(InvBillno,'+
                         'whCode,'+
                         'InvBilldate,'+
                         'InvBillMonth,'+
                         'DeptCode,'+
                         'MoNo,'+
                         'BillTypeCode,'+
                         'EmployeeCode,'+
                         'Sfc_EmployeeCode,'+
                         'WhPositionCode,'+
                         'wh_EmployeeCode2,'+
                         'shiftType,'+
                         'InvBillRemArk)'+

⌨️ 快捷键说明

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