📄 mrp_enter_newpassmo.pas
字号:
unit Mrp_Enter_NewPassMo;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Check, Menus, Db, ActnList, AdODB, Grids, DBGridEh, StdCtrls,
ExtCtrls, ComCtrls, ToolWin, DBCtrls, jpeg, ExtPrintReport;
Type
TFrm_Mrp_Enter_NewPassMo = Class(TFrm_Base_Check)
AdoQry_HeadMONO: TStringField;
AdoQry_HeadMoLineNO: TIntegerField;
AdoQry_HeadItemCode: TStringField;
AdoQry_HeadMOQTY: TFloatField;
AdoQry_HeadMoLineDATE: TDateTimeField;
AdoQry_HeadMoNoFinishQTY: TFloatField;
AdoQry_HeadMoLineSTATUS: TIntegerField;
AdoQry_HeadMOStArtWorkDate: TDateTimeField;
AdoQry_HeadDeptCode: TStringField;
AdoQry_HeadDeptName: TStringField;
AdoQry_HeadItemName: TStringField;
AdoQry_HeadMODATE: TDateTimeField;
AdoQry_HeadUomName: TStringField;
AdoQry_HeadItemFlag: TStringField;
AdoQry_HeadDeptFlag: TStringField;
Label1: TLabel;
DBText1: TDBText;
AdoQry_HeadMoLinecheck: TIntegerField;
AdoQry_HeadSSQty: TFloatField;
Label2: TLabel;
DBText2: TDBText;
AdoQry_HeadByProduct: TIntegerField;
AdoQry_HeadMoRealInQty: TFloatField;
AdoQry_HeadMoInQty: TFloatField;
AdoQry_HeadCloseRemArk: TStringField;
AdoQry_HeadBilllineremArk: TStringField;
AdoQry_HeadParentMoLineNo: TIntegerField;
AdoQry_HeadMONO_1: TStringField;
AdoQry_HeadMORemArk: TStringField;
AdoQry_HeadMOSpecial: TIntegerField;
AdoQry_HeadSaleType: TStringField;
AdoQry_HeadStandardFlag: TIntegerField;
DBText3: TDBText;
Label3: TLabel;
AdoQry_HeadPla_EmployeeCode: TStringField;
AdoQry_Headplaflag: TStringField;
AdoQry_HeadBackFlush: TIntegerField;
AdoQry_HeadReferenceNo: TStringField;
Button1: TButton;
procedure FormDestroy(Sender: TObject);
procedure Act_CheckExecute(Sender: TObject);
procedure Act_CancelCheckExecute(Sender: TObject);
procedure DBGridEhDblClick(Sender: TObject);
procedure DBGridEhTitleClick(Column: TColumnEh);
procedure AdoQry_HeadBeforeInsert(DataSet: TDataSet);
procedure Act_LookExecute(Sender: TObject);
procedure Act_DeleteExecute(Sender: TObject);
procedure AdoQry_HeadBeforeEdit(DataSet: TDataSet);
procedure FormCreate(Sender: TObject);
procedure Act_ModifyExecute(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure AdoQry_HeadAfterPost(DataSet: TDataSet);
private
Flag:Boolean;
SelectedCount :integer;
procedure PassbyProduct;
procedure PassMoLine(mono:string;MoLineno:integer);
procedure PassbyProductMoLine(mono:string;MoLineno:integer);
procedure savebyProducthistory(mono:string;MoLineno:integer);
function IsBomChange(ItemCode:String;MoDate:String):boolean;
{ Private declarations }
public
procedure openBom(ItemCode:string;Mpsqty:real;requiredate:string);
function existssonItem1(ItemCode:string):boolean;
procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
// function getPmCode(ItemCode:string):integer;
function getQclt(ItemCode:string):string;{ Public declarations }
function existsnoPassmo(mono:string;MoLineno:integer):boolean;
function checkCurrentonhandInv(mono:string;MoLineno:integer;var haveInv:integer;var strWhName:string):boolean;
function getDeptCode(mono:string):string;
function getDeptName(DeptCode:string):string;
function createstallmoveBill(mono:string;MoLineno:integer;BatchCtrl:integer):boolean;
function beenProducted(mono:string;MoLineno:integer):boolean;
function beendilivered(mono:string;MoLineno:integer):boolean;
function beenbuildBill(mono:string;MoLineno:integer):boolean;
function getBatchCtrl(ItemCode:string):integer;
procedure updateMoLine(mono:string;MoLineno:integer;isupdate:boolean);
procedure deletemnList(mono:string;MoLineno:integer);
function getstatus(mono:string;MoLineno:integer):integer;
function existssonItem(ItemCode:string):boolean;
end;
var
Frm_Mrp_Enter_NewPassMo: TFrm_Mrp_Enter_NewPassMo;
isBackflush:integer; ishaveInv:integer; strWHName:string;
tmpCode:string;
ItemCode : String;
RequireDate : string;
RequireQty : double;
implementation
uses Sys_Global, Mrp_Enter_MoParent,Mrp_Global,
Mrp_Enter_NewMoSsParent,Mrp_Enter_PassMo_D, Mrp_Qry_AnalyzerMrpMo;
{$R *.DFM}
function TFrm_Mrp_Enter_NewPassMo.IsBomChange(ItemCode:String;MoDate:String):boolean;
var AdoQry : TAdoQuery;
SqlText : String;
begin
Result := False;
AdoQry := TAdoQuery.Create(self) ;
AdoQry.Connection := Dbconnect;
AdoQry.EnableBCD := False;
try
SqlText := 'select logid from BomChangeInfo '
+ ' where ite_ItemCode='+QuotedStr(ItemCode)
+' and LogDate> '+QuotedStr(MoDate);
ExecuteSql(AdoQry,SqlText,0) ;
if AdoQry.RecordCount>0 then Result := True;
finally
AdoQry.free;
end;
end;
function TFrm_Mrp_Enter_NewPassMo.existssonItem1(ItemCode:string):boolean;
var AdoQry:TAdoQuery;
sqltext:string;
begin
Result:=False;
AdoQry:=TAdoQuery.Create(Application);
AdoQry.EnableBCD:=False;
AdoQry.Connection:=dbconnect;
sqltext:='select ItemCode from Bom where ite_ItemCode='+quotedstr(ItemCode);
// +' and ItemCode not in (select ItemCode from Item where PmCode=1 or PmCode=2)';
try
Executesql(AdoQry,sqltext,0);
if AdoQry.RecordCount>0 then
Result:=True;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_NewPassMo.openBom(ItemCode:string;Mpsqty:real;requiredate:string);
var AdoQry:TAdoQuery;
sqltext:string;
begin
AdoQry:=TAdoQuery.Create(Application);
AdoQry.EnableBCD:=False;
AdoQry.Connection:=dbconnect;
try
sqltext:='Select Bom.ItemCode,Bom.BomItemType,Item.PmCode, '+#13+
' Item.MnLdTime, '+#13+
' t2.mnldtime as Itemnldtime, '+
floattostr(Mpsqty)+'*Bom.BomQty*(1+ BomScrAp_Percent/100) as requireqty,'
+' Item.ItemName,Item.CurrentonhandInv,Item.CurrentonCheckInv, '+#13+
' Itemflag=Bom.ItemCode+'' ''+Item.ItemName'+#13+
// ' into #tmpBom '+#13+
' From Bom '+#13+
' Join Item On Bom.ItemCode=Item.ItemCode '+#13+
' join Item t2 on t2.ItemCode=Bom.ite_ItemCode '+
' where Bom.ite_ItemCode='''+ItemCode+''''+
' and Bom.Bomstatus in (0,2) ';
Executesql(AdoQry,sqltext,0);
with AdoQry do
begin
First;
while not eof do
begin
if fieldbyname('BomItemType').asinteger<>3 then
begin
sqltext:='insert into #tmpBom '
+'Values('+quotedstr(fieldbyname('ItemCode').asstring)+','
+quotedstr(AdoQry_Head.fieldbyname('mono').asstring)+','
+inttostr(AdoQry_Head.fieldbyname('MoLineno').asinteger)+','
+inttostr(fieldbyname('BomItemType').asinteger)+','
+inttostr(fieldbyname('PmCode').asinteger)+','
+quotedstr(slCalendar(dbconnect,requiredate,(fieldbyname('Itemnldtime').asinteger)))+','
+floattostr(fieldbyname('requireqty').asfloat)+','
+quotedstr(fieldbyname('ItemName').asstring)+','
+floattostr(fieldbyname('CurrentonhandInv').asfloat)+','
+floattostr(fieldbyname('CurrentonCheckInv').asfloat)+','
+quotedstr(fieldbyname('Itemflag').asstring)
+')';
Executesql(AdoQry_tmp,sqltext,1);
end;
if existssonItem1(fieldbyname('ItemCode').asstring) and (fieldbyname('BomItemType').asinteger=3) then
openBom(fieldbyname('ItemCode').asstring,fieldbyname('requireqty').asfloat,slCalendar(dbconnect,requiredate,-(fieldbyname('mnldtime').asinteger)));
next;
end;
end;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_NewPassMo.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
begin
Application.ProcessMessages;
Inherited;
SelectFromSql:='Select MoLine.*,Mo.*,Dept.DeptName,Item.ItemName,Uom.UomName,'
+' Item.ItemCode+'''+' '+'''+Item.ItemName As ItemFlag,'
+' Item.Pla_EmployeeCode+'' ''+Employee.EmployeeName as plaflag,'
+' Item.Pla_EmployeeCode, '
+' Dept.DeptCode+'''+' '+'''+Dept.DeptName As DeptFlag '
+' From MoLine '
+' Join Mo On MoLine.MoNo=Mo.MoNo '
+' Join Item On MoLine.ItemCode=Item.ItemCode '
+' left join Employee on Item.Pla_EmployeeCode=Employee.EmployeeCode '
+' left Join Dept On Mo.DeptCode=Dept.DeptCode '
+' left Join Uom On Item.UomCode=Uom.UomCode ' ;
condition:='MoLinestatus=5';
conditionuserDefine:=' (MoLineStatus=6 or MoLinestatus=5)'+' and Mo.MoNo not In( Select MoNo From Mo Where MoSpecial=1)';
OrderByFields:='MoDate,MoNo';
GetData;
ActiveControl := Dbgrideh;
Flag:=False;
SelectedCount := 0;
end;
procedure TFrm_Mrp_Enter_NewPassMo.FormDestroy(Sender: TObject);
begin
inherited;
Frm_Mrp_Enter_NewPassMo:=Nil;
end;
procedure TFrm_Mrp_Enter_NewPassMo.Act_CheckExecute(Sender: TObject);
var
BookMArk:String;
tmPmono:string;
tmPMoLineno:integer;
i:integer;
begin
inherited;
i:=0;
isBackflush:=0;
tmPmono:='zzzzzzzzzzzzzzzzzzzzzzz';
tmPMoLineno:=9999999;
ishaveInv:=0;
strwhName:='strwhName';
If AdoQry_Head.RecordCount=0 Then
Abort;
BookMArk:=AdoQry_Head.BookmArk;
If DispInfo('确认批准选定生产订单吗?',2)='y' Then
begin
Try
AdoQry_Head.First;
While Not AdoQry_Head.Eof Do
begin
i:=i+1;
if (AdoQry_Head.fieldbyname('MoLinecheck').asinteger=0) then
begin
if AdoQry_Head.fieldbyname('byProduct').asinteger=1 then
if (AdoQry_Head.fieldbyname('mono').asstring=tmPmono)
and (AdoQry_Head.fieldbyname('ParentMoLineno').asinteger=tmPMoLineno)
then
PassbyProduct;
AdoQry_Head.next;
continue;
end;
If (AdoQry_Head.fieldbyname('MoLineCheck').AsInteger=1) And (AdoQry_Head.fieldbyname('MoLineStatus').AsInteger=5) Then
begin
tmPmono:=AdoQry_Head.fieldbyname('mono').asstring;
tmPMoLineno:=AdoQry_Head.fieldbyname('MoLineno').asinteger;
if not existsnoPassmo(tmPmono,tmPMoLineno) then //判断真实数据库中是否存在相应的未批准的订单行
begin
If DbConnect.InTransaction Then
DbConnect.RollBackTrans;
DispInfo('选定的第'+IntToStr(i)+'条生产订单行状态已被其它用户修改,请刷新!',3);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -