📄 bas_bom2_d.pas
字号:
{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBase $00400000}
{$ApPType GUI}
unit Bas_Bom2_D;
Interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Base_Detail, StdCtrls, Db, AdODB, ExtCtrls, ExtEdit, ComCtrls, ActnList;
Type
TFrm_Bas_Bom2_D = Class(TFrm_Base_Detail)
Label1: TLabel;
Lbl_MasterCode: TLabel;
Label3: TLabel;
Lbl_MasterType: TLabel;
Label5: TLabel;
Lbl_MasterUom: TLabel;
Label7: TLabel;
Lbl_MasterName: TLabel;
Label9: TLabel;
Label13: TLabel;
Label15: TLabel;
Lbl_SlaveName: TLabel;
Label17: TLabel;
Edt_Qty: TEdit;
CmBx_Type: TComboBox;
Label14: TLabel;
Edt_ScrAp: TEdit;
Label18: TLabel;
Label19: TLabel;
CmBx_Status: TComboBox;
Label20: TLabel;
Edt_DeptCode: TEdit;
Lbl_DeptName: TLabel;
Edt_ItemCode: TEdit;
Label10: TLabel;
StatusBar1: TStatusBar;
ActionList1: TActionList;
Action1: TAction;
Label2: TLabel;
Edt_RemArk: TEdit;
Label4: TLabel;
CmBx_usestyle: TComboBox;
Label6: TLabel;
Lbl_SlaveUom: TLabel;
AdoQry_tmp1: TAdoQuery;
procedure FormCreate(Sender: TObject);
procedure Edt_ItemCodeExit(Sender: TObject);
procedure Edt_DeptCodeExit(Sender: TObject);
procedure btn_okClick(Sender: TObject);
procedure Action1Execute(Sender: TObject);
procedure Edt_ScrApExit(Sender: TObject);
procedure Edt_QtyExit(Sender: TObject);
procedure CmBx_TypeExit(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Edt_QtyChange(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
lc_ItemExist:Boolean;
lc_TempBuffer:string;
fPmCode:integer;
Lc_Identity:integer;
tmp_ItemCode:string;
function CicleCheckSlaveValid(R_MasterCode:string;R_SlaveCode:string):Boolean;
procedure SetPnl_Slave(R_ItemCode:String);
Function PickSlaveCode(InitCode:String):String;
Function PickDeptCode(InitCode:String):String;
Function SlaveCodeUsable(R_ItemCode:String):Boolean;
Function DeptCodeUsable(R_DeptCode:string):Boolean;
procedure SetDept(R_DeptCode:String);
Function FoundBom(MasterCode:String;SlaveCode:String):Boolean; //在Bom中是否存在该记录
procedure InsertBom; //插入Bom
procedure UpdateBom; //修改Bom
//procedure CheckVerity(R_MasterCodeCheck: string);
Function IsNewBom(ItemCode:String):Boolean; //判断是否为新的Bom
procedure EraseOldRoot; //删除旧的为根的节点
procedure SaveModifyToLog; //存入修改日志文件
procedure SaveAddToLog; //存入增加日志文件
//是否存在替代虚项
Function FoundReplaceVirtual(MasterCode:string):boolean;
procedure clearSinGleReCode; //删除单个的Bom记录
procedure InsertBomChange(realite_ItemCode:string); //新增时存入BomChange;
procedure updateBomChange(realite_ItemCode:string); //修改时存入BomChange;
procedure JudgeChild(ItemCode:string); // 判断子项是否是虚项并作出处理
function GetUomName(ItemCode:string):string; //获得计量单位
procedure GetWorkCenterQTY;
{ Private declarations }
public
MasterCode:string;
SlaveCode:string;
procedure SaveData;Override;
procedure InitControls;Override;
{ Public declarations }
end;
var
Frm_Bas_Bom2_D: TFrm_Bas_Bom2_D;
implementation
uses Sys_Global, Bas_Bom2;
{$R *.DFM}
{procedure TFrm_Bas_Bom_D.CheckVerity(R_MasterCodeCheck: string);
begin
end;}
function TFrm_Bas_Bom2_D.CicleCheckSlaveValid(R_MasterCode,
R_SlaveCode: string):Boolean;
var
Tmp_Str:string;
begin
StatusBar1.Panels[0].Text:='正在进行校验...';
StatusBar1.Refresh;
lc_TempBuffer:=R_SlaveCode;
//调用检查的存储过程进行校验
with AdoQry_Tmp do
begin
Close;
sql.clear;
Tmp_Str:='declAre @aa chAr(1) '+
'exec CheckVerity_New '''+R_SlaveCode+''','''+r_MasterCode+''',@aa output '+
'select @aa as VerityResult ';
sql.Add(Tmp_Str);
open;
if fieldbyname('verityResult').asstring='F' then
Result:=False
else Result:=True;
Close;
end;
StatusBar1.Panels[0].Text:='';
end;
procedure TFrm_Bas_Bom2_D.InitControls;
var
T_Sql:string;
T_ItemCode:string;
T_Type:integer;
begin
if Add then
begin
SetFocus_Control:=Edt_ItemCode;
end
else
begin
SetFocus_Control:=CmBx_Type;
end;
inherited;
AdoQry_tmp1.Connection :=AdoQry_tmp.Connection ;
if Add then
begin
Edt_ItemCode.Enabled:=True
end
else
begin
Edt_ItemCode.Enabled:=False;
end;
T_ItemCode:=MasterCode;
Lbl_MasterCode.Caption:=MasterCode;
with AdoQry_Tmp do
begin
Close;
SQL.clear;
if T_ItemCode<>'' then
begin
T_Sql:=
'Select ItemName,'+
' UomName, '+
' ItemType '+
'From Item I inner join Uom U '+
' on I.UomCode=U.UomCode '+
'Where I.ItemCode='''+T_ItemCode+''' ';
SQL.Add(T_Sql);
open;
if not eof then
begin
Lbl_MasterUom.Caption:=fieldbyname('UomName').AsString;
Lbl_MasterName.Caption:=fieldbyname('ItemName').AsString;
T_Type:=fieldbyname('ItemType').AsInteger;
case T_Type of
0:Lbl_MasterType.Caption:='普通物料';
1:Lbl_MasterType.Caption:='工作中心';
2:Lbl_MasterType.Caption:='工具';
3:Lbl_MasterType.Caption:='参考';
4:Lbl_MasterType.Caption:='结构虚项';
5:Lbl_MasterType.Caption:='劳务';
6:Lbl_MasterType.Caption:='副产品';
7:Lbl_MasterType.Caption:='成本中心';
8:Lbl_MasterType.Caption:='替代虚象';
end;
end;
end;
end;
if AdoQry_Maintain.Active then
begin
with AdoQry_Maintain do
begin
Edt_ItemCode.Text:=fieldbyname('ItemCode').AsString;
Lbl_SlaveName.Caption:=fieldbyname('ItemName').AsString;
Lbl_SlaveUom.Caption:=fieldbyname('UomName').asstring;
Cmbx_Type.ItemIndex:=fieldbyname('BomItemType').AsInteger;
Edt_Qty.Text:=fieldbyname('BomQty').Asstring;
Edt_ScrAp.Text:=FloatToStr(fieldbyname('BomScrAp_Percent').AsFloat);
Cmbx_Status.ItemIndex:=fieldbyname('BomStatus').AsInteger;
Edt_DeptCode.Text:=fieldbyname('DeptCode').AsString;
Lbl_DeptName.Caption:=fieldbyname('DeptName').AsString;
CmBx_usestyle.ItemIndex :=fieldbyname('usestyle').asinteger;
Edt_RemArk.Text:=fieldbyname('RemArk').AsString;
end;
end;
end;
procedure TFrm_Bas_Bom2_D.SaveData;
begin
inherited;
AdoQry_tmp.Connection.beginTrans;
try
if (Add) then //新增的情况
begin
InsertBom;
//插入到LOG中
// SaveAddToLog;
//删除子项原为最终产品的记录
EraseOldRoot;
//清除单个的Bom记录
clearSinGleReCode;
//新增时存入BomChange;
InsertBomChange(Trim(Lbl_MasterCode.Caption));
end
else
begin
//先插入到LOG中
// SaveModifyToLog;
UpdateBom;
//清除单个的Bom记录
clearSinGleReCode;
//修改时存入BomChange;
updateBomChange(Trim(Lbl_MasterCode.Caption));
end;
AdoQry_tmp.Connection.CommitTrans;
except
AdoQry_tmp.Connection.RollBackTrans;
DispInfo('存盘失败!请再试!',1);
end;
with AdoQry_Maintain do
begin
fieldbyname('ItemCode').AsString:=Edt_ItemCode.Text;
fieldbyname('ItemName').AsString:=Lbl_SlaveName.Caption;
fieldbyname('BomItemType').AsInteger:=Cmbx_Type.ItemIndex;
fieldbyname('BomQty').AsFloat:=StrToFloat(Edt_Qty.Text);
fieldbyname('BomScrAp_Percent').AsFloat:=StrToFloat(Edt_ScrAp.Text);
fieldbyname('BomStatus').AsInteger:=Cmbx_Status.ItemIndex;
fieldbyname('DeptCode').AsString:=Edt_DeptCode.Text;
fieldbyname('DeptName').AsString:=Lbl_DeptName.Caption;
fieldbyname('usestyle').asinteger:=CmBx_usestyle.Itemindex;
fieldbyname('RemArk').AsString:=Edt_RemArk.Text;
fieldbyname('PmCode').AsInteger:=fPmCode;
post;
end;
end;
procedure TFrm_Bas_Bom2_D.FormCreate(Sender: TObject);
begin
inherited;
//变量初始化
MasterCode:='';
SlaveCode:='';
Lc_ItemExist:=False;
lc_TempBuffer:='';
fPmCode:=0;
Lc_Identity:=0;
//LABEL初始化
Lbl_MasterCode.Caption:='';
Lbl_MasterType.Caption:='';
Lbl_MasterUom.Caption:='';
Lbl_SlaveUom.Caption:='';
Lbl_MasterName.Caption:='';
Lbl_SlaveName.Caption:='';
Lbl_DeptName.Caption:='';
end;
procedure TFrm_Bas_Bom2_D.SetPnl_Slave(R_ItemCode:String);
var
T_Sql:string;
//T_Type:integer;
begin
if R_ItemCode<>'' then
begin
T_Sql:=
'select ItemName,'+
' UomName,'+
' PmCode, '+
' ItemType '+
'From Item I inner join Uom U '+
'on I.UomCode=I.UomCode '+
'where I.ItemCode='''+R_ItemCode+''' ';
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add(T_Sql);
Open;
if not eof then
begin
Lbl_SlaveName.Caption:=fieldbyname('ItemName').AsString;
fPmCode:=fieldbyname('PmCode').AsInteger;
//如果Item类型为1 资源、4 结构虚项、8 替代虚项
//则Bom的子项属性就必须和相应的中文一样的含义
//Bom的相关属性有:1 资源、3 结构虚项、6 替代虚项
Case fieldbyname('ItemType').AsInteger of
1:begin
CmBx_Type.ItemIndex:=1;
end;
4:begin
if FoundReplaceVirtual(lbl_MasterCode.Caption) then
begin
// DispInfo('替代虚项下不能有结构虚项!',1);
// abort;
end;
CmBx_Type.ItemIndex:=3;
end;
7:begin
if FoundReplaceVirtual(lbl_MasterCode.Caption) then
begin
// DispInfo('替代虚项下不能再有替代虚项!',1);
// abort;
end;
CmBx_Type.ItemIndex:=6;
end;
else
begin
if FoundReplaceVirtual(lbl_MasterCode.Caption) then
begin
if (Cmbx_Type.ItemIndex=3) or (Cmbx_Type.ItemIndex=6) then
begin
// DispInfo('替代虚项下不能再有虚项!',1);
// abort;
end;
end;
end;
end;
end;
Close;
end;
end;
end;
function TFrm_Bas_Bom2_D.PickSlaveCode(InitCode:String):String;
begin
Result:=GetCodeHint(
AdoQry_Tmp,
'ItemName','物料描述',
'ItemCode','物料代码',
'Item',InitCode,'ItemUsable=1');
end;
function TFrm_Bas_Bom2_D.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_Bom2_D.Edt_ItemCodeExit(Sender: TObject);
begin
if(ActiveControl.Name='btn_Cancel')then
exit;
//先判断父项子项是否相同,相同则退出
Lbl_SlaveUom.Caption:=GetUomName(Edt_ItemCode.text);
if Lbl_MasterCode.Caption=Edt_ItemCode.Text then
begin
DispInfo('父项和子项不能相同!',1);
TWinControl(Sender).SetFocus;
Abort;
end;
//判断输入的对应关系是否已经存在
if FoundBom(Lbl_MasterCode.Caption,Edt_ItemCode.Text) then
begin
DispInfo('该物料的Bom已经存在!',1);
TWinControl(Sender).SetFocus;
Abort;
end;
JudgeChild(Edt_ItemCode.Text);
if SlaveCodeUsable(Edt_ItemCode.Text) then
begin
//循环校验输入的子项是否有效,如果无效则退出,
//如果为新的Bom则不进行检查
if not IsNewBom(Lbl_MasterCode.Caption) then
begin
if not CicleCheckSlaveValid(Lbl_MasterCode.Caption,Edt_ItemCode.Text ) then
begin
DispInfo('物料循环使用!',1);
TWinControl(Sender).SetFocus;
Abort;
end;
end;
SetPnl_Slave(Edt_ItemCode.Text);
end
else
begin
DispInfo('输入代码没找到!',1);
TWinControl(Sender).SetFocus;
Abort;
end;
inherited;
end;
function TFrm_Bas_Bom2_D.FoundBom(MasterCode, SlaveCode: String): Boolean;
var
T_String:string;
begin
T_String:='';
if MasterCode='' then
begin
T_String:='select Count(*) as RecordCount '+
'From BomA '+
'Where Ite_ItemCode is null '+
' and ItemCode='''+Edt_ItemCode.Text+''' ';
end
else
begin
T_String:='select Count(*) as RecordCount '+
'From BomA '+
'Where Ite_ItemCode='''+Lbl_MasterCode.Caption+''' '+
' and ItemCode='''+Edt_ItemCode.Text+''' ';
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_Bom2_D.PickDeptCode(InitCode: String): String;
begin
Result:=GetCodeHint(
AdoQry_Tmp,
'DeptName','部门名称',
'DeptCode','部门代码',
'Dept',InitCode,'');
end;
function TFrm_Bas_Bom2_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_Bom2_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_Bom2_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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -