📄 pm_enter_newsspoinfo4.pas
字号:
unit Pm_Enter_NewSsPoInfo4;
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_NewSsPoInfo4 = 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_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);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
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_NewSsPoInfo4: TFrm_Pm_Enter_NewSsPoInfo4;
ItemCode:string;
implementation
uses Sys_Global, Mrp_Enter_MoSsParent,
Mrp_Qry_InformalTotalMrp_vd, Mrp_Qry_InformalTotalMrp_Item,
Mrp_Qry_UpRightMrp_D, Mrp_Qry_OblongMrp_D,Pm_Enter_NewAutoPo2,
Mrp_Qry_NewUpRightMrp_D, Mrp_Qry_NewOblongMrp_D;
{$R *.DFM}
procedure TFrm_Pm_Enter_NewSsPoInfo4.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.PmCode,'
+' #ss.sScheck,#ss.OrderLineStatus,#ss.DeptVendorCode as DeptVendorCode,'
+' #ss.GrossRequireQty as GrossQty '//,#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 PmParamValueN from PmParam '
+' where PmParamCode='''+'SSForwArdDay'+'''';
AdoQry_Tmp.Open;
Lbl_Condition.Caption:='系统建议下达(约定开工日-'+FormatDateTime('yyyy.mm.dd',Date())+')'
+'<=建议可见提前天数('+IntToStr(AdoQry_Tmp.fieldbyname('PmParamValueN').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_NewSsPoInfo4.FormDestroy(Sender: TObject);
begin
inherited;
Frm_Pm_Enter_NewSsPoInfo4:=Nil;
end;
procedure TFrm_Pm_Enter_NewSsPoInfo4.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_NewAutoPo2:=TFrm_Pm_Enter_NewAutoPo2.Create(Application);
Frm_Pm_Enter_NewAutoPo2.InitForm(DbConnect,'Add',AdoQry_Main);
Frm_Pm_Enter_NewAutoPo2.SetFormParam(PcNo,IntToStr(PmCode),'','','','');
Frm_Pm_Enter_NewAutoPo2.SetSysParam(UserCode,ModuleCode,MenuId,LoginDate);
Frm_Pm_Enter_NewAutoPo2.ShowModal;
Frm_Pm_Enter_NewAutoPo2.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_NewSsPoInfo4.FormCreate(Sender: TObject);
begin
inherited;
ExtendCaption:=False;
// TlBtn_Copy.Action:=Act_Check;
PcNo:='';
PmCode:=0;
Selected:=0;
end;
procedure TFrm_Pm_Enter_NewSsPoInfo4.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_NewSsPoInfo4.AdoQry_MainBeforeInsert(
DataSet: TDataSet);
begin
inherited;
Abort;
end;
procedure TFrm_Pm_Enter_NewSsPoInfo4.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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -