📄 bas_bom2_d.pas
字号:
end;
procedure TFrm_Bas_Bom2_D.UpdateBom;
var
T_MasterString:string;
T_DeptString:string;
//T_usestyle:string;
begin
T_MasterString:='';
T_DeptString:='';
//T_usestyle:='';
//如果父项为'',则在相应的字段输入NULL
if Lbl_MasterCode.Caption='' then
T_MasterString:=' null '
else T_MasterString:=' '''+Lbl_MasterCode.Caption+''' ';
//如果部门为'',则在相应的字段输入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 BomA '+
' 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='''+Lbl_MasterCode.Caption+''' '+
' and ItemCode='''+Edt_ItemCode.Text+'''');
ExecSQL;
end;
end;
procedure TFrm_Bas_Bom2_D.InsertBom;
var
T_MasterString:string;
T_DeptString:string;
begin
T_MasterString:='';
T_DeptString:='';
//T_usestyle:='';
//如果为新的构造Bom则增加一条父项为NULL的记录
if IsNewBom(Lbl_MasterCode.Caption) then
begin
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add('Insert into '+
'BomA(Ite_ItemCode, '+
' ItemCode,'+
' BomItemType, '+
' BomQty, '+
' BomScrAp_Percent, '+
' BomStatus, '+
' usestyle, '+
' DeptCode) '+
'Values(null, '+
' '''+Lbl_MasterCode.Caption+''','+
' 0, '+
' 1, '+
' 0.0, '+
' 0, '+
' 0, '+
' null) '+
'SELECT @@IDENTITY AS Lc_Identity ');
Open;
Lc_Identity:=fieldbyname('Lc_Identity').AsInteger;
Close;
end;
end;
//如果父项为'',则在相应的字段输入NULL
if Lbl_MasterCode.Caption='' then
T_MasterString:=' null '
else T_MasterString:=' '''+Lbl_MasterCode.Caption+''' ';
//如果部门为'',则在相应的字段输入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 '+
'BomA(Ite_ItemCode, '+
' ItemCode,'+
' BomItemType, '+
' BomQty, '+
' BomScrAp_Percent, '+
' BomStatus, '+
' DeptCode, '+
' usestyle,'+
' RemArk) '+
'Values('+T_MasterString+', '+
' '''+Edt_ItemCode.Text+''','+
' '+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_Bom2_D.btn_okClick(Sender: TObject);
begin
JudgeChild(Edt_ItemCode.Text);
//给全局变量赋值
SlaveCode:=Edt_ItemCode.Text;
inherited;
Frm_Bas_Bom2.UpdateBomOk(Frm_Bas_Bom2.Edt_Ite_ItemCode.Text);
StatusBar1.Panels[0].Text:='';
end;
function TFrm_Bas_Bom2_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 BomA '+
'where ItemCode='''+ItemCode+''' ');
open;
Tmp_Count:=fieldbyname('ReccordCount').AsInteger;
Close;
sql.clear;
sql.Add('select Count(*) as reccordCount '+
'from BomA '+
'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_Bom2_D.Action1Execute(Sender: TObject);
begin
inherited;
if ActiveControl.Name='Edt_ItemCode' then
begin
Edt_ItemCode.Text:=PickSlaveCode(Edt_ItemCode.Text);
Edt_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_Bom2_D.EraseOldRoot;
var
Tmp_Str:String;
begin
Tmp_Str:='Delete From BomA '+
'where ItemCode='''+Edt_ItemCode.Text+''' '+
' and Ite_ItemCode is null ';
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add(Tmp_Str);
ExecSql;
Close;
end;
end;
procedure TFrm_Bas_Bom2_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;
execsql;
Close;
end;
end;
procedure TFrm_Bas_Bom2_D.SaveAddToLog;
var
T_MasterString:string;
T_DeptString:string;
begin
T_MasterString:='';
T_DeptString:='';
with AdoQry_Tmp do
begin
Close;
sql.clear;
//如果父项为'',则在相应的字段输入NULL
if Lbl_MasterCode.Caption='' then
T_MasterString:=' null '
else T_MasterString:=' '''+Lbl_MasterCode.Caption+''' ';
//如果部门为'',则在相应的字段输入NULL
if Edt_DeptCode.Text='' then
T_DeptString:=' null '
else T_DeptString:=' '''+Edt_DeptCode.Text+''' ';
//这里是修改的时候,删除在另外的地方
sql.text:='insert into BomChangeInfo '+
' (LogDate,'+
' EmployeeCode,'+
' LogAction,'+
' BomId,'+
' Ite_ItemCode,'+
' ItemCode,'+
' BomItemType,'+
' BomQty,'+
' BomScrAp_Percent,'+
' BomStatus,'+
' DeptCode,'+
' usestyle,'+
' BomMArk) '+
'Values '+
' (getdate(),'+
' '''+UserCode+''','+
' 0,'+
' '+IntToStr(Lc_Identity)+','+
' '+T_MasterString+','+
' '''+Edt_ItemCode.Text+''','+
' '+GetCode(Cmbx_Type.Text)+','+
' '+Edt_Qty.Text+','+
' '+Edt_ScrAp.Text+','+
' '+GetCode(CmBx_Status.Text)+','+
' '+T_DeptString+','+
' '+getCode(CmBx_usestyle.text)+','+
' 0) ';
execsql;
Close;
end;
end;
procedure TFrm_Bas_Bom2_D.Edt_ScrApExit(Sender: TObject);
begin
inherited;
FloatCheck(sender);
//损耗率不能大于100%
if StrToFloat(Edt_ScrAp.Text)>100 then
begin
DispInfo('损耗率不能超过100%',1);
Edt_ScrAp.SetFocus;
end;
if StrToFloat(Edt_ScrAp.Text)<0 then
begin
DispInfo('损耗率不能小于0!',1);
Edt_ScrAp.SetFocus;
end;
Edt_ScrAp.Text:=FormatFloat('0.#####',StrToFloat(Edt_ScrAp.Text));
end;
procedure TFrm_Bas_Bom2_D.Edt_QtyExit(Sender: TObject);
begin
inherited;
FloatCheck(Edt_Qty);
if StrToFloat(Edt_Qty.Text)<0 then
begin
DispInfo('定额不能小于0!',1);
Edt_Qty.SetFocus;
end;
Edt_Qty.Text:=FormatFloat('0.########',StrToFloat(Edt_Qty.Text));
end;
{
Item
1 工作中心、4 结构虚项、7 替代虚项
Bom
1 工作中心、3 结构虚项、6 替代虚项
}
procedure TFrm_Bas_Bom2_D.CmBx_TypeExit(Sender: TObject);
begin
inherited;
SetPnl_Slave(Edt_ItemCode.Text);
JudgeChild(Edt_ItemCode.Text);
end;
Function TFrm_Bas_Bom2_D.FoundReplaceVirtual(MasterCode:string):boolean;
begin
with AdoQry_Tmp do
begin
Close;
sql.clear;
sql.Add('select * from BomA where ItemCode='''+MasterCode+''' ');
open;
if Locate('BomItemType',6,[]) then Result:=True
else Result:=False;
Close;
end;
end;
procedure TFrm_Bas_Bom2_D.clearSinGleReCode;
begin
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('delete '+
'from BomA '+
'where ItemCode not in '+
' ( select case when ite_ItemCode is null then '''' else ite_ItemCode end '+
' from BomA '+
' ) '+
' and ite_ItemCode is null '+
'');
execsql;
Close;
end;
end;
procedure TFrm_Bas_Bom2_D.InsertBomChange(realite_ItemCode:string);
begin
tmp_ItemCode:='';
with AdoQry_tmp1 do
begin
Close;
sql.clear;
sql.Add(' exec Find_Real_Ite_ItemCode '''+realite_ItemCode+'''');
Prepared;
open;
end;
AdoQry_tmp1.First ;
while not AdoQry_tmp1.Eof do
begin
tmp_ItemCode:=AdoQry_tmp1.fieldbyname ('ite_ItemCode').asstring;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('insert BomChange(real_ItemCode,ite_ItemCode,ItemCode,BomItemType0,'+
' Bomstatus0,Bomqty0,BomScrAp_Percent0, BomItemType1,Bomstatus1,Bomqty1,BomScrAp_Percent1,BomChangetime)'+
'Values('''+tmp_ItemCode+''','+
' '''+Trim(Lbl_MasterCode.Caption)+''','+
' '''+Trim(Edt_ItemCode.text)+''','+
' 0,0,0,0,'+
' '''+getCode(Trim(CmBx_Type.text))+''','+
' '''+getCode(Trim(CmBx_Status.text))+''','+
' '''+Trim(Edt_Qty.text)+''','+
' '''+Trim(Edt_ScrAp.text)+''','+
' getdate())');
execsql;
end;
AdoQry_tmp1.Next;
end;
end;
procedure TFrm_Bas_Bom2_D.updateBomChange(realite_ItemCode:string);
begin
tmp_ItemCode:='';
with AdoQry_tmp1 do
begin
Close;
sql.clear;
sql.Add(' exec Find_Real_Ite_ItemCode '''+realite_ItemCode+'''');
Prepared;
open;
end;
AdoQry_tmp1.First ;
tmp_ItemCode:=AdoQry_tmp1.fieldbyname ('ite_ItemCode').asstring;
while not AdoQry_tmp1.Eof do
begin
tmp_ItemCode:=AdoQry_tmp1.fieldbyname ('ite_ItemCode').asstring;
with AdoQry_tmp do
begin
Close;
sql.clear;
sql.Add('insert BomChange(real_ItemCode,ite_ItemCode,ItemCode,BomItemType0,'+
' Bomstatus0,Bomqty0,BomScrAp_Percent0, BomItemType1,Bomstatus1,Bomqty1,BomScrAp_Percent1,BomChangetime)'+
'Values('''+tmp_ItemCode+''','+
' '''+Trim(Lbl_MasterCode.Caption)+''','+
' '''+Trim(Edt_ItemCode.text)+''','+
' '''+inttostr(AdoQry_Maintain.fieldbyname('BomItemType').asinteger)+''','+
' '''+inttostr(AdoQry_Maintain.fieldbyname('BomStatus').asinteger)+''','+
' '''+FormatFloat('0.########',AdoQry_Maintain.fieldbyname('BomQty').asfloat)+''','+
' '''+floattostr(AdoQry_Maintain.fieldbyname('BomScrAp_Percent').asfloat)+''','+
' '''+getCode(Trim(CmBx_Type.text))+''','+
' '''+getCode(Trim(CmBx_Status.text))+''','+
' '''+Trim(Edt_Qty.text)+''','+
' '''+Trim(Edt_ScrAp.text)+''','+
' getdate())');
execsql;
end;
AdoQry_tmp1.next;
end;
end;
procedure TFrm_Bas_Bom2_D.JudgeChild(ItemCode:string);
var
S:string;
begin
S:=' select ItemType from Item where ItemCode='+QuotedStr(ItemCode);
with AdoQry_tmp do
begin
Close;
SQL.clear;
SQL.Add(S);
Open;
end;
case AdoQry_tmp.fieldbyname('ItemType').asinteger of
0: if CmBx_Type.ItemIndex<>4 then CmBx_Type.ItemIndex:=0;
1: CmBx_Type.ItemIndex:=1;
4: CmBx_Type.ItemIndex:=3;
5:
begin
DispInfo('劳务不允许挂入Bom',1);
Edt_ItemCode.SetFocus;
abort;
end;
6: CmBx_Type.ItemIndex:=5;
7: CmBx_Type.ItemIndex:=6;
3: CmBx_Type.ItemIndex:=7;
end;
end;
procedure TFrm_Bas_Bom2_D.FormActivate(Sender: TObject);
begin
inherited;
if Frm_Bas_Bom2.AdoQry_Main.IsEmpty then
begin
Edt_Qty.Text:='1';
Edt_ScrAp.Text:='0'
end;
Edt_Qty.Text:=FormatFloat('0.########',StrToFloat(Edt_Qty.Text));
end;
function TFrm_Bas_Bom2_D.GetUomName(ItemCode:string):string; //获得计量单位
var
sSQL:string;
begin
if Trim(ItemCode)='' then
begin
DispInfo('物料代码不能为空',1) ;
abort;
end;
sSQL:=' select Uom.UomName from Item join Uom on Item.UomCode=Uom.UomCode'+
' where Item.ItemCode='+quotedstr(Trim(ItemCode));
with AdoQry_tmp do
begin
Close;
SQL.clear;
SQL.Add(sSQL);
Open;
Result:=fieldbyname('UomName').AsString;
end;
end;
procedure TFrm_Bas_Bom2_D.Edt_QtyChange(Sender: TObject);
begin
inherited;
if Length(Edt_Qty.Text)>12 then
begin
DispInfo('您所录入的数据已超过规定长度,请查证后再录入',1);
Edt_Qty.text:='';
Abort;
end
else
btn_ok.Enabled:=True;
end;
procedure TFrm_Bas_Bom2_D.GetWorkCenterQTY;
begin
end;
procedure TFrm_Bas_Bom2_D.Button1Click(Sender: TObject);
begin
inherited;
GetWorkCenterQTY;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -