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

📄 mrp_enter_assignalternative1.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Mrp_Enter_AssignAlterNative1;
//
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, jpeg;

Type
  TFrm_Mrp_Enter_AssignAlterNative1 = Class(TFrm_Base_Entry_Body)
    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_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;
    AdoQry_BodySSQty: TFloatField;
    Panel1: TPanel;
    DBGridEh1: TDBGridEh;
    Splitter1: TSplitter;
    DataSource1: TDataSource;
    AdoQry_Body1: TAdoQuery;
    StringField1: TStringField;
    DateTimeField1: TDateTimeField;
    DateTimeField2: TDateTimeField;
    StringField2: TStringField;
    FloatField1: TFloatField;
    StringField3: TStringField;
    IntegerField1: TIntegerField;
    FloatField2: TFloatField;
    StringField4: TStringField;
    FloatField3: TFloatField;
    StringField5: TStringField;
    FloatField4: TFloatField;
    FloatField5: TFloatField;
    AdoQry_Body1SSSysInfoFlag: TIntegerField;
    AdoQry_Body1BomItemType: TIntegerField;
    btn_fmo: TButton;
    procedure Act_SaveExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure DateCheck(Sender: TObject);
    procedure Act_DeleteLineExecute(Sender: TObject);
    procedure Act_QuitExecute(Sender: TObject);
    procedure Act_ExcelExecute(Sender: TObject);
    procedure Act_ModifyExecute(Sender: TObject);
    procedure AdoQry_BodyAfterScroll(DataSet: TDataSet);
    procedure AdoQry_BodyAfterPost(DataSet: TDataSet);
    procedure btn_fmoClick(Sender: TObject);
    procedure FormActivate(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(AdoQry:TAdoQuery);
    procedure  insertss1;
    //插入建议
    function existsvir(ItemCode:string):boolean;
    function savess(ItemCode,duedate:string;Ssqty:Double):boolean;
    { Public declarations }
    procedure  insertItemss(ItemCode,ssdate,duedate,DeptVendorCode:string;
                            PmType:integer;ssqty:double);
    { Public declarations }
  end;

var
  Frm_Mrp_Enter_AssignAlterNative1: TFrm_Mrp_Enter_AssignAlterNative1;
implementation

uses  Sys_Global,Mrp_Enter_AssignAlterNative1_D,Mrp_Enter_AssignAlterNative_Mo;

{$R *.DFM}
procedure TFrm_Mrp_Enter_AssignAlterNative1.insertItemss(ItemCode,ssdate,duedate,DeptVendorCode:string;
                            PmType:integer;ssqty:double);
    function getgroupordinal(ItemCode:string):integer;
      begin
       Result:=0;
       try
       Executesql(AdoQry_tmp,'select groupordinal from MrpResult where ItemCode='+quotedstr(ItemCode),0);
       Result:=AdoQry_tmp.fieldbyname('groupordinal').asinteger;
       except
       Result:=0;
       end;
      end;
var sqltext:string;
begin
  SqlText:='insert into  MrpResult(groupordinal,ItemCode,ordinal,releasedate,PmCode,duedate,onhand,reMainqty,DeptVendorCode,pegging,sScheck,canpegging) '
          +'Values('+inttostr(getgroupordinal(ItemCode))+','
                    +quotedstr(ItemCode)+','
                    +'3,'
                    +quotedstr(ssdate)+','
                    +inttostr(PmType)+','
                    +quotedstr(duedate)+','
                    +floattostr(ssqty)+','
                    +floattostr(ssqty)+','
                    +quotedstr(DeptVendorCode)+','
                    +quotedstr('系统建议下达')+','
                    +'0,0'
                    +')';
  AdoQry_Tmp.Close;
  AdoQry_Tmp.SQL.Text:=SqlText;
  try
  AdoQry_Tmp.ExecSQL;
  except
  end;
end;


function TFrm_Mrp_Enter_AssignAlterNative1.savess(ItemCode,duedate:string;Ssqty:double):boolean;
var AdoQry,AdoQry1:TAdoQuery;
    SqlText:String;
    j:integer;
begin
  AdoQry := TAdoQuery.Create(self);
  AdoQry.Connection := Dbconnect;
  AdoQry.EnableBCD:=False;
  AdoQry1 := TAdoQuery.Create(self);
  AdoQry1.Connection := Dbconnect;
  AdoQry1.EnableBCD:=False;
  try
    SqlText:=' Select Top 0 MrpResult.*,MrpResult.duedate as ssdate,MrpResult.PmCode as PmType,Bom.Bomqty,Bom.BomScrAp_Percent,'
            +' Bom.ite_ItemCode,Bom.Bomqty as ssqty,Bom.BomItemType as ssSysInfoflag,Item.CurrentonhandInv,Item.ItemName,Uom.UomName '
            +' From MrpResult '
            +' Join Item On MrpResult.ItemCode=Item.ItemCode '
            +' join Bom on MrpResult.ItemCode=Bom.ite_ItemCode '
            +' Left Join Uom On Item.UomCode=Uom.UomCode';
    Executesql(AdoQry,sqltext,0);
    SqlText:=' Select Bom.*,Item.PmCode,Bom.BomItemType as ssSysInfoflag,Item.ItemName,Uom.UomName,Item.CurrentonhandInv,ldtime=Preparelt+runlt+Qclt '
            +' From Bom  '
            +'  join Item on Bom.ItemCode=Item.ItemCode '
            +'  left outer join Uom on Item.UomCode=Uom.UomCode '
            +' Where ite_ItemCode='+quotedstr(ItemCode);
    Executesql(AdoQry1,sqltext,0);
    while not AdoQry1.Eof do
    begin
      J:=AdoQry_Temp.fieldbyname('ldtime').AsInteger;
      AdoQry.Append;
      AdoQry.fieldbyname('ItemCode').AsString:=AdoQry1.fieldbyname('ItemCode').AsString;
      AdoQry.fieldbyname('ItemName').AsString:=AdoQry1.fieldbyname('ItemName').AsString;
      AdoQry.fieldbyname('UomName').AsString:=AdoQry1.fieldbyname('UomName').AsString;
      AdoQry.fieldbyname('ssSysInfoflag').asinteger:=j;
      AdoQry.fieldbyname('Bomqty').AsFloat:=AdoQry1.fieldbyname('Bomqty').asfloat;
      AdoQry.fieldbyname('ite_ItemCode').AsString:=floattostr(AdoQry1.fieldbyname('BomScrAp_Percent').Asfloat/100)+'%';
      AdoQry.fieldbyname('BomScrAp_Percent').asfloat:=AdoQry1.fieldbyname('BomScrAp_Percent').asfloat;
      AdoQry.fieldbyname('PmType').Asinteger:=AdoQry1.fieldbyname('PmCode').asinteger;
      AdoQry.fieldbyname('CurrentonhandInv').AsFloat:=AdoQry1.fieldbyname('CurrentonhandInv').asfloat;
      AdoQry.fieldbyname('ssDate').Asstring:=duedate;
      AdoQry.fieldbyname('DeptVendorCode').Asstring:=AdoQry.fieldbyname('DeptVendorCode').asstring;
      AdoQry.fieldbyname('duedate').Asstring:=slCalendar(dbconnect,duedate,J);
      AdoQry.fieldbyname('ssqty').AsFloat:=ssqty*AdoQry_Body1.fieldbyname('Bomqty').asfloat*(1+AdoQry_Body1.fieldbyname('BomScrAp_Percent').asfloat/100.00);
      AdoQry.Post;
     // getbyProduct(AdoQry_Body.fieldbyname('ItemCode').AsString,AdoQry_Body.fieldbyname('MoQty').AsFloat,AdoQry_Body.fieldbyname('MoLineDate').Asstring,AdoQry_Body.fieldbyname('MoStArtWorkDate').Asstring);
      AdoQry1.Next;
    end;
    AdoQry.First;
    while not AdoQry.Eof do
    begin
      if existsItemss(AdoQry.fieldbyname('ItemCode').asstring,AdoQry.fieldbyname('ssdate').asstring) then
         sumItemss(AdoQry.fieldbyname('ItemCode').asstring,AdoQry.fieldbyname('ssdate').asstring,AdoQry.fieldbyname('ssqty').asfloat)
      else 
        insertItemss(AdoQry.fieldbyname('ItemCode').asstring,
                     AdoQry.fieldbyname('ssdate').asstring,
                     AdoQry.fieldbyname('duedate').asstring,
                     AdoQry.fieldbyname('DeptVendorCode').asstring,
                     AdoQry.fieldbyname('PmType').asinteger,
                     AdoQry.fieldbyname('ssqty').asfloat);
      if existsvir(AdoQry.fieldbyname('ItemCode').asstring) then
        savess(AdoQry.fieldbyname('ItemCode').asstring,
               AdoQry.fieldbyname('duedate').asstring,
               AdoQry.fieldbyname('ssqty').asfloat);
      AdoQry.next;
    end;
  finally
    AdoQry.Free;
    AdoQry1.free;
  end;
end;

function TFrm_Mrp_Enter_AssignAlterNative1.existsvir(ItemCode:string):boolean;
var sqltext:string;
begin
  Result:=False;
  sqltext:='select * from Bom where BomItemType=3 and ite_ItemCode='+quotedstr(ItemCode);
  Executesql(AdoQry_tmp,sqltext,0)    ;
  if AdoQry_tmp.RecordCount<>0 then Result:=True;
end;

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_AssignAlterNative1.GetalterItem(AdoQry:TAdoQuery;ite_ItemCode:string);
var
  SqlText:String;
  I,j:Integer;
begin
  AdoQry_Tmp.Connection:=AdoQry.Connection;
  AdoQry_Temp.Connection:=AdoQry.Connection;
  AdoQry_Body.Connection:=AdoQry.Connection;
  AdoQry_Body1.Connection:=AdoQry.Connection;
  DbConnect:=AdoQry.Connection;
  AdoQry_Head1:=AdoQry;
  AdoQry_Head:=AdoQry;
  SqlText:=' Select Top 0 #tmpalterssInfo.*,Bom.Bomqty,Bom.BomScrAp_Percent,'
          +'Bom.ite_ItemCode,Item.CurrentonhandInv,Item.ItemName,Uom.UomName '
          +' From #tmpalterssInfo '
          +' Join Item On #tmpalterssInfo.ItemCode=Item.ItemCode '
          +' join Bom on #tmpalterssInfo.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=Preparelt+runlt+Qclt '
          +' 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_AssignAlterNative1.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.DisableControls;
    AdoQry_Body1.DisableControls;
    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);
{        AdoQry_Body1.First;
        while not AdoQry_Body1.eof do
        begin
          if existsItemss(AdoQry_Body1.fieldbyname('ItemCode').asstring,AdoQry_Body1.fieldbyname('ssdate').asstring) then
             sumItemss(AdoQry_Body1.fieldbyname('ItemCode').asstring,AdoQry_Body1.fieldbyname('ssdate').asstring,AdoQry_Body1.fieldbyname('ssqty').asfloat)
          else insertss1;
          AdoQry_Body1.Next;
        end;           }
       if existsvir(AdoQry_Body.fieldbyname('ItemCode').asstring) then
        savess(AdoQry_Body.fieldbyname('ItemCode').asstring,
               AdoQry_Body.fieldbyname('duedate').asstring,
               AdoQry_Body.fieldbyname('ssqty').asfloat);
        AdoQry_Body.Next;
      end;
    sqltext:='update MrpResult '
            +' set reMainqty=reMainqty-('+floattostr(ite_TotalAssignqty)+')'
            +' where MrpResultid='+inttostr(ite_Ssid);
    Executesql(AdoQry_tmp,sqltext,1);

⌨️ 快捷键说明

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