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

📄 bas_qry_bomamount.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
//功能:任一最终产品或中间产品材料汇总.
unit Bas_Qry_BomAmount;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Panel, ActnList, Db, AdODB, ExtCtrls, ComCtrls, ToolWin, Grids,
  DBGridEh, StdCtrls, ExtEdit, PrnDbgeh, ExtPrintReport, jpeg,variants;

Type
  TFrm_Bas_Qry_BomAmount = Class(TFrm_Base_Panel)
    ToolButton1: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    DBGridEh1: TDBGridEh;
    DataSource: TDataSource;
    lbl_Code: TLabel;
    ExtEdt_ItemCode: TExtEdit;
    lbl_Name: TLabel;
    lbl_ItemName: TLabel;
    Act_Run: TAction;
    AdoQry_Main: TAdoQuery;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton6: TToolButton;
    ExtPrintReport1: TExtPrintReport;
    ToolButton7: TToolButton;
    ToolButton8: TToolButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Act_HintExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ExtEdt_ItemCodeExit(Sender: TObject);
    procedure Act_PreviewExecute(Sender: TObject);
    procedure Act_PrintExecute(Sender: TObject);
    procedure Act_ExcelExecute(Sender: TObject);
  private
    lc_String:string;  //记录代码值,防止重复操作.
    Function MasterCodeUsable(R_Code:String):Boolean;//查询代码是否有效
    Function PickMasterCode(InitCode:String):String;
    procedure SetPnl_Head(ItemCode:String);//标记标题属性
    procedure Show_it;//调用存储过程进行查询
    procedure SetReport; //调用打印过程
    { Private declarations }
  protected
    procedure DBGridEhToExcel(DBGridEh:TDBGridEh);   
  public
    procedure InitForm(AdOConnection:TAdOConnection);
    { Public declarations }
  end;

var
  Frm_Bas_Qry_BomAmount: TFrm_Bas_Qry_BomAmount;
  Temp_DBGridEh:TDBGridEh;
implementation
uses Sys_Global,comobj;
{$R *.DFM}

{ TFrm_Bas_Qry_BomAmount }

procedure TFrm_Bas_Qry_BomAmount.InitForm(AdOConnection: TAdOConnection);
begin
  inherited;
  AdoQry_Main.Connection:=AdOConnection;
  AdoQry_Tmp.Connection:=AdOConnection;
end;

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

