📄 bas_bombatchreplace2.pas
字号:
unit Bas_BomBatchReplace2;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Outer, Menus, ExtPrintReport, Db, ActnList, AdODB, Grids, DBGridEh,
StdCtrls, ExtCtrls, ComCtrls, ToolWin, ExtEdit, jpeg;
Type
TFrm_Bas_BomBatchReplace2 = Class(TFrm_Base_Outer)
Label1: TLabel;
Extedt_ItemCode1: TExtEdit;
Extedt_ItemCode2: TExtEdit;
Lb_ItemCode1: TLabel;
Label3: TLabel;
Lb_ItemCode2: TLabel;
Label5: TLabel;
AdoQry_Tmp1: TAdoQuery;
AdoQry_Mainite_ItemCode: TStringField;
AdoQry_MainItemName: TStringField;
AdoQry_Mainite_ItemCodeB: TStringField;
AdoQry_MainItemCode: TStringField;
AdoQry_MainItemName_1: TStringField;
AdoQry_MainItemCodeB: TStringField;
AdoQry_MainBommArk: TIntegerField;
CheckBox1: TCheckBox;
Label2: TLabel;
procedure FormActivate(Sender: TObject);
procedure DBGridEhTitleClick(Column: TColumnEh);
procedure Extedt_ItemCode1Exit(Sender: TObject);
procedure Extedt_ItemCode2Exit(Sender: TObject);
procedure Act_nextExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
Flag:boolean;
OldChildItemCode,NewChildItemCode:string;
function CicleCheckSlaveValid(R_MasterCode:string;R_SlaveCode:string):Boolean;
function JudgeCanChange(NewItemCode,ParentItem:string):boolean; //校验是否可以替换
procedure GetParentItem(ItemCode:string); //得到被替换的物料的所有的父项
function MasterCodePass(ItemCode:string):boolean; //判断物料是否已审核
procedure GetBomParam;
public
{ Public declarations }
procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
end;
var
Frm_Bas_BomBatchReplace2: TFrm_Bas_BomBatchReplace2;
implementation
uses Sys_Global;
{$R *.DFM}
function TFrm_Bas_BomBatchReplace2.CicleCheckSlaveValid(R_MasterCode:string;R_SlaveCode:string):Boolean;
var
sSQL:string;
begin
Pnl_Hint.Caption:='正在循环校验......';
with AdoQry_Tmp do
begin
Close;
Sql.clear;
sSQL:='declAre @aa chAr(1) '+
'exec CheckVerity_New '''+R_SlaveCode+''','''+r_MasterCode+''',@aa output '+
'select @aa as VerityResult ';
sql.Add(sSQL);
open;
if fieldbyname('verityResult').asstring='F' then
begin
Result:=False;
if CheckBox1.Checked then
DispInfo(QuotedStr(R_SlaveCode)+'在'+QuotedStr(R_MasterCode)+'中不能循环使用',1);
end
else Result:=True;
Close;
end;
Pnl_Hint.Caption:='';
end;
procedure TFrm_Bas_BomBatchReplace2.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
begin
inherited;
GetBomParam;
Caption:= '子项成批替换';
Pnl_Title.Caption:='子项成批替换';
AdoQry_tmp1.Connection:=AdOConnection;
ToolButton6.Visible:=False;
TlBtn_Filter.Visible:=False;
TlBtn_Locate.Visible:=False;
TlBtn_Order.Visible:=False;
ToolButton2.Visible:=False;
end;
function TFrm_Bas_BomBatchReplace2.JudgeCanChange(NewItemCode,ParentItem:string):boolean;
var
ScanChange:string;
begin
ScanChange:=' select Count(ItemCode) as Count from BomA where ite_ItemCode='+QuotedStr(ParentItem)+
' and ItemCode='+QuotedStr(NewItemCode);
With AdoQry_tmp do
begin
Close;
SQL.clear;
SQL.Add(ScanChange);
Open;
if fieldbyname('Count').AsInteger<1 then
Result:=False
else
begin
Result:=True;
if CheckBox1.Checked then
DispInfo(QuotedStr(ParentItem)+'已有子项'+QuotedStr(NewItemCode),1);
end;
end;
end;
procedure TFrm_Bas_BomBatchReplace2.GetParentItem(ItemCode:string);
var
sSQL:string;
begin
sSQL:=' select BomA.ite_ItemCode,'+
' Item.ItemName,'+
' BomA.ite_ItemCode+'' ''+Item.ItemName as ite_ItemCodeB,'+
' BomA.ItemCode,'+
' I.ItemName,'+
' BomA.ItemCode+'' ''+I.ItemName as ItemCodeB,'+
' BomA.BommArk'+
' from BomA'+
' join Item on BomA.ite_ItemCode=Item.ItemCode'+
' join Item I on BomA.ItemCode=I.ItemCode'+
' where BomA.ItemCode='+Quotedstr(ItemCode);
with AdoQry_Main do
begin
Close;
SQL.clear;
SQL.Add(sSQL);
Open;
end;
end;
procedure TFrm_Bas_BomBatchReplace2.FormActivate(Sender: TObject);
begin
// inherited;
Extedt_ItemCode1.SetFocus;
Flag:=False;
TlBtn_New.Action:=Act_next;
end;
procedure TFrm_Bas_BomBatchReplace2.DBGridEhTitleClick(Column: TColumnEh);
begin
inherited;
If Trim(Column.Title.Caption)<>'标记' Then
Abort;
If AdoQry_Main.RecordCount=0 Then
Abort;
If Not Flag Then
begin
AdoQry_Main.First;
While Not AdoQry_Main.Eof Do
begin
AdoQry_Main.Edit;
AdoQry_Main.fieldbyname('BomMArk').AsInteger:=1;
AdoQry_Main.Post;
AdoQry_Main.Next;
end;
end
Else
begin
AdoQry_Main.First;
While Not AdoQry_Main.Eof Do
begin
AdoQry_Main.Edit;
AdoQry_Main.fieldbyname('BomMArk').AsInteger:=0;
AdoQry_Main.Post;
AdoQry_Main.Next;
end;
end;
Flag:=Not Flag;
end;
procedure TFrm_Bas_BomBatchReplace2.Extedt_ItemCode1Exit(Sender: TObject);
begin
inherited;
OldChildItemCode:=Extedt_ItemCode1.Text;
ItemCodeCheck(Extedt_ItemCode1);
GetParentItem(OldChildItemCode);
end;
procedure TFrm_Bas_BomBatchReplace2.Extedt_ItemCode2Exit(Sender: TObject);
begin
inherited;
NewChildItemCode:=Extedt_ItemCode2.Text;
ItemCodeCheck(Extedt_ItemCode2);
end;
procedure TFrm_Bas_BomBatchReplace2.Act_nextExecute(Sender: TObject);
var
sUpdateSQL:string;
ParentCode:string;
Ite_ItemType:string;
GetItemType:string;
begin
ItemCodeCheck(Extedt_ItemCode1);
ItemCodeCheck(Extedt_ItemCode2);
if Trim(Extedt_ItemCode1.Text)=Trim(Extedt_ItemCode2.Text) then
begin
DispInfo('替换与被替换的物料不能相同!',1);
abort;
end;
if AdoQry_Main.IsEmpty then
begin
DispInfo('没有任何物料可以替换!',1);
abort;
end;
if DispInfo('真的开始替换吗?',2)='n' then abort;
GetItemType:='select ItemType from Item where ItemCode='+Quotedstr(NewChildItemCode);
with AdoQry_tmp do
begin
Close;
SQL.clear;
SQL.Add(GetItemType);
open;
case AdoQry_tmp.fieldbyname('ItemType').asinteger of
0: Ite_ItemType:='0';
1: Ite_ItemType:='1';
2: Ite_ItemType:='2';
// 3: Ite_ItemType:='0';
4: Ite_ItemType:='3';
// 5: Ite_ItemType:='0';
6: Ite_ItemType:='5';
7: Ite_ItemType:='6';
end;
end;
sUpdateSQL:=' ';
AdoQry_Main.First;
While Not AdoQry_Main.Eof Do
begin
ParentCode:=AdoQry_Main.fieldbyname('Ite_ItemCode').asstring;
if AdoQry_Main.fieldbyname('BommArk').asinteger<>0 then
begin
if not JudgeCanChange(NewChildItemCode,ParentCode) then
begin
if CicleCheckSlaveValid(ParentCode,NewChildItemCode) then
begin
if MasterCodePass(ParentCode) then
begin
if checkbox1.Checked then DispInfo(ParentCode+'已审核,不允许替换!',1);
end
else
sUpdateSQL:=sUpdateSQL+
' update BomA set ItemCode='+QuotedStr(NewChildItemCode)+','+
' BomItemType='+Ite_ItemType+
' where ite_ItemCode='+QuotedStr(ParentCode)+
' and ItemCode='+QuotedStr(OldChildItemCode);
end;
end;
end;
AdoQry_Main.Next;
end;
AdoQry_Tmp.Connection.beginTrans ;
try
with AdoQry_tmp do
begin
Close;
SQL.clear;
SQL.Add(sUpdateSQL);
Prepared;
ExecSQL;
AdoQry_Tmp.Connection.CommitTrans;
DispInfo('替换完毕!',1);
Extedt_ItemCode1.SetFocus;
Extedt_ItemCode2.SetFocus;
Extedt_ItemCode1.SetFocus;
end;
except
AdoQry_Tmp.Connection.RollBackTrans ;
DispInfo('替换失败!',1);
end;
end;
procedure TFrm_Bas_BomBatchReplace2.FormCreate(Sender: TObject);
begin
inherited;
Extedt_ItemCode1.Text:='';
Extedt_ItemCode2.Text:='';
Lb_ItemCode1.Caption:='';
Lb_ItemCode2.Caption:='';
end;
function TFrm_Bas_BomBatchReplace2.MasterCodePass(ItemCode:string):boolean;
var
sSQL:String;
begin
sSQL:='select Bomok from Item where ItemCode='+Quotedstr(ItemCode);
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add(sSQL);
Open;
end;
if AdoQry_Tmp.fieldbyname('Bomok').AsInteger<>1 then
Result:=False
else
begin
Result:=True;
end;
end;
procedure TFrm_Bas_BomBatchReplace2.GetBomParam;
var
sSQL:string;
begin
sSQL:=' select ParamValueN from Bom_Param where ParamCode=''AuditBom'' and ParamName=''Bom构造是否要审核'' ';
with AdoQry_tmp do
begin
Close;
SQL.clear;
SQL.Add(sSQL);
Open;
end;
if AdoQry_tmp.Eof then DispInfo('你尚没设置相关系统参数!',1)
else
begin
if AdoQry_tmp.fieldbyname('ParamValueN').AsInteger=0 then
begin
DispInfo('对不起,系统已设定Bom构造不须审核',1);
Frm_Bas_BomBatchReplace2.Close;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -