⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bas_bomqry.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Bas_BomQry;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Outer, Menus, ExtPrintReport, Db, ActnList, AdODB, Grids, DBGridEh,
  StdCtrls, ExtCtrls, ComCtrls, ToolWin, jpeg;

Type
  TFrm_Bas_BomQry = Class(TFrm_Base_Outer)
    Lbl_IteCode: TLabel;
    Lbl_Name: TLabel;
    Lbl_Name_D: TLabel;
    Label1: TLabel;
    Lbl_RecordCount: TLabel;
    AdoQry_tmp1: TAdoQuery;
    Label3: TLabel;
    Lb_PmCode: TLabel;
    Label5: TLabel;
    Lb_PreparelLT: TLabel;
    Label7: TLabel;
    Lb_RunLT: TLabel;
    Label9: TLabel;
    Lb_QcLT: TLabel;
    Label11: TLabel;
    Lb_DesignNo: TLabel;
    lbl_ItemCode: TLabel;
    procedure Action1Execute(Sender: TObject);
    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 Action2Execute(Sender: TObject);
    procedure AdoQueryAfterOpen(DataSet: TDataSet);
    procedure DBGridEhGetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
    procedure DBGridEhTitleClick(Column: TColumnEh);
  private
    Lc_OldMaster:TStrinGlist;
    tmp_ItemCode:string;
    Flag:Boolean;
    procedure InsertOldMaster(ItemCode:string); //把当前查询的父项插入
    procedure GetOldMaster;                     //根据历史的父项得到数据
    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的数据
    procedure GetLbName(ite_ItemCode:string);
    procedure GetBomParam;//系统是否对Bom进行审核
    procedure checkPmItem(ItemCode:string);//是否采购件
    { Private declarations }
  public
    Ite_ItemCode : String;
    procedure InitReport; Override;//设置报表表头属性
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
    Function  SetDeleteSql:string;Override;
    { Public declarations }
  end;

var
  Frm_Bas_BomQry: TFrm_Bas_BomQry;

implementation

uses Sys_Global,Bas_Bom_D;
{$R *.DFM}

procedure TFrm_Bas_BomQry.InitReport; //设置报表表头属性
begin
  inherited;
  ExtprintReport.Subtitle3:='父项标识:'+lbl_ItemCode.Caption+' '+lbl_Name_D.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_BomQry.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_BomQry.GetSlave(R_Code:string);
var
  T_Sql:string;
begin
  T_Sql:=  ' select  B.BomId,'+
           ' B.Ite_ItemCode,'+
           ' B.BomMArk,'+
           ' B.ItemCode,'+
           ' B.RemArk,'+
           ' I.ItemName,'+
           ' I.ItemUsable,'+
           ' B.ItemCode+'' ''+I.ItemName as ItemCodeName ,'+
           ' U.UomName,'+
           ' B.BomItemType,'+
           ' B.BomQty,'+
           ' B.BomQty as BomQty_Disp,'+
           ' B.BomScrAp_Percent as BomScrAp_Percent_Disp,'+
           ' B.BomScrAp_Percent,'+
           ' B.BomStatus,'+
           ' B.DeptCode,'+
           ' D.DeptName,'+
           ' B.DeptCode+'' ''+D.DeptName as DeptCodeName,'+
           ' B.usestyle,'+
           ' I.PmCode,'+
	   ' I.PrepareLT ,'+
	   ' I.RunLt ,'+
	   ' I.QcLT ,'+
	   ' I.DesignNo ,'+
	   ' I.PmCode  '+
   ' From Bom B'+
     ' left join Item I on B.ItemCode=I.ItemCode'+
     ' left join Dept D on B.DeptCode=D.DeptCode'+
     ' left join Uom U on I.UomCode=U.UomCode'+
   ' Where B.Ite_ItemCode='+Quotedstr(R_Code)+
     ' Order by B.ItemCode ';

  with AdoQry_Main do
  begin
    Close;
    SQL.clear;
    SQL.Add(T_Sql);
    open;
    //设置BOTTON的提示信息
    Lbl_RecordCount.Caption:=IntTostr(RecordCount);
  end;

end;

function TFrm_Bas_BomQry.HaveSlave(R_Code:string):Boolean;
var
  T_Count:integer;
  T_Sql:string;
begin
  T_Sql:=
    'Select Count(*) as RecordCount '+
    'from Bom '+
    '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_BomQry.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_BomQry.PickMasterCode(R_InitCode:string):String;
begin
 //根据InitCode调用QuickPick
  Result:=GetCodeHint (
        AdoQry_Main,
        'ItemName','物料描述',
        'ItemCode','物料代码',
        'Item',R_InitCode,'ItemUsable=1');
end;

procedure TFrm_Bas_BomQry.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
var
  T_ItemCode:string;
begin
  inherited;
  GetBomParam;
  AdoQry_tmp1.Connection :=AdoQry_tmp.Connection ;
  Frm_Sys_Detail:=TFrm_Bas_Bom_D.Create(Application);
  T_ItemCode:=Trim(lbl_ItemCode.Caption);
  if T_ItemCode<>'' then
  begin
    checkPmItem(T_ItemCode);
    if MasterCodeUsable(T_ItemCode) then
    begin
      InsertOldMaster(T_ItemCode);
      SetPnl_Head(T_ItemCode);
      GetSlave(T_ItemCode);
    end
  end
  else
  begin
    clearPnl_Head;
    GetSlave(T_ItemCode);
  end;
  GetLbName(lbl_ItemCode.Caption);
  TlBtn_New.Enabled:=True;
  TlBtn_Modify.Enabled:=True;
  TlBtn_Delete.Enabled:=True;
  
end;

function TFrm_Bas_BomQry.SetDeleteSql:string;
var
  T_ItemCode:string;
  Tmp_Str:String;
begin
  try
    AdoQry_Main.First;
    While Not AdoQry_Main.Eof Do
    begin
      if AdoQry_Main.fieldbyname('BommArk').asinteger<>0 then
      begin
        Tmp_Str:=Tmp_Str+
             ' Delete from Bom '+
             ' where BomId='+IntToStr(AdoQry_Main.fieldbyname('BomId').AsInteger)+' ';
      SaveDeleteToLog;
      end;
      AdoQry_Main.Next;
    end;
  finally
    Result:=Tmp_Str;
  end;
end;

procedure TFrm_Bas_BomQry.Action1Execute(Sender: TObject);
var T_ItemCode:string;
begin
  inherited;
  if AdoQry_Main.Eof then
  begin
    if Not AdoQry_Main.Bof then
    begin
      AdoQry_Main.Prior;
      AdoQry_Main.Next;
    end;
  end;
  if not AdoQry_Main.eof then
  begin
    T_ItemCode:=AdoQry_Main.fieldbyname('ItemCode').AsString;
    lbl_ItemCode.Caption:=t_ItemCode;
    InsertOldMaster(T_ItemCode);
    SetPnl_Head(T_ItemCode);
    GetSlave(T_ItemCode);
  end;
end;

procedure TFrm_Bas_BomQry.Act_NewExecute(Sender: TObject);
begin
  //强制类型转换
end;

procedure TFrm_Bas_BomQry.FormCreate(Sender: TObject);
begin
  inherited;
  ExtendCaption:=False;
  Lc_OldMaster:=TStrinGlist.Create;
  Lbl_Name_D.Caption:='';
  Lbl_RecordCount.Caption:='';
//  TlBtn_Hint.left:=TlBtn_Help.left+TlBtn_Help.Width;
end;

procedure TFrm_Bas_BomQry.FormActivate(Sender: TObject);
begin
  inherited;
  Lbl_Name_D.Caption:='';

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -