📄 bas_bom3.pas
字号:
unit Bas_Bom3;
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_Bom3 = Class(TFrm_Base_Outer)
Lbl_IteCode: TLabel;
Label1: TLabel;
Lbl_RecordCount: TLabel;
AdoQry_tmp1: TAdoQuery;
Extedt_ItemCode: TExtEdit;
AdoQry_MainBomid: TAutoIncField;
AdoQry_Mainite_ItemCode: TStringField;
AdoQry_MainItemName: TStringField;
AdoQry_MainUomName: TStringField;
AdoQry_MainPmCode: TIntegerField;
AdoQry_MainPrepareLT: TIntegerField;
AdoQry_MainRunLt: TIntegerField;
AdoQry_MainQcLT: TIntegerField;
AdoQry_MainItemUsable: TIntegerField;
AdoQry_MainDesignNo: TStringField;
AdoQry_MainItemCode: TStringField;
AdoQry_MainBomItemType: TIntegerField;
AdoQry_MainBomqty: TFloatField;
AdoQry_MainBomScrAp_Percent: TFloatField;
AdoQry_MainBomstatus: TIntegerField;
AdoQry_MainDeptCode: TStringField;
AdoQry_MainDeptName: TStringField;
AdoQry_MainDeptB: TStringField;
AdoQry_Mainusestyle: TIntegerField;
AdoQry_MainremArk: TStringField;
Label2: TLabel;
Lb_ItemName: TLabel;
Label3: TLabel;
Lb_PmCode: TLabel;
Lb_DesignNo: TLabel;
Label11: TLabel;
Lb_QcLT: TLabel;
Label9: TLabel;
Lb_RunLT: TLabel;
Label7: TLabel;
Lb_PreparelLT: TLabel;
Label5: TLabel;
AdoQry_MainBommArk: TIntegerField;
Label4: TLabel;
Lb_Uom: TLabel;
procedure Act_NewExecute(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormActivate(Sender: TObject);
procedure Act_ModifyExecute(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Act_HintExecute(Sender: TObject);
procedure Act_DeleteExecute(Sender: TObject);
procedure AdoQueryAfterOpen(DataSet: TDataSet);
procedure DBGridEhGetCellParams(Sender: TObject; Column: TColumnEh;
AFont: TFont; var Background: TColor; State: TGridDrawState);
procedure Extedt_ItemCodeExit(Sender: TObject);
procedure DBGridEhTitleClick(Column: TColumnEh);
procedure Act_FilterExecute(Sender: TObject);
private
Flag:Boolean;
Lc_OldMaster:TStrinGlist;
tmp_ItemCode:string;
BookMArk: String;
procedure InsertOldMaster(ItemCode:string); //把当前查询的父项插入
procedure SetPnl_Head(R_Code:string);
procedure GetSlave(R_Code:string); //选出所有父项
function PickMasterCode(R_InitCode:string):string;
function HaveSlave(R_Code:string):Boolean;
function MasterCodeUsable(R_Code:string):Boolean;
procedure clearPnl_Head;
procedure LocateToSlave(T_ItemCode:String); //定位到父项代码
function ItemIsSource(ItemCode: String): Boolean;
procedure SaveDeleteToLog; //存入删除日志文件
procedure clearSinGleReCode;
procedure GetReal_ItemCode(realite_ItemCode:string);//生成BomChange删除Bom的数据
function Selected:boolean;
procedure GetBomParam;
procedure CheckChilType(ItemCode:string);//检查子项属性
{ Private declarations }
public
function CheckBomOK(ite_ItemCode:string):boolean; //Bom是否审核
procedure UpdateBomOk(Ite_ItemCode:string);
procedure InitReport; Override;//设置报表表头属性
procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
Function SetDeleteSql:string;Override;
{ Public declarations }
end;
var
Frm_Bas_Bom3: TFrm_Bas_Bom3;
implementation
uses Sys_Global,Bas_Bom3_D;
{$R *.DFM}
function TFrm_Bas_Bom3.Selected:boolean;
begin
AdoQry_Main.First;
while not AdoQry_Main.Eof do
begin
if AdoQry_Main.fieldbyname('BomMArk').Asinteger=1 then
begin
Result:=True;
exit;
end
else
Result:=False;
AdoQry_Main.Next;
end;
end;
procedure TFrm_Bas_Bom3.UpdateBomOk(Ite_ItemCode:string);
var
UpBomOK:string;
begin
if AdoQry_Main.IsEmpty then abort;
UpBomOK:=' update Item set BomOk=0 where ItemCode='+QuotedStr(ite_ItemCode);
with AdoQry_tmp do
begin
Close;
SQL.clear;
SQL.Add(UpBomOK);
Prepared;
ExecSQL;
end;
end;
function TFrm_Bas_Bom3.CheckBomOK(ite_ItemCode:string):boolean;
var
sSQL:string;
begin
sSQL:='select BomOK from Item where ItemCode='+QuotedStr(ite_ItemCode);
with AdoQry_tmp1 do
begin
Close;
SQl.clear;
SQL.Add(sSQL);
Open;
if AdoQry_tmp1.fieldbyname('BomOK').AsInteger=1 then
Result:=True
else
Result:=False;
end;
end;
procedure TFrm_Bas_Bom3.InitReport; //设置报表表头属性
begin
inherited;
ExtprintReport.Subtitle3:=Lbl_IteCode.Caption+Extedt_ItemCode.Text+' '+Label2.Caption+ Lb_ItemName.Caption+' '+Label3.Caption+Lb_PmCode.Caption+' '+#13+
Label5.Caption+Lb_PreparelLT.Caption+' '+Label7.Caption+Lb_RunLT.Caption+' '+Label9.Caption+Lb_QcLT.Caption+' '+Label11.Caption+Lb_DesignNo.Caption;
end;
procedure TFrm_Bas_Bom3.SetPnl_Head(R_Code:string);
var
T_Sql:string;
T_Type:integer;
begin
if R_Code<>'' then
begin
T_Sql:=
'select ItemName,'+
'ItemShortName,'+
'UomName,'+
'ItemType '+
'From Item I inner join Uom U '+
'on I.UomCode=I.UomCode '+
'where I.ItemCode='''+R_Code+''' ';
with AdoQry_Tmp do
begin
Close;
SQL.clear;
SQL.Add(T_Sql);
Open;
if not eof then
begin
// Lbl_Name_D.Caption:=fieldbyname('ItemName').AsString;
end;
Close;
end;
end;
end;
procedure TFrm_Bas_Bom3.GetSlave(R_Code:string);
var
T_Sql:string;
begin
T_Sql:=' select BomA.Bomid,'+
'BomA.ite_ItemCode,'+
'Item.ItemName,'+
'Uom.UomName,'+
'Item.PmCode,'+
'Item.PrepareLT,'+
'Item.RunLt,'+
'Item.QcLT,'+
'Item.ItemUsable,'+
'Item.DesignNo,'+
'BomA.ItemCode,'+
'BomA.BomItemType,'+
'BomA.Bomqty,'+
'BomA.BomScrAp_Percent,'+
'BomA.Bomstatus,'+
'BomA.DeptCode,'+
'Dept.DeptName,'+
'BomA.DeptCode+'' ''+Dept.DeptName as DeptB,'+
'BomA.usestyle ,'+
'BomA.BomMArK,'+
'BomA.remArk'+
' from BomA'+
' join Item on Item.ItemCode=BomA.ite_ItemCode'+
' join Uom on Uom.UomCode=Item.UomCode'+
' join Dept on Dept.DeptCode=BomA.DeptCode'+
' and BomA.ItemCode='+Quotedstr(R_Code)+
' Order by BomA.ite_ItemCode ';
with AdoQry_Main do
begin
Close;
SQL.clear;
SQL.Add(T_Sql);
open;
//设置BOTTON的提示信息
Lbl_RecordCount.Caption:=IntTostr(RecordCount);
end;
DBGridEh.Columns[0].Visible:=True;
// if not AdoQry_Main.IsEmpty then AdoQry_Main.BookmArk:=BookMArk;
Flag:=False;
end;
function TFrm_Bas_Bom3.HaveSlave(R_Code:string):Boolean;
var
T_Count:integer;
T_Sql:string;
begin
T_Sql:=
'Select Count(*) as RecordCount '+
'from BomA '+
'where Ite_ItemCode='''+R_Code+'''';
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;
function TFrm_Bas_Bom3.MasterCodeUsable(R_Code:string):Boolean;
var
T_Count:integer;
T_Sql:string;
begin
T_Sql:=
'Select Count(*) as RecordCount '+
'from Item '+
'where ItemCode='''+R_Code+''' '+
' 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;
function TFrm_Bas_Bom3.PickMasterCode(R_InitCode:string):String;
begin
//根据InitCode调用QuickPick
Result:=GetCodeHint (
AdoQry_Main,
'ItemName','物料描述',
'ItemCode','物料代码',
'Item',R_InitCode,'ItemUsable=1');
end;
procedure TFrm_Bas_Bom3.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
var
T_ItemCode:string;
begin
inherited;
GetBomParam;
AdoQry_tmp1.Connection :=AdoQry_tmp.Connection ;
T_ItemCode:='';
Frm_Sys_Detail:=TFrm_Bas_Bom3_D.Create(Application);
// GetSlave('');
end;
function TFrm_Bas_Bom3.SetDeleteSql:string;
var
T_ItemCode:string;
Tmp_Str:String;
begin
BookMArk:=AdoQry_Main.BookmArk;
try
AdoQry_Main.First;
While Not AdoQry_Main.Eof Do
begin
if AdoQry_Main.fieldbyname('BomMArK').asinteger<>0 then
begin
if CheckBomOK(AdoQry_Main.fieldbyname('Ite_ItemCode').AsString) then
begin
DispInfo(Quotedstr(AdoQry_Main.fieldbyname('Ite_ItemCode').AsString)+'Bom已审核,不会执行删除动作!',1);
end
else
begin
Tmp_Str:=Tmp_Str+
' Delete from BomA '+
' where BomId='+IntToStr(AdoQry_Main.fieldbyname('BomId').AsInteger)+' ';
//SaveDeleteToLog;
UpdateBomOk(AdoQry_Main.fieldbyname('Ite_ItemCode').AsString);
end;
end;
AdoQry_Main.Next;
end;
finally
Result:=Tmp_Str;
end;
AdoQry_Main.BookmArk:=BookMArk;
end;
procedure TFrm_Bas_Bom3.Act_NewExecute(Sender: TObject);
begin
//强制类型转换
TFrm_Bas_Bom3_D(Frm_Sys_Detail).SlaveCode:=Extedt_ItemCode.Text;
if not AdoQry_Main.Eof then
begin
TFrm_Bas_Bom3_D(Frm_Sys_Detail).MasterCode:=AdoQry_Main.fieldbyname('ite_ItemCode').AsString
end
else TFrm_Bas_Bom3_D(Frm_Sys_Detail).MasterCode:='';
//判断子项是否为资源
if ItemIsSource(Extedt_ItemCode.Text) then
begin
DispInfo('资源不允许增加父项!',1);
Abort;
end;
inherited;
GetSlave(Extedt_ItemCode.Text);
LocateToSlave(TFrm_Bas_Bom3_D(Frm_Sys_Detail).MasterCode);
end;
procedure TFrm_Bas_Bom3.FormCreate(Sender: TObject);
begin
inherited;
ExtendCaption:=False;
Lc_OldMaster:=TStrinGlist.Create;
Lbl_RecordCount.Caption:='';
// TlBtn_Hint.left:=TlBtn_Help.left+TlBtn_Help.Width;
Extedt_ItemCode.Text:='';
Lb_ItemName.Caption:='';
Lb_PmCode.Caption:='';
Lb_PreparelLT.Caption:='';
Lb_RunLT.Caption:='';
Lb_QcLT.Caption:='';
Lb_DesignNo.Caption:='';
Lb_Uom.Caption:='';
end;
procedure TFrm_Bas_Bom3.FormActivate(Sender: TObject);
begin
inherited;
// TlBtn_filter.Action:=Action1;
// ToolButton6.Action:=Action2;
Extedt_ItemCode.Setfocus;
// Act_New.ImageIndex:=4;
// TlBtn_filter.Visible:=False;
ToolButton6.Visible:=False;
// TlBtn_Hint.Visible:=False;
end;
procedure TFrm_Bas_Bom3.clearPnl_Head;
begin
// Lbl_Name_D.Caption:='';
end;
procedure TFrm_Bas_Bom3.Act_ModifyExecute(Sender: TObject);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -