📄 mrp_enter_assignalternative2.pas
字号:
unit Mrp_Enter_AssignAlterNative2;
//
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, jpeg;
Type
TFrm_Mrp_Enter_AssignAlterNative2 = Class(TFrm_Base_Entry_Body)
AdoQry_Head1: TAdoQuery;
AdoQry_Temp: TAdoQuery;
Label1: TLabel;
lbl_Item: TLabel;
Label2: TLabel;
Label3: TLabel;
Label6: TLabel;
Label8: TLabel;
Label11: TLabel;
Label12: TLabel;
AdoQry_BodyItemCode: TStringField;
AdoQry_BodySSDate: TDateTimeField;
AdoQry_Bodyduedate: TDateTimeField;
AdoQry_BodyItemName: TStringField;
AdoQry_BodyCurrentonhandInv: TFloatField;
AdoQry_BodyUomName: TStringField;
AdoQry_BodyBomqty: TFloatField;
AdoQry_Bodyite_ItemCode: TStringField;
AdoQry_BodyBomScrAp_Percent: TFloatField;
AdoQry_BodySSQty: TFloatField;
Panel1: TPanel;
DBGridEh1: TDBGridEh;
Splitter1: TSplitter;
DataSource1: TDataSource;
AdoQry_Body1: TAdoQuery;
StringField1: TStringField;
DateTimeField1: TDateTimeField;
DateTimeField2: TDateTimeField;
StringField2: TStringField;
FloatField1: TFloatField;
StringField3: TStringField;
FloatField3: TFloatField;
StringField5: TStringField;
FloatField4: TFloatField;
FloatField5: TFloatField;
AdoQry_Body1BomItemType: TIntegerField;
AdoQry_Body1ssSysInfoflag: TIntegerField;
procedure Act_SaveExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure DateCheck(Sender: TObject);
procedure Act_DeleteLineExecute(Sender: TObject);
procedure Act_QuitExecute(Sender: TObject);
procedure Act_ExcelExecute(Sender: TObject);
procedure Act_ModifyExecute(Sender: TObject);
procedure AdoQry_BodyAfterScroll(DataSet: TDataSet);
procedure AdoQry_BodyAfterPost(DataSet: TDataSet);
procedure btn_fmoClick(Sender: TObject);
private
{ Private declarations }
public
flag:integer;
ite_ToDate:String; //父项日期
Ite_ItemCode : String; //父项物料代码
Ite_SSReleaseDate : String; //父项系统建议约定交货日
ite_reMainqty:Double;
procedure SetStatus(CurrentStatus:String;var AnswerStatus,EnableControls:String); Override;
procedure GetalterItem(var 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(AdoQry:TAdoQuery);
procedure insertss1;
//插入建议
function existsvir(ItemCode:string):boolean;
function savess(ItemCode,duedate:string;Ssqty:Double):boolean;
{ Public declarations }
procedure insertItemss(ItemCode,ssdate,duedate:string;
ssqty:double);
{ Public declarations }
end;
var
Frm_Mrp_Enter_AssignAlterNative2: TFrm_Mrp_Enter_AssignAlterNative2;
implementation
uses Sys_Global,Mrp_Enter_AssignAlterNative2_D,Mrp_Enter_AssignAlterNative_Mo;
{$R *.DFM}
procedure TFrm_Mrp_Enter_AssignAlterNative2.insertItemss(ItemCode,ssdate,duedate:string;
ssqty:double);
var sqltext:string;
begin
SqlText:='insert into PurchaseApplyAssign '
+' (ToDate,ItemCode,SSQty,PlanQty, '
+' SSReleaseDate,PlanDueDate,PlanReleaseDate, '
+' CreateEmployeeCode,CreateDate, '
+' EdItEmployeeCode,EditDate) '
+'Values('+QuotedStr(Ite_ToDate)+','
+quotedstr(ItemCode)+','
+floattostr(SSQty)+','
+floattostr(SSQty)+','
+quotedstr(SsDate)+','
+quotedstr(DueDate)+','
+quotedstr(SSDate)+','
+QuotedStr(UserCode)+','
+'GetDate(),'
+quotedstr(UserCode)+','
+'GetDate()'
+')';
AdoQry_Tmp.Close;
AdoQry_Tmp.SQL.Text:=SqlText;
try
AdoQry_Tmp.ExecSQL;
except
end;
end;
function TFrm_Mrp_Enter_AssignAlterNative2.savess(ItemCode,duedate:string;Ssqty:double):boolean;
var AdoQry,AdoQry1:TAdoQuery;
SqlText:String;
j:integer;
begin
AdoQry := TAdoQuery.Create(self);
AdoQry.Connection := Dbconnect;
AdoQry.EnableBCD:=False;
AdoQry1 := TAdoQuery.Create(self);
AdoQry1.Connection := Dbconnect;
AdoQry1.EnableBCD:=False;
try
SqlText:=' Create table #TMps '
+' ( ItemCode varchAr(16) , '
+' ItemName varchAr(200) , '
+' SSSysInfoFlag int , '
+' BomQty decimal(20,8) , '
+' BomItemType int, '
+' Ite_ItemCode varchAr(16) , '
+' BomScrAp_Percent decimal(20,8) , '
+' CurrentOnHandInv decimal(20,8) , '
+' SsDate SmallDateTime , '
+' DueDate SmallDateTime , '
+' SSQty decimal(20,8) '
+' ) '
+' select * from #TMps ';
Executesql(AdoQry,sqltext,0);
SqlText:=' Select Bom.*,Item.PmCode,Bom.BomItemType as ssSysInfoflag,Item.ItemName,Item.CurrentonhandInv,ldtime=Preparelt+runlt+Qclt '
+' From Bom '
+' join Item on Bom.ItemCode=Item.ItemCode '
+' Where ite_ItemCode='+quotedstr(ItemCode)
+' ' ;
Executesql(AdoQry1,sqltext,0);
while not AdoQry1.Eof do
begin
J:=AdoQry_Temp.fieldbyname('ldtime').AsInteger;
AdoQry.Append;
AdoQry.fieldbyname('ItemCode').AsString:=AdoQry1.fieldbyname('ItemCode').AsString;
AdoQry.fieldbyname('ItemName').AsString:=AdoQry1.fieldbyname('ItemName').AsString;
AdoQry.fieldbyname('ssSysInfoflag').asinteger:=j;
AdoQry.fieldbyname('Bomqty').AsFloat:=AdoQry1.fieldbyname('Bomqty').asfloat;
AdoQry.fieldbyname('BomItemType').AsInteger:=AdoQry1.fieldbyname('BomItemType').AsInteger;
AdoQry.fieldbyname('ite_ItemCode').AsString:=floattostr(AdoQry1.fieldbyname('BomScrAp_Percent').Asfloat/100)+'%';
AdoQry.fieldbyname('BomScrAp_Percent').asfloat:=AdoQry1.fieldbyname('BomScrAp_Percent').asfloat;
AdoQry.fieldbyname('CurrentonhandInv').AsFloat:=AdoQry1.fieldbyname('CurrentonhandInv').asfloat;
AdoQry.fieldbyname('ssDate').Asstring:=duedate;
AdoQry.fieldbyname('duedate').Asstring:=slCalendar(dbconnect,duedate,J);
AdoQry.fieldbyname('ssqty').AsFloat:=ssqty*AdoQry_Body1.fieldbyname('Bomqty').asfloat*(1+AdoQry_Body1.fieldbyname('BomScrAp_Percent').asfloat/100.00);
AdoQry.Post;
AdoQry1.Next;
end;
ExecuteSql(AdoQry_Tmp,'drop table #TMps',1);
AdoQry.First;
while not AdoQry.Eof do
begin
If AdoQry.fieldbyname('BomItemType').AsInteger<>3 then
begin
if existsItemss(AdoQry.fieldbyname('ItemCode').asstring,AdoQry.fieldbyname('ssdate').asstring) then
sumItemss(AdoQry.fieldbyname('ItemCode').asstring,AdoQry.fieldbyname('ssdate').asstring,AdoQry.fieldbyname('ssqty').asfloat)
else
insertItemss(AdoQry.fieldbyname('ItemCode').asstring,
AdoQry.fieldbyname('ssdate').asstring,
AdoQry.fieldbyname('duedate').asstring,
AdoQry.fieldbyname('ssqty').asfloat);
end
else begin
savess(AdoQry.fieldbyname('ItemCode').asstring,
AdoQry.fieldbyname('duedate').asstring,
AdoQry.fieldbyname('ssqty').asfloat);
end;
AdoQry.next;
end;
finally
AdoQry.Free;
AdoQry1.free;
end;
end;
function TFrm_Mrp_Enter_AssignAlterNative2.existsvir(ItemCode:string):boolean;
var sqltext:string;
begin
Result:=False;
sqltext:='select * from Bom where BomItemType=3 and ite_ItemCode='+quotedstr(ItemCode);
Executesql(AdoQry_tmp,sqltext,0) ;
if AdoQry_tmp.RecordCount<>0 then Result:=True;
end;
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_AssignAlterNative2.GetalterItem(var AdoQry:TAdoQuery;ite_ItemCode:string);
var
SqlText:String;
I,j:Integer;
begin
AdoQry_Tmp.Connection:=AdoQry.Connection;
AdoQry_Temp.Connection:=AdoQry.Connection;
AdoQry_Body.Connection:=AdoQry.Connection;
AdoQry_Body1.Connection:=AdoQry.Connection;
DbConnect:=AdoQry.Connection;
AdoQry_Head1:=AdoQry;
AdoQry_Head:=AdoQry;
SqlText:=' Select Top 0 #tmpalterssInfo.*,Bom.Bomqty,Bom.BomScrAp_Percent,'
+'Bom.ite_ItemCode,Item.CurrentonhandInv,Item.ItemName,Uom.UomName '
+' From #tmpalterssInfo '
+' left 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=Preparelt+runlt+Qclt '
+' 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('CurrentonhandInv').AsFloat:=AdoQry_tmp.fieldbyname('CurrentonhandInv').asfloat;
AdoQry_Body.fieldbyname('ssDate').Asstring:=label8.Caption;
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_AssignAlterNative2.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<>StrToFloat(Label12.Caption) then
begin
DispInfo('替代件分配建议下达量必须等于父项计划量,请修改!',1);
exit;
end;
DbConnect.beginTrans;
AdoQry_Body.DisableControls;
AdoQry_Body1.DisableControls;
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);
if existsvir(AdoQry_Body.fieldbyname('ItemCode').asstring) then
savess(AdoQry_Body.fieldbyname('ItemCode').asstring,
AdoQry_Body.fieldbyname('duedate').asstring,
AdoQry_Body.fieldbyname('ssqty').asfloat);
AdoQry_Body.Next;
end;
sqltext:='update PurchaseApply '
+' set IScreatePo=1 ,'
+' IsAssign=1 '
+' where ToDate='+QuotedStr(Ite_ToDate)
+' and ItemCode='+QuotedStr(Ite_ItemCode)
+' and SSReleaseDate='+QuotedStr(Ite_SsReleaseDate);
Executesql(AdoQry_tmp,sqltext,1);
sqltext:='update #TmpAlterSsInfo '
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -