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

📄 bas_bom3.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
begin
  if  CheckBomOK(AdoQry_Main.fieldbyname('Ite_ItemCode').AsString) then
  begin
    DispInfo('父项物料Bom已审核,不能执行修改动作!',1);
    abort;
  end;
  //强制类型转换
  if not AdoQry_Main.Eof then
  begin
    TFrm_Bas_Bom3_D(Frm_Sys_Detail).MasterCode:=AdoQry_Main.fieldbyname('ite_ItemCode').AsString;
    TFrm_Bas_Bom3_D(Frm_Sys_Detail).SlaveCode:=Extedt_ItemCode.Text;
    inherited;
    if Frm_Sys_Detail.ModalResult=MrOk then
    begin
      GetSlave(Extedt_ItemCode.Text);
      LocateToSlave(TFrm_Bas_Bom3_D(Frm_Sys_Detail).MasterCode);
    end;
  end;
end;

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

procedure TFrm_Bas_Bom3.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_Bom3.Act_DeleteExecute(Sender: TObject);
begin
  if not Selected then
  begin
    DispInfo('你没有选定任何物料!',1);
    abort;
  end;

  if activecontrol.Name='Extedt_ItemCode' then abort;
  inherited;
  //清除单个的Bom记录
  //  clearSinGleReCode;
  GetReal_ItemCode(AdoQry_Main.fieldbyname('ite_ItemCode').asstring);
  GetSlave(Extedt_ItemCode.text);
end;

procedure TFrm_Bas_Bom3.LocateToSlave(T_ItemCode: String);
begin
  if AdoQry_Main.Active then
    AdoQry_Main.Locate('ite_ItemCode',T_ItemCode,[]);
end;

procedure TFrm_Bas_Bom3.InsertOldMaster(ItemCode: string);
begin
  if (Lc_OldMaster.Count=0) or
    ((Lc_OldMaster.Strings[Lc_OldMaster.Count-1])<>ItemCode) then
  begin
    Lc_OldMaster.Add(ItemCode);
  end;
//  ListBOX1.ItemS:=lC_OLDMaster;
end;


function TFrm_Bas_Bom3.ItemIsSource(ItemCode: String): Boolean;
var
  T_String:String;
begin
  T_String:='';
  T_String:='select ItemType '+
            'From Item '+
            'Where ItemCode='''+ItemCode+''' ';
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    sql.Add(T_String);
    open;
    if not eof then
    begin
      //判断是否为资源
      if fieldbyname('ItemType').AsInteger=1 then
        Result:=True
      else Result:=False;
    end
    Else Result:=False;
    Close;
  end;
end;

procedure TFrm_Bas_Bom3.SaveDeleteToLog;
begin
  with AdoQry_Tmp do
  begin
    Close;
    sql.clear;
    //这里是删除的时候,修改在另外的地方
    sql.text:='insert into BomChangeInfo '+
    '  (LogDate,'+
    '   EmployeeCode,'+
    '   LogAction,'+
    '   BomId,'+
    '   Ite_ItemCode,'+
    '   ItemCode,'+
    '   BomItemType,'+
    '   BomQty,'+
    '   BomScrAp_Percent,'+
    '   BomStatus,'+
    '   DeptCode,'+
    '   usestyle,'+
    '   BomMArK) '+
    'Values '+
    '  (getdate(),'+
    '   '''+UserCode+''','+
    '   2,'+
    '   '+IntToStr(AdoQry_Main.fieldbyname('BomId').AsInteger)+','+
    '   '''+AdoQry_Main.fieldbyname('Ite_ItemCode').AsString+''','+
    '   '''+AdoQry_Main.fieldbyname('ItemCode').AsString+''','+
    '   '+IntToStr(AdoQry_Main.fieldbyname('BomItemType').AsInteger)+','+
    '   '+FloatToStr(AdoQry_Main.fieldbyname('BomQty').AsFloat)+','+
    '   '+FloatToStr(AdoQry_Main.fieldbyname('BomScrAp_Percent').AsFloat)+','+
    '   '+IntToStr(AdoQry_Main.fieldbyname('BomStatus').AsInteger)+','+
    '   '''+AdoQry_Main.fieldbyname('DeptCode').AsString+''','+
    '   '+IntToStr(AdoQry_Main.fieldbyname('usestyle').AsInteger)+','+
    '   '+IntToStr(AdoQry_Main.fieldbyname('BomMArK').AsInteger)+') ';
    execsql;
    Close;
  end;
end;


procedure TFrm_Bas_Bom3.AdoQueryAfterOpen(DataSet: TDataSet);
begin
  inherited;
//  TFloatField(DataSet.fieldbyname('BomQty_Disp')).DisplayFormat:='0.#####';
//  TFloatField(DataSet.fieldbyname('BomScrAp_Percent_Disp')).DisplayFormat:='0.#####';
end;

procedure TFrm_Bas_Bom3.clearSinGleReCode;
var
  S:string;
begin
  S:='Delete from BomA '+
           'where BomId='+IntToStr(AdoQry_Main.fieldbyname('BomId').AsInteger)+' ';
  with AdoQry_tmp do
  begin
    Close;
    sql.clear;
    sql.Add(S);
    execsql;
    Close;
  end;
end;


procedure TFrm_Bas_Bom3.DBGridEhGetCellParams(Sender: TObject;
  Column: TColumnEh; AFont: TFont; var Background: TColor;
  State: TGridDrawState);
begin
  inherited;
//  if AdoQry_Main.fieldbyname('ItemUsable').asInteger=0 then
//  begin
//    AFont.Color:=clRed;
//  end;

  if  not CheckBomOK(AdoQry_Main.fieldbyname('Ite_ItemCode').AsString)  then
  begin
    AFont.Color:=clRed;
  end;
end;

procedure TFrm_Bas_Bom3.GetReal_ItemCode(realite_ItemCode: string);
var
  tmp_ItemCode:string;
  tmpAdoQry:TAdoQuery;
begin
  tmp_ItemCode:='';
  with AdoQry_tmp1 do
  begin
    Close;
    sql.clear;
    sql.Add(' exec Find_Real_Ite_ItemCode '''+realite_ItemCode+'''');
    Prepared;
    open;
  end;
  AdoQry_tmp1.First ;
  while not AdoQry_tmp1.Eof do
  begin
    tmp_ItemCode:=AdoQry_tmp1.fieldbyname ('ite_ItemCode').asstring;
    with AdoQry_Tmp do
    begin
      Close;
      sql.clear;
      sql.Add('insert  into BomChange(real_ItemCode,ite_ItemCode,ItemCode,BomItemType0,Bomstatus0,Bomqty0,BomScrAp_Percent0, BomItemType1,Bomstatus1,Bomqty1,BomScrAp_Percent1,BomChangetime)'+
               ' Values('''+tmp_ItemCode+''','+
               ' '''+AdoQry_Main.fieldbyname('ite_ItemCode').asstring+''','+
               ' '''+AdoQry_Main.fieldbyname('ItemCode').asstring+''','+
               ' '''+inttostr(AdoQry_Main.fieldbyname('BomItemType').asinteger)+''','+
               ' '''+inttostr(AdoQry_Main.fieldbyname('BomStatus').asinteger)+''','+
               ' '''+floattostr(AdoQry_Main.fieldbyname('BomQty').asfloat)+''','+
               ' '''+floattostr(AdoQry_Main.fieldbyname('BomScrAp_Percent').asfloat)+''','+
               ' 0,0,0,0, getdate())');
      execsql;
    end;
    AdoQry_tmp1.Next;
  end;
end;
procedure TFrm_Bas_Bom3.Extedt_ItemCodeExit(Sender: TObject);
var
  sSQL:string;
  T_ItemCode:string;
begin
  ItemCodeCheck(Extedt_ItemCode);

  if Trim(Extedt_ItemCode.Text)<>'' then TlBtn_New.Enabled:=True;

  T_ItemCode:=Trim(Extedt_ItemCode.text);
  CheckChilType(T_ItemCode);
  if T_ItemCode<>'' then
  begin
    if MasterCodeUsable(T_ItemCode) then
    begin
      InsertOldMaster(T_ItemCode);
      SetPnl_Head(T_ItemCode);
      GetSlave(T_ItemCode);
    end
    else
    begin
      DispInfo('代码错误!',1);
      TWinControl(Sender).SetFocus;
      Abort;
    end;
  end
  else
  begin
    clearPnl_Head;
    GetSlave(T_ItemCode);
  end;
  inherited;

  sSQL:='select ItemName,PmCode= case PmCode when 0 then ''制造'' when 1 then ''采购'' when 2 then ''委外加工'' when 3 then ''既制造又委外'' end,'+
        'PrepareLT,RunLt,QcLT,DesignNo,UomName  from Item ' +
        ' join Uom on Item.UomCode=Uom.UomCode '+        
        'where ItemCode='+ Quotedstr(Extedt_ItemCode.Text);
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.clear;
  AdoQry_Tmp.SQL.Add(sSQL);
  AdoQry_Tmp.Open;

  Lb_ItemName.Caption:=AdoQry_Tmp.fieldbyname('ItemName').AsString;
  Lb_PmCode.Caption:=AdoQry_Tmp.fieldbyname('PmCode').AsString;
  Lb_PreparelLT.Caption:=AdoQry_Tmp.fieldbyname('PrepareLT').AsString;
  Lb_RunLT.Caption:=AdoQry_Tmp.fieldbyname('RunLT').AsString;
  Lb_QcLT.Caption:=AdoQry_Tmp.fieldbyname('QcLT').AsString;
  Lb_DesignNo.Caption:=AdoQry_Tmp.fieldbyname('DesignNo').AsString;
  Lb_Uom.Caption:=AdoQry_Tmp.fieldbyname('UomName').AsString;

  TlBtn_New.Enabled:=True;
  TlBtn_Modify.Enabled:=True;
  TlBtn_Delete.Enabled:=True;
  
end;

procedure TFrm_Bas_Bom3.DBGridEhTitleClick(Column: TColumnEh);
var
  BookMArk:String;
begin
  inherited;
  If Trim(Column.Title.Caption)<>'标记' Then
    Abort;
  If AdoQry_Main.RecordCount=0 Then
    Abort;
  BookMArk:=AdoQry_Main.BookmArk;

  If Not Flag Then
  begin
    AdoQry_Main.First;
    While Not AdoQry_Main.Eof Do
    begin
      AdoQry_Main.Edit;
      AdoQry_Main.fieldbyname('BomMArK').AsInteger:=1;
      AdoQry_Main.Post;
      AdoQry_Main.Next;
    end;
  end
  Else
  begin
    AdoQry_Main.First;
    While Not AdoQry_Main.Eof Do
    begin
      AdoQry_Main.Edit;
      AdoQry_Main.fieldbyname('BomMArK').AsInteger:=0;
      AdoQry_Main.Post;
      AdoQry_Main.Next;
    end;
  end;
  if not AdoQry_Main.IsEmpty then AdoQry_Main.BookmArk:=BookMArk;
  Flag:=Not Flag;
end;

procedure TFrm_Bas_Bom3.Act_FilterExecute(Sender: TObject);
begin
  selectfromsql:=' select BomA.Bomid,'+
         'BomA.ite_ItemCode,'+
         'Item.ItemName,'+
         'Uom.UomName,'+
         'Item.PmCode,'+
         'Item.PrepareLT,'+
         'Item.RunLt,'+
         'Item.QcLT,'+
         'Item.ItemUsable,'+
         'Item.DesignNo,'+
         'BomA.ItemCode,'+
         'U.UomName as UomName1,'+
         'BomA.BomItemType,'+
         'BomA.Bomqty,'+
         'BomA.BomScrAp_Percent,'+
         'BomA.Bomstatus,'+
         'BomA.DeptCode,'+
         'Dept.DeptName,'+
         'BomA.DeptCode+'' ''+Dept.DeptName as DeptB,'+
         'BomA.usestyle ,'+
         'BomA.BomMArK,'+
         'BomA.remArk'+
  ' from BomA'+
  ' join Item on BomA.ite_ItemCode=Item.ItemCode'+
  ' join Uom on Item.UomCode=Uom.UomCode'+
  ' join Dept on BomA.DeptCode=Dept.DeptCode'+
  ' join Item I on BomA.ItemCode=I.ItemCode'+
  ' join Uom U on I.UomCode=U.UomCode'+
  ' and BomA.ItemCode='+Quotedstr(Extedt_ItemCode.text);
  inherited;
end;

procedure TFrm_Bas_Bom3.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
  begin
    DispInfo('你尚没设置相关系统参数!',1);
    Frm_Bas_Bom3.Close;
  end
  else
  begin
     if AdoQry_tmp.fieldbyname('ParamValueN').AsInteger=0 then
     begin
       DispInfo('对不起,系统已设定Bom构造不须审核',1);
       Frm_Bas_Bom3.Close;
     end;
  end;
end;

procedure TFrm_Bas_Bom3.CheckChilType(ItemCode:string);//检查子项属性
var
  sSQL:string;
begin
  sSQL:=' select ItemType from Item where ItemCode='+QuotedStr(ItemCode);
  with AdoQry_tmp do
  begin
    Close;
    SQL.clear;
    SQL.Add(sSQL);
    Open;
    if fieldbyname('ItemType').AsInteger=5 then
    begin
      DispInfo('劳务不允许挂入Bom',1);
      Extedt_ItemCode.SetFocus;
      abort;
    end;
  end;
end;


end.


⌨️ 快捷键说明

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