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

📄 mrp_qry_newmrpinfo.pas

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

Interface

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

Type
  TFrm_Mrp_Qry_NewMrpInfo = Class(TFrm_Base_Qry)
    AdoQry_MainSSId: TAutoIncField;
    AdoQry_MainItemCode: TStringField;
    AdoQry_MainSSSysInfoFlag: TIntegerField;
    AdoQry_MaInOrderNo: TStringField;
    AdoQry_MaInOrderLineNo: TIntegerField;
    AdoQry_MainSSDate: TDateTimeField;
    AdoQry_MainSSQty: TFloatField;
    AdoQry_MainSScheck: TIntegerField;
    AdoQry_MainItemName: TStringField;
    AdoQry_MainUomName: TStringField;
    AdoQry_MainDeptName: TStringField;
    AdoQry_MaInOrderLineStatus: TIntegerField;
    AdoQry_MainItemFlag: TStringField;
    AdoQry_MainDeptFlag: TStringField;
    AdoQry_MainDeptVendorCode: TStringField;
    Label2: TLabel;
    DBText2: TDBText;
    Label3: TLabel;
    DBText3: TDBText;
    Label1: TLabel;
    DBText1: TDBText;
    AdoQry_MainSSName: TStringField;
    Label4: TLabel;
    DBText4: TDBText;
    AdoQry_MainEmployeeCode: TStringField;
    AdoQry_MainEmployeeName: TStringField;
    AdoQry_MainEmployeeFlag: TStringField;
    AdoQry_MainDueDate: TDateTimeField;
    AdoQry_MainMnldTime: TFloatField;
    AdoQry_MainReMainQty: TFloatField;
    AdoQry_MaintMpssreMainqty: TFloatField;
    AdoQry_MainPmCode: TIntegerField;
    AdoQry_MainSysqty: TFloatField;
    AdoQry_Mainmoqty: TFloatField;
    btn_Item: TButton;
    btn_ite_Item: TButton;
    btn_Order: TButton;
    Button1: TButton;
    btn_uPMrp: TButton;
    btn_OblongMrp: TButton;
    Button2: TButton;
    Label5: TLabel;
    AdOCommand: TAdOCommand;
    AdoQry_Maincanuseonhand: TFloatField;
    AdoQry_MainRealReleaseDate: TDateTimeField;
    Button3: TButton;
    Button4: TButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure Act_LookExecute(Sender: TObject);
    procedure btn_ItemClick(Sender: TObject);
    procedure btn_ite_ItemClick(Sender: TObject);
    procedure btn_OrderClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure btn_uPMrpClick(Sender: TObject);
    procedure btn_OblongMrpClick(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure DataSourceDataChange(Sender: TObject; Field: TField);
    procedure DBGridEhGetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
  private
    function ismorethanzero(fieldName:string;tableName:string;conditionfield:string):boolean;
    { Private declarations }
  public
    procedure InitForm(AdOConnection:TAdOConnection;ShowExtendColumn:Boolean);Override;
   function getQclt(ItemCode:string):string;{ Public declarations }
    { Public declarations }
  end;

var
  Frm_Mrp_Qry_NewMrpInfo: TFrm_Mrp_Qry_NewMrpInfo;

implementation

uses Public_Show, Sys_Global, Mrp_Enter_NewMoSsParent,
  Mrp_Qry_InformalTotalMrp_Item, Mrp_Qry_InformalTotalMrp_Mo,
   Mrp_Enter_CloseMo1,
  Mrp_Qry_NewUpRightMrp_D, Mrp_Qry_NewOblongMrp_D,
  Bas_Qry_MultiBomSViewMaster, Mrp_Enter_NewEditPassMo1;

{$R *.DFM}
procedure TFrm_Mrp_Qry_NewMrpInfo.InitForm(AdOConnection:TAdOConnection;ShowExtendColumn:Boolean);
var sqltext:string;
begin
  Application.ProcessMessages;
  createpanel(1,dbgrideh);
  Inherited;
    Adocommand.Connection:=dbconnect;
{    sqltext:='select MrpResult.*,ssid=MrpResultid,ssdate=releasedate,ssSysInfoflag=1,MoLine.moqty,ssqty=MrpResult.onhand,Sysqty=MrpResult.onhand,ssreMainqty=reMainqty '
           +'  into #tMpssInfoQry from MrpResult                '
           +' left outer join MoLine on MrpResult.Orderno=MoLine.mono '
           +'    and MrpResult.Orderlineno=MoLine.MoLineno  '
           +' where (ordinal=3 )                    '
           +'  and  PmCode=0   '
           +' union                                    '
           +' select MrpResult.*,ssid=MrpResultid,ssdate=releasedate,ssSysInfoflag=3,MoLine.moqty,ssqty=MrpResult.Orderqty,Sysqty=MrpResult.Orderqty,ssreMainqty=0 from MrpResult                         '
           +'  join MoLine on MrpResult.Orderno=MoLine.mono '
           +'    and MrpResult.Orderlineno=MoLine.MoLineno  '
           +' where ordinal=2                    '
           +'   and Orderlinestatus=6                 '
           +'   and realOrderqty<=0           '
           +'   and exists(select mono from MoLine where Orderno=MoLine.mono and Orderlineno=MoLine.MoLineno and MoLine.MoLinestatus<>7) '
           +' union                                    '
           +' select MrpResult.*,ssid=MrpResultid,ssdate=releasedate,ssSysInfoflag=4,MoLine.moqty,ssqty=MrpResult.Orderqty,Sysqty=MrpResult.Orderqty,ssreMainqty=0 from MrpResult                         '
           +'  join MoLine on MrpResult.Orderno=MoLine.mono '
           +'    and MrpResult.Orderlineno=MoLine.MoLineno  '
           +' where ordinal=2                    '
           +'   and Orderlinestatus=5 '
           +'   and onhand>0  '
           +'   and (releasedate<dateName(yy,getdate())+''.''+dateName(mm,getdate())+''.''+dateName(dd,getdate()) or duedate<dateName(yy,getdate())+''.''+dateName(mm,getdate())+''.''+dateName(dd,getdate()))  '
          // +'   and Orderlinestatus<>7                 '
           +'   and exists(select mono from MoLine where Orderno=MoLine.mono and Orderlineno=MoLine.MoLineno and MoLine.MoLinestatus<>7) '
           +' union                                    '
           +' select MrpResult.*,ssid=MrpResultid,ssdate=releasedate,ssSysInfoflag=6,MoLine.moqty,ssqty=MrpResult.onhand,Sysqty=MrpResult.onhand,ssreMainqty=0 from MrpResult                         '
           +'  join MoLine on MrpResult.Orderno=MoLine.mono '
           +'    and MrpResult.Orderlineno=MoLine.MoLineno  '
           +' where ordinal=2                    '
           +'   and Orderlinestatus<>7 ' 
           +'   and canuseonhand=1  '
          // +'   and Orderlinestatus<>7                 '
           +'   and exists(select mono from MoLine where Orderno=MoLine.mono and Orderlineno=MoLine.MoLineno and MoLine.MoLinestatus<>7) '
           +' union                                    '
           +' select MrpResult.*,    '
           +'        ssid=MrpResultid,'
           +'        ssdate=releasedate, '
           +'        ssSysInfoflag=2, '
           +'        MoLine.moqty,   '
          // +'       Sysqty=case  when ss.reMainqty<MoLine.moqty then MoLine.moqty-ss.reMainqty '
          // +'             else 0  '
          // +'             end,          '
           +'         ssqty=Orderqty-onhand, '
           +'        Sysqty=Orderqty-onhand,  '
           +'        ssreMainqty=0       '
           +'   from MrpResult,MoLine           '
           +'  where (ordinal=2 )    '
            +'  and Orderlinestatus<>7   '
            +'  and Orderqty>onhand      '
            +'  and MrpResult.ItemCode not  in (select ItemCode from MrpResult with(index(ordinal)) where ordinal=4 )'
//            +'  and exists(select mono from MoLine where Orderno=MoLine.mono) '
            +'  and MrpResult.Orderno=MoLine.mono          '
            +'  and MrpResult.Orderlineno=MoLine.MoLineno  '
           +' union                                    '
           +' select MrpResult.*,    '
           +'        ssid=MrpResultid,'
           +'        ssdate=releasedate, '
           +'        ssSysInfoflag=5, '
           +'        MoLine.moqty,   '
          // +'       Sysqty=case  when ss.reMainqty<MoLine.moqty then MoLine.moqty-ss.reMainqty '
          // +'             else 0  '
          // +'             end,          '
          +'         ssqty=Orderqty-onhand, '
           +'        Sysqty=Orderqty-onhand,  '
           +'        ssreMainqty=0       '
           +'   from MrpResult,MoLine           '
           +'  where (ordinal=2 )    '
            +'  and Orderlinestatus<>7   '
            +'  and Orderqty>onhand      '
            +'  and MrpResult.ItemCode in (select ItemCode from MrpResult   with(index(ordinal)) where ordinal=4)'
//            +'  and exists(select mono from MoLine where Orderno=MoLine.mono) '
            +'  and MrpResult.Orderno=MoLine.mono          '
            +'  and MrpResult.Orderlineno=MoLine.MoLineno  ';

  with Adocommand do
    begin
     commandtext:=sqltext;
     Execute;
    end;
   //Executesql(AdoQry_Main,sqltext,1);
    sqltext:='select #tMpssInfoQry.*,tMpssreMainqty=case #tMpssInfoQry.ssreMainqty when 0 then null else #tMpssInfoQry.ssreMainqty end,Item.mnldtime,Item.ItemName,Uom.UomName,Dept.DeptCode,Dept.DeptName,'
            +'  Employee.EmployeeCode,Employee.EmployeeName,'
                +' haslocated=0, '
                +' ssflag=convert(varchAr,#tMpssInfoQry.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 #tMpssInfoResultQry '
                +' From #tMpssInfoQry '
                +' Join Item On #tMpssInfoQry.ItemCode=Item.ItemCode '
                +' And #tMpssInfoQry.PmCode=0 '
                +' Left Join Dept On  isnull(#tMpssInfoQry.DeptVendorCode,Item.DeptCode)=Dept.DeptCode'
                //+' Left Join Dept On (Case When #tMpssInfoQry.SsSysInfoFlag<>1 Then #tMpssInfoQry.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 #tMpssInfoQry.SSSysInfoFlag=SysSsInfo.SSCode'
                +' where  ((#tMpssInfoQry.SsSysInfoFlag=1 '
                      +' And Item.LongPurchLT=0 And #tMpssInfoQry.DueDate-(select MrpParamValueN from MrpParam '
                      +' where MrpParamCode='''+'SSForwArdDay'+''')<='''+DateTimeToStr(Date())+''')'
                      +' Or (#tMpssInfoQry.SsSysInfoFlag=1 And Item.LongPurchLT=1) Or (#tMpssInfoQry.SsSysInfoFlag<>1 and #tMpssInfoQry.Sysqty<>0)) '
                      +' Order by #tMpssInfoQry.ItemCode,releasedate ';
}
  sqltext:=' exec sp_MrpInfo '''+userCode+''',0 ';
     with Adocommand do
    begin
     commandtext:=sqltext;
     Execute;
    end;
   sqltext:=' select * into #tMpssInfoResultQry from SSProductionInfoResult ';
   Executesql(AdoQry_tmp,sqltext,1);

    // Executesql(AdoQry_Main,sqltext,1);
     Executesql(AdoQry_Main,'select * from #tMpssInfoResultQry',0);
    selectfromsql:='select * from #tMpssInfoResultQry';
  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;
  if ShowAnimate<>nil then ShowAnimate.Free;
  if ShowPanel<>nil then ShowPanel.Free;

  Application.ProcessMessages;

    {sqltext:='select ss.*,MoLine.moqty,Sysqty=ss.ssqty,ssreMainqty=reMainqty  into #tMpssInfoQryQry from ss                         '
           +'  left outer  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                         '
           +'      join MoLine with (index(MoLine_idx_Mono)) on ss.Orderno=MoLine.mono     '
           +'        and ss.Orderlineno=MoLine.MoLineno '
           +' where ssSysInfoflag=3                    '
           +'   and Orderlinestatus<>7                 '
           +'   and exists(select mono from MoLine where Orderno=MoLine.mono and Orderlineno=MoLine.MoLineno and MoLine.MoLinestatus<>7) '
           +' union                                    '
           +' select ss.*,MoLine.moqty,Sysqty=ss.ssqty,ssreMainqty=0 from ss                         '
           +'  join MoLine on ss.Orderno=MoLine.mono '
           +'    and ss.Orderlineno=MoLine.MoLineno  '
           +' where ssSysInfoflag=4                    '
          // +'   and Orderlinestatus<>7                 '
           +'   and exists(select mono from MoLine where Orderno=MoLine.mono and Orderlineno=MoLine.MoLineno ) '
           +' 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   with (index(MoLine_idx_Mono))        '
           +'  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  '
            +'  create  nonclustered index ssindex on #tMpssInfoQryQry(ssdate)';}
{    Adocommand.Connection:=AdoQry_Main.Connection;
  sqltext:='select MrpResult.*,ssid=MrpResultid,ssdate=releasedate,ssSysInfoflag=1,MoLine.moqty,ssqty=MrpResult.onhand,Sysqty=MrpResult.onhand,ssreMainqty=reMainqty '
           +'  into #tMpssInfoQryQry from MrpResult                '
           +' left outer join MoLine on MrpResult.Orderno=MoLine.mono '
           +'    and MrpResult.Orderlineno=MoLine.MoLineno  '
           +' where (ordinal=3 )                    '
           +'  and  PmCode=0   '
           +' union                                    '
           +' select MrpResult.*,ssid=MrpResultid,ssdate=releasedate,ssSysInfoflag=3,MoLine.moqty,ssqty=MrpResult.Orderqty,Sysqty=MrpResult.Orderqty,ssreMainqty=0 from MrpResult                         '
           +'  join MoLine on MrpResult.Orderno=MoLine.mono '
           +'    and MrpResult.Orderlineno=MoLine.MoLineno  '
           +' where ordinal=2                    '

⌨️ 快捷键说明

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