📄 bas_bom_copy.pas
字号:
unit Bas_Bom_Copy;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Dialog, Db, AdODB, StdCtrls, ExtEdit, ActnList;
Type
TFrm_Bas_Bom_Copy = Class(TFrm_Base_Dialog)
Label1: TLabel;
Label2: TLabel;
ExtEdt_ItemCode1: TExtEdit;
ExtEdt_ItemCode2: TExtEdit;
Label3: TLabel;
Label4: TLabel;
lbl_ItemName2: TLabel;
Label7: TLabel;
AdoQry_Main: TAdoQuery;
lbl_ItemName1: TLabel;
ActionList1: TActionList;
Action1: TAction;
procedure FormActivate(Sender: TObject);
procedure btn_okClick(Sender: TObject);
procedure ExtEdt_ItemCode1Change(Sender: TObject);
procedure ExtEdt_ItemCode2Change(Sender: TObject);
procedure btn_CancelClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Action1Execute(Sender: TObject);
procedure ExtEdt_ItemCode1Exit(Sender: TObject);
procedure ExtEdt_ItemCode2Exit(Sender: TObject);
private
{ Private declarations }
function IsMasterCode(ItemCode:String):boolean; //是否被引用
function SlaveCodeUsable(R_ItemCode:String):Boolean;
function PickSlaveCode(InitCode:String):string;
procedure checkv(pstr:string;sstr:string);
procedure GetBomParam;//系统是否对Bom进行审核
procedure checkPmItem(ItemCode:string);//是否采购件
public
{ Public declarations }
procedure InitForm(AdoConnection: TAdoConnection);
end;
var
Frm_Bas_Bom_Copy: TFrm_Bas_Bom_Copy;
implementation
uses Sys_Global;
{$R *.DFM}
procedure TFrm_Bas_Bom_Copy.FormActivate(Sender: TObject);
begin
inherited;
btn_ok.Enabled:=False;
btn_Cancel.Enabled :=False;
end;
procedure TFrm_Bas_Bom_Copy.btn_okClick(Sender: TObject);
var
useCodestr:string;
i:integer;
BomStatusstr:string;
begin
inherited;
i:=0;
BomStatusstr:='';
useCodestr:=userCode;
//判断源物料是否有下级内容
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select ItemCode '+
' from Bom '+
' where ite_ItemCode='''+Trim(Extedt_ItemCode1.text)+'''');
open;
if recordCount=0 then
begin
DispInfo('此物料无下级物料',3);
Extedt_ItemCode1.setfocus;
abort;
end;
end;
// 判断源物料状态
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select BomStatus '+
' from Bom '+
' where ItemCode='''+Trim(Extedt_ItemCode1.text)+'''');
open;
if recordCount>0 then
begin
i:=AdoQry_Tmp.fieldbyname('BomStatus').asinteger;
if i>0 then
begin
case i of
1: BomStatusstr:='未生效';
2: BomStatusstr:='暂定';
3: BomStatusstr:='暂停使用';
end;
DispInfo('此物料Bom状态:'+BomStatusstr+'不能复制',3);
Extedt_ItemCode1.setfocus;
abort;
end;
end;
end;
//检查目的物料是否存在Bom中,如果存在则不允许复制
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select ItemCode '+
' from Bom '+
' where ite_ItemCode='''+Trim(Extedt_ItemCode2.text)+'''');
open;
if recordCount>0 then
begin
DispInfo('目标物料已经有下级物料,不允许复制!',1);
Extedt_ItemCode2.setfocus;
abort;
end;
{Close;
sql.clear;
sql.Add('select ItemCode '+
' from Bom '+
' where ItemCode='''+Trim(Extedt_ItemCode2.text)+'''');
open;
if recordCount>0 then
begin
DispInfo('目标物料已经有上级物料,不允许复制!',1);
Extedt_ItemCode2.setfocus;
abort;
end;}
end;
if Trim(Extedt_ItemCode2.text)=Trim(Extedt_ItemCode1.text) then
begin
DispInfo('物料代码1不能与物料代码2相同 ',3);
Extedt_ItemCode1.setfocus;
abort;
end;
//循环校验源节点下级的所有的树中是否有目的节点
Screen.Cursor:=CrSQLWait;
checkv(Trim(ExtEdt_ItemCode1.text),Trim(ExtEdt_ItemCode2.text)); //循环校验
try
AdoQry_Tmp.Connection.beginTrans ;
//复制
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('insert Bom '+
' (ite_ItemCode,'+
' ItemCode,'+
' BomItemType,'+
' Bomqty,'+
' BomScrAp_Percent,'+
' Bomstatus,'+
' DeptCode,'+
' BommArk )'+
' select '''+Trim(Extedt_ItemCode2.text)+''', ' +
' ItemCode, '+
' BomItemType, '+
' BomQty, '+
' BomScrAp_Percent,' +
' BomStatus ,'+
' DeptCode ,'+
' BomMArk '+
' from Bom '+
' where ite_ItemCode='''+Extedt_ItemCode1.text+'''');
execsql;
//保留更改Bom记录到表BomChangeInfo;
Close;
sql.clear;
sql.Add('insert into BomChangeInfo '+
'(logdate,EmployeeCode,logaction ,Bomid,ite_ItemCode,ItemCode,'+
' BomItemType,Bomqty,BomScrAp_Percent,Bomstatus,DeptCode,BommArk,remArk )'+
' select getdate() as a ,'+
' '''+useCodestr+''' ,'+
' ''0'' ,'+
' Bom.Bomid,'+
' Bom.ite_ItemCode,'+
' '''+Trim(ExtEdt_ItemCode1.text)+''' ,'+
' Bom.BomItemType,'+
' Bom.Bomqty,'+
' isnull(Bom.BomScrAp_Percent,0),'+
' Bom.Bomstatus,'+
' Bom.DeptCode,'+
' Bom.BommArk,'+
' '''+Trim(ExtEdt_ItemCode1.text)+'''+''复制到''+'''+Trim(ExtEdt_ItemCode2.text)+''' '+
' from Bom '+
' where ite_ItemCode='''+Trim(ExtEdt_ItemCode2.text)+''' ');
execsql;
end;
if not IsMasterCode(Trim(Extedt_ItemCode2.text)) then //如果Extedt_ItemCode2没有被引用
begin
With AdoQry_Tmp do
begin
Close;
Sql.clear ;
sql.Add('insert Bom '+
' (ite_ItemCode,'+
' ItemCode,Bomqty,BomScrAp_Percent)'+
' Values '+
' ( null, ' +
' '''+Trim(Extedt_ItemCode2.text)+''',''0'',''0'') ');
execsql;
//保留更改Bom记录到表BomChangeInfo;
Close;
sql.clear;
sql.Add('insert into BomChangeInfo '+
'(logdate,EmployeeCode,logaction ,Bomid,ite_ItemCode,ItemCode,'+
' BomItemType,Bomqty,BomScrAp_Percent,Bomstatus,DeptCode,BommArk,remArk )'+
' select getdate() as a ,'+
' '''+useCodestr+''' ,'+
' ''0'' ,'+
' Bom.Bomid,'+
' ''null'','+
' '''+Trim(ExtEdt_ItemCode2.text)+''' ,'+
' Bom.BomItemType,'+
' Bom.Bomqty,'+
' isnull(Bom.BomScrAp_Percent,0),'+
' Bom.Bomstatus,'+
' Bom.DeptCode,'+
' Bom.BommArk,'+
' '''+Trim(ExtEdt_ItemCode1.text)+'''+''复制到''+'''+Trim(ExtEdt_ItemCode2.text)+''' '+
' from Bom '+
' where ite_ItemCode='''+Trim(ExtEdt_ItemCode2.text)+''' ');
execsql;
end;
end;
AdoQry_Tmp.Connection.CommitTrans ;
Screen.Cursor:=CrDefault;
DispInfo('复制成功!',3);
btn_ok.enabled:=False;
except
AdoQry_Tmp.Connection.RollBackTrans ;
DispInfo('复制失败!',1);
abort;
end;
end;
procedure TFrm_Bas_Bom_Copy.InitForm(AdoConnection: TAdoConnection);
begin
inherited;
SetDBConnect(AdoConnection);
AdoQry_tmp.Connection :=AdoConnection ;
AdoQry_Main.Connection :=AdoConnection ;
GetBomParam;
end;
procedure TFrm_Bas_Bom_Copy.ExtEdt_ItemCode1Change(Sender: TObject);
begin
inherited;
if Extedt_ItemCode1.Text<>'' then
begin
btn_Cancel.Enabled:=True;
btn_ok.enabled:=Extedt_ItemCode2.Text<>'';
end;
end;
procedure TFrm_Bas_Bom_Copy.ExtEdt_ItemCode2Change(Sender: TObject);
begin
inherited;
if Extedt_ItemCode2.Text<>'' then
begin
btn_Cancel.Enabled:=True;
btn_ok.enabled:=( Extedt_ItemCode1.Text<>'');
end;
end;
procedure TFrm_Bas_Bom_Copy.btn_CancelClick(Sender: TObject);
begin
inherited;
Close;
{Extedt_ItemCode1.text:='';
Extedt_ItemCode2.text:='';
lbl_ItemName1.Caption:='';
lbl_ItemName2.Caption:='';
btn_ok.enabled:=False;
btn_Cancel.enabled:=False;}
end;
procedure TFrm_Bas_Bom_Copy.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
inherited;
action:=cafree;
end;
function TFrm_Bas_Bom_Copy.PickSlaveCode(InitCode: String): string;
begin
Result:=GetCodeHint(
AdoQry_Tmp,
'ItemName','项目描述',
'ItemCode','项目代码',
'Item',InitCode,'ItemUsable=1');
end;
function TFrm_Bas_Bom_Copy.SlaveCodeUsable(R_ItemCode: String): Boolean;
var
T_Count:integer;
T_Sql:string;
begin
T_Sql:=
'Select Count(*) as RecordCount '+
'from Item '+
'where ItemCode='''+R_ItemCode+''' '+
' and ItemUsable=1';
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add(T_Sql);
open;
T_Count:=fieldbyname('RecordCount').AsInteger;
Close;
end;
if (T_Count>0 ) then
Result:=True
else
Result:=False;
end;
procedure TFrm_Bas_Bom_Copy.Action1Execute(Sender: TObject);
begin
inherited;
if ActiveControl.Name='ExtEdt_ItemCode1' then
begin
ExtEdt_ItemCode1.Text:=PickSlaveCode(ExtEdt_ItemCode1.Text);
ExtEdt_ItemCode1.SetFocus;
end;
if ActiveControl.Name='ExtEdt_ItemCode2' then
begin
ExtEdt_ItemCode2.Text:=PickSlaveCode(ExtEdt_ItemCode2.Text);
ExtEdt_ItemCode2.SetFocus;
end;
end;
procedure TFrm_Bas_Bom_Copy.ExtEdt_ItemCode1Exit(Sender: TObject);
begin
inherited;
if getfocus()<>btn_Cancel.Handle then
if not SlaveCodeUsable(Trim(ExtEdt_ItemCode1.Text)) then
begin
DispInfo('请输入代码没找到!',1);
TWinControl(Sender).SetFocus;
Abort;
end
else
begin
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select ItemName '+
' from Item '+
' where ItemCode='''+Trim(ExtEdt_ItemCode1.Text)+'''');
open;
Lbl_ItemName1.Caption:=fieldbyname('ItemName').asstring;
Close;
end;
end;
end;
procedure TFrm_Bas_Bom_Copy.ExtEdt_ItemCode2Exit(Sender: TObject);
begin
inherited;
if getfocus()<>btn_Cancel.Handle then
if not SlaveCodeUsable(Trim(ExtEdt_ItemCode2.Text)) then
begin
DispInfo('请输入代码没找到!',1);
TWinControl(Sender).SetFocus;
Abort;
end
else
begin
checkPmItem(Trim(ExtEdt_ItemCode2.Text));
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select ItemName '+
' from Item '+
' where ItemCode='''+Trim(ExtEdt_ItemCode2.Text)+'''');
open;
Lbl_ItemName2.Caption:=fieldbyname('ItemName').asstring;
Close;
end;
end;
end;
procedure TFrm_Bas_Bom_Copy.checkv(pstr, sstr: string);
var
Tmp_Str:string;
s1:string;
begin
with AdoQry_Tmp do
begin
Close;
sql.clear;
Tmp_Str:='declAre @aa chAr(1) '+
'exec checkverity '''+Trim(pstr)+''','''+Trim(sstr)+''',@aa output '+
'select @aa as VerityResult ';
sql.Add(Tmp_Str);
open;
s1:= fieldbyname('verityResult').asstring;
if s1='F' then
begin
DispInfo('循环校验出错!',1);
Screen.Cursor:=CrDefault;
abort;
end;
end;
end;
function TFrm_Bas_Bom_Copy.IsMasterCode(ItemCode: String): boolean;
begin
with AdoQry_Tmp do
begin
Close;
Sql.clear;
Sql.Add('Select * from Bom '+
' where ItemCode='''+Trim(ItemCode)+'''');
open;
if recordCount>0 then
Result:=True
else
Result:=False;
end;
end;
procedure TFrm_Bas_Bom_Copy.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=1 then
begin
DispInfo('对不起,系统已设定Bom构造须审核',1);
Frm_Bas_Bom_Copy.Close;
end;
end;
end;
procedure TFrm_Bas_Bom_Copy.checkPmItem(ItemCode:string);//是否采购件
var
sSQL:string;
begin
sSQL:='select PmCode from Item where ItemCode='+Quotedstr(ItemCode);
with AdoQry_tmp do
begin
Close;
SQL.clear;
SQL.Add(sSQL);
Open;
if fieldbyname('PmCode').AsInteger=1 then
begin
DispInfo('不允许采购件下挂子项',1);
abort;
end;
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -