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

📄 mrp_qry_dynamicmrpinfo.pas

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

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Outer, Menus, ExtPrintReport, Db, ActnList, AdODB, Grids, DBGridEh,
  StdCtrls, ExtCtrls, ComCtrls, ToolWin, DBTables;

Type
  TFrm_Mrp_Qry_DynamicMrpInfo = Class(TFrm_Base_Outer)
    AdoQry_MainSSId: TAutoIncField;
    AdoQry_MainItemCode: TStringField;
    AdoQry_MainSSSysInfoFlag: TIntegerField;
    AdoQry_MaInOrderNo: TStringField;
    AdoQry_MaInOrderLineNo: TIntegerField;
    AdoQry_MainSSDate: TDateTimeField;
    AdoQry_MainSSQty: TFloatField;
    AdoQry_MainPmType: TIntegerField;
    AdoQry_MainSScheck: TIntegerField;
    AdoQry_MainGrossRequireQty: TFloatField;
    AdoQry_MaInPlanInvQty: TFloatField;
    AdoQry_MaInOrderLineStatus: TIntegerField;
    AdoQry_MainDeptVendorCode: TStringField;
    AdoQry_Mainduedate: TDateTimeField;
    AdoQry_MainReMainQty: TFloatField;
    AdoQry_MainItemName: TStringField;
    AdoQry_MainEmployeeCode: TStringField;
    AdoQry_MainEmployeeName: TStringField;
    AdoQry_MainDeptCode: TStringField;
    AdoQry_MainDeptName: TStringField;
    AdoQry_MainUomName: TStringField;
    AdoQry_MainSSName: TStringField;
    AdoQry_Mainssflag: TStringField;
    AdoQry_Mainmnldtime: TFloatField;
    AdoQry_MainEmployeeFlag: TStringField;
    AdoQry_MainDeptFlag: TStringField;
    AdoQry_MainItemFlag: TStringField;
    AdoQry_MaintMpssreMainqty: TFloatField;
    Label1: TLabel;
    lbl_RunMrpdate: TLabel;
    AdOCommand: TAdOCommand;
    AdoQry_MainPmCode: TIntegerField;
    AdoQry_MainSysqty: TFloatField;
    AdoQry_Mainmoqty: TFloatField;
    procedure FormDestroy(Sender: TObject);
    procedure Act_NewExecute(Sender: TObject);
    procedure Act_LookExecute(Sender: TObject);
    procedure AdoQry_MainBeforeEdit(DataSet: TDataSet);
    procedure AdoQry_MainBeforeInsert(DataSet: TDataSet);
    procedure DBGridEhTitleClick(Column: TColumnEh);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    checked:boolean;
    { Private declarations }
  public
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
    function getMrpdate:string;
   function getQclt(ItemCode:string):string;{ Public declarations }
{ Public declarations }
  end;

var
  Frm_Mrp_Qry_DynamicMrpInfo: TFrm_Mrp_Qry_DynamicMrpInfo;

implementation

uses Mrp_Enter_AutoMo, Mrp_Enter_MoSsParent,Sys_Global;

{$R *.DFM}
{ TFrm_Mrp_Qry_DynamicMrpInfo }

procedure TFrm_Mrp_Qry_DynamicMrpInfo.InitForm(
  AdOConnection: TAdOConnection; ReadOnly: Boolean);
var sqltext:string;
begin
Application.ProcessMessages;
  inherited;
  If ReadOnly=True Then
  begin
    TlBtn_Copy.Visible:=False;
  end;
  lbl_RunMrpdate.Caption:=getMrpdate;
  Adocommand.Connection:=AdoQry_Main.Connection;
  sqltext:='select ss.*,null as moqty,Sysqty=ss.ssqty,ssreMainqty=reMainqty '
           +' into #tmpdynssInfo from ss                         '
          // +'   join MoLine on ss.Orderno=MoLine.mono '
          // +'      and ss.Orderlineno=MoLine.MoLineno '
           +' where ssSysInfoflag=1                    '
           +'  and  PmType=0   '
           +' union                                    '
           +' select ss.*,MoLine.moqty,Sysqty=ss.ssqty,ssreMainqty=0 from ss,MoLine                         '
           +' where ssSysInfoflag=3                    '
           +'   and Orderlinestatus<>7                 '
           +'   and ss.Orderno=MoLine.mono and ss.Orderlineno=MoLine.MoLineno and MoLine.MoLinestatus<>7 '
           +' union                                    '
           +' select ss.*,    '
           +'       MoLine.moqty, '
           +'       Sysqty=case  when ss.reMainqty<MoLine.moqty then MoLine.moqty-ss.reMainqty '
           +'             else 0  '
           + '             end,          '
           +'        ssreMainqty=0       '
           +'   from ss,MoLine           '
           +'  where ssSysInfoflag=2     '
            +'  and Orderlinestatus<>7   '
            +'  and exists(select mono from MoLine where Orderno=MoLine.mono) '
            +'  and ss.Orderno=MoLine.mono          '
            +'  and ss.Orderlineno=MoLine.MoLineno  ';
     with Adocommand do
    begin
     commandtext:=sqltext;
     Execute;
    end;

   //Executesql(AdoQry_Main,sqltext,1);
    sqltext:='select #tmpdynssInfo.*,tMpssreMainqty=case #tmpdynssInfo.ssreMainqty when 0 then null else #tmpdynssInfo.ssreMainqty end,Item.mnldtime,Item.ItemName,Uom.UomName,Dept.DeptCode,Dept.DeptName,'
            +'  Employee.EmployeeCode,Employee.EmployeeName,'
                +' ssflag=convert(varchAr,#tmpdynssInfo.ssSysInfoflag)+'' ''+SysssInfo.ssName,'
                +' Employee.EmployeeCode+'''+' '+'''+Employee.EmployeeName As EmployeeFlag,'
                +' Dept.DeptCode+'''+' '+'''+Dept.DeptName As DeptFlag, '
                +' Item.ItemCode+'''+' '+'''+Item.ItemName As ItemFlag,'
                +' Item.PmCode,'
                +' ConVert(varchAr,SysSsInfo.SSCode)+'''+' '+'''+SysSsInfo.SsName As SsName'
                +'  into #tmpdynssInfoResult '
                +' From #tmpdynssInfo '
                +' Join Item On #tmpdynssInfo.ItemCode=Item.ItemCode '
                +' And PmType=0 '
                +' Left Join Dept On  isnull(#tmpdynssInfo.DeptVendorCode,Item.DeptCode)=Dept.DeptCode'
//                +' Left Join Dept On (Case When #tMpssInfo.SsSysInfoFlag<>1 Then #tMpssInfo.DeptVendorCode Else Item.DeptCode end)=Dept.DeptCode'
                +' Left Join Employee On Item.Pla_EmployeeCode=Employee.EmployeeCode'
                +' Join Uom On Item.UomCode=Uom.UomCode'
                +' Join SysSsInfo On #tmpdynssInfo.SSSysInfoFlag=SysSsInfo.SSCode'
                +' where  ((#tmpdynssInfo.SsSysInfoFlag=1 '
                      +' And Item.LongPurchLT=0 And #tmpdynssInfo.DueDate-(select MrpParamValueN from MrpParam '
                      +' where MrpParamCode='''+'SSForwArdDay'+''')<='''+DateTimeToStr(Date())+''')'
                      +' Or (#tmpdynssInfo.SsSysInfoFlag=1 And Item.LongPurchLT=1) Or (#tmpdynssInfo.SsSysInfoFlag<>1 and #tmpdynssInfo.Sysqty<>0)) '
                      +' Order by ssdate,Employee.EmployeeCode';
     with Adocommand do
    begin
     commandtext:=sqltext;
     Execute;
    end;

    // Executesql(AdoQry_Main,sqltext,1);
     Executesql(AdoQry_Main,'select * from #tmpdynssInfoResult',0);
    selectfromsql:='select * from #tmpdynssInfoResult';
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:='Select MrpParamValueN from MrpParam '
                      +' where MrpParamCode='''+'SSForwArdDay'+'''';
  AdoQry_Tmp.Open;
  Lbl_Condition.Caption:='系统建议下达(约定开工日-'+FormatDateTime('yyyy.mm.dd',Date())+')'
                        +'<=建议可见提前天数('+IntToStr(AdoQry_Tmp.fieldbyname('MrpParamValueN').AsInteger)+')   其它(全部)';
  AdoQry_Tmp.Close;
  Checked:=False;
  Application.ProcessMessages;


end;

procedure TFrm_Mrp_Qry_DynamicMrpInfo.FormDestroy(Sender: TObject);
begin
  inherited;
  Frm_Mrp_Qry_DynamicMrpInfo:=nil;
end;

procedure TFrm_Mrp_Qry_DynamicMrpInfo.Act_NewExecute(Sender: TObject);
var
  I:Boolean;
  BookmArk:String;
begin
  inherited;
  If AdoQry_Main.RecordCount=0   Then
  begin
    Abort;
  end;
  I:=False;
  BookmArk:=AdoQry_Main.BookmArk;
  AdoQry_Main.First;
  While Not AdoQry_Main.Eof do
  begin
    If AdoQry_Main.fieldbyname('sScheck').AsInteger>0 Then
    begin
     I:=True;
     Break;
    end;
    AdoQry_Main.Next;
  end;
  If I=True Then
  begin
    Frm_Mrp_Enter_AutoMo:=TFrm_Mrp_Enter_AutoMo.Create(Application);
    Frm_Mrp_Enter_AutoMo.SetSysParam(UserCode,ModuleCode,MenuId,DateTimeToStr(Now));
    Frm_Mrp_Enter_automo.edt_DeptCode.Text:=AdoQry_Main.fieldbyname('DeptCode').asstring;
    Frm_Mrp_Enter_automo.edt_DeptName.Text:=AdoQry_Main.fieldbyname('DeptName').asstring;
    reMainqty:=AdoQry_Main.fieldbyname('reMainqty').asfloat;
    Frm_Mrp_Enter_AutoMo.flag:=3;
    Frm_Mrp_Enter_AutoMo.GetConnect(AdoQry_Main);
    Frm_Mrp_Enter_AutoMo.ShowModal;
  end;
end;


procedure TFrm_Mrp_Qry_DynamicMrpInfo.Act_LookExecute(Sender: TObject);
begin
  inherited;
 If (AdoQry_Main.RecordCount>0) And (AdoQry_Main.fieldbyname('SsSysInfoFlag').AsInteger=1) Then
 if  Frm_Mrp_Enter_MoSsParent=nil then
 begin
  Frm_Mrp_Enter_MoSsParent:=TFrm_Mrp_Enter_MoSsParent.Create(Self);
  Frm_Mrp_Enter_MoSsParent.SetSysParam(userCode,ModuleCode,menuid,formatdatetime('yyyy.mm.dd',now));
  Frm_Mrp_Enter_MoSsParent.ItemCode:=AdoQry_Main.fieldbyname('ItemCode').asstring;
  tmplowPmCode:=AdoQry_Main.fieldbyname('PmCode').asinteger;
  Frm_Mrp_Enter_MoSsParent.Qclt:=getQclt(AdoQry_Main.fieldbyname('ItemCode').asstring);
  Frm_Mrp_Enter_MoSsParent.duedate:=datetimetostr(AdoQry_Main.fieldbyname('ssdate').asdatetime);
  Frm_Mrp_Enter_MoSsParent.strpath:=AdoQry_Main.fieldbyname('ItemCode').asstring+',';
  Frm_Mrp_Enter_MoSsParent.InitForm(dbconnect,True);
 end
 else  Frm_Mrp_Enter_MoSsParent.Show;
end;

procedure TFrm_Mrp_Qry_DynamicMrpInfo.AdoQry_MainBeforeEdit(
  DataSet: TDataSet);
begin
  inherited;
  If AdoQry_Main.fieldbyname('SSSysInfoFlag').AsInteger<>1 Then
  begin
    DispInfo('本条建议不为"建议下达",不能执行选定操作!',3);
    Abort;
  end;
  If AdoQry_Main.fieldbyname('ReMainQty').AsFloat<=0 Then
  begin
    DispInfo('本条建议"系统建议余量"已分配完毕,不能执行选定操作!',3);
    Abort;
  end;
end;

procedure TFrm_Mrp_Qry_DynamicMrpInfo.AdoQry_MainBeforeInsert(
  DataSet: TDataSet);
begin
  inherited;
  Abort;

end;

procedure TFrm_Mrp_Qry_DynamicMrpInfo.DBGridEhTitleClick(
  Column: TColumnEh);
var
  BookMArk:String;
begin
  inherited;
  If Trim(Column.Title.Caption)<>'标记' Then
    Abort;
  If AdoQry_Main.RecordCount=0 Then
    Abort;
  BookMArk:=AdoQry_Main.BookmArk;
  If Not Checked Then
  begin
    AdoQry_Main.First;
    While Not AdoQry_Main.Eof Do
    begin
      If AdoQry_Main.fieldbyname('SsSysInfoFlag').AsInteger=1 then
      begin
        AdoQry_Main.Edit;
        AdoQry_Main.fieldbyname('SScheck').AsInteger:=1;
        AdoQry_Main.Post;
      end;
      AdoQry_Main.Next;
    end;
  end
  Else
  begin
    AdoQry_Main.First;
    While Not AdoQry_Main.Eof Do
    begin
      If AdoQry_Main.fieldbyname('SsSysInfoFlag').AsInteger=1 then
      begin
        AdoQry_Main.Edit;
        AdoQry_Main.fieldbyname('SScheck').AsInteger:=0;
        AdoQry_Main.Post;
      end;
      AdoQry_Main.Next;
    end;
  end;
  AdoQry_Main.BookmArk:=BookMArk;
  Checked:=Not Checked;
end;


procedure TFrm_Mrp_Qry_DynamicMrpInfo.FormCreate(Sender: TObject);
begin
  inherited;
  ExtendCaption:=False;

end;

procedure TFrm_Mrp_Qry_DynamicMrpInfo.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
Executesql(AdoQry_tmp,'drop table #tmpdynssInfo,#tmpdynssInfoResult',1);
end;

function TFrm_Mrp_Qry_DynamicMrpInfo.getMrpdate: string;
var AdoQry:TAdoQuery;
begin
 AdoQry:=TAdoQuery.Create(self);
 try
   with AdoQry do
     begin
       Close;
       Connection:=dbconnect;
       sql.clear;
       sql.Text:=' Select MrpParamValueC    '
                    +'  From MrpParam         '
                   +'   Where MrpParamCode=''RunMrpDate''       ';
       Prepared;
       try
       open;
       Result:=fieldbyname('MrpParamValuec').asstring;
       except
       Result:='';
       end;
     end;
  finally
   AdoQry.Free;
  end;
end;

function TFrm_Mrp_Qry_DynamicMrpInfo.getQclt(ItemCode: string): string;
begin
try
 Executesql(AdoQry_tmp,'select Qclt from Item where ItemCode='+quotedstr(ItemCode),0);
 Result:=inttostr(AdoQry_tmp.fieldbyname('Qclt').asinteger);
except
 Result:='9999999';
end;
end;

end.

⌨️ 快捷键说明

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