📄 bas_bom1_d.pas
字号:
if(ActiveControl.Name='btn_Cancel')then
exit;
//先判断父项子项是否相同,相同则退出
if Extedt_ite_ItemCode.text=Lb_ItemCode.Caption then
begin
DispInfo('父项和子项不能相同!',1);
TWinControl(Sender).SetFocus;
Abort;
end;
//判断输入的对应关系是否已经存在
if FoundBom(Extedt_ite_ItemCode.Text,Lb_ItemCode.Caption) then
begin
DispInfo('该物料的Bom已经存在!',1);
TWinControl(Sender).SetFocus;
Abort;
end;
if SlaveCodeUsable(Lb_ItemCode.Caption) then
begin
//循环校验输入的子项是否有效,如果无效则退出,
//如果为新的Bom则不进行检查
if not IsNewBom(Extedt_ite_ItemCode.Text) then
begin
if not CicleCheckSlaveValid(Extedt_ite_ItemCode.Text,Lb_ItemCode.Caption ) then
begin
DispInfo('物料循环使用!',1);
TWinControl(Sender).SetFocus;
Abort;
end;
end;
SetPnl_Slave(Lb_ItemCode.Caption);
end
else
begin
DispInfo('请输入代码没找到!',1);
TWinControl(Sender).SetFocus;
Abort;
end;
inherited;
end;
function TFrm_Bas_Bom1_D.FoundBom(MasterCode, SlaveCode: String): Boolean;
var
T_String:string;
begin
T_String:='';
if MasterCode='' then
begin
T_String:='select Count(*) as RecordCount '+
'From Bom '+
'Where Ite_ItemCode is null '+
' and ItemCode='''+Lb_ItemCode.Caption+''' ';
end
else
begin
T_String:='select Count(*) as RecordCount '+
'From Bom '+
'Where Ite_ItemCode='''+Extedt_ite_ItemCode.Text+''' '+
' and ItemCode='''+Lb_ItemCode.Caption+''' ';
end;
with AdoQry_Tmp Do
begin
Close;
sql.clear;
sql.Add(T_String);
open;
if fieldbyname('RecordCount').AsInteger=0 then Result:=False
else Result:=True;
Close;
end;
end;
function TFrm_Bas_Bom1_D.PickDeptCode(InitCode: String): String;
begin
Result:=GetCodeHint(
AdoQry_Tmp,
'DeptName','部门名称',
'DeptCode','部门代码',
'Dept',InitCode,'');
end;
function TFrm_Bas_Bom1_D.DeptCodeUsable(R_DeptCode: string): Boolean;
var
T_Count:integer;
T_Sql:string;
begin
T_Sql:=
'Select Count(*) as RecordCount '+
'from Dept '+
'where DeptCode='''+R_DeptCode+''' ';
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_Bom1_D.SetDept(R_DeptCode: String);
var
T_Sql:string;
//T_Type:integer;
begin
if R_DeptCode<>'' then
begin
T_Sql:=
'select DeptName '+
'From Dept '+
'where DeptCode='''+R_DeptCode+''' ';
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add(T_Sql);
Open;
if not eof then
begin
Lbl_DeptName.Caption:=fieldbyname('DeptName').AsString;
end;
Close;
end;
end;
end;
procedure TFrm_Bas_Bom1_D.Edt_DeptCodeExit(Sender: TObject);
begin
inherited;
if(ActiveControl.Name='btn_Cancel')then
exit;
if DeptCodeUsable(Edt_DeptCode.Text) then
begin
SetDept(Edt_DeptCode.Text);
end
else
begin
DispInfo('请输入代码没找到!',1);
TWinControl(Sender).SetFocus;
Abort;
end;
end;
procedure TFrm_Bas_Bom1_D.UpdateBom;
var
T_MasterString:string;
T_DeptString:string;
//T_usestyle:string;
begin
T_MasterString:='';
T_DeptString:='';
//T_usestyle:='';
//如果父项为'',则在相应的字段输入NULL
if Extedt_ite_ItemCode.Text='' then
T_MasterString:=' null '
else T_MasterString:=' '''+Extedt_ite_ItemCode.Text+''' ';
//如果部门为'',则在相应的字段输入NULL
if Edt_DeptCode.Text='' then
T_DeptString:=' DeptCode is null '
else T_DeptString:=' DeptCode='''+Edt_DeptCode.Text+''' ';
{if Trim(CmBx_usestyle.text)='' then
T_usestyle:='0'
else
T_usestyle:=inttostr(CmBx_usestyle.Itemindex );}
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add('Update Bom '+
' set BomItemType='+GetCode(Cmbx_Type.Text)+', '+
' BomQty='+Edt_Qty.Text+', '+
' BomScrAp_Percent='+Edt_ScrAp.Text+', '+
' BomStatus='+GetCode(CmBx_Status.Text)+', '+
' RemArk='''+Edt_RemArk.Text+''', '+
' usestyle='+getCode(CmBx_usestyle.text)+','+
T_DeptString+''+
'where Ite_ItemCode='''+Extedt_ite_ItemCode.Text+''' '+
' and ItemCode='''+Lb_ItemCode.Caption+'''');
ExecSQL;
end;
end;
procedure TFrm_Bas_Bom1_D.InsertBom;
var
T_MasterString:string;
T_DeptString:string;
//T_usestyle:string;
begin
T_MasterString:='';
T_DeptString:='';
//T_usestyle:='';
//如果为新的构造Bom则增加一条父项为NULL的记录
if IsNewBom(Extedt_ite_ItemCode.Text) then
begin
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add('Insert into '+
'Bom(Ite_ItemCode, '+
' ItemCode,'+
' BomItemType, '+
' BomQty, '+
' BomScrAp_Percent, '+
' BomStatus, '+
' usestyle, '+
' DeptCode) '+
'Values(null, '+
' '''+Extedt_ite_ItemCode.Text+''','+
' 0, '+
' 1, '+
' 0.0, '+
' 0, '+
' 0, '+
' null) '+
'SELECT @@IDENTITY AS Lc_Identity ');
Open;
Lc_Identity:=fieldbyname('Lc_Identity').AsInteger;
Close;
end;
end;
//如果父项为'',则在相应的字段输入NULL
if Extedt_ite_ItemCode.Text='' then
T_MasterString:=' null '
else T_MasterString:=' '''+Extedt_ite_ItemCode.Text+''' ';
//如果部门为'',则在相应的字段输入NULL
if Edt_DeptCode.Text='' then
T_DeptString:=' null '
else T_DeptString:=' '''+Edt_DeptCode.Text+''' ';
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add('Insert into '+
'Bom(Ite_ItemCode, '+
' ItemCode,'+
' BomItemType, '+
' BomQty, '+
' BomScrAp_Percent, '+
' BomStatus, '+
' DeptCode, '+
' usestyle,'+
' RemArk) '+
'Values('+T_MasterString+', '+
' '''+Lb_ItemCode.Caption+''','+
' '+GetCode(Cmbx_Type.Text)+', '+
' '+Edt_Qty.Text+', '+
' '+Edt_ScrAp.Text+', '+
' '+GetCode(CmBx_Status.Text)+', '+
' '+T_DeptString+','+
' '+getCode(CmBx_usestyle.text)+','+
' '''+Edt_RemArk.Text+''') '+
'SELECT @@IDENTITY AS Lc_Identity ');
Open;
Lc_Identity:=fieldbyname('Lc_Identity').AsInteger;
end;
end;
procedure TFrm_Bas_Bom1_D.btn_okClick(Sender: TObject);
begin
JudgeChild(Frm_Bas_Bom1.Extedt_ItemCode.Text);
//给全局变量赋值
SlaveCode:=Lb_ItemCode.Caption;
inherited;
StatusBar1.Panels[0].Text:='';
end;
function TFrm_Bas_Bom1_D.IsNewBom(ItemCode: String): Boolean;
var
Tmp_IteCount,Tmp_Count:integer;
begin
Tmp_IteCount:=0;
Tmp_Count:=0;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('select Count(*) as reccordCount '+
'from Bom '+
'where ItemCode='''+ItemCode+''' ');
open;
Tmp_Count:=fieldbyname('ReccordCount').AsInteger;
Close;
sql.clear;
sql.Add('select Count(*) as reccordCount '+
'from Bom '+
'where Ite_ItemCode='''+ItemCode+''' ');
open;
Tmp_IteCount:=fieldbyname('ReccordCount').AsInteger;
if (Tmp_IteCount+Tmp_Count)=0 then
Result:=True
else Result:=False;
Close;
end;
end;
procedure TFrm_Bas_Bom1_D.Action1Execute(Sender: TObject);
begin
inherited;
if ActiveControl.Name='Extedt_ite_ItemCode' then
begin
Extedt_ite_ItemCode.Text:=PickSlaveCode(Extedt_ite_ItemCode.Text);
Extedt_ite_ItemCode.SetFocus;
end;
if ActiveControl.Name='Edt_DeptCode' then
begin
Edt_DeptCode.Text:=PickDeptCode(Edt_DeptCode.Text);
Edt_DeptCode.SetFocus;
end;
end;
procedure TFrm_Bas_Bom1_D.EraseOldRoot;
var
Tmp_Str:String;
begin
Tmp_Str:='Delete From Bom '+
'where ItemCode='''+Lb_ItemCode.Caption+''' '+
' and Ite_ItemCode is null ';
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add(Tmp_Str);
ExecSql;
Close;
end;
end;
procedure TFrm_Bas_Bom1_D.SaveModifyToLog;
begin
with AdoQry_Tmp do
begin
Close;
sql.clear;
if not Add then
begin
//这里是修改的时候,删除在另外的地方
sql.text:='insert into BomChangeInfo '+
' (LogDate,'+
' EmployeeCode,'+
' LogAction,'+
' BomId,'+
' Ite_ItemCode,'+
' ItemCode,'+
' BomItemType,'+
' BomQty,'+
' BomScrAp_Percent,'+
' BomStatus,'+
' DeptCode,'+
' usestyle,'+
' BomMArk) '+
'Values '+
' (getdate(),'+
' '''+UserCode+''','+
' 1,'+
' '+IntToStr(AdoQry_Maintain.fieldbyname('BomId').AsInteger)+','+
' '''+AdoQry_Maintain.fieldbyname('Ite_ItemCode').AsString+''','+
' '''+AdoQry_Maintain.fieldbyname('ItemCode').AsString+''','+
' '+IntToStr(AdoQry_Maintain.fieldbyname('BomItemType').AsInteger)+','+
' '+FloatToStr(AdoQry_Maintain.fieldbyname('BomQty').AsFloat)+','+
' '+FloatToStr(AdoQry_Maintain.fieldbyname('BomScrAp_Percent').AsFloat)+','+
' '+IntToStr(AdoQry_Maintain.fieldbyname('BomStatus').AsInteger)+','+
' '''+AdoQry_Maintain.fieldbyname('DeptCode').AsString+''','+
' '+inttostr(AdoQry_Maintain.fieldbyname('usestyle').asinteger)+','+
' '+IntToStr(AdoQry_Maintain.fieldbyname('BomMArk').AsInteger)+') ';
end;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -