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

📄 sfc_wipbomopen.pas

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

Interface

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

Type
  TFrm_Sfc_WipBomOpen = Class(TFrm_Base_Outer)
    Label1: TLabel;
    lbl_SfcName: TLabel;
    Label2: TLabel;
    lbl_fatherItem: TLabel;
    AdoQuery1: TAdoQuery;
    procedure Act_SaveExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure DBGridEhGetCellParams(Sender: TObject; Column: TColumnEh;
      AFont: TFont; var Background: TColor; State: TGridDrawState);
    procedure Act_ModifyExecute(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Act_DeleteExecute(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
     tmp_Month,tmp_Sfc,tmp_fatherQty,tmp_ItemCode,tmp_ItemName:string;
     procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
     function  SetDeleteSql:String;Override;
     procedure InitReport; Override;
     procedure SetFormParam(FrmParam1,FrmParam2,FrmParam3,FrmParam4,FrmParam5,FrmParam6:String);Override;
  end;

var
  Frm_Sfc_WipBomOpen: TFrm_Sfc_WipBomOpen;

implementation
 uses Sfc_WipBomopen_D,Sys_Global;
{$R *.DFM}

procedure  TFrm_Sfc_WipBomOpen.InitReport ;
begin
  inherited;
  ExtPrintReport.Subtitle1 :=lbl_Conditiontitle.Caption+lbl_Condition.Caption+'         '+label1.Caption+lbl_SfcName.Caption ;
  ExtPrintReport.Subtitle2 :=lbl_Ordertitle.Caption+lbl_Order.Caption+'         '+label2.Caption+lbl_fatherItem.Caption ; 
end;
function TFrm_Sfc_WipBomOpen.SetDeleteSql: String;
begin
//
end;

procedure TFrm_Sfc_WipBomOpen.InitForm(AdOConnection: TAdOConnection;
  ReadOnly: Boolean);
begin
  FreeFields:='Bomqty,BomScrAp_Percent,sonqty,';
  inherited;
  AdoQuery1.Connection :=AdoQry_tmp.Connection ;
  lbl_Condition.Caption :=tmp_Month;
  lbl_SfcName.Caption :=tmp_Sfc;
  lbl_Order.Caption :=tmp_fatherqty;
  lbl_fatherItem.Caption :=tmp_ItemCode+' '+tmp_ItemName;
  self.Height :=460;
  self.Width :=780;
  with AdoQry_tmp do
  begin
    Close;
    sql.Text:='drop table #tmp_Bom1,#tmp_Bom2,#tmp1';
    try
      execsql;
    except
    end;
    Close;
    sql.text:='select ite_ItemCode,ItemCode,BomItemType,Bomqty,BomScrAp_Percent into #tmp_Bom1 from Bom where ite_ItemCode='+
               quotedstr(tmp_ItemCode)+' and Bomstatus<>1 and Bomstatus<>3 Order by ItemCode ';
    execsql;
    Close;
    sql.text:='select b.ItemCode,b.BomItemType,b.Bomqty*b1.Bomqty as Bomqty,'+
              ' b.BomScrAp_Percent+b1.BomScrAp_Percent+b.BomScrAp_Percent*b1.BomScrAp_Percent as BomScrAp_Percent'+
              ' into #tmp1 from Bom b,#tmp_Bom1 b1 where b.ite_ItemCode=b1.ItemCode '+
              ' and (b1.BomItemType=3 or b1.BomItemType=6) and Bomstatus<>1 and Bomstatus<>3 '+
              ' delete from #tmp_Bom1 where BomItemType=3 or BomItemType=6 ';
    execsql;
    Close;
    sql.text:='select * from #tmp1';
    open;
    while not eof do
    begin
      Close;
      sql.text:=' insert #tmp_Bom1 select '+quotedstr(tmp_ItemCode)+
                ' ,ItemCode,BomItemType,Bomqty,BomScrAp_Percent from #tmp1 '+
                ' drop table #tmp1 '+
                ' select b.ItemCode,b.BomItemType,b.Bomqty*b1.Bomqty as Bomqty,'+
                ' b.BomScrAp_Percent+b1.BomScrAp_Percent+b.BomScrAp_Percent*b1.BomScrAp_Percent as BomScrAp_Percent'+
                ' into #tmp1 from Bom b,#tmp_Bom1 b1 where b.ite_ItemCode=b1.ItemCode '+
                ' and (b1.BomItemType=3 or b1.BomItemType=6) and Bomstatus<>1 and Bomstatus<>3 '+
                ' delete from #tmp_Bom1 where BomItemType=3 or BomItemType=6 ';
      execsql;
      Close;
      sql.text:='select * from #tmp1';
      open;
    end;

  end;
  SelectFromSQL:=' select b.ite_ItemCode,b.ItemCode+'' ''+i.ItemName as ItemDESC, '+
                 '           b.Bomqty,b.BomScrAp_Percent,round('+
                             tmp_fatherqty+'*b.Bomqty*(1+b.BomScrAp_Percent/100),0) as sonqty into #tmp_Bom2 '+
                 ' from #tmp_Bom1 b,Item i '+
                 ' where  b.ItemCode=i.ItemCode ';
  with AdoQry_tmp do
  begin
    Close;
    sql.Text:=selectfromsql;
    execsql;
  end;
  SelectFromSQL:='select * from #tmp_Bom2 Order by ItemDESC';
//  FreeFields:='Bomqty,BomScrAp_Percent,sonqty,';
  getdata;

//  Frm_Sys_Condition:=TFrm_Sfc_WipInv_C.Create(Application);
  Frm_Sys_Detail:=TFrm_Sfc_WipBomOpen_D.Create(Application);
//  Act_Filter.Execute;
end;

procedure TFrm_Sfc_WipBomOpen.SetFormParam(FrmParam1, FrmParam2, FrmParam3,
  FrmParam4, FrmParam5, FrmParam6: String);
begin
  inherited;
  tmp_Month:=frmParam1;
  tmp_Sfc:=frmParam2;
  tmp_fatherQty:=frmParam3;
  tmp_ItemCode:=frmParam4;
  tmp_ItemName:=frmParam5;
//  Frm_Sys_Detail.SetFormParam(FrmParam1,FrmParam2,'','','','');
end;

procedure TFrm_Sfc_WipBomOpen.Act_SaveExecute(Sender: TObject);
var
  Bookm:tBookmArk;
  sqltext:string;
begin
  Bookm:=AdoQry_Main.GetBookmArk ;
  AdoQry_Main.DisableControls ;
  AdoQry_Main.First ;
  AdoQry_Main.Connection.beginTrans ;
  try
      with AdoQry_Main do
      begin
        while not eof do
        begin
           AdoQry_tmp.Close;
           AdoQry_tmp.SQL.text:='insert into wipBomOpen Values('''+lbl_Condition.Caption+''','+
                                ''''+getCode(lbl_SfcName.Caption)+''','+
                                ''''+getCode(lbl_fatherItem.Caption)+''','+
                                ''''+getCode(fieldbyname('ItemDESC').asstring)+''','+
                                lbl_Order.Caption+','+
                                fieldbyname('Bomqty').asstring+','+
                                fieldbyname('BomScrAp_Percent').asstring+','+
                                fieldbyname('sonqty').asstring+')';
           AdoQry_tmp.ExecSQL ;
           if (copy(fieldbyname('ItemDESC').asstring,1,1)='+') or
              (copy(fieldbyname('ItemDESC').asstring,1,1)='-') then
           begin
             next;
             continue;
           end
           else
           begin
               AdoQuery1.Close;
               AdoQuery1.SQL.Text:='select ItemCode from wipInv where wipInvMonth='''+lbl_Condition.Caption+''' and DeptCode='''+getCode(lbl_SfcName.Caption)+''' '+
                                                         'and ItemCode='''+getCode(fieldbyname('ItemDESC').asstring)+'''';
               AdoQuery1.Open ;
               if AdoQuery1.Eof then
               begin
                  AdoQry_tmp.Close;
                  AdoQry_tmp.SQL.Text:='insert wipInv Values('''+lbl_Condition.Caption+''','''+getCode(lbl_SfcName.Caption)+''','+
                                             ''''+getCode(fieldbyname('ItemDESC').asstring)+''','+fieldbyname('sonqty').asstring+','+'0,0'+')';
                  AdoQry_tmp.ExecSQL ;
               end
               else
               begin
                  AdoQry_tmp.Close;
                  AdoQry_tmp.SQL.Text:='update wipInv set wipInvQty=wipInvQty+'+fieldbyname('sonqty').asstring+' where wipInvMonth='''+lbl_Condition.Caption+''' and DeptCode='''+getCode(lbl_SfcName.Caption)+''' and ItemCode='+
                                             ''''+getCode(fieldbyname('ItemDESC').asstring)+''' ';
                  AdoQry_tmp.ExecSQL ;
               end;
               next;
           end;
        end;
      end;
      AdoQry_Main.Connection.CommitTrans ;
  except
      AdoQry_Main.Connection.RollBackTrans ;
      AdoQry_Main.GotoBookmArk(Bookm);
      AdoQry_Main.EnableControls ;
      DispInfo('保存失败,请稍后进行!',3);
      abort;
  end;
  AdoQry_Main.GotoBookmArk(Bookm);
  AdoQry_Main.EnableControls ;
  act_Save.Enabled :=False;
end;

procedure TFrm_Sfc_WipBomOpen.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  if act_Save.Enabled then
  begin
    if DispInfo('数据已更改,要保存吗?',2)='y' then
       act_Save.Execute ;
  end;  
  with AdoQry_tmp do
  begin
    Close;
    sql.Text:='drop table #tmp_Bom1 drop table #tmp_Bom2';
    try
      execsql;
    except
    end;  
  end;
  action:=cafree;
end;

procedure TFrm_Sfc_WipBomOpen.DBGridEhGetCellParams(Sender: TObject;
  Column: TColumnEh; AFont: TFont; var Background: TColor;
  State: TGridDrawState);
begin
  inherited;
  if copy(dbgrideh.DataSource.DataSet.fieldbyname('ItemDESC').asstring,1,1)='+' then
     afont.Color :=clred;
  if copy(dbgrideh.DataSource.DataSet.fieldbyname('ItemDESC').asstring,1,1)='-' then
     afont.Color :=clblue;
end;

procedure TFrm_Sfc_WipBomOpen.Act_ModifyExecute(Sender: TObject);
begin
  if (copy(AdoQry_Main.fieldbyname('ItemDESC').asstring,1,1)='+') or
     (copy(AdoQry_Main.fieldbyname('ItemDESC').asstring,1,1)='-') then
     exit;  
  TFrm_Sfc_WipBomOpen_D(Frm_Sys_Detail).SetformParam(lbl_fatherItem.Caption,AdoQry_Main.fieldbyname('ItemDESC').asstring,lbl_Order.Caption,'','','');
  inherited;
end;

procedure TFrm_Sfc_WipBomOpen.FormActivate(Sender: TObject);
begin
  inherited;
  toolbutton6.Action :=act_Save;
end;

procedure TFrm_Sfc_WipBomOpen.Act_DeleteExecute(Sender: TObject);
begin
   AdoQry_Main.delete;
end;

end.

⌨️ 快捷键说明

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