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

📄 pm_enter_sspoinfo4.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Pm_Enter_SsPoInfo4;
 
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_Pm_Enter_SsPoInfo4 = Class(TFrm_Base_Outer)
    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_MainItemName: TStringField;
    AdoQry_MainUomCode: TStringField;
    AdoQry_MainUomName: TStringField;
    AdoQry_MaInOrderLineStatus: TIntegerField;
    AdoQry_MainItemflag: TStringField;
    AdoQry_MainSsName: TStringField;
    Label1: TLabel;
    DBText1: TDBText;
    DBText2: TDBText;
    Label2: TLabel;
    Label3: TLabel;
    DBText3: TDBText;
    AdoQry_MainDeptVendorCode: TStringField;
    AdoQry_Loop: TAdoQuery;
    AdoQry_MainPcNo: TStringField;
    AdoQry_MainPmCode: TIntegerField;
    Label4: TLabel;
    DBText4: TDBText;
    AdoQry_MainEmployeeCode: TStringField;
    AdoQry_MainEmployeeName: TStringField;
    AdoQry_MainEmployeeFlag: TStringField;
    AdoQry_Mainduedate: TDateTimeField;
    AdoQry_MainReMainQty: TFloatField;
    Label6: TLabel;
    Lab_RunMrpDate: TLabel;
    AdoQry_MainReMainQty2: TFloatField;
    AdoQry_MainQclt: TIntegerField;
    btn_ite_Item: TButton;
    btn_Vendor: TButton;
    btn_Item: TButton;
    AdoQry_MainSSQty2: TFloatField;
    AdoQry_Mainpoinqty: TFloatField;
    AdoQry_MainDeptVendorCode2: TStringField;
    Label5: TLabel;
    DBText5: TDBText;
    AdoQry_MainSSId: TAutoIncField;
    AdoQry_MainSSId2: TAutoIncField;
    btn_uPMrp: TButton;
    btn_OblongMrp: TButton;
    procedure FormDestroy(Sender: TObject);
    procedure Act_NewExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Act_CheckExecute(Sender: TObject);
    procedure AdoQry_MainBeforeInsert(DataSet: TDataSet);
    procedure AdoQry_MainBeforeEdit(DataSet: TDataSet);
    procedure AdoQry_MainAfterPost(DataSet: TDataSet);
    procedure DBGridEhTitleClick(Column: TColumnEh);
    procedure Act_LookExecute(Sender: TObject);
    procedure btn_ItemClick(Sender: TObject);
    procedure btn_VendorClick(Sender: TObject);
    procedure btn_ite_ItemClick(Sender: TObject);
    procedure btn_uPMrpClick(Sender: TObject);
    procedure btn_OblongMrpClick(Sender: TObject);
  private
 //  Flag:Integer;
    Checked:Boolean;
    PcNo:String;
    PmCode:Integer;
    Selected:Integer;//选定个数
    function ismorethanzero(fieldName:string;tableName:string;conditionfield:string):boolean;

    { Private declarations }
  public
    untionfalg:integer;
    frentform,falg:integer;
    LDdate:integer;
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
    procedure Initselect;
    procedure GetData;Override;
    function getQclt(ItemCode:string):string;{ Public declarations }
    { Public declarations }
  end;

var
  Frm_Pm_Enter_SsPoInfo4: TFrm_Pm_Enter_SsPoInfo4;
  ItemCode:string;

implementation
uses Sys_Global,  Pm_Enter_AutoPo2, Mrp_Enter_MoSsParent,
  Mrp_Qry_InformalTotalMrp_vd, Mrp_Qry_InformalTotalMrp_Item,
  Pm_Enter_SsPoInfo4_C, Pm_Enter_SsPoInfo1, Pm_Enter_SsPoInfo2,
  Mrp_Qry_UpRightMrp_D, Mrp_Qry_OblongMrp_D;
{$R *.DFM}
procedure TFrm_Pm_Enter_SsPoInfo4.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
var
  SqlText,ItemCode,StArtSsdate,endSsdate :string;
  AdoQuery,AdoQuery1:TAdoQuery;
begin
  Application.ProcessMessages;
  inherited;

//  --选出每种产品中Min(SSdate)放入#C_Ss3
  SqlText:=' CREATE TABLE [#C_Ss3] ('
          +' [SsId] [int] ,'
          +' [ItemCode] [varchAr] (50) ,'
          +' [ssdate] [datetime]  , '
          +' [duedate] [datetime] ,  '
          +' [SSQty] [float]  ,   '
          +' [ReMainQty] [float]  ,'
          +' [ssreMainqty] [float]  ) '

          +' CREATE TABLE [#C_Ss4] ('
          +' [StArtSsId] [int] ,'
          +' [endSsId] [int] ,'
          +' [ItemCode] [varchAr] (50) ,'
          +' [ssdate] [datetime]  ,'
          +' [duedate] [datetime] ,'
          +' [SSQty] [float]  ,'
          +' [ReMainQty] [float]  ,'
          +' [ssreMainqty] [float]  )'


          +' insert into #C_Ss3 (ItemCode,ssdate)'
          +' select ItemCode,min(ssdate) ssdate  '
          +' from #C_Ss2 group by ItemCode   ';
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.Text := SqlText;
  AdoQry_Tmp.ExecSQL;

//--循环从#C_Ss3中起出日期 并合成日期段 汇总后放入#C_Ss4并栓去#C_Ss3中的记录,#C_Ss2中的记录段

  repeat
    AdoQuery:=TAdoQuery.Create(self);
    AdoQuery.Connection := DbConnect;

    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text := ' Select * from #C_Ss3 ';
    AdoQry_Tmp.open;

    while not  AdoQry_Tmp.Eof do
    begin
      ItemCode:= AdoQry_Tmp.fieldbyname('ItemCode').asstring;
      StArtSsDate:= AdoQry_Tmp.fieldbyname('SsDate').asstring;
      endSsDate:=SlCalendar(DbConnect,StArtSsDate,LDdate);
      SqlText:= ' insert into #C_Ss4 (StArtSsId,endSsId,ItemCode,ssdate,'
               +' duedate,SSQty,ReMainQty,ssreMainqty)'
               +' select min(SsId) as StArtSsId,max(SsId) as endSsId,ItemCode,'
               +' min(ssdate) ssdate, min(duedate) duedate,sum(SSQty) as SSQty ,'
               +' sum(ReMainQty) as ReMainQty ,sum(ssReMainQty) as ssReMainQty'
               +' from #C_Ss2  where ssdate >='''+StArtSsDate+''' and ssdate <='''+endSsDate+''''
               +' and ItemCode= '''+AdoQry_Tmp.fieldbyname('ItemCode').asstring+''''
               +' group by ItemCode'
               +' Delete #C_Ss2 where  ssdate >='''+StArtSsDate+''' and ssdate <='''+endSsDate+''' '
               +' and ItemCode= '''+AdoQry_Tmp.fieldbyname('ItemCode').asstring+'''';
      AdoQuery.Close;
      AdoQuery.SQL.Text :=SqlText;
      AdoQuery.ExecSQL ;
      AdoQry_Tmp.Next;
    end;
    if  AdoQry_Tmp.Eof then
    begin
      AdoQuery.Close;
      AdoQuery.SQL.Text :=' Delete #C_Ss3'
                         +' insert into #C_Ss3 (ItemCode,ssdate)'
                         +' select ItemCode,min(ssdate) ssdate  '
                         +' from #C_Ss2 group by ItemCode ';
      AdoQuery.ExecSQL;
    end;
    SqlText:= 'Select * from #C_Ss2 ';
    AdoQuery1:=TAdoQuery.Create(self);
    AdoQuery1.Connection := DbConnect;
    AdoQuery1.Close;
    AdoQuery1.SQL.clear;
    AdoQuery1.SQL.Text := SqlText;
    AdoQuery1.Open;
  until (AdoQuery1.RecordCount = 0) ;

  try
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.clear;
    AdoQry_Tmp.SQL.Text := 'Drop table #ss12  ';
    AdoQry_Tmp.ExecSQL;
  except
  end;
  SqlText:=' select  #C_Ss4.StArtSsId as StArtSsId,#C_Ss4.endSsId as endSsId,'
          +' #C_Ss4.ItemCode as ItemCode,#C_Ss4.ssdate as ssdate,#C_Ss4.duedate as duedate,'
          +' #C_Ss4.SSQty,#C_Ss4.ReMainQty,#C_Ss4.ssreMainqty ,'
          +' #ss.ssSysInfoflag, #ss.Orderno,#ss.Orderlineno, #ss.PmType,'
          +' #ss.sScheck,#ss.OrderLineStatus,#ss.DeptVendorCode,'
          +' #ss.GrossRequireQty,#ss.PlanInvQty'
          +' into #ss12 from #C_Ss4 join #SS'
          +' on #C_Ss4.StArtSsId=#SS.SsId';

  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.Text := SqlText;
  AdoQry_Tmp.ExecSQL;

{insert into #C_Ss4 (StArtSsId,endSsId,ItemCode,ssdate,duedate,SSQty,ReMainQty,ssreMainqty)
select min(SsId) as StArtSsId,max(SsId) as endSsId,ItemCode,min(ssdate) ssdate,
    min(duedate) duedate,sum(SSQty) as SSQty ,sum(ReMainQty) as ReMainQty ,sum(ssReMainQty) as ssReMainQty
from #C_Ss2 group by ItemCode
  }

  Initselect;

  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;

  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:='Select MrpParamValueC from MrpParam '
                      +' where MrpParamCode='''+'RunMrpDate'+'''';
  AdoQry_Tmp.Open;
  lab_RunMrpDate.Caption :=AdoQry_Tmp.fieldbyname('MrpParamValueC').AsString;

  Checked:=False;

end;


procedure TFrm_Pm_Enter_SsPoInfo4.FormDestroy(Sender: TObject);
begin
  inherited;
  Frm_Pm_Enter_SsPoInfo4:=Nil;
end;

procedure TFrm_Pm_Enter_SsPoInfo4.Act_NewExecute(Sender: TObject);
var
  I:Boolean;
  BookMArk:String;
begin
  inherited;
  frentform:=1;
  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;
     BookMArk:=AdoQry_Main.BookmArk ;
     Break;
    end;
    AdoQry_Main.Next;
  end;
  If I=True Then
  begin
    falg:=1;
    Frm_Pm_Enter_AutoPo2:=TFrm_Pm_Enter_AutoPo2.Create(Application);
    Frm_Pm_Enter_AutoPo2.InitForm(DbConnect,'Add',AdoQry_Main);
    Frm_Pm_Enter_AutoPo2.SetFormParam(PcNo,IntToStr(PmCode),'','','','');
    Frm_Pm_Enter_AutoPo2.SetSysParam(UserCode,ModuleCode,MenuId,LoginDate);
    Frm_Pm_Enter_AutoPo2.ShowModal;
    Frm_Pm_Enter_AutoPo2.Free;
  end
  Else
  begin
    AdoQry_Main.BookmArk:=BookMArk;
    DispInfo('没有选定记录,不能执行新增操作!',3);
    Abort;
  end;
//  BookMArk:=AdoQry_Main.BookmArk ;
  AdoQry_Main.First;
  While Not AdoQry_Main.Eof Do
  begin
    If AdoQry_Main.fieldbyname('SScheck').AsInteger=1 Then
    begin
      PcNo:=AdoQry_Main.fieldbyname('PcNo').AsString;
      PmCode:=AdoQry_Main.fieldbyname('PmType').AsInteger;
      Break;
    end
    Else
      AdoQry_Main.Next;
  end;
  If AdoQry_Main.Eof Then
  begin
    PcNo:='';
    PmCode:=0;
  end;
  AdoQry_Main.BookmArk:=BookMArk;
end;

procedure TFrm_Pm_Enter_SsPoInfo4.FormCreate(Sender: TObject);
begin
  inherited;
  ExtendCaption:=False;
//  TlBtn_Copy.Action:=Act_Check;
  PcNo:='';
  PmCode:=0;
  Selected:=0;
end;

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

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

procedure TFrm_Pm_Enter_SsPoInfo4.AdoQry_MainBeforeEdit(DataSet: TDataSet);
begin
  inherited;
{  I:=0;
  BookmArk:=AdoQry_Main.BookmArk;
  AdoQry_Main.First;
  while  not AdoQry_Main.Eof  do
  begin
    if AdoQry_Main.fieldbyname('SScheck').asinteger = 1 then
    begin
      I:=1;
      exit;
    end;
    AdoQry_Main.next;
  end;
  if I=0 then
    pcno:='';
  AdoQry_Main.BookmArk:= BookmArk;}
  IF (AdoQry_Main.fieldbyname('pcno').AsString='替代件待分配')  and (ActiveControl.Name='DBGridEh' ) Then    //(Flag=1) And
  begin
    DispInfo('本条建议不能下单,请按 "替代件建议分配"按钮!',3);
    Abort;
  end;  
  IF (AdoQry_Main.fieldbyname('SSSysInfoFlag').AsInteger<>1) Then    //(Flag=1) And
  begin
    DispInfo('本条建议不为"建议下达",不能执行选定操作!',3);
    Abort;
  end;
  If Trim(AdoQry_Main.fieldbyname('PcNo').AsString)='' Then
  begin
    DispInfo('不能对一条没有可用采购合同号的记录进行操作!',3);
    Abort;
  end;
  If AdoQry_Main.fieldbyname('ssReMainQty').AsFloat<=0 Then
  begin
    DispInfo('本条建议"系统建议余量"已分配完毕,不能执行选定操作!',3);
    Abort;
  end;
  If (PmCode=1) And (AdoQry_Main.fieldbyname('PmType').AsInteger<>PmCode) Then
  begin
    DispInfo('本条记录物料制构类型与选定的不一值!',3);
    Abort;
  end;
  If (PmCode In [2,3]) And (AdoQry_Main.fieldbyname('PmType').AsInteger=1) Then
  begin
    DispInfo('本条记录物料制构类型与选定的不一值!',3);
    Abort;
  end;
  If (Length(PcNo)>0) And (AdoQry_Main.fieldbyname('PcNo').AsString<>PcNo) Then

⌨️ 快捷键说明

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