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

📄 mrp_enter_mrpinfo1.pas

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

Interface

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

Type
  TFrm_Mrp_Enter_MrpInfo1 = 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_MainItemName: TStringField;
    AdoQry_MainDeptName: TStringField;
    AdoQry_MainUomName: TStringField;
    AdoQry_MainSScheck: TIntegerField;
    AdoQry_MaInOrderLineStatus: TIntegerField;
    AdoQry_MainDeptFlag: TStringField;
    AdoQry_MainItemFlag: TStringField;
    AdoQry_MainDeptVendorCode: TStringField;
    AdoQry_MainDeptCode: TStringField;
    Label1: TLabel;
    DBText1: TDBText;
    Label2: TLabel;
    DBText2: TDBText;
    Label3: TLabel;
    DBText3: TDBText;
    AdoQry_MainSSName: TStringField;
    AdoQry_MainEmployeeName: TStringField;
    AdoQry_MainEmployeeFlag: TStringField;
    Label4: TLabel;
    DBText4: TDBText;
    AdoQry_MaindueDate: TDateTimeField;
    AdoQry_MainMnldTime: TFloatField;
    AdoQry_MainEmployeeCode: TStringField;
    AdoQry_MainReMainQty: TFloatField;
    AdoQry_Mainssflag: TStringField;
    lbl_RunMrpdate: TLabel;
    Label5: TLabel;
    AdoQry_MaintMpssreMainqty: TFloatField;
    AdoQry_MainPmCode: TIntegerField;
    AdoQry_MainSysqty: TFloatField;
    btn_Item: TButton;
    btn_ite_Item: TButton;
    btn_Order: TButton;
    AdoQry_Mainmoqty: TFloatField;
    btn_uPMrp: TButton;
    btn_OblongMrp: TButton;
    Button1: TButton;
    Button2: TButton;
    AdoQry_MainRealReleaseDate: TDateTimeField;
    Label6: TLabel;
    Button3: TButton;
    AdOCommand: TAdOCommand;
    procedure FormDestroy(Sender: TObject);
    procedure Act_NewExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Act_CheckExecute(Sender: TObject);
    procedure AdoQry_MainBeforeEdit(DataSet: TDataSet);
    procedure AdoQry_MainBeforeInsert(DataSet: TDataSet);
    procedure Act_DeleteExecute(Sender: TObject);
    procedure DBGridEhTitleClick(Column: TColumnEh);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure btn_ItemClick(Sender: TObject);
    procedure btn_ite_ItemClick(Sender: TObject);
    procedure btn_OrderClick(Sender: TObject);
    procedure btn_uPMrpClick(Sender: TObject);
    procedure btn_OblongMrpClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure DataSourceDataChange(Sender: TObject; Field: TField);
    procedure Button3Click(Sender: TObject);
    procedure DBGridEhGetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
  private
    Checked:Boolean;
    function ismorethanzero(fieldName:string;tableName:string;conditionfield:string):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_Enter_MrpInfo1: TFrm_Mrp_Enter_MrpInfo1;
  //ItemCode:string;

implementation
uses Sys_Global, Mrp_Enter_AutoMo, Public_Show, Mrp_Enter_MoSsParent,
  Mrp_Qry_UpRightMrp_D_Item, Mrp_Qry_InformalTotalMrp_Item,
  Mrp_Qry_InformalTotalMrp_Po, Mrp_Qry_InformalTotalMrp_Mo,
  Mrp_Qry_UpRightMrp_D, Mrp_Qry_OblongMrp_D, Mrp_Enter_CloseMo1,Bas_Qry_MultiBomSViewMaster;
{$R *.DFM}
procedure TFrm_Mrp_Enter_MrpInfo1.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
var sqltext:string;
begin
  Application.ProcessMessages;
  inherited;
  If ReadOnly=True Then
  begin
    TlBtn_Copy.Visible:=False;
  end;
  Application.ProcessMessages;
  lbl_RunMrpdate.Caption:=getMrpdate;
    Adocommand.Connection:=AdoQry_Main.Connection;
    sqltext:='select ss.*,MoLine.moqty,Sysqty=ss.ssqty,ssreMainqty=reMainqty '
           +'  into #tMpssInfo1 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 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 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  ';
  // Executesql(AdoQry_Main,sqltext,1);
    with Adocommand do
    begin
     commandtext:=sqltext;
     Execute;
    end;
    sqltext:='select #tMpssInfo1.*,tMpssreMainqty=case #tMpssInfo1.ssreMainqty when 0 then null else #tMpssInfo1.ssreMainqty end,Item.mnldtime,Item.ItemName,Uom.UomName,Dept.DeptCode,Dept.DeptName,'
            +'  Employee.EmployeeCode,Employee.EmployeeName,'
                +' ssflag=convert(varchAr,#tMpssInfo1.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 #tMpssInfoResult1 '
                +' From #tMpssInfo1 '
                +' Join Item On #tMpssInfo1.ItemCode=Item.ItemCode '
                +' And PmType=0 '
                +' and Item.Pla_EmployeeCode='+quotedstr(userCode)
                +' Left Join Dept On  isnull(#tMpssInfo1.DeptVendorCode,Item.DeptCode)=Dept.DeptCode'
             //   +' Left Join Dept On (Case When #tMpssInfo1.SsSysInfoFlag<>1 Then #tMpssInfo1.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 #tMpssInfo1.SSSysInfoFlag=SysSsInfo.SSCode'
                +' where  ((#tMpssInfo1.SsSysInfoFlag=1 '
                      +' And Item.LongPurchLT=0 And #tMpssInfo1.DueDate-(select MrpParamValueN from MrpParam '
                      +' where MrpParamCode='''+'SSForwArdDay'+''')<='''+DateTimeToStr(Date())+''')'
                      +' Or (#tMpssInfo1.SsSysInfoFlag=1 And Item.LongPurchLT=1) Or (#tMpssInfo1.SsSysInfoFlag<>1 and #tMpssInfo1.Sysqty<>0)) '
                      +' Order by #tMpssInfo1.ItemCode,ssdate';
   //  Executesql(AdoQry_Main,sqltext,1);
     with Adocommand do
    begin
     commandtext:=sqltext;
     Execute;
    end;
     Executesql(AdoQry_Main,'select * from #tMpssInfoResult1',0);
    selectfromsql:='select * from #tMpssInfoResult1';

  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_Enter_MrpInfo1.FormDestroy(Sender: TObject);
begin
  inherited;
  Frm_Mrp_Enter_MrpInfo1:=Nil;
end;

procedure TFrm_Mrp_Enter_MrpInfo1.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;
  try
  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:=1;
        Frm_Mrp_Enter_AutoMo.GetConnect(AdoQry_Main);
    Frm_Mrp_Enter_AutoMo.ShowModal;
  end;
  finally
   AdoQry_Main.BookmArk:=BookmArk;
  end;
end;

procedure TFrm_Mrp_Enter_MrpInfo1.FormCreate(Sender: TObject);
begin
  inherited;
  activecontrol:=dbgrideh;
  ExtendCaption:=False;
//  TlBtn_Copy.Action:=Act_Check;
end;

procedure TFrm_Mrp_Enter_MrpInfo1.Act_CheckExecute(Sender: TObject);
var
  BookmArk:String;
begin
  inherited;
  If AdoQry_Main.RecordCount=0 Then
    Abort;
  BookmArk:=AdoQry_Main.BookmArk;
  AdoQry_Main.First;
  While Not AdoQry_Main.Eof Do
  begin
    AdoQry_Main.Edit;
    AdoQry_Main.fieldbyname('SScheck').AsInteger:=1;
    AdoQry_Main.Post;
    AdoQry_Main.Next;
  end;
  AdoQry_Main.BookmArk:=BookmArk;
end;

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

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

procedure TFrm_Mrp_Enter_MrpInfo1.Act_DeleteExecute(Sender: TObject);
begin
 // inherited;

end;

procedure TFrm_Mrp_Enter_MrpInfo1.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;

function TFrm_Mrp_Enter_MrpInfo1.getMrpdate: string;
var AdoQry:TAdoQuery;
begin
 AdoQry:=TAdoQuery.Create(self);
 AdoQry.EnableBCD:=False;
 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;



procedure TFrm_Mrp_Enter_MrpInfo1.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
Executesql(AdoQry_tmp,'drop table #tMpssInfo1,#tMpssInfoResult1',1);
end;

function TFrm_Mrp_Enter_MrpInfo1.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

⌨️ 快捷键说明

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