📄 mrp_enter_newassignalternative.pas
字号:
unit Mrp_Enter_NewAssignAlterNative;
//
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Entry_Body, Db, ActnList, AdODB, Grids, DBGridEh, StdCtrls,
ExtCtrls, ComCtrls, ToolWin, Mask, ExtEdit, DBCtrls, ExtPrintReport;
Type
TFrm_Mrp_Enter_NewAssignAlterNative = Class(TFrm_Base_Entry_Body)
DBGridEh1: TDBGridEh;
AdoQry_Head1: TAdoQuery;
Lbl_SaleType: TLabel;
Lbl_DeptName: TLabel;
AdoQry_Temp: TAdoQuery;
Label1: TLabel;
lbl_Item: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label8: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
AdoQry_BodyItemCode: TStringField;
AdoQry_BodySSDate: TDateTimeField;
AdoQry_Bodyduedate: TDateTimeField;
AdoQry_BodyItemName: TStringField;
AdoQry_BodyCurrentonhandInv: TFloatField;
AdoQry_BodyUomName: TStringField;
AdoQry_BodyPmType: TIntegerField;
AdoQry_BodyReMainQty: TFloatField;
AdoQry_BodyDeptVendorCode: TStringField;
AdoQry_BodyBomqty: TFloatField;
AdoQry_Bodyite_ItemCode: TStringField;
AdoQry_BodyBomScrAp_Percent: TFloatField;
AdoQry_BodySSQty: TFloatField;
procedure Act_SaveExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DateCheck(Sender: TObject);
procedure Act_DeleteLineExecute(Sender: TObject);
procedure Act_QuitExecute(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Act_ExcelExecute(Sender: TObject);
procedure Act_ModifyExecute(Sender: TObject);
private
{ Private declarations }
public
flag:integer;
ite_Ssid:integer;
ite_reMainqty:real;
procedure SetStatus(CurrentStatus:String;var AnswerStatus,EnableControls:String); Override;
procedure GetalterItem(AdoQry:TAdoQuery;ite_ItemCode:string);
procedure getbyProduct(ItemCode:string;qty:real;MoLinedate,mostArtdate:string);
procedure deletebyProduct(MoLineno:integer);
function existsItemss(ItemCode:string;releasedate:string):boolean;
//是否已存在该物料约定交货日的建议下达信息
procedure sumItemss(ItemCode:string;releasedate:string;ssqty:real);
//汇总该物料约定交货日的约定交货量
procedure insertss;
//插入建议
{ Public declarations }
end;
var
Frm_Mrp_Enter_NewAssignAlterNative: TFrm_Mrp_Enter_NewAssignAlterNative;
implementation
uses Sys_Global,Mrp_Enter_AssignAlterNative_D;
{$R *.DFM}
function checksymbol(Source:string;disptext:string):boolean; //检查输入中是否有单引号
var
i:integer;
s:string;
begin
s:=Trim(Source);
for i:=1 to length(s) do
if s[i]='''' then
begin
DispInfo(disptext+'中不能使用单引号!',1);
Result:=False;
exit;
end;
Result:=True;
end;
procedure TFrm_Mrp_Enter_NewAssignAlterNative.GetalterItem(AdoQry:TAdoQuery;ite_ItemCode:string);
var
SqlText:String;
I,j:Integer;
begin
AdoQry_Tmp.Connection:=AdoQry.Connection;
AdoQry_Body.Connection:=AdoQry.Connection;
DbConnect:=AdoQry.Connection;
AdoQry_Head1:=AdoQry;
SqlText:=' Select Top 0 #tmpalterssInfo.*,Bom.Bomqty,Bom.BomScrAp_Percent,'
+'Bom.ite_ItemCode,Item.CurrentonhandInv,Item.ItemName,Uom.UomName '
+' From #tmpalterssInfo '
+' Join Item On #tmpalterssInfo.ItemCode=Item.ItemCode '
+' join Bom on #tmpalterssInfo.ItemCode=Bom.ite_ItemCode '
+' Left Join Uom On Item.UomCode=Uom.UomCode';
AdoQry_Body.Close;
AdoQry_Body.SQL.Text:=SqlText;
AdoQry_Body.Open;
SqlText:=' Select Bom.*,Item.PmCode,Item.ItemName,Uom.UomName,Item.CurrentonhandInv,ldtime=case Item.PmCode when 0 then runlt when 3 then runlt else purchldtime end '
+' From Bom '
+' join Item on Bom.ItemCode=Item.ItemCode '
+' left outer join Uom on Item.UomCode=Uom.UomCode '
+' Where ite_ItemCode='+quotedstr(ite_ItemCode);
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:=SqlText;
AdoQry_Tmp.Open;
while not AdoQry_tmp.Eof do
begin
J:=AdoQry_Tmp.fieldbyname('ldtime').AsInteger;
AdoQry_Body.Append;
AdoQry_Body.fieldbyname('ItemCode').AsString:=AdoQry_tmp.fieldbyname('ItemCode').AsString;
AdoQry_Body.fieldbyname('ItemName').AsString:=AdoQry_tmp.fieldbyname('ItemName').AsString;
AdoQry_Body.fieldbyname('UomName').AsString:=AdoQry_tmp.fieldbyname('UomName').AsString;
AdoQry_Body.fieldbyname('SsQty').AsFloat:=0.0;
AdoQry_Body.fieldbyname('Bomqty').AsFloat:=AdoQry_tmp.fieldbyname('Bomqty').asfloat;
AdoQry_Body.fieldbyname('ite_ItemCode').AsString:=floattostr(AdoQry_tmp.fieldbyname('BomScrAp_Percent').Asfloat/100)+'%';
AdoQry_Body.fieldbyname('BomScrAp_Percent').asfloat:=AdoQry_tmp.fieldbyname('BomScrAp_Percent').asfloat;
AdoQry_Body.fieldbyname('PmType').Asinteger:=AdoQry_tmp.fieldbyname('PmCode').asinteger;
AdoQry_Body.fieldbyname('CurrentonhandInv').AsFloat:=AdoQry_tmp.fieldbyname('CurrentonhandInv').asfloat;
AdoQry_Body.fieldbyname('ssDate').Asstring:=label8.Caption;
AdoQry_Body.fieldbyname('DeptVendorCode').Asstring:=AdoQry_Body.fieldbyname('DeptVendorCode').asstring;
AdoQry_Body.fieldbyname('duedate').Asstring:=slCalendar(dbconnect,label8.Caption,J);
AdoQry_Body.Post;
// getbyProduct(AdoQry_Body.fieldbyname('ItemCode').AsString,AdoQry_Body.fieldbyname('MoQty').AsFloat,AdoQry_Body.fieldbyname('MoLineDate').Asstring,AdoQry_Body.fieldbyname('MoStArtWorkDate').Asstring);
AdoQry_tmp.Next;
end;
DataSource.DataSet:=AdoQry_Body;
dataSource.DataSet.First;
end;
procedure TFrm_Mrp_Enter_NewAssignAlterNative.Act_SaveExecute(Sender: TObject);
var
SqlText:String;
I:integer;
BookmArk:string;
bodymArk:string;
TotalAssignqty:real;
ite_TotalAssignqty:real;
begin
TotalAssignqty:=0;
ite_TotalAssignqty:=0;
try
bodymArk:=AdoQry_Body.BookmArk;
If AdoQry_Body.RecordCount=0 Then
begin
DispInfo('没有行数据,不能保存!',3);
Abort;
end;
AdoQry_Body.First;
I:=0;
While Not AdoQry_Body.Eof Do
begin
I:=I+1;
TotalAssignqty:=TotalAssignqty+AdoQry_Body.fieldbyname('ssqty').asfloat;
ite_TotalAssignqty:=ite_TotalAssignqty+AdoQry_Body.fieldbyname('ssqty').asfloat/(AdoQry_Body.fieldbyname('Bomqty').asfloat*(1+AdoQry_Body.fieldbyname('BomScrAp_Percent').asfloat/100));
AdoQry_Body.Next;
end; //校验数据
AdoQry_Body.First;
if TotalAssignqty=0 then
begin
DispInfo('分配建议下达总量必须大于0,请修改!',1);
exit;
end;
if ite_TotalAssignqty>ite_reMainqty then
begin
DispInfo('替代件分配建议下达量不能超过父项系统建议余量,请修改!',1);
exit;
end;
DbConnect.beginTrans;
AdoQry_Body.First;
While Not AdoQry_Body.Eof Do
begin
if AdoQry_Body.fieldbyname('ssqty').asfloat=0 then
begin
AdoQry_Body.Next;
continue;
end;
if existsItemss(AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('ssdate').asstring) then
sumItemss(AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('ssdate').asstring,AdoQry_Body.fieldbyname('ssqty').asfloat)
else insertss;
AdoQry_Body.Next;
end;
sqltext:='update MrpResult'
+' set reMainqty=reMainqty-('+floattostr(ite_TotalAssignqty)+')'
+' where MrpResultid='+inttostr(ite_Ssid);
Executesql(AdoQry_tmp,sqltext,1);
If AdoQry_Head1.Locate('SsId',ite_Ssid,[loCaseInsensitive]) Then
begin
AdoQry_Head1.edit;
AdoQry_Head1.fieldbyname('tMpssreMainqty').AsFloat:=AdoQry_Head1.fieldbyname('tMpssreMainqty').AsFloat-ite_TotalAssignqty;
AdoQry_Head1.Post;
end;
DbConnect.CommitTrans;
Act_Save.Enabled:=False;
DispInfo('数据保存完毕!',3);
Except
If DbConnect.InTransaction Then
DbConnect.RollBackTrans;
DispInfo('保存数据失败,请重试!',1);
Abort;
end;
Act_Save.Enabled:=False;
AdoQry_Body.BookmArk:=bodymArk;
self.Close;
end;
procedure TFrm_Mrp_Enter_NewAssignAlterNative.FormCreate(Sender: TObject);
begin
inherited;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -