📄 mrp_enter_freedelmo.pas
字号:
unit Mrp_Enter_FreeDelMo;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Check, Menus, Db, ActnList, AdODB, Grids, DBGridEh, StdCtrls,
ExtCtrls, ComCtrls, ToolWin, DBCtrls, ExtPrintReport, jpeg;
Type
TFrm_Mrp_Enter_FreeDelMo = 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_HeadMODATE: TDateTimeField;
AdoQry_HeadDeptName: TStringField;
AdoQry_HeadItemName: TStringField;
AdoQry_HeadUomName: TStringField;
AdoQry_HeadItemFlag: TStringField;
AdoQry_HeadDeptFlag: TStringField;
Label1: TLabel;
DBText1: TDBText;
Label2: TLabel;
DBText2: TDBText;
Label3: TLabel;
DBText3: TDBText;
AdoQry_HeadMoLineCheck: TIntegerField;
AdoQry_HeadMoRealInQty: TFloatField;
AdoQry_HeadMoInQty: TFloatField;
AdoQry_HeadSSQty: TFloatField;
AdoQry_HeadCloseRemArk: TStringField;
AdoQry_HeadBilllineremArk: TStringField;
AdoQry_HeadByProduct: TIntegerField;
AdoQry_HeadParentMoLineNo: TIntegerField;
AdoQry_HeadMONO_1: TStringField;
AdoQry_HeadMORemArk: TStringField;
AdoQry_HeadMOSpecial: TIntegerField;
AdoQry_HeadSaleType: TStringField;
AdoQry_HeadStandardFlag: TIntegerField;
AdoQry_HeadBackFlush: TIntegerField;
AdoQry_HeadReferenceNo: TStringField;
procedure FormDestroy(Sender: TObject);
procedure Act_CheckExecute(Sender: TObject);
procedure DBGridEhDblClick(Sender: TObject);
procedure DBGridEhTitleClick(Column: TColumnEh);
procedure Act_DeleteExecute(Sender: TObject);
private
Flag:Boolean;
{ Private declarations }
public
procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
function existsnofCloseMo(mono:string;MoLineno:integer):boolean;
{ Public declarations }
end;
var
Frm_Mrp_Enter_FreeDelMo: TFrm_Mrp_Enter_FreeDelMo;
IntMoLineBackFluch:integer;
IntMoLineFinish:double;
implementation
uses Sys_Global,Mrp_Enter_DelMo_C;
{$R *.DFM}
procedure TFrm_Mrp_Enter_FreeDelMo.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
var monos,monoe,Depts,Depte,dates,datee:string;
begin
Application.ProcessMessages;
Inherited;
with TFrm_Mrp_Enter_DelMo_C.Create(self) do
begin
SetDBConnect(dbconnect);
// Frm_Mrp_Enter_DelMo_C.Caption:='独立生产订单清除';
showmodal;
if modalResult=mrok then
try
monos:=edt_Mono.text;
monoe:=edt_End_Mono.text;
Depts:=edt_DeptCode.text;
Depte:=edt_End_DeptCode.text;
dates:=medt_Modate.Text;
datee:=medt_End_Modate.Text;
finally
Frm_Mrp_Enter_DelMo_C.Free;
end;
if modalResult<>mrok then
Frm_Mrp_Enter_DelMo_C.Free;
end;
SelectFromSql:='Select MoLine.*,Mo.*,Dept.DeptName,Item.ItemName,Uom.UomName,'
+' Item.ItemCode+'''+' '+'''+Item.ItemName As ItemFlag,'
+' Dept.DeptCode+'''+' '+'''+Dept.DeptName As DeptFlag '
+' From MoLine,Mo,Dept,Item,Uom ';
ConditionUserDefine:='(MoLine.MoNo=Mo.MoNo '
+' and MoLine.mono between '+quotedstr(monos)+' and '+quotedstr(monoe)
+' And MoLine.ItemCode=Item.ItemCode '
+' And Mo.DeptCode=Dept.DeptCode '
+' and mo.DeptCode between '+quotedstr(Depts)+' and '+quotedstr(Depte)
+' and mo.modate between '+quotedstr(dates)+' and '+quotedstr(datee)
+' And Item.UomCode=Uom.UomCode'
+' And (MoLine.MoLineStatus=8)'
+' And Mo.moSpecial=1)';
Condition:=' (MoLine.MoLineStatus=8) ';
OrderByFields:='DeptCode,MoDate,MoNo';
GetData;
Flag:=True;
end;
procedure TFrm_Mrp_Enter_FreeDelMo.FormDestroy(Sender: TObject);
begin
inherited;
Frm_Mrp_Enter_FreeDelMo:=Nil;
end;
procedure TFrm_Mrp_Enter_FreeDelMo.Act_CheckExecute(Sender: TObject);
var
intMoLineStatus, I:Integer;
//行状态、订单未结量是否为0、是否拉式领料
BookmArk,a,b:string;
begin
{ inherited;
IntMoLineBackFluch:=0;
If AdoQry_Head.RecordCount=0 Then
Abort;
BookMArk:=AdoQry_Head.BookmArk;
If DispInfo('确认结算选定生产订单吗?',2)='y' Then
begin
I:=1;
Try
AdoQry_Head.First;
While Not AdoQry_Head.Eof Do
begin
DbConnect.beginTrans;
intMoLineStatus :=AdoQry_Head.fieldbyname('MoLinestatus').Asinteger;
If (AdoQry_Head.fieldbyname('MoLineCheck').AsInteger=1) And (intMoLineStatus=7) Then
begin
if not existsnofCloseMo(AdoQry_Head.fieldbyname('mono').asstring,AdoQry_Head.fieldbyname('MoLineno').asinteger) then
//判断数据是否已被别人修改
begin
If DbConnect.InTransaction Then
DbConnect.RollBackTrans;
DispInfo('选定的第'+IntToStr(I)+'条生产订单行状态已被其它用户修改,请刷新!',3);
Abort;
end;
saveMoLineHistory(dbconnect,AdoQry_Head.fieldbyname('mono').asstring,AdoQry_Head.fieldbyname('MoLineno').asinteger,userCode,7);
//保存历史操作信息
if not ChangeMoLineStatus(AdoQry_Head.fieldbyname('MoNo').AsString,AdoQry_Head.fieldbyname('MoLineNo').AsString) then
begin
If DbConnect.InTransaction Then
DbConnect.RollBackTrans;
DispInfo('更改订单号为:'+AdoQry_Head.fieldbyname('MoNo').AsString+'行号为:'+AdoQry_Head.fieldbyname('MoLineNo').AsString+' 的订单行状态失败,'+chAr(13)+chAr(10)+'请稍后重试!',1);
abort;
end;
a:='C'+FormatDateTime('yymm',date());
// showmessage(a);
// abort;
b:=AdoQry_Head.fieldbyname('MoNo').AsString+AdoQry_Head.fieldbyname('MoLineNo').AsString;
IF (IntMoLineBackFluch=1) and (IntMoLineFinish>=0) then
if not BackFlushInvOut(AdoQry_Head.fieldbyname('MoNo').AsString+AdoQry_Head.fieldbyname('MoLineNo').AsString,'C'+FormatDateTime('yymm',date())) then
begin
If DbConnect.InTransaction Then
DbConnect.RollBackTrans;
DispInfo('订单号为:'+AdoQry_Head.fieldbyname('MoNo').AsString+'行号为:'+AdoQry_Head.fieldbyname('MoLineNo').AsString+'的订单结算失败,'+chAr(13)+chAr(10)+'请稍后重试!',1);
exit;
end;
I:=I+1;
end
Else
begin
I:=I+1;
AdoQry_Head.Next;
end;
DbConnect.CommitTrans;
end;
Except
If DbConnect.InTransaction Then
DbConnect.RollBackTrans;
DispInfo('更改数据时发生错误,数据未更改,请重试!',1);
AdoQry_Head.BookMArk:=BookmArk;
Abort;
end;
end;
AdoQry_Head.BookMArk:=BookmArk;
Flag:=Not Flag; }
end;
procedure TFrm_Mrp_Enter_FreeDelMo.DBGridEhDblClick(Sender: TObject);
begin
inherited;
{If AdoQry_Head.fieldbyname('MoLineStatus').AsInteger=7 then
Act_CheckExecute(Act_Check); }
end;
procedure TFrm_Mrp_Enter_FreeDelMo.DBGridEhTitleClick(
Column: TColumnEh);
var
BookMArk:String;
begin
inherited;
If Trim(Column.Title.Caption)<>'标记' Then
Abort;
If AdoQry_Head.RecordCount=0 Then
Abort;
BookMArk:=AdoQry_Head.BookmArk;
If Not Flag Then
begin
AdoQry_Head.First;
While Not AdoQry_Head.Eof Do
begin
AdoQry_Head.Edit;
AdoQry_Head.fieldbyname('MoLineCheck').AsInteger:=1;
AdoQry_Head.Post;
AdoQry_Head.Next;
end;
end
Else
begin
AdoQry_Head.First;
While Not AdoQry_Head.Eof Do
begin
AdoQry_Head.Edit;
AdoQry_Head.fieldbyname('MoLineCheck').AsInteger:=0;
AdoQry_Head.Post;
AdoQry_Head.Next;
end;
end;
AdoQry_Head.BookmArk:=BookMArk;
Flag:=Not Flag;
end;
function TFrm_Mrp_Enter_FreeDelMo.existsnofCloseMo(mono: string;
MoLineno: integer): boolean;
var sqltext:string;
AdoQry:TAdoQuery;
begin
Result:=True;
SqlText:=' Select * From MoLine '
+' Where MoNo='''+mono+''''
+' And MoLineNo='''+IntToStr(MoLineno)+''''
+' And MoLineStatus=7 ';
AdoQry:=TAdoQuery.Create(self);
AdoQry.Connection:=dbconnect;
try
AdoQry.Close;
AdoQry.SQL.Text:=SqlText;
AdoQry.Open;
if AdoQry.RecordCount=0 then Result:=False
else
begin
IntMoLineBackFluch := AdoQry.fieldbyname('Backflush').AsInteger;
IntMoLineFinish := AdoQry.fieldbyname('MoNoFinishqty').Asfloat;
end;
finally
AdoQry.Free;
end;
end;
procedure TFrm_Mrp_Enter_FreeDelMo.Act_DeleteExecute(Sender: TObject);
var
SqlText:String;
BookmArk:string;
begin
// Inherited;
if AdoQry_Head.RecordCount=0 then
exit;
if DispInfo('确定清除选定的独立生产订单吗?',2)<>'y' then
exit;
DbConnect.beginTrans;
Try
BookmArk:=AdoQry_Head.BookmArk;
AdoQry_Head.First;
While Not AdoQry_Head.Eof Do
begin
if AdoQry_Head.fieldbyname('MoLinecheck').asinteger<>0 then
begin
AdoQry_Head.Next;
continue;
end;
saveMoLineHistory(dbconnect,AdoQry_Head.fieldbyname('mono').asstring,AdoQry_Head.fieldbyname('MoLineno').asinteger,userCode,8);
// saveMoLineHistory(dbconnect,AdoQry_Head.fieldbyname('Mpsid').asinteger,userCode,7);
SqlText:='Delete from MoLine Where Mono='+quotedstr(AdoQry_Head.fieldbyname('mono').asstring)
+' and MoLineno='+inttostr(AdoQry_Head.fieldbyname('MoLineno').asinteger);
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:=SqlText;
AdoQry_Tmp.ExecSQL;
AdoQry_Head.Delete;
AdoQry_Head.Next;
end;
try
AdoQry_Head.BookmArk:=BookmArk;
except
end;
DbConnect.CommitTrans;
// Edt_StArt_ItemCode.SetFocus;
Except
DbConnect.RollBackTrans;
DispInfo('由于数据受到约束,不能清除!',3);
// Edt_StArt_ItemCode.SetFocus;
Abort;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -