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

📄 bas_bom_copy1.pas

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

unit Bas_Bom_Copy1;

Interface

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

Type
  TFrm_Bas_Bom_Copy1 = Class(TFrm_Base_Dialog)
    Label1: TLabel;
    Label2: TLabel;
    ExtEdt_ItemCode1: TExtEdit;
    ExtEdt_ItemCode2: TExtEdit;
    Label3: TLabel;
    Label4: TLabel;
    lbl_ItemName2: TLabel;
    Label7: TLabel;
    AdoQry_Main: TAdoQuery;
    lbl_ItemName1: TLabel;
    ActionList1: TActionList;
    Action1: TAction;
    procedure FormActivate(Sender: TObject);
    procedure btn_okClick(Sender: TObject);
    procedure ExtEdt_ItemCode1Change(Sender: TObject);
    procedure ExtEdt_ItemCode2Change(Sender: TObject);
    procedure btn_CancelClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Action1Execute(Sender: TObject);
    procedure ExtEdt_ItemCode1Exit(Sender: TObject);
    procedure ExtEdt_ItemCode2Exit(Sender: TObject);

  private
    { Private declarations }
    function IsMasterCode(ItemCode:String):boolean;       //是否被引用
    function SlaveCodeUsable(R_ItemCode:String):Boolean;
    function PickSlaveCode(InitCode:String):string;
    procedure checkv(pstr:string;sstr:string);
    function MasterCodePass(ItemCode:string):boolean;  //判断物料是否已审核
    procedure GetBomParam;
    procedure checkPmItem(ItemCode:string);//是否采购件
  public
    { Public declarations }
    procedure InitForm(AdoConnection: TAdoConnection);
  end;

var
  Frm_Bas_Bom_Copy1: TFrm_Bas_Bom_Copy1;

implementation

uses Sys_Global;

{$R *.DFM}

procedure TFrm_Bas_Bom_Copy1.FormActivate(Sender: TObject);
begin
  inherited;
  btn_ok.Enabled:=False;
  btn_Cancel.Enabled :=False;
end;

procedure TFrm_Bas_Bom_Copy1.btn_okClick(Sender: TObject);
var
 useCodestr:string;
 i:integer;
 BomStatusstr:string;
 test:string;
begin
  inherited;
  i:=0;
  BomStatusstr:='';
  useCodestr:=userCode;

  if MasterCodePass(ExtEdt_ItemCode2.Text)= True then
  begin
    DispInfo(Quotedstr(ExtEdt_ItemCode2.Text)+'已审核,不允许复制!',1);
    Abort; 
  end;
  //判断源物料是否有下级内容
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select ItemCode '+
                    ' from BomA '+
                    ' where ite_ItemCode='''+Trim(Extedt_ItemCode1.text)+'''');
    open;
    if recordCount=0 then
    begin
      DispInfo('此物料无下级物料',3);
      Extedt_ItemCode1.setfocus;
      abort;
    end;
  end;

  // 判断源物料状态
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select BomStatus '+
                    ' from BomA '+
                    ' where ItemCode='''+Trim(Extedt_ItemCode1.text)+'''');
    open;
    if recordCount>0 then
    begin
      i:=AdoQry_Tmp.fieldbyname('BomStatus').asinteger;
      if i>0 then
      begin
        case  i of
            1: BomStatusstr:='未生效';
            2: BomStatusstr:='暂定';
            3: BomStatusstr:='暂停使用';
        end;
        DispInfo('此物料Bom状态:'+BomStatusstr+'不能复制',3);
        Extedt_ItemCode1.setfocus;
        abort;
      end;
    end;
  end;


  //检查目的物料是否存在BomA中,如果存在则不允许复制
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.Add('select ItemCode '+
                    ' from BomA '+
                    ' where ite_ItemCode='''+Trim(Extedt_ItemCode2.text)+'''');
    open;

    if recordCount>0 then
    begin
      DispInfo('目标物料已经有下级物料,不允许复制!',1);
      Extedt_ItemCode2.setfocus;
      abort;
    end;
    {Close;
    sql.clear;
    sql.Add('select ItemCode '+
                    ' from Bom '+
                    ' where ItemCode='''+Trim(Extedt_ItemCode2.text)+'''');
    open;
    if recordCount>0 then
    begin
      DispInfo('目标物料已经有上级物料,不允许复制!',1);
      Extedt_ItemCode2.setfocus;
      abort;
    end;}
  end;
  if Trim(Extedt_ItemCode2.text)=Trim(Extedt_ItemCode1.text) then
  begin
    DispInfo('物料代码1不能与物料代码2相同 ',3);
    Extedt_ItemCode1.setfocus;
    abort;
  end;

  //循环校验源节点下级的所有的树中是否有目的节点
    Screen.Cursor:=CrSQLWait;
    checkv(Trim(ExtEdt_ItemCode1.text),Trim(ExtEdt_ItemCode2.text));       //循环校验


  try
    AdoQry_Tmp.Connection.beginTrans ;
    //复制
    with AdoQry_Tmp do
    begin
      Close;
      sql.clear;
      sql.Add('insert BomA '+
              '  (ite_ItemCode,'+
              '   ItemCode,'+
              '   BomItemType,'+
              '   Bomqty,'+
              '   BomScrAp_Percent,'+
              '   Bomstatus,'+
              '   DeptCode,'+
              '   UseStyle,'+
              '   BommArk )'+
              ' select '''+Trim(Extedt_ItemCode2.text)+''', ' +
              ' ItemCode, '+
              ' BomItemType, '+
              ' BomQty, '+
              ' BomScrAp_Percent,' +
              ' BomStatus ,'+
              ' DeptCode ,'+
              ' UseStyle,'+
              ' BomMArk '+
              ' from BomA '+
              ' where ite_ItemCode='''+Extedt_ItemCode1.text+'''');
      execsql;
    end;

    if not IsMasterCode(Trim(Extedt_ItemCode2.text)) then    //如果Extedt_ItemCode2没有被引用
    begin

      With AdoQry_Tmp do
      begin
        Close;
        Sql.clear ;
        sql.Add('insert BomA '+
                '  (ite_ItemCode,'+
                '   ItemCode,Bomqty,BomScrAp_Percent,UseStyle,BomSTATUS,BomItemType)'+
                '  Values '+
                ' ( null, ' +
                ' '''+Trim(Extedt_ItemCode2.text)+''',''0'',''0'',''0'',''0'',''0'') ');
        execsql;
      end;
    end;
    AdoQry_Tmp.Connection.CommitTrans ;
    Screen.Cursor:=CrDefault;
    DispInfo('复制成功!',3);
    btn_ok.enabled:=False;
  except
    AdoQry_Tmp.Connection.RollBackTrans ;
    DispInfo('复制失败!',1);
    abort;
  end;
end;

procedure TFrm_Bas_Bom_Copy1.InitForm(AdoConnection: TAdoConnection);
begin
  inherited;
  SetDBConnect(AdoConnection);
  AdoQry_tmp.Connection :=AdoConnection ;
  AdoQry_Main.Connection :=AdoConnection ;
  GetBomParam;  
end;

procedure TFrm_Bas_Bom_Copy1.ExtEdt_ItemCode1Change(Sender: TObject);
begin
  inherited;
 if Extedt_ItemCode1.Text<>'' then
 begin
   btn_Cancel.Enabled:=True;
   btn_ok.enabled:=Extedt_ItemCode2.Text<>'';
 end;
end;

procedure TFrm_Bas_Bom_Copy1.ExtEdt_ItemCode2Change(Sender: TObject);
begin
  inherited;
 if Extedt_ItemCode2.Text<>'' then
 begin
   btn_Cancel.Enabled:=True;
   btn_ok.enabled:=( Extedt_ItemCode1.Text<>'');
 end;
end;

procedure TFrm_Bas_Bom_Copy1.btn_CancelClick(Sender: TObject);
begin
  inherited;
  Close;
  {Extedt_ItemCode1.text:='';
  Extedt_ItemCode2.text:='';
  lbl_ItemName1.Caption:='';
  lbl_ItemName2.Caption:='';
  btn_ok.enabled:=False;
  btn_Cancel.enabled:=False;}
end;

procedure TFrm_Bas_Bom_Copy1.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
  action:=cafree;
end;


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

end;

function TFrm_Bas_Bom_Copy1.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_Bom_Copy1.Action1Execute(Sender: TObject);
begin
  inherited;
  if ActiveControl.Name='ExtEdt_ItemCode1' then
  begin
    ExtEdt_ItemCode1.Text:=PickSlaveCode(ExtEdt_ItemCode1.Text);
    ExtEdt_ItemCode1.SetFocus;
  end;
  if ActiveControl.Name='ExtEdt_ItemCode2' then
  begin
    ExtEdt_ItemCode2.Text:=PickSlaveCode(ExtEdt_ItemCode2.Text);
    ExtEdt_ItemCode2.SetFocus;
  end;
end;

procedure TFrm_Bas_Bom_Copy1.ExtEdt_ItemCode1Exit(Sender: TObject);
begin
  inherited;
  if getfocus()<>btn_Cancel.Handle then
  if not SlaveCodeUsable(Trim(ExtEdt_ItemCode1.Text)) then
  begin
    DispInfo('请输入代码没找到!',1);
    TWinControl(Sender).SetFocus;
    Abort;
  end
  else
  begin
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.Add('select ItemName '+
                      ' from Item '+
                      '  where ItemCode='''+Trim(ExtEdt_ItemCode1.Text)+'''');
      open;
      Lbl_ItemName1.Caption:=fieldbyname('ItemName').asstring;
      Close;
    end;
  end;
end;

procedure TFrm_Bas_Bom_Copy1.ExtEdt_ItemCode2Exit(Sender: TObject);
begin
  inherited;
  if getfocus()<>btn_Cancel.Handle then
  if not SlaveCodeUsable(Trim(ExtEdt_ItemCode2.Text)) then
  begin
    DispInfo('请输入代码没找到!',1);
    TWinControl(Sender).SetFocus;
    Abort;
  end
  else
  begin
    checkPmItem(Trim(ExtEdt_ItemCode2.Text));
    with AdoQry_tmp do
    begin
      Close;
      sql.clear;
      sql.Add('select ItemName '+
                      ' from Item '+
                      '  where ItemCode='''+Trim(ExtEdt_ItemCode2.Text)+'''');
      open;
      Lbl_ItemName2.Caption:=fieldbyname('ItemName').asstring;
      Close;
    end;
  end;
end;

procedure TFrm_Bas_Bom_Copy1.checkv(pstr, sstr: string);
var
  Tmp_Str:string;
  s1:string;
begin
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    Tmp_Str:='declAre @aa chAr(1) '+
            'exec CheckVerity_New  '''+Trim(pstr)+''','''+Trim(sstr)+''',@aa output '+
            'select @aa as VerityResult ';
    sql.Add(Tmp_Str);
    open;
    s1:= fieldbyname('verityResult').asstring;
    if s1='F' then
    begin
      DispInfo('循环校验出错!',1);
      Screen.Cursor:=CrDefault;
      abort;
    end;
  end;
end;

function TFrm_Bas_Bom_Copy1.IsMasterCode(ItemCode: String): boolean;
begin
   with AdoQry_Tmp do
   begin
     Close;
     Sql.clear;
     Sql.Add('Select * from BomA '+
                     ' where ItemCode='''+Trim(ItemCode)+'''');
     open;
     if recordCount>0 then
       Result:=True
     else
       Result:=False;
   end;
end;

function TFrm_Bas_Bom_Copy1.MasterCodePass(ItemCode:string):boolean;
var
  sSQL:String;
begin
  sSQL:='select  top 1 PassFlag from BomA where Ite_ItemCode='+Quotedstr(ItemCode);
  with AdoQry_Tmp do
  begin
    Close;
    SQL.clear;
    SQL.Add(sSQL);
    Open;
  end;
  if AdoQry_Tmp.fieldbyname('Passflag').AsInteger<>1 then
    Result:=False
  else
    Result:=True;
end;

procedure TFrm_Bas_Bom_Copy1.GetBomParam;
var
  sSQL:string;
begin
  sSQL:=' select ParamValueN from Bom_Param where ParamCode=''AuditBom'' and ParamName=''Bom构造是否要审核'' ';
  with AdoQry_tmp do
  begin
    Close;
    SQL.clear;
    SQL.Add(sSQL);
    Open;
  end;

  if AdoQry_tmp.Eof then  DispInfo('你尚没设置相关系统参数!',1)
  else
  begin
     if AdoQry_tmp.fieldbyname('ParamValueN').AsInteger=0 then
     begin
       DispInfo('对不起,系统已设定Bom构造不须审核',1);
       Frm_Bas_Bom_Copy1.Close;
     end;
  end;
end;

procedure TFrm_Bas_Bom_Copy1.checkPmItem(ItemCode:string);//是否采购件
var
  sSQL:string;
begin
  sSQL:='select PmCode from Item where ItemCode='+Quotedstr(ItemCode);
  with AdoQry_tmp do
  begin
    Close;
    SQL.clear;
    SQL.Add(sSQL);
    Open;
    if  fieldbyname('PmCode').AsInteger=1 then
    begin
      DispInfo('不允许采购件下挂子项',1);
      abort;
    end;
  end;
end;

end.

⌨️ 快捷键说明

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