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

📄 bas_bom1_d.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{$A+,B-,C+,D+,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O+,P+,Q-,R-,S-,T-,U-,V+,W-,X+,Y+,Z1}
{$MINSTACKSIZE $00004000}
{$MAXSTACKSIZE $00100000}
{$IMAGEBase $00400000}
{$ApPType GUI}
unit Bas_Bom1_D;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Detail, StdCtrls, Db, AdODB, ExtCtrls, ExtEdit, ComCtrls, ActnList;

Type
  TFrm_Bas_Bom1_D = Class(TFrm_Base_Detail)
    StatusBar1: TStatusBar;
    ActionList1: TActionList;
    Action1: TAction;
    AdoQry_tmp1: TAdoQuery;
    Label1: TLabel;
    Lb_ItemCode: TLabel;
    Label3: TLabel;
    Lb_ItemName: TLabel;
    Label5: TLabel;
    Lb_PmCode: TLabel;
    Label7: TLabel;
    Lb_PrepareLT: TLabel;
    Label9: TLabel;
    Lb_RunLt: TLabel;
    Label11: TLabel;
    Lb_QcLT: TLabel;
    Label13: TLabel;
    Lb_DesignNo: TLabel;
    Label15: TLabel;
    Label17: TLabel;
    Label19: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    Label22: TLabel;
    Label23: TLabel;
    Lbl_DeptName: TLabel;
    Label24: TLabel;
    Label25: TLabel;
    Label27: TLabel;
    Label28: TLabel;
    Label30: TLabel;
    Lb_UomName: TLabel;
    Label32: TLabel;
    Lb_ite_PmCode: TLabel;
    Label34: TLabel;
    Lb_ite_PrepareLT: TLabel;
    Label36: TLabel;
    Lb_ite_RunLt: TLabel;
    Label38: TLabel;
    Lb_ite_QcLT: TLabel;
    Label40: TLabel;
    Lb_ite_DesignNo: TLabel;
    Label42: TLabel;
    Lb_ite_ItemName: TLabel;
    Edt_Qty: TEdit;
    CmBx_Type: TComboBox;
    Edt_ScrAp: TEdit;
    CmBx_Status: TComboBox;
    Edt_RemArk: TEdit;
    CmBx_usestyle: TComboBox;
    Extedt_ite_ItemCode: TExtEdit;
    Edt_DeptCode: TExtEdit;
    procedure FormCreate(Sender: TObject);
    procedure Edt_ItemCodeExit(Sender: TObject);
    procedure Edt_DeptCodeExit(Sender: TObject);
    procedure btn_okClick(Sender: TObject);
    procedure Action1Execute(Sender: TObject);
    procedure Edt_ScrApExit(Sender: TObject);
    procedure Edt_QtyExit(Sender: TObject);
    procedure CmBx_TypeExit(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure ItemCodeCheck(Sender: TObject);
    procedure Edt_QtyChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    lc_ItemExist:Boolean;
    lc_TempBuffer:string;
    fPmCode:integer;
    Lc_Identity:integer;
    tmp_ItemCode:string;
    function  CicleCheckSlaveValid(R_MasterCode:string;R_SlaveCode:string):Boolean;
    procedure SetPnl_Slave(R_ItemCode:String);
    Function  PickSlaveCode(InitCode:String):String;
    Function  PickDeptCode(InitCode:String):String;
    Function  SlaveCodeUsable(R_ItemCode:String):Boolean;
    Function  DeptCodeUsable(R_DeptCode:string):Boolean;
    procedure SetDept(R_DeptCode:String);
    Function  FoundBom(MasterCode:String;SlaveCode:String):Boolean; //在Bom中是否存在该记录
    procedure InsertBom;                            //插入Bom
    procedure UpdateBom;                            //修改Bom
    //procedure CheckVerity(R_MasterCodeCheck: string);
    Function  IsNewBom(ItemCode:String):Boolean;    //判断是否为新的Bom
    procedure EraseOldRoot;                         //删除旧的为根的节点
    procedure SaveModifyToLog;          //存入修改日志文件
    procedure SaveAddToLog;             //存入增加日志文件
    //是否存在替代虚项
    Function  FoundReplaceVirtual(MasterCode:string):boolean;
    procedure clearSinGleReCode;        //删除单个的Bom记录
    procedure InsertBomChange(realite_ItemCode:string);         //新增时存入BomChange;
    procedure updateBomChange(realite_ItemCode:string);          //修改时存入BomChange;
    procedure JudgeChild(ItemCode:string);     // 判断子项是否是虚项并作出处理
    procedure checkPmItem(ItemCode:string);//是否采购件
    procedure GetWorkCenterQTY;
    { Private declarations }
   public
    MasterCode:string;
    SlaveCode:string;
    procedure SaveData;Override;
    procedure InitControls;Override;
    { Public declarations }
  end;

var
  Frm_Bas_Bom1_D: TFrm_Bas_Bom1_D;

implementation

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

{procedure TFrm_Bas_Bom_D.CheckVerity(R_MasterCodeCheck: string);
begin
end;}

function TFrm_Bas_Bom1_D.CicleCheckSlaveValid(R_MasterCode,
  R_SlaveCode: string):Boolean;
var
  Tmp_Str:string;
begin
  StatusBar1.Panels[0].Text:='正在进行校验...';
  StatusBar1.Refresh;
  lc_TempBuffer:=R_SlaveCode;

  //调用检查的存储过程进行校验
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    Tmp_Str:='declAre @aa chAr(1) '+
            'exec checkverity  '''+R_SlaveCode+''','''+r_MasterCode+''',@aa output '+
            'select @aa as VerityResult ';
    sql.Add(Tmp_Str);
    open;
    if fieldbyname('verityResult').asstring='F' then
      Result:=False
    else Result:=True;
    Close;
  end;
  StatusBar1.Panels[0].Text:='';
end;

procedure TFrm_Bas_Bom1_D.InitControls;
var
  T_Sql:string;
  T_ItemCode:string;
  T_Type:integer;
begin
  if Add then
  begin
    SetFocus_Control:=Extedt_ite_ItemCode;
  end
  else
  begin
    SetFocus_Control:=CmBx_Type;
  end;

  inherited;
  AdoQry_tmp1.Connection :=AdoQry_tmp.Connection ;
  if Add then
  begin
    Extedt_ite_ItemCode.Enabled:=True
  end
  else
  begin
    Extedt_ite_ItemCode.Enabled:=False;
  end;
  T_ItemCode:=MasterCode;

  if AdoQry_Maintain.Active then
  begin
    with AdoQry_Maintain do
    begin
      Extedt_ite_ItemCode.Text:=fieldbyname('ite_ItemCode').asstring;
      Cmbx_Type.ItemIndex:=fieldbyname('BomItemType').AsInteger;
      Edt_Qty.Text:= fieldbyname('Bomqty').asstring;
      Edt_ScrAp.Text:=fieldbyname('BomScrAp_Percent').asstring;
      CmBx_Status.ItemIndex:=fieldbyname('Bomstatus').AsInteger;
      Edt_DeptCode.Text:=fieldbyname('DeptCode').asstring;
      CmBx_usestyle.ItemIndex:=fieldbyname('usestyle').AsInteger;
      Edt_RemArk.Text:= fieldbyname('remArk').asstring;
    end;
  end;
end;

procedure TFrm_Bas_Bom1_D.SaveData;
var
  S1,S2:string;
begin
  inherited;
  AdoQry_tmp.Connection.beginTrans;
  try
    if (Add) then //新增的情况
    begin
      InsertBom;
      //插入到LOG中
      SaveAddToLog;
      //删除子项原为最终产品的记录
      EraseOldRoot;
      //清除单个的Bom记录
      clearSinGleReCode;
      //新增时存入BomChange;
      InsertBomChange(Trim(Extedt_ite_ItemCode.text));
    end
    else
    begin
      //先插入到LOG中
      SaveModifyToLog;
      UpdateBom;
      //清除单个的Bom记录
      clearSinGleReCode;
      //修改时存入BomChange;
      updateBomChange(Trim(Extedt_ite_ItemCode.Text));
    end;

    AdoQry_tmp.Connection.CommitTrans;
  except
    AdoQry_tmp.Connection.RollBackTrans;
    DispInfo('存盘失败!请再试!',1);
  end;

  {with AdoQry_Tmp do
  begin
    Close;
    SQL.clear;
    if(Add)then
    begin
      S1:= ' insert into Bom(Ite_ItemCode,ItemCode,BomItemType,BomQty,BomScrAp_Percent,BomSTATUS,DeptCode,usestyle,remArk) Values ( '+quotedstr(Extedt_ite_ItemCode.Text)+' , '+Quotedstr(SlaveCode)+' , '+inttostr(CmBx_Type.ItemIndex)+' , '+Edt_Qty.Text+','+Edt_ScrAp.Text+','+inttostr(CmBx_Status.ItemIndex)+','+Quotedstr(Edt_DeptCode.Text)+','+inttostr(CmBx_usestyle.ItemIndex)+','+Quotedstr(Edt_RemArk.Text)+' ) ';
      SQL.Add(' insert into Bom(Ite_ItemCode,ItemCode,BomItemType,BomQty,BomScrAp_Percent,BomSTATUS,DeptCode,usestyle,remArk) Values ( '+quotedstr(Extedt_ite_ItemCode.Text)+' , '+Quotedstr(SlaveCode)+' , '+inttostr(CmBx_Type.ItemIndex)+' , '+Edt_Qty.Text+','+Edt_ScrAp.Text+','+inttostr(CmBx_Status.ItemIndex)+','+Quotedstr(Edt_DeptCode.Text)+','+inttostr(CmBx_usestyle.ItemIndex)+','+Quotedstr(Edt_RemArk.Text)+' ) ' );
    end
    else
    begin
      s2:=' update Bom set Ite_ItemCode = '+quotedstr(Extedt_ite_ItemCode.Text)+','+' ItemCode = '+quotedstr(SlaveCode)+','+' BomItemType = '+inttostr(CmBx_Type.ItemIndex)+','+' BomQty= '+Edt_Qty.Text+','+'BomScrAp_Percent='+Edt_ScrAp.Text+','+'BomSTATUS='+inttostr(CmBx_Status.ItemIndex)+','+'DeptCode='+Quotedstr(Edt_DeptCode.Text)+','+'usestyle='+inttostr(CmBx_usestyle.ItemIndex)+','+'remArk='+Quotedstr(Edt_RemArk.Text)+' where Bom.Bomid= '+AdoQry_Maintain.fieldbyname('Bomid').asstring;
      SQL.Add(' update Bom set Ite_ItemCode = '+quotedstr(Extedt_ite_ItemCode.Text)+','+' ItemCode = '+quotedstr(SlaveCode)+','+' BomItemType = '+inttostr(CmBx_Type.ItemIndex)+','+' BomQty= '+Edt_Qty.Text+','+'BomScrAp_Percent='+Edt_ScrAp.Text+','+'BomSTATUS='+inttostr(CmBx_Status.ItemIndex)+','+'DeptCode='+Quotedstr(Edt_DeptCode.Text)+','+'usestyle='+inttostr(CmBx_usestyle.ItemIndex)+','+'remArk='+Quotedstr(Edt_RemArk.Text)+' where Bom.Bomid= '+AdoQry_Maintain.fieldbyname('Bomid').asstring);
    end;
    execSQL;
  end;}

  with AdoQry_Maintain do
  begin
    fieldbyname('Ite_ItemCode').asstring:=Extedt_ite_ItemCode.Text;
//    fieldbyname('ItemCode').asstring:=sItemCode;
    fieldbyname('BomItemType').AsInteger:=Cmbx_Type.ItemIndex;
    fieldbyname('BomQty').AsFloat:=StrToFloat(Edt_Qty.Text);
    fieldbyname('BomScrAp_Percent').AsFloat:=StrToFloat(Edt_ScrAp.Text);
    fieldbyname('BomStatus').AsInteger:=Cmbx_Status.ItemIndex;
    fieldbyname('DeptCode').AsString:=Edt_DeptCode.Text;
    fieldbyname('usestyle').asinteger:=CmBx_usestyle.Itemindex;
    fieldbyname('RemArk').AsString:=Edt_RemArk.Text;
    post;
  end;
end;

procedure TFrm_Bas_Bom1_D.FormCreate(Sender: TObject);
begin
  inherited;
  //变量初始化
  MasterCode:='';
  SlaveCode:='';
  Lc_ItemExist:=False;
  lc_TempBuffer:='';
  fPmCode:=0;
  Lc_Identity:=0;
end;

procedure TFrm_Bas_Bom1_D.SetPnl_Slave(R_ItemCode:String);
var
  T_Sql:string;
  //T_Type:integer;
begin
  if R_ItemCode<>'' then
  begin
    T_Sql:=
      'select ItemName,'+
      '  UomName,'+
      '  PmCode, '+
      '  ItemType '+
      'From Item I inner join Uom U '+
            'on I.UomCode=I.UomCode '+
      'where I.ItemCode='''+R_ItemCode+''' ';
    with AdoQry_Tmp do
    begin
      Close;
      SQL.clear;
      SQL.Add(T_Sql);
      Open;
      if not eof then
      begin
//        Lbl_SlaveName.Caption:=fieldbyname('ItemName').AsString;
        fPmCode:=fieldbyname('PmCode').AsInteger;
        //如果Item类型为1  资源、4  结构虚项、8 替代虚项
        //则Bom的子项属性就必须和相应的中文一样的含义
        //Bom的相关属性有:1  资源、3  结构虚项、6 替代虚项
        Case fieldbyname('ItemType').AsInteger of
        1:begin
            CmBx_Type.ItemIndex:=1;
          end;
        4:begin
            if FoundReplaceVirtual(Extedt_ite_ItemCode.Text) then
            begin
//              DispInfo('替代虚项下不能有结构虚项!',1);
//              abort;
            end;
            CmBx_Type.ItemIndex:=3;
          end;
        7:begin
            if FoundReplaceVirtual(Extedt_ite_ItemCode.Text) then
            begin
//              DispInfo('替代虚项下不能再有替代虚项!',1);
//              abort;
            end;
            CmBx_Type.ItemIndex:=6;
          end;
        else
          begin
            if FoundReplaceVirtual(Extedt_ite_ItemCode.text) then
            begin
              if (Cmbx_Type.ItemIndex=3) or (Cmbx_Type.ItemIndex=6) then
              begin
//                DispInfo('替代虚项下不能再有虚项!',1);
//                abort;
              end;
            end;
          end;
        end;
      end;
      Close;
    end;
  end;
end;

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

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

procedure TFrm_Bas_Bom1_D.Edt_ItemCodeExit(Sender: TObject);
begin

⌨️ 快捷键说明

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