{procedure TFrm_Bas_Qry_BomAmount.GetBomAmount(ItemCode:String);
var
  Temp_Qry:TAdoQuery;
  SQl_Txt:string;
  Temp_var,Temp_Precent:real;
begin
  lc_String:=ExtEdt_ItemCode.Text;
  Temp_var:=0.0;
  Temp_Precent:=0.0;
  Temp_Qry:=TAdoQuery.Create(nil);
  Temp_Qry.Connection:=AdoQry_Main.Connection;
  Sql_txt:='select  ItemCode, '+
                   'Bomqty,'+
                   'BomScrAp_Percent,'+
                   'Ite_ItemCode '+
                   'from Bom '+
                   'where Ite_ItemCode='''+ItemCode+'''';
  with Temp_Qry do
  begin
    sql.clear;
    sql.Add(Sql_txt);
    open;
    if Not IsEmpty then
    while not eof do
    begin
      lc_ItemCode_Set.Add(fieldbyname('ItemCode').asstring);
      Temp_var:=fieldbyname('Bomqty').asfloat;
      Temp_Precent:=fieldbyname('BomScrAp_Percent').asfloat;
      Temp_Precent:=1+(Temp_Precent/100);
      lc_Precent_var:=lc_Precent_var*Temp_var;
      lc_qty.Add(floattostr(Temp_var));
      lc_qty_Precent.Add(floattostr(Temp_Precent));
      GetBomAmount(fieldbyname('ItemCode').asstring);
      lc_Precent_var:=1.0;
      Next;
    end;
    Free;
  end;
end;}

function TFrm_Bas_Qry_BomAmount.MasterCodeUsable(R_Code: String): Boolean;
begin
  if ExtEdt_ItemCode.text<>'' then
  begin
    with AdoQry_tmp do
    begin
      sql.clear;
      sql.Add('select * from Item '+
              'where ItemCode='''+R_Code+''' '+
              '  and ItemUsable=1 ');
      Prepared;
      open;
      if not eof then Result:=True
      else Result:=False;
      Close;
    end;
  end
  else Result:=True;
end;

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

procedure TFrm_Bas_Qry_BomAmount.Act_HintExecute(Sender: TObject);
begin
  inherited;
  if ActiveControl.Name='ExtEdt_ItemCode' then
  begin
    Extedt_ItemCode.Text:=PickMasterCode(Extedt_ItemCode.Text);
    Extedt_ItemCode.setfocus;
  end;
end;

procedure TFrm_Bas_Qry_BomAmount.FormCreate(Sender: TObject);
begin
  inherited;
  //lc_Precent_var:=1.0;
  Temp_DBGridEh:=Tdbgrideh.Create(nil);
end;

procedure TFrm_Bas_Qry_BomAmount.SetPnl_Head(ItemCode: String);
var
  Temp_Qry:TAdoQuery;
begin
  Temp_Qry:=TAdoQuery.Create(nil);
  Temp_Qry.Connection:=AdoQry_Main.Connection;
  Temp_Qry.EnableBCD:=False;
  with Temp_Qry do
  begin
    sql.clear;
    sql.Add('select ItemCode ,ItemName'+
                    ' from Item'+
                    ' where ItemCode='''+ItemCode+'''');
    Prepared;
    open;
    lbl_ItemName.Caption:=fieldbyname('ItemName').asstring;
  end;
end;

{procedure TFrm_Bas_Qry_BomAmount.Bom_Filter;
var
  i,j:integer;
  Multi_Item:boolean;
  Temp_var,Temp_var1:real;
begin
  for i:=0 to lc_ItemCode_Set.Count-1 do
  begin
    Multi_Item:=False;
    if i+1>lc_ItemCode_Set.Count-1 then break;
    for j:=i+1 to lc_ItemCode_Set.Count-1 do
    begin
      Temp_var1:=strtofloat(lc_qty.Strings[i]);
      if lc_ItemCode_Set.Strings[i]=lc_ItemCode_Set.Strings[j] then
      begin
        Multi_Item:=True;
        Temp_var:=strtofloat(lc_qty.Strings[i])+
        strtofloat(lc_qty.strings[j]);
        lc_qty.Strings[i]:=floattostr(Temp_var);
        Temp_var1:=strtofloat(lc_qty.strings[j])*
        strtofloat(lc_qty_Precent.Strings[j])+
        Temp_var1;
        lc_qty_Precent.Strings[i]:=floattostr(Temp_var1);
        lc_ItemCode_Set.Delete(j);
        lc_qty.Delete(j);
        lc_qty_Precent.Delete(j);
      end;
        if (j>=lc_ItemCode_Set.Count-1)then
        begin
          lc_ItemCode_Set.Delete(lc_ItemCode_Set.Count-1);
          Break;
        end;
    end;
    if not Multi_Item then
    begin
      Temp_var:=strtofloat(lc_qty.strings[i])*
      strtofloat(lc_qty_Precent.Strings[i]);
      lc_qty_Precent.Strings[i]:=floattostr(Temp_var);
    end;
  end;
end;}

procedure TFrm_Bas_Qry_BomAmount.Show_it;
var
  SQL_Txt:string;
  i:integer;
begin
  lc_String:=ExtEdt_ItemCode.Text;
{  SQL_Txt:='select Item.ItemCode,'+
                  'Item.ItemCode+''  ''+'+
                  'Item.ItemName AS ItemCodeName,'+
                  'Uom.UomName,'+
                  'Item.ItemType,'+
                  'Item.PmBatch,'+
                  'CapacityHours'+
           ' from Item'+
           ' join Uom on Item.UomCode=Uom.UomCode '+
           ' where ';
  if lc_ItemCode_Set.Count<1 then
  begin
    DispInfo('没有子项!',3);
    ExtEdt_ItemCode.Color:=clWindow;
    ExtEdt_ItemCode.SetFocus;
    Abort;
  end;
  for i:=0 to lc_ItemCode_Set.Count-1 do
  if i<lc_ItemCode_Set.Count-1 then
    SQL_Txt:=SQL_Txt+' ItemCode='+
             Quotedstr(lc_ItemCode_Set.Strings[i])+' or'

⌨️ 快捷键说明

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