bas_bom_d.pas

来自「一个MRPII系统源代码版本」· PAS 代码 · 共 1,100 行 · 第 1/3 页

PAS
1,100
字号
{$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_Bom_D;

Interface

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

Type
  TFrm_Bas_Bom_D = Class(TFrm_Base_Detail)
    Label1: TLabel;
    Lbl_MasterCode: TLabel;
    Label3: TLabel;
    Lbl_MasterType: TLabel;
    Label5: TLabel;
    Lbl_MasterUom: TLabel;
    Label7: TLabel;
    Lbl_MasterName: TLabel;
    Label9: TLabel;
    Label13: TLabel;
    Label15: TLabel;
    Lbl_SlaveName: TLabel;
    Label17: TLabel;
    Edt_Qty: TEdit;
    CmBx_Type: TComboBox;
    Label14: TLabel;
    Edt_ScrAp: TEdit;
    Label18: TLabel;
    Label19: TLabel;
    CmBx_Status: TComboBox;
    Label20: TLabel;
    Edt_DeptCode: TEdit;
    Lbl_DeptName: TLabel;
    Edt_ItemCode: TEdit;
    Label10: TLabel;
    StatusBar1: TStatusBar;
    ActionList1: TActionList;
    Action1: TAction;
    Label2: TLabel;
    Edt_RemArk: TEdit;
    Label4: TLabel;
    CmBx_usestyle: TComboBox;
    Label6: TLabel;
    Lbl_SlaveUom: TLabel;
    AdoQry_tmp1: TAdoQuery;
    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 Edt_QtyChange(Sender: TObject);
    procedure FormActivate(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);     // 判断子项是否是虚项并作出处理
    function GetUomName(ItemCode:string):string;      //获得计量单位
    procedure GetWorkCenterQTY;
    { Private declarations }
   public
    MasterCode:string;
    SlaveCode:string;
    procedure SaveData;Override;
    procedure InitControls;Override;

    { Public declarations }
  end;

var
  Frm_Bas_Bom_D: TFrm_Bas_Bom_D;

implementation

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

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

function TFrm_Bas_Bom_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_Bom_D.InitControls;
var
  T_Sql:string;
  T_ItemCode:string;
  T_Type:integer;
begin
  if Add then
  begin
    SetFocus_Control:=Edt_ItemCode;
  end
  else
  begin
    SetFocus_Control:=CmBx_Type;
  end;

  inherited;
  AdoQry_tmp1.Connection :=AdoQry_tmp.Connection ;
  if Add then
  begin
    Edt_ItemCode.Enabled:=True
  end
  else
  begin
    Edt_ItemCode.Enabled:=False;
  end;
  T_ItemCode:=MasterCode;
  Lbl_MasterCode.Caption:=MasterCode;
  with AdoQry_Tmp do
  begin
    Close;
    SQL.clear;
    if T_ItemCode<>'' then
    begin
      T_Sql:=
         'Select ItemName,'+
         '  UomName, '+
         '  ItemType '+
         'From Item I inner join Uom U '+
         '  on I.UomCode=U.UomCode  '+
         'Where I.ItemCode='''+T_ItemCode+''' ';
      SQL.Add(T_Sql);
      open;
      if not eof then
      begin
        Lbl_MasterUom.Caption:=fieldbyname('UomName').AsString;
        Lbl_MasterName.Caption:=fieldbyname('ItemName').AsString;
        T_Type:=fieldbyname('ItemType').AsInteger;
        case T_Type of
          0:Lbl_MasterType.Caption:='普通物料';
          1:Lbl_MasterType.Caption:='工作中心';
          2:Lbl_MasterType.Caption:='工具';
          3:Lbl_MasterType.Caption:='参考';
          4:Lbl_MasterType.Caption:='结构虚项';
          5:Lbl_MasterType.Caption:='劳务';
          6:Lbl_MasterType.Caption:='副产品';
          7:Lbl_MasterType.Caption:='成本中心';
          8:Lbl_MasterType.Caption:='替代虚象';
        end;
      end;
    end;
  end;
  if AdoQry_Maintain.Active then
  begin
    with AdoQry_Maintain do
    begin
      Edt_ItemCode.Text:=fieldbyname('ItemCode').AsString;
      Lbl_SlaveName.Caption:=fieldbyname('ItemName').AsString;
      Lbl_SlaveUom.Caption:=fieldbyname('UomName').asstring;
      Cmbx_Type.ItemIndex:=fieldbyname('BomItemType').AsInteger;
      Edt_Qty.Text:=FloatToStr(fieldbyname('BomQty').AsFloat);
      Edt_ScrAp.Text:=FloatToStr(fieldbyname('BomScrAp_Percent').AsFloat);
      Cmbx_Status.ItemIndex:=fieldbyname('BomStatus').AsInteger;
      Edt_DeptCode.Text:=fieldbyname('DeptCode').AsString;
      Lbl_DeptName.Caption:=fieldbyname('DeptName').AsString;
      CmBx_usestyle.ItemIndex :=fieldbyname('usestyle').asinteger;
      Edt_RemArk.Text:=fieldbyname('RemArk').AsString;
    end;
  end;
end;

procedure TFrm_Bas_Bom_D.SaveData;
begin
  inherited;
  AdoQry_tmp.Connection.beginTrans;

  try
    if (Add) then //新增的情况
    begin
      InsertBom;
      //插入到LOG中
      SaveAddToLog;
      //删除子项原为最终产品的记录
      EraseOldRoot;
      //清除单个的Bom记录
      clearSinGleReCode;
      //新增时存入BomChange;
      InsertBomChange(Trim(Lbl_MasterCode.Caption));
    end
    else
    begin
      //先插入到LOG中
      SaveModifyToLog;
      UpdateBom;
      //清除单个的Bom记录
      clearSinGleReCode;
      //修改时存入BomChange;
      updateBomChange(Trim(Lbl_MasterCode.Caption));
    end;

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

  with AdoQry_Maintain do
  begin
    fieldbyname('ItemCode').AsString:=Edt_ItemCode.Text;
    fieldbyname('ItemName').AsString:=Lbl_SlaveName.Caption;
    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('DeptName').AsString:=Lbl_DeptName.Caption;
    fieldbyname('usestyle').asinteger:=CmBx_usestyle.Itemindex;
    fieldbyname('RemArk').AsString:=Edt_RemArk.Text;
    fieldbyname('PmCode').AsInteger:=fPmCode;
    post;
  end;
end;

procedure TFrm_Bas_Bom_D.FormCreate(Sender: TObject);
begin
  inherited;
  //变量初始化
  MasterCode:='';
  SlaveCode:='';
  Lc_ItemExist:=False;
  lc_TempBuffer:='';
  fPmCode:=0;
  Lc_Identity:=0;
  //LABEL初始化
  Lbl_MasterCode.Caption:='';
  Lbl_MasterType.Caption:='';
  Lbl_MasterUom.Caption:='';
  Lbl_SlaveUom.Caption:='';
  Lbl_MasterName.Caption:='';
  Lbl_SlaveName.Caption:='';
  Lbl_DeptName.Caption:='';
end;

procedure TFrm_Bas_Bom_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(lbl_MasterCode.Caption) then
            begin
//              DispInfo('替代虚项下不能有结构虚项!',1);
//              abort;
            end;
            CmBx_Type.ItemIndex:=3;
          end;
        7:begin
            if FoundReplaceVirtual(lbl_MasterCode.Caption) then
            begin
//              DispInfo('替代虚项下不能再有替代虚项!',1);
//              abort;
            end;
            CmBx_Type.ItemIndex:=6;
          end;
        else
          begin
            if FoundReplaceVirtual(lbl_MasterCode.Caption) 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_Bom_D.PickSlaveCode(InitCode:String):String;
begin
  Result:=GetCodeHint(
        AdoQry_Tmp,
        'ItemName','物料描述',
        'ItemCode','物料代码',
        'Item',InitCode,'ItemUsable=1');
end;

function TFrm_Bas_Bom_D.SlaveCodeUsable(R_ItemCode:String):Boolean;

⌨️ 快捷键说明

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