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

📄 mrp_enter_assignalternative.pas

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

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Entry_Body, Db, ActnList, AdODB, Grids, DBGridEh, StdCtrls,
  ExtCtrls, ComCtrls, ToolWin, Mask, ExtEdit, DBCtrls, ExtPrintReport;

Type
  TFrm_Mrp_Enter_AssignAlterNative = Class(TFrm_Base_Entry_Body)
    DBGridEh1: TDBGridEh;
    AdoQry_Head1: TAdoQuery;
    Lbl_SaleType: TLabel;
    Lbl_DeptName: TLabel;
    AdoQry_Temp: TAdoQuery;
    Label1: TLabel;
    lbl_Item: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label8: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    AdoQry_BodyItemCode: TStringField;
    AdoQry_BodySSDate: TDateTimeField;
    AdoQry_Bodyduedate: TDateTimeField;
    AdoQry_BodySSQty: TFloatField;
    AdoQry_BodyItemName: TStringField;
    AdoQry_BodyCurrentonhandInv: TFloatField;
    AdoQry_BodyUomName: TStringField;
    AdoQry_BodyPmType: TIntegerField;
    AdoQry_BodyReMainQty: TFloatField;
    AdoQry_BodyDeptVendorCode: TStringField;
    AdoQry_BodyBomqty: TFloatField;
    AdoQry_Bodyite_ItemCode: TStringField;
    AdoQry_BodyBomScrAp_Percent: TFloatField;
    procedure Act_SaveExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure DateCheck(Sender: TObject);
    procedure Act_DeleteLineExecute(Sender: TObject);
    procedure Act_QuitExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Act_ExcelExecute(Sender: TObject);
    procedure Act_ModifyExecute(Sender: TObject);
  private
    { Private declarations }
  public
    flag:integer;
    ite_Ssid:integer;
    ite_reMainqty:real;
    procedure SetStatus(CurrentStatus:String;var AnswerStatus,EnableControls:String); Override;
    procedure GetalterItem(AdoQry:TAdoQuery;ite_ItemCode:string);
    procedure getbyProduct(ItemCode:string;qty:real;MoLinedate,mostArtdate:string);
    procedure deletebyProduct(MoLineno:integer);
    function  existsItemss(ItemCode:string;releasedate:string):boolean;
    //是否已存在该物料约定交货日的建议下达信息
    procedure  sumItemss(ItemCode:string;releasedate:string;ssqty:real);
    //汇总该物料约定交货日的约定交货量
    procedure  insertss;
    //插入建议
    { Public declarations }
  end;

var
  Frm_Mrp_Enter_AssignAlterNative: TFrm_Mrp_Enter_AssignAlterNative;
implementation

uses  Sys_Global,Mrp_Enter_AssignAlterNative_D;

{$R *.DFM}
function checksymbol(Source:string;disptext:string):boolean;   //检查输入中是否有单引号
var
  i:integer;
  s:string;
begin
  s:=Trim(Source);
  for i:=1 to length(s) do
    if s[i]='''' then
    begin
      DispInfo(disptext+'中不能使用单引号!',1);
      Result:=False;
      exit;
    end;
  Result:=True;
end;


procedure TFrm_Mrp_Enter_AssignAlterNative.GetalterItem(AdoQry:TAdoQuery;ite_ItemCode:string);
var
  SqlText:String;
  I,j:Integer;
begin
  AdoQry_Tmp.Connection:=AdoQry.Connection;
  AdoQry_Body.Connection:=AdoQry.Connection;
  DbConnect:=AdoQry.Connection;
  AdoQry_Head1:=AdoQry;
  SqlText:=' Select Top 0 ss.*,Bom.Bomqty,Bom.BomScrAp_Percent,'
          +'Bom.ite_ItemCode,Item.CurrentonhandInv,Item.ItemName,Uom.UomName '
          +' From ss '
          +' Join Item On ss.ItemCode=Item.ItemCode '
          +' join Bom on ss.ItemCode=Bom.ite_ItemCode '
          +' Left Join Uom On Item.UomCode=Uom.UomCode';
  AdoQry_Body.Close;
  AdoQry_Body.SQL.Text:=SqlText;
  AdoQry_Body.Open;
      SqlText:=' Select Bom.*,Item.PmCode,Item.ItemName,Uom.UomName,Item.CurrentonhandInv,ldtime=case Item.PmCode when 0 then runlt when 3 then runlt else purchldtime end '
             +' From Bom  '
              +'  join Item on Bom.ItemCode=Item.ItemCode '
              +'  left outer join Uom on Item.UomCode=Uom.UomCode '
              +' Where ite_ItemCode='+quotedstr(ite_ItemCode);
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      AdoQry_Tmp.Open;
  while not AdoQry_tmp.Eof do
     begin
      J:=AdoQry_Tmp.fieldbyname('ldtime').AsInteger;
      AdoQry_Body.Append;
      AdoQry_Body.fieldbyname('ItemCode').AsString:=AdoQry_tmp.fieldbyname('ItemCode').AsString;
      AdoQry_Body.fieldbyname('ItemName').AsString:=AdoQry_tmp.fieldbyname('ItemName').AsString;
      AdoQry_Body.fieldbyname('UomName').AsString:=AdoQry_tmp.fieldbyname('UomName').AsString;
      AdoQry_Body.fieldbyname('SsQty').AsFloat:=0.0;
      AdoQry_Body.fieldbyname('Bomqty').AsFloat:=AdoQry_tmp.fieldbyname('Bomqty').asfloat;
      AdoQry_Body.fieldbyname('ite_ItemCode').AsString:=floattostr(AdoQry_tmp.fieldbyname('BomScrAp_Percent').Asfloat/100)+'%';
      AdoQry_Body.fieldbyname('BomScrAp_Percent').asfloat:=AdoQry_tmp.fieldbyname('BomScrAp_Percent').asfloat;
      AdoQry_Body.fieldbyname('PmType').Asinteger:=AdoQry_tmp.fieldbyname('PmCode').asinteger;
      AdoQry_Body.fieldbyname('CurrentonhandInv').AsFloat:=AdoQry_tmp.fieldbyname('CurrentonhandInv').asfloat;
      AdoQry_Body.fieldbyname('ssDate').Asstring:=label8.Caption;
      AdoQry_Body.fieldbyname('DeptVendorCode').Asstring:=AdoQry_Body.fieldbyname('DeptVendorCode').asstring;
      AdoQry_Body.fieldbyname('duedate').Asstring:=slCalendar(dbconnect,label8.Caption,J);
      AdoQry_Body.Post;
     // getbyProduct(AdoQry_Body.fieldbyname('ItemCode').AsString,AdoQry_Body.fieldbyname('MoQty').AsFloat,AdoQry_Body.fieldbyname('MoLineDate').Asstring,AdoQry_Body.fieldbyname('MoStArtWorkDate').Asstring);
      AdoQry_tmp.Next;
     end;
  DataSource.DataSet:=AdoQry_Body;
  dataSource.DataSet.First;
end;

procedure TFrm_Mrp_Enter_AssignAlterNative.Act_SaveExecute(Sender: TObject);
var
  SqlText:String;
  I:integer;
  BookmArk:string;
  bodymArk:string;
  TotalAssignqty:real;
  ite_TotalAssignqty:real;
begin
TotalAssignqty:=0;
ite_TotalAssignqty:=0;
 try
  bodymArk:=AdoQry_Body.BookmArk;
  If AdoQry_Body.RecordCount=0 Then
  begin
    DispInfo('没有行数据,不能保存!',3);
    Abort;
  end;
  AdoQry_Body.First;
  I:=0;
  While Not AdoQry_Body.Eof Do
  begin
    I:=I+1;
    TotalAssignqty:=TotalAssignqty+AdoQry_Body.fieldbyname('ssqty').asfloat;
    ite_TotalAssignqty:=ite_TotalAssignqty+AdoQry_Body.fieldbyname('ssqty').asfloat/(AdoQry_Body.fieldbyname('Bomqty').asfloat*(1+AdoQry_Body.fieldbyname('BomScrAp_Percent').asfloat/100));
    AdoQry_Body.Next;
  end; //校验数据
  AdoQry_Body.First;
  if TotalAssignqty=0 then
    begin
      DispInfo('分配建议下达总量必须大于0,请修改!',1);
      exit;
    end;
  if ite_TotalAssignqty>ite_reMainqty then
    begin
      DispInfo('替代件分配建议下达量不能超过父项系统建议余量,请修改!',1);
      exit;
    end;
  DbConnect.beginTrans;
    AdoQry_Body.First;
    While Not AdoQry_Body.Eof Do
    begin
       if AdoQry_Body.fieldbyname('ssqty').asfloat=0 then
        begin
         AdoQry_Body.Next;
         continue;
        end;
       if existsItemss(AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('ssdate').asstring) then
           sumItemss(AdoQry_Body.fieldbyname('ItemCode').asstring,AdoQry_Body.fieldbyname('ssdate').asstring,AdoQry_Body.fieldbyname('ssqty').asfloat)
       else insertss;
      AdoQry_Body.Next;
     end;
     sqltext:='update ss'
             +' set reMainqty=reMainqty-('+floattostr(ite_TotalAssignqty)+')'
             +' where ssid='+inttostr(ite_Ssid);
     Executesql(AdoQry_tmp,sqltext,1);
     If AdoQry_Head1.Locate('SsId',ite_Ssid,[loCaseInsensitive]) Then
           begin
          AdoQry_Head1.edit;
          AdoQry_Head1.fieldbyname('tMpssreMainqty').AsFloat:=AdoQry_Head1.fieldbyname('tMpssreMainqty').AsFloat-ite_TotalAssignqty;
          AdoQry_Head1.Post;
          end;
    DbConnect.CommitTrans;
    Act_Save.Enabled:=False;

    DispInfo('数据保存完毕!',3);
  Except
    If DbConnect.InTransaction Then
      DbConnect.RollBackTrans;
    DispInfo('保存数据失败,请重试!',1);
    Abort;
  end;
  Act_Save.Enabled:=False;
  AdoQry_Body.BookmArk:=bodymArk;
  self.Close;
end;

procedure TFrm_Mrp_Enter_AssignAlterNative.FormCreate(Sender: TObject);
begin
  inherited;
  ExtendCaption:=False;
  Frm_Entry_Detail:=TFrm_Mrp_Enter_AssignAlterNative_D.Create(Self);
end;

procedure TFrm_Mrp_Enter_AssignAlterNative.SetStatus(CurrentStatus: String;
  var AnswerStatus, EnableControls: String);
begin
  inherited;
end;

procedure TFrm_Mrp_Enter_AssignAlterNative.DateCheck(Sender: TObject);
begin
  If (ActiveControl.Name='DBGridEh1') Or (ActiveControl.Name='ControlBar')  Then
    Exit;
  inherited;

end;

procedure TFrm_Mrp_Enter_AssignAlterNative.Act_DeleteLineExecute(Sender: TObject);
begin
  if AdoQry_Body.RecordCount=0 then exit;
  If DispInfo('确认真的要删除这行吗?',2)<>'y' Then
    Abort;
  AdoQry_Body.Delete;
end;

procedure TFrm_Mrp_Enter_AssignAlterNative.Act_QuitExecute(Sender: TObject);
begin
 Close;

end;

procedure TFrm_Mrp_Enter_AssignAlterNative.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
//  inherited;

end;

procedure TFrm_Mrp_Enter_AssignAlterNative.Act_ExcelExecute(Sender: TObject);
begin
  //inherited;
  DbGridEhToExcel(DbGridEh1);
end;




procedure TFrm_Mrp_Enter_AssignAlterNative.getbyProduct(ItemCode: string;qty:real;MoLinedate,mostArtdate:string);
var tmpAdoQry:TAdoQuery;
    tmPMoLineno:integer;

begin
  tmpAdoQry:=TAdoQuery.Create(Application);
  tmpAdoQry.EnableBCD:=False;
  try
    tmPMoLineno:=AdoQry_Body.RecordCount;
    with tmpAdoQry do
    begin
      Close;
      Connection:=dbconnect;
      sql.clear;
      sql.Text:='select Bom.ItemCode,    '
              +'        Item.ItemName, '
              +'        Bom.Bomqty,   '
              +'        Uom.UomName  '
              +' from Bom '
              +' join Item on Bom.ItemCode=Item.ItemCode '
              +' left outer join Uom on Item.UomCode=Uom.UomCode '
              +' where ite_ItemCode='+quotedstr(ItemCode)
               +' and BomItemType=4';
      Prepared;
      open;
      if recordCount=0 then exit;
      First;
        while not eof do
        begin
          AdoQry_Body.Append;
          AdoQry_Body.fieldbyname('MoLineNo').AsInteger:=AdoQry_Body.RecordCount+1;
          AdoQry_Body.fieldbyname('LimItOut').AsInteger:=99999999;
          AdoQry_Body.fieldbyname('ItemCode').AsString:=fieldbyname('ItemCode').AsString;
          AdoQry_Body.fieldbyname('ItemName').AsString:=fieldbyname('ItemName').AsString;
          AdoQry_Body.fieldbyname('UomName').AsString:=fieldbyname('UomName').AsString;
          AdoQry_Body.fieldbyname('SsQty').AsFloat:=qty*fieldbyname('Bomqty').asfloat;
          AdoQry_Body.fieldbyname('MoQty').AsFloat:=qty*fieldbyname('Bomqty').asfloat;
          AdoQry_Body.fieldbyname('MoNoFinishQty').AsFloat:=qty*fieldbyname('Bomqty').asfloat;
          AdoQry_Body.fieldbyname('MoLineStatus').AsInteger:=5;
          AdoQry_Body.fieldbyname('MoLineDate').Asstring:=MoLinedate;
          AdoQry_Body.fieldbyname('MoStArtWorkDate').Asstring:=mostArtdate;
          AdoQry_Body.fieldbyname('byProduct').Asinteger:=1;
          AdoQry_Body.fieldbyname('ParentMoLineno').Asinteger:=tmPMoLineno;
          AdoQry_Body.Post;
           next;
        end;
         AdoQry_Body.First;
    end;

  finally
    tmpAdoQry.Free;
  end;

end;

procedure TFrm_Mrp_Enter_AssignAlterNative.deletebyProduct(MoLineno: integer);
var tmPmArk:string;
    tmplineno:integer;
    Count:integer;
begin
   tmPmArk:=AdoQry_Body.BookmArk;
   Count:=AdoQry_Body.RecordCount;
  tmplineno:=AdoQry_Body.fieldbyname('MoLineno').asinteger;
  with AdoQry_Body do
    begin
      First;
      while Count>0  do
        begin
          if AdoQry_Body.fieldbyname('ParentMoLineno').asinteger=tmplineno then
            AdoQry_Body.Delete;
          next;
          Count:=Count-1;
        end;
    end;
  AdoQry_Body.BookmArk:=tmPmArk;
end;

procedure TFrm_Mrp_Enter_AssignAlterNative.Act_ModifyExecute(
  Sender: TObject);
var BookmArk:string;
begin
try
  BookmArk:=AdoQry_Body.BookmArk;
  inherited;
finally
 activecontrol:=dbgrideh;
 dbgrideh.SetFocus;
 AdoQry_Body.BookmArk:=BookmArk;
end;

end;



procedure TFrm_Mrp_Enter_AssignAlterNative.sumItemss(ItemCode,
  releasedate: string; ssqty: real);
var tmpQry:TAdoQuery;
    sqltext:string;
begin
  if not existsItemss(ItemCode,releasedate) then exit;
  tmpQry:=TAdoQuery.Create(self);
  tmpQry.Connection:=dbconnect;
  sqltext:='update ss'
          +'  set  ssqty=ssqty+'+floattostr(ssqty)+','
          +'       reMainqty=reMainqty+'+floattostr(ssqty)
          +' where ItemCode='+quotedstr(ItemCode)
          +'   and ssdate='+quotedstr(releasedate)
          +'   and ssSysInfoflag=1 ';
  try
    Executesql(tmpQry,sqltext,1);
  finally
   tmpQry.Free;
  end;
end;

procedure TFrm_Mrp_Enter_AssignAlterNative.insertss;
var sqltext:string;
begin
      SqlText:='insert into  Ss(ItemCode,ssSysInfoflag,ssdate,PmType,duedate,ssqty,reMainqty) '
              +'Values('+quotedstr(AdoQry_Body.fieldbyname('ItemCode').asstring)+','
                        +'1,'
                        +quotedstr(AdoQry_Body.fieldbyname('ssdate').asstring)+','
                        +inttostr(AdoQry_Body.fieldbyname('PmType').asinteger)+','
                        +quotedstr(AdoQry_Body.fieldbyname('duedate').asstring)+','
                        +floattostr(AdoQry_Body.fieldbyname('ssqty').asfloat)+','
                        +floattostr(AdoQry_Body.fieldbyname('ssqty').asfloat)+')';
      AdoQry_Tmp.Close;
      AdoQry_Tmp.SQL.Text:=SqlText;
      try
      AdoQry_Tmp.ExecSQL;
      except
      end;

end;

function TFrm_Mrp_Enter_AssignAlterNative.existsItemss(ItemCode,
  releasedate: string): boolean;
var AdoQry:TAdoQuery;
    sqltext:string;
begin
 Result:=False;
 AdoQry:=TAdoQuery.Create(nil);
 AdoQry.Connection:=AdoQry_Body.Connection;
 sqltext:='select * from ss '
          +' where ItemCode='+quotedstr(ItemCode)
          +'   and ssdate='+quotedstr(releasedate)
          +'   and ssSysInfoflag=1 ';
 try
  Executesql(AdoQry,sqltext,0);
  if AdoQry.RecordCount>0 then Result:=True;
 finally
  AdoQry.Free;
 end;

end;

end.

⌨️ 快捷键说明

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