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

📄 bas_qry_bomsviewmaster.pas

📁 一个MRPII系统源代码版本
💻 PAS
字号:
//最后修改: 功能:Bom循环校验求最终产品
unit Bas_Qry_BomSViewMaster;

Interface

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

Type
  TFrm_Bas_Qry_BomSViewMaster = Class(TFrm_Base_Qry)
    Lbl_ChildCode: TLabel;
    Extedt_Code: TExtEdit;
    Lbl_ChildName: TLabel;
    Ckbx_EndCode: TCheckBox;
    Extedt_Name: TLabel;
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure DBGridEhDblClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Action2Execute(Sender: TObject);
    procedure Extedt_CodeExit(Sender: TObject);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_HintExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Ckbx_EndCodeClick(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    procedure DataSourceDataChange(Sender: TObject; Field: TField);
  private
    { Private declarations }
    Return_Set:TstrinGlist;//记录结果
    lc_flag:boolean;//标志位
    lc_oldword:string; //上次查询代码,防止重复操作
    procedure GetMaster(ItemCode:string);//调用存储过程进行查询
    procedure setPnl_Head(ItemCode:string);//设置标题行
    Function  PickslaveCode(initCode:string):string;
    Function  SlaveCodeUsable:boolean;//子项是否可用
  public
    { Public declarations }
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
  end;

var
  Frm_Bas_Qry_BomSViewMaster: TFrm_Bas_Qry_BomSViewMaster;

implementation
uses Sys_Global;
{$R *.DFM}
procedure TFrm_Bas_Qry_BomSViewMaster.FormDestroy(Sender: TObject);
begin
  inherited;
  Frm_Bas_Qry_BomSViewMaster:=nil;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.GetMaster(ItemCode: string);
var
  S:string;
  i:integer;
begin
  lc_Flag:=False;
  Return_Set:=TstrinGlist.Create;
  i:=0;
  AdoQry_Main.Close;
  dbgrideh.Refresh;
  if  Ckbx_EndCode.Checked = False then
  begin
    S:='select Bom.ite_ItemCode,'+
               'Item.ItemName, '+
               'Uom.UomName,'+
               ' BomItemType, '+
               ' Bom.BomQty, '+      // 加定额
               ' Bom.BomScrAp_Percent'+  //加损耗
               ' from Bom'+
               ' join Item on Bom.ite_ItemCode=Item.ItemCode'+
               ' join Uom on Item.UomCode=Uom.UomCode where Bom.ItemCode= '+ Quotedstr(Extedt_Code.text)+
               ' and ItemUsable=1';
    AdoQry_Main.Close;
    AdoQry_Main.SQL.clear;
    AdoQry_Main.SQL.Add(s);
    AdoQry_Main.Open;
    DBGridEh.Columns[0].FieldName:='ite_ItemCode';
    DBGridEh.Columns[0].Title.Caption:='父项代码';
    DBGridEh.Columns[1].Title.Caption:='父项描述';
    DBGridEh.Columns[3].Title.Caption:='子项属性';
    DBGridEh.Columns[4].Visible:=True;
    DBGridEh.Columns[5].Visible:=True;
  end
  else
  begin
    S:=' set noCount on'+
        ' create table #table(ItemCode varchAr(40))'+
        ' insert into #table(ItemCode)'+
        ' exec findroot '+QuotedStr(Extedt_Code.Text)+
        ' select #table.ItemCode from #table'+
        ' join Item'+
        ' on #table.ItemCode=Item.ItemCode and'+
        ' Item.ItemUsable=1'+
        ' drop table #table';

    AdoQry_Main.Close;
    AdoQry_Main.SQL.clear;
    AdoQry_Main.SQL.Add(s);
    AdoQry_Main.Open;
    if (AdoQry_Main.RecordCount<=1) then
    begin
      Pnl_Hint.Caption:='';
      DispInfo('已经是最终产品!',3);
      abort;
    end;
    for i:=0 to AdoQry_Main.RecordCount do
    begin
    Return_Set.Add(AdoQry_Main.fieldbyname('ItemCode').asstring);
    AdoQry_Main.next;
    end;

    S:='select '+
             'Item.ItemCode,'+
             'Item.ItemName,'+
             'Uom.UomName,'+
             ' Item.ItemType'+
             ' from Item'+
             ' join Uom on Item.UomCode= Uom.UomCode where ItemUsable=1 and ';

    for i:=0 to Return_Set.Count-1 do
    begin
      S:=S+' ItemCode='+Quotedstr(Return_Set.strings[i]);
      if  i<Return_Set.Count-1 then
      S:=S+' or ';
    end;
    Return_Set.Free;
    AdoQry_Main.Close;
    AdoQry_Main.SQL.clear;
    AdoQry_Main.SQL.Add(s);
    AdoQry_Main.Open;
    DBGridEh.Columns[0].FieldName:='ItemCode';
    DBGridEh.Columns[0].Title.Caption:='产品代码';
    DBGridEh.Columns[1].Title.Caption:='产品描述';
    DBGridEh.Columns[3].FieldName:='ItemType';
    DBGridEh.Columns[3].Title.Caption:='产品类别';
    DBGridEh.Columns[4].Visible:=False;
    DBGridEh.Columns[5].Visible:=False;
  end;
end;


procedure TFrm_Bas_Qry_BomSViewMaster.InitForm(
  AdOConnection: TAdOConnection; ReadOnly: Boolean);
begin
  inherited;
  selectfromSQL:= 'select Bom.ite_ItemCode,Item.ItemName, Uom.UomName,'+
       ' ItemType =case Item.ItemType when 0 then ''0 普通物料'' when 1 then''1 资源''  when 2'+
       ' then ''2 工具''  when 3 then ''3 参考'' when 4 then ''4 虚项'' when 5'+
       ' then ''5 劳务 '' when 6 then ''6 副产品'' when 7 then ''7 成本''   end'+
       ' from Bom'+
       ' join Item on Bom.ite_ItemCode=Item.ItemCode'+
       ' join Uom on Item.UomCode=Uom.UomCode';
//  GetData;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.FormShow(Sender: TObject);
begin
  inherited;
  Extedt_Code.Text:='';
  Extedt_Name.Caption:='';

end;

function TFrm_Bas_Qry_BomSViewMaster.PickslaveCode(initCode: string): string;
begin
 //根据InitCode调用QuickPick
  Result:=GetCodeHint(
        AdoQry_Tmp,
        'ItemName','项目描述',
        'ItemCode','项目代码',
        'Item',InitCode,'ItemUsable=1');
end;

procedure TFrm_Bas_Qry_BomSViewMaster.setPnl_Head(ItemCode: string);
begin
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.Add('select Item.ItemCode ,Item.ItemName,Item.ItemshortName,'+
                           ' ItemType =case Item.ItemType when 0 then ''0 普通物料'' when 1 then''1 资源''  when 2'+
                           ' then ''2 工具''  when 3 then ''3 参考'' when 4 then ''4 虚项'' when 5'+
                           ' then ''5 劳务'' when 6 then ''6 副产品'' when 7 then ''7 成本''   end ,   Uom.UomName'+
                    ' from Item'+
                    ' join Uom  on Item.UomCode= Uom.UomCode');
  AdoQry_Tmp.Open;
  if  AdoQry_Tmp.Locate('ItemCode',Extedt_Code.text,[]) then
  begin
    Extedt_Name.Caption:=AdoQry_Tmp.fieldbyname('ItemName').asstring;
    Lbl_Order.Caption:=Extedt_Name.Caption;
  end;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.DBGridEhDblClick(Sender: TObject);
begin
  inherited;
  if not Ckbx_EndCode.Checked then
  begin
    if AdoQry_Main.RecordCount>0 then
    begin
      Extedt_Code.Text:=AdoQry_Main.fieldbyname('ite_ItemCode').asstring;
      Lbl_Condition.Caption:=Extedt_Code.Text;
      setPnl_Head(Extedt_Code.text);
      GetMaster(Extedt_Code.text);
    if AdoQry_Main.RecordCount<=0 then
      Application.MessageBox('已为树根,没有父项了!','提示',mb_ok);
    end
    else
    begin
      Application.MessageBox('已为树根,没有父项了!','提示',mb_ok);
      exit;
    end;
  end
  else
  begin
    Application.MessageBox('已为树根,没有父项了!','提示',mb_ok);
    exit;
  end;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.FormCreate(Sender: TObject);
begin
  inherited;
  TlBtn_Sum.Action:=Action2;
  ToolBar.Width:=210;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.Action2Execute(Sender: TObject);
begin
  inherited;
  if Extedt_Code.Text=''then
  begin
    DispInfo('输入的代码不存在!',1);
    abort;
  end;
  if not Ckbx_EndCode.Checked then
  begin
    if AdoQry_Main.RecordCount>0 then
    begin
      Extedt_Code.Text:=AdoQry_Main.fieldbyname('ite_ItemCode').asstring;
      Lbl_Condition.Caption:=Extedt_Code.Text;
      setPnl_Head(Extedt_Code.text);
      GetMaster(Extedt_Code.text);
    if AdoQry_Main.RecordCount<=0 then
      Application.MessageBox('已为树根,没有父项了!','提示',mb_ok);
    end
    else
    begin
      Application.MessageBox('已为树根,没有父项了!','提示',mb_ok);
      exit;
    end;
  end
  else
  begin
    Application.MessageBox('已为树根,没有父项了!','提示',mb_ok);
    exit;
  end;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.Extedt_CodeExit(Sender: TObject);
var
  S:string;
begin
  inherited;
  if Extedt_Code.Text=''then
  begin
    DispInfo('输入的代码不存在!',1);
    ExtEdt_Code.SetFocus;
    abort;
  end;

  S:='select ItemUsable from Item where ItemCode='+Quotedstr(Extedt_Code.text);
  AdoQry_tmp.Close;
  AdoQry_tmp.SQL.clear;
  AdoQry_tmp.SQL.Add(S);
  AdoQry_tmp.Open;
  if  AdoQry_tmp.fieldbyname('ItemUsable').asinteger<>1 then
  begin
    Application.MessageBox('子项无效,请确认后重新输入!','信息提示',MB_OK+MB_IconInfoRMATION) ;
    abort;
  end;

  if (Extedt_Code.Text<>'') and (Extedt_Code.Text<>lc_oldword) then
  if SlaveCodeUsable then
  begin
    ControlBar.Enabled:=True;
    lc_oldword:=Extedt_Code.Text;
    setPnl_Head(Extedt_Code.text);
    pnl_Hint.Caption:='正在进行查询数据...请稍候!';
    pnl_Hint.Refresh;
    GetMaster(Extedt_Code.text);
    if not lc_Flag then
    Pnl_Hint.Caption:='提示:共有'+inttostr(AdoQry_Main.RecordCount)+'条记录'
    else
    Pnl_Hint.Caption:='提示:已为最终产品';
  end
  else
  begin
    DispInfo('输入的代码不存在!',1);
    ExtEdt_Code.SetFocus;
    abort;
  end;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.Act_PreviewExecute(Sender: TObject);
begin
  if not AdoQry_Main.Active then
  begin
    Application.MessageBox('您还没有输入查询条件','提示',mb_ok);
    exit ;
  end
  else
  begin
    if Ckbx_EndCode.Checked then
    Lbl_Condition.Caption:=Extedt_Code.text+'(最终产品)'
    else
    Lbl_Condition.Caption:=Extedt_Code.text;
    inherited;
  end;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.Act_HintExecute(Sender: TObject);
begin
  inherited;
  if ActiveControl.Name='Extedt_Code' then
  begin
    Extedt_Code.Text:='';
    Extedt_Code.Text:=PickSlaveCode(Extedt_Code.Text);
    Extedt_Code.setfocus;
  end;
end;

function TFrm_Bas_Qry_BomSViewMaster.SlaveCodeUsable: boolean;
begin
  if Extedt_Code.text<>'' then
  begin
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.Add('select * from Item '+
              'where ItemCode='''+Extedt_Code.Text+''' '+
              '  and ItemUsable=1 ');
      open;
      if not eof then Result:=True
      else Result:=False;
      Close;
    end;
  end
  else Result:=True;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  Action:=caFree;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.Ckbx_EndCodeClick(Sender: TObject);
begin
  inherited;
  if SlaveCodeUsable then
  begin
    lc_oldword:=Extedt_Code.Text;
    setPnl_Head(Extedt_Code.text);
    pnl_Hint.Caption:='正在进行查询数据...请稍候!';
    pnl_Hint.Refresh;
    GetMaster(Extedt_Code.text);
    if not lc_Flag then
      Pnl_Hint.Caption:='提示:共有'+inttostr(AdoQry_Main.RecordCount)+'条记录'
    else
    Pnl_Hint.Caption:='提示:已为最终产品';
  end
  else
  begin
    DispInfo('输入的代码不存在!',1);
    ExtEdt_Code.SetFocus;
    abort;
  end;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.Act_PrintExecute(Sender: TObject);
begin
  if not AdoQry_Main.Active then
  begin
    Application.MessageBox('您还没有输入查询条件','提示',mb_ok);
    exit ;
  end
  else
  begin
    if Ckbx_EndCode.Checked then
    Lbl_Condition.Caption:=Extedt_Code.text+'(最终产品)'
    else
    Lbl_Condition.Caption:=Extedt_Code.text;
    inherited;
  end;
end;

procedure TFrm_Bas_Qry_BomSViewMaster.DataSourceDataChange(Sender: TObject;
  Field: TField);
begin
  inherited;
  Pnl_Hint.Caption:='提示:共有'+inttostr(AdoQry_Main.RecordCount)+'条记录'
end;

end.

⌨️ 快捷键说明

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