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

📄 bas_qry_multibom_new.pas

📁 一个MRPII系统源代码版本
💻 PAS
字号:
unit Bas_Qry_MultiBom_New;

Interface

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

Type
  TFrm_Bas_Qry_MultiBom_New = Class(TFrm_Base_Qry)
    Label1: TLabel;
    Edt_ItemCode: TEdit;
    Label3: TLabel;
    Lbl_ItemName: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure Edt_ItemCodeExit(Sender: TObject);
    procedure AdoQueryAfterOpen(DataSet: TDataSet);
    procedure DBGridEhGetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
    procedure Edt_ItemCodeKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    OldItemCode:string;                                        //保存当前输入物料编码;
    procedure SetPnl_Head(ItemCode:String);                    //显示输入物料其它属性 ;
    Function ItemCodeUsable(Code:String):Boolean;              //判断物料是否存在.可用;
    Function PickItemCode(InitCode:String):string;             // 得到正确的物料编码 ;
    function SlaveCodeUsable(R_ItemCode:String):Boolean;
    function PickSlaveCode(InitCode:String):string;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Frm_Bas_Qry_MultiBom_New: TFrm_Bas_Qry_MultiBom_New;

implementation
uses Sys_Global;
{$R *.DFM}

procedure TFrm_Bas_Qry_MultiBom_New.FormCreate(Sender: TObject);
begin
  inherited;
  OldItemCode:='';
end;

procedure TFrm_Bas_Qry_MultiBom_New.Edt_ItemCodeExit(Sender: TObject);
begin
  inherited;
  if Trim(OldItemCode)=Trim(Edt_ItemCode.text) then
    abort;
  if not SlaveCodeUsable(Trim(Edt_ItemCode.Text)) then
  begin
    DispInfo('输入代码没找到!',1);
    Edt_ItemCode.SetFocus;
    Abort;
  end;
  AdoQry_Main.Close;
  Pnl_Hint.Caption:='';
  if ItemCodeUsable(Trim(Edt_ItemCode.text)) Then
  begin
    Pnl_Hint.Caption:='提示:Bom正在展开!';
    Pnl_Hint.refresh;
    SetPnl_Head(Trim(Edt_ItemCode.text));
    Lbl_ItemName.Refresh;
    try
      Screen.Cursor:=CrSQLWait;
      with AdoQry_Main do
      begin
        Close;
        sql.clear;
        sql.Add(' exec expandBom '''+Trim(Edt_ItemCode.text)+'''');
        Prepared;
        open;
      end;
      OldItemCode:=Trim(Edt_ItemCode.text);
      TlBtn_Print.enabled:=(AdoQry_Main.recordCount>0);
      TlBtn_Preview.enabled:=(AdoQry_Main.recordCount>0);
    finally
      Screen.Cursor:=crDefault ;
    end;
    Pnl_Hint.Caption:='提示:Bom展开完毕!';
    Pnl_Hint.refresh;
    TlBtn_Excel.Enabled :=(AdoQry_Main.RecordCount>0);
    if AdoQry_Main.active=False then AdoQry_Main.active:= True ;
      AdoQry_Main.First ;
    if AdoQry_Main.recordCount>0 then
      Pnl_Hint.Caption:='提示:共有:'+''+inttostr(AdoQry_Main.recordCount)+''+'条记录'
    else
      Pnl_Hint.Caption:='提示:此物料无子项!';
  end
  else
  begin
    Edt_ItemCode.text:=PickItemCode(Trim(Edt_ItemCode.text));
    Edt_ItemCode.SetFocus;
  end;

end;

procedure TFrm_Bas_Qry_MultiBom_New.AdoQueryAfterOpen(DataSet: TDataSet);
begin
  inherited;
  TFloatField(DataSet.fieldbyname('BomQty')).DisplayFormat:='0.#####';
  TFloatField(DataSet.fieldbyname('BomScrAp_Percent')).DisplayFormat:='0.#####';
  if AdoQry_Main.recordCount>0 then
    Pnl_Hint.Caption:='提示:共有:'+''+inttostr(AdoQry_Main.recordCount)+''+'条记录'
  else
    Pnl_Hint.Caption:='提示:此物料无子项!';
end;

procedure TFrm_Bas_Qry_MultiBom_New.DBGridEhGetCellParams(Sender: TObject;
  Column: TColumnEh; AFont: TFont; var Background: TColor;
  State: TGridDrawState);
begin
  inherited;
  if (AdoQry_Main.fieldbyname ('ItemUsable').asstring='0') then
   AFont.Color:=clRed;

end;

procedure TFrm_Bas_Qry_MultiBom_New.SetPnl_Head(ItemCode: String);
begin
  with AdoQry_Tmp do
  begin
    Close;
    Sql.clear;
    Sql.Add('select Item.ItemName ,'+
                    ' Uom.UomName,'+
                    ' Item.ItemShortName,'+
                    ' ItemType '+
                    ' from Item left join Uom '+
                    ' on Item.UomCode=Uom.UomCode '+
                    ' where  ItemCode= '+''''+Trim(ItemCode)+'''');
    Prepared;
    open;
    Lbl_ItemName.Caption:=fieldbyname('ItemName').AsString;
  end;
end;

function TFrm_Bas_Qry_MultiBom_New.ItemCodeUsable(Code: String): Boolean;
begin
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select ItemName '+
                    ' From Item '+
                    ' Where ItemCode= '+''''+Code+''''+
                    ' and  ItemUsable=1 ' );
    Prepared;
    open;
    Result:=(AdoQry_Tmp.recordCount>0);
  end;
end;

function TFrm_Bas_Qry_MultiBom_New.PickItemCode(InitCode: String): string;
begin
  Result:=GetCodeHint(AdoQry_Tmp,
                      'ItemName','物料描述',
                      'ItemCode','物料代码',
                      'Item','InitCode','ItemUsable=1');
end;

function TFrm_Bas_Qry_MultiBom_New.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;

function TFrm_Bas_Qry_MultiBom_New.PickSlaveCode(InitCode: String): string;
begin
  Result:=GetCodeHint(
        AdoQry_Tmp,
        'ItemName','项目描述',
        'ItemCode','项目代码',
        'Item',InitCode,'ItemUsable=1');
end;

procedure TFrm_Bas_Qry_MultiBom_New.Edt_ItemCodeKeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
begin
  inherited;
  If key=120 Then
  CommOnHint(Sender,AdoQry_Tmp,'ItemName','物料描述','ItemCode','物料代码','Item','ItemUsable=1 And (PmCode=0 or PmCode=2)')
end;

end.



⌨️ 快捷键说明

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