📄 mrp_enter_newrunmrp.pas
字号:
// Author:ZhuZhongfu
// Date:2001.20.28
// Version:2.0
unit Mrp_Enter_NewRunMrp;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Condition, StdCtrls, Db, AdODB,Sys_Global, ExtCtrls, Mask, Buttons,
Grids, DBGrids, DBClient, MConnect,InifileS,Math;
Type
TFrm_Mrp_Enter_NewRunMrp = Class(TFrm_Base_Condition)
AdoQry_Main: TAdoQuery;
AdoQry_MainSSId: TAutoIncField;
AdoQry_MainItemCode: TStringField;
AdoQry_MainDeptCode: 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_MainMoLinestatus: TIntegerField;
AdoQry_MainSScheck: TIntegerField;
EdtRunMrpStatus: TEdit;
RdGrpSelectRunMrpType: TRadioGroup;
RdBtnInformalMrp: TRadioButton;
RdBtnMrp: TRadioButton;
MaskEdit1: TMaskEdit;
Label1: TLabel;
DCOMConnection1: TDCOMConnection;
procedure btn_okClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure btn_CancelClick(Sender: TObject);
procedure RdBtnMrpClick(Sender: TObject);
procedure RdBtnInformalMrpClick(Sender: TObject);
procedure DCOMConnection1AfterConnect(Sender: TObject);
private
{ Private declarations }
procedure CalculateMrpResult(R_AdoQry_Calculate:TAdoQuery;
R_AdoQry_Calculate1:TAdoQuery;
R_StrItemCode:String;R_StrReleaseDate:String;
R_StrMinQty:String;R_StrBatchStrat:String;
R_StrBatchQty:String;R_StrSubReleaseDate:String;
R_StrMrpResult:String;R_StrDueDate:String);//计算Mrp结果
procedure VoidCalculateMrpResult(R_AdoQry_Calculate:TAdoQuery;
R_AdoQry_Calculate1:TAdoQuery;
R_StrItemCode:String;R_StrReleaseDate:String;
R_StrMinQty:String;R_StrBatchStrat:String;
R_StrBatchQty:String;R_StrSubReleaseDate:String;
R_StrMrpResult:String;R_StrDueDate:String);//计算Mrp结果
procedure CutComponent(R_AdoQry_Calculate:TAdoQuery;
R_AdoQry_Calculate1:TAdoQuery;
R_DBConnect:TAdOConnection;
R_StrItemCode:String );//产生子项需求
procedure VoidCutComponent(R_AdoQry_Calculate:TAdoQuery;
R_AdoQry_Calculate1:TAdoQuery;
R_DBConnect:TAdOConnection;
R_StrItemCode:String );//产生子项需求
procedure DelTmpTable();//删除整个RunMrp的临时表
procedure DropTable(R_TableName:String);//删除表
procedure ExecuteCmd(R_AdOCmd_Execute:TAdOCommand;R_StrSqlText:String);
Function GetCalendar(R_AdOConnection:TAdOConnection;R_ParentRequireDate:String;R_LdTime:Integer):String;//计算约定交货日
Function OpenBom(R_AdoQry_Mrpmain:TAdoQuery):Integer;//新分解Bom程序
procedure OpenBomDetail(R_AdoQry_Bom:TAdoQuery;R_StrItemCode:String);
procedure RunMrpFirstStep(R_AdOCmd_FirstStep:TAdOCommand;R_MrpCondition:String;R_MrpCondition1:String);//做运算Mrp的前期工作
procedure WrIteMrpFlag(R_FlagInfo:String);//写入Mrp日志
procedure AssignCurrentInv(R_AdoQry_Mrpmain:TAdoQuery);
procedure ESpecialAssignCurrentInv(R_AdoQry_Mrpmain:TAdoQuery;
R_AdoQry_Mrpmain1:TAdoQuery);
procedure CalculateAlterNativeOnHand(R_AdoQry_Mrpmain:TAdoQuery);
procedure CalculateAlterNativeOnCheck(R_AdoQry_Mrpmain:TAdoQuery);
procedure CalculateAlterNativeOnHandOnCheckMOPO(R_AdoQry_Mrpmain:TAdoQuery);
procedure SaveLeaveMOPO(R_AdoQry_Mrpmain:TAdoQuery;R_AdoQry_Mrpmain1:TAdoQuery);
procedure SaveDynamicOperation(R_AdOCmd:TAdOCommand;
R_AdoQry:TAdoQuery;
R_AdoQry1:TAdoQuery);
public
{ Public declarations }
end;
var
Frm_Mrp_Enter_NewRunMrp: TFrm_Mrp_Enter_NewRunMrp;
IntMaxLLC:Integer;//最大LLC值
IntCurrentLLC:Integer; //当前LLC值
TflRunMrpFlag:TextFile; //日志文件
StrLastMoPoDate:String;//最后订单日期与之相反算订单未结量就是最前日期
StrBatchStrat:String; //批量政策
StrBatchQty:String; //批量
StrMinQty:String; //安全库存
StrItemCode:String; //货品编码
StrReleaseDate:String; //约定交货日
StrDueDate:String; //约定开工日
StrSubReleaseDate:String;//子项约定交货日
StrGrossQty:String; //毛需求量
StrmdlMrpResult:String; //存放Mrp中间结果表名
StrPmCode:String;//制购码
StrPegging:String; //需求溯源
IntItemType:Integer; //物料类型
IntGroupOrdinal:integer; //组序号
StrToDate:String;//今天日期
StrMrpResult:String; //存放Mrp结果表名
StrPeggingNo:String;
Tmp_Inifile:tInifile; //操作ini文件的对象
Tmp_lserverip:string;
Tmp_ldataBaseName:string;
Tmp_ldbuserid:string;
Tmp_ldbPass:string;
IntPurchLDTime:Integer;
IntMNLDTime:Integer;
IntPrepareLTTime:Integer;
IntQcLTTime:Integer;
IntRunLTTime:Integer;
DblCapacityHours:Double;
WinDirectory: PchAr;
implementation
{$R *.DFM}
procedure TFrm_Mrp_Enter_NewRunMrp.WrIteMrpFlag(R_FlagInfo:String);//写入Mrp日志
begin
AssignFile(TflRunMrpFlag,WinDirectory+'\Temp\RMrpFlag.Txt');
Append(TflRunMrpFlag);
WriteLn(TflRunMrpFlag,DateTimeToStr(Now)+' '+R_FlagInfo);
CloseFile(TflRunMrpFlag);
end;
procedure TFrm_Mrp_Enter_NewRunMrp.ExecuteCmd(R_AdOCmd_Execute:TAdOCommand;R_StrSqlText:String);
begin
With R_AdOCmd_Execute Do
begin
CommandText:=R_StrSQLText;
Prepared;
Execute;
end;
end;
procedure TFrm_Mrp_Enter_NewRunMrp.DropTable(R_TableName:String);//删除表
var StrSQLText:String;
begin
Try
StrSQLText:='Drop Table '+R_TableName+'';
ExecuteSql(Frm_Mrp_Enter_NewRunMrp.AdoQry_Main,StrSqlText,1);
Except
end;
end;
procedure TFrm_Mrp_Enter_NewRunMrp.DelTmpTable();//删除整个RunMrp的临时表
begin
DropTable('#TmPmps');
DropTable('#TmPmoPo');
DropTable('#TmPmoPoAlterNative');
DropTable('#TmpItem');
DropTable('#TmpBom');
DropTable('#TmpCalendar');
DropTable('#TmPMrpResult');
DropTable('#TmPMrpResult1');
DropTable('#TmPmdlMps');
DropTable('#TmPmdlMps1');
DropTable('#TmPmdlMps11');
DropTable('#TmPmNItemList');
DropTable('#TmpOPerationMps');
DropTable('#TmpOPerationMO');
DropTable('#TmpOPerationPO');
DropTable('#TmpOPerationMOSc');
DropTable('#TmpOPerationPOSc');
DropTable('#TmpAlterNativeOrder');
end;
Function TFrm_Mrp_Enter_NewRunMrp.GetCalendar(R_AdOConnection:TAdOConnection;R_ParentRequireDate:String;R_LdTime:Integer):String;//计算约定交货日
var AdoQry_Calendar:TAdoQuery;
StrSqlText:String;
IntTmpDate:Integer;
StrSDate:String;
begin
AdoQry_Calendar:=TAdoQuery.Create(Nil);
AdoQry_Calendar.EnableBCD:=False;
AdoQry_Calendar.Connection:=R_AdOConnection;
With AdoQry_Calendar Do
begin
Close;
Sql.clear;
StrSqlText:='Select DayOrdinal '+
'From #TmpCalendar With(Index(Sdate)) '+
'Where SDate<=:SDate And WorkDay=1 '+
'Order By SDate DESC';
Sql.Add(StrSqlText);
StrSDate:=FormatDateTime('yyyy.mm.dd',StrToDateTime(R_ParentRequireDate));
Parameters.ParamByName('SDate').Value:=StrToDateTime(StrSDate);//FormatDateTime('yyyy.mm.dd',StrToDateTime(R_ParentRequireDate));
Prepared;
Open();
If AdoQry_Calendar.RecordCount>0 Then
IntTmpDate:=AdoQry_Calendar.fieldbyname('DayOrdinal').Value
Else
IntTmpDate:=0;
end;
If IntTmpDate=0 Then
Result:=DateTimeToStr(StrToDateTime(R_ParentRequireDate)-R_LDTime)
Else
begin
With AdoQry_Calendar Do
begin
Close;
Sql.clear;
StrSqlText:='Select SDate '+
'From #TmpCalendar With(Index(Sdate)) '+
'Where DayOrdinal<=:DayOrdinal '+
'Order By SDate DESC';
Sql.Add(StrSqlText);
Parameters.ParamByName('DayOrdinal').Value:=IntTmpDate-R_LDTime;
Prepared;
Open();
end;
IF AdoQry_Calendar.RecordCount>0 Then
Result:=AdoQry_Calendar.fieldbyname('SDate').AsString
Else
Result:=DateTimeToStr(StrToDateTime(R_ParentRequireDate)-R_LDTime)
end;
AdoQry_Calendar.Free;
end;
procedure TFrm_Mrp_Enter_NewRunMrp.OpenBomDetail(R_AdoQry_Bom:TAdoQuery;R_StrItemCode:String);
var StrSqlText:String;
begin
StrSqlText:='Truncate Table #TmpOpenBom '+
'Insert #TmpParent(ItemCode,BomItemType)Values('''+R_StrItemCode+''',0) '+
'Insert #TmpOpenBom '+
'Select ItemCode,0 AS LLC,0 As BomItemType From #TmpParent '+
'DeclAre @IntOrdinal Integer '+
'Select @IntOrdinal=1 '+
'While Exists (Select * From #TmpParent) '+ // 循环到没有子项为止
'begin '+
'Truncate Table #TmPmdlOpenBom '+ //--产生下一层的子项
'Insert #TmPmdlOpenBom(ItemCode,LLC,BomItemType) '+
'Select ItemCode,@IntOrdinal As LLC,BomItemType '+
'From #TmpBom Where Ite_ItemCode In '+
'(Select #TmpParent.ItemCode As Ite_ItemCode '+
'From #TmpParent Where BomItemType<>6) '+
'And (BomItemType=0 Or BomItemType=3 Or BomItemType=6) '+
'Truncate Table #TmpParent '+
'Insert #TmpParent '+
'Select ItemCode ,BomItemType From #TmPmdlOpenBom '+
'Insert #TmpOpenBom '+
'Select * From #TmPmdlOpenBom '+
'Select @IntOrdinal=@IntOrdinal+1 '+
'end';
ExecuteSql(R_AdoQry_Bom,StrSqlText,1);
StrSqlText:='Update #TmpItem Set LowLevelCode=#TmpLLC.LLC '+
'From (Select ItemCode,Max(LLC) As LLc '+
'From #TmpOpenBom '+
'Group By ItemCode ) #TmpLLC '+
'Where #TmpItem.ItemCode=#TmpLLC.ItemCode And '+
'#TmpLLC.LLC>#TmpItem.LowLevelCode';
ExecuteSql(R_AdoQry_Bom,StrSqlText,1);
end;
Function TFrm_Mrp_Enter_NewRunMrp.OpenBom(R_AdoQry_Mrpmain:TAdoQuery):Integer;//新分解Bom程序
var AdoQry_Bom:TAdoQuery;
AdoQry_SaveLC:TAdoQuery;
StrSQLText:String;
begin
AdoQry_Bom:=TAdoQuery.Create(nil);
AdoQry_Bom.EnableBCD:=False;
AdoQry_SaveLC:=TAdoQuery.Create(nil);
AdoQry_SaveLC.EnableBCD:=False;
AdoQry_Bom.Connection:=R_AdoQry_Mrpmain.Connection;
AdoQry_SaveLC.Connection:=R_AdoQry_Mrpmain.Connection;
StrSqlText:='set noCount on '+
'Create Table #TmpOpenBom(ItemCode varChAr(16),'+
'LLC Integer,'+
'BomItemType Integer) '+
'Create Table #TmPmdlOpenBom(ItemCode varChAr(16),'+
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -