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

📄 mrp_enter_passmps.pas

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

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Check, Menus, Db, ActnList, AdODB, Grids, DBGridEh, StdCtrls,
  ExtCtrls, ComCtrls, ToolWin, DBCtrls;

Type
  TFrm_Mrp_Enter_PassMps = Class(TFrm_Base_Check)
    AdoQry_HeadMpsId: TBCDField;
    AdoQry_HeadMpsMonth: TStringField;
    AdoQry_HeadItemCode: TStringField;
    AdoQry_HeadMpsDATE: TDateTimeField;
    AdoQry_HeadMpsQTY: TFloatField;
    AdoQry_HeadMpsStatus: TIntegerField;
    AdoQry_HeadMpsFinishQty: TFloatField;
    AdoQry_HeadMpsOutQty: TFloatField;
    AdoQry_HeadMpsRemArk: TStringField;
    AdoQry_HeadItemName: TStringField;
    AdoQry_HeadUomName: TStringField;
    AdoQry_HeadMpsNoFinishQty: TFloatField;
    AdoQry_HeadItemflag: TStringField;
    DBText2: TDBText;
    Label2: TLabel;
    Label3: TLabel;
    Label1: TLabel;
    DBText1: TDBText;
    DBText3: TDBText;
    AdoQry_HeadMpScheck: TIntegerField;
    procedure FormDestroy(Sender: TObject);
    procedure Act_CheckExecute(Sender: TObject);
    procedure Act_CancelCheckExecute(Sender: TObject);
    procedure DBGridEhDblClick(Sender: TObject);
    procedure DBGridEhTitleClick(Column: TColumnEh);
    procedure AdoQry_HeadBeforeInsert(DataSet: TDataSet);
    procedure FormCreate(Sender: TObject);
    procedure Act_ExcelExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    Flag:Boolean;
    Function SaveHistory:Boolean;
    { Private declarations }
  public
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
    { Public declarations }
  end;

var
          Frm_Mrp_Enter_PassMps: TFrm_Mrp_Enter_PassMps;

implementation

uses Sys_Global;

{$R *.DFM}
Function TFrm_Mrp_Enter_PassMps.SaveHistory; //保存历史记录
var
  Sqltext:String;
begin
  Try
    SqlText:='Insert MpsHistory '
            + ' (MpsMonth,ItemCode,Mpsdate,Mpsqty,Mpsstatus,'
            + ' MpsremArk,MpSchgEmployeeCode,MpSchgTime,MpsId,MpSchgType)'
            + ' Values('
            + ''''+AdoQry_Head.fieldbyname('MpsMonth').AsString+''','
            +''''+AdoQry_Head.fieldbyname('ItemCode').AsString+''','
            +''''+DateTimeToStr(AdoQry_Head.fieldbyname('MpsDate').AsDateTime)+''','
            +''''+FormatFloat('##0.##',AdoQry_Head.fieldbyname('MpsQty').AsFloat)+''','
            +''''+IntToStr(AdoQry_Head.fieldbyname('MpsStatus').AsInteger)+''','
            +''''+AdoQry_Head.fieldbyname('MpsRemArk').AsString+''''+','
            +''''+UserCode+''''+','
            +'Getdate(),'
            +''''+IntToStr(AdoQry_Head.fieldbyname('Mpsid').AsInteger)+''','''+'更改行状态'+''')';
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.Text:=SqlText;
    AdoQry_Tmp.ExecSQL;
    Result:=True;
  Except
    Result:=False;
  end;
end;


procedure TFrm_Mrp_Enter_PassMps.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
var sqltext:string;
begin
  Application.ProcessMessages;
  Inherited;
  sqltext:=' Select Mps.*,Item.ItemName,Item.ItemCode+'''+' '+'''+Item.ItemName As ItemFlag,Uom.UomName,MpsNoFinishQty=MpsQty-MpsFinishQty '
               +' into #tmPmpsPass '
                +' From Mps '
                +' Join Item On Mps.ItemCode=Item.ItemCode'
                +' Join Uom On Item.UomCode=Uom.UomCode'
           +' where (MpsStatus=2 or MpsStatus=3) '
           +' Order by MpsMonth,Mps.ItemCode,MpsDate';
 Executesql(AdoQry_Head,sqltext,1);
 selectfromsql:='select * from #tmPmpsPass';
 Executesql(AdoQry_Head,'select * from #tmPmpsPass',0);
 Flag:=False;
end;

procedure TFrm_Mrp_Enter_PassMps.FormDestroy(Sender: TObject);
begin
  inherited;
  Frm_Mrp_Enter_PassMps:=Nil;
end;

procedure TFrm_Mrp_Enter_PassMps.Act_CheckExecute(Sender: TObject);
var
  SqlText,BookMArk:String;
  I:Integer;
begin
  inherited;
  If AdoQry_Head.RecordCount=0 Then
    Abort;
  BookMArk:=AdoQry_Head.BookmArk;
  If DispInfo('确认批准选定的主生产计划吗?',2)='y' Then
  begin
    Dbconnect.beginTrans;
    I:=1;
    Try
      AdoQry_Head.First;
      While Not AdoQry_Head.Eof Do
        If (AdoQry_Head.fieldbyname('MpScheck').AsInteger=1) And (AdoQry_Head.fieldbyname('MpsStatus').AsInteger=2) Then
        begin
          SqlText:=' Select * From Mps Where MpsId='''+IntToStr(AdoQry_Head.fieldbyname('MpsId').AsInteger)+'''';
//                  +' And MpsStatus=2 ';
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:=SqlText;
          AdoQry_Tmp.Open;
          If AdoQry_Tmp.Eof Then
          begin
            If DbConnect.InTransaction Then
              DbConnect.RollBackTrans;
              DispInfo('选定的第'+IntToStr(I)+'条主生产计划已被删除,请刷新!',3);
              Abort;
          end
          else
          begin
            if AdoQry_Tmp.fieldbyname('MpsStatus').AsInteger <> 2 then
              begin
                If DbConnect.InTransaction Then
                  DbConnect.RollBackTrans;
                  DispInfo('选定的第'+IntToStr(I)+'条主生产计划行状态已被其它用户修改,请刷新!',3);
                  Abort;
              end
          end;
          {If AdoQry_Tmp.Eof Then
          begin
            If DbConnect.InTransaction Then
              DbConnect.RollBackTrans;
            DispInfo('选定的第'+IntToStr(I)+'条主生产计划行状态已被其它用户修改,请刷新!',3);
            Abort;
          end;}
          //SaveHistory;
          saveMpshistory(dbconnect,AdoQry_Head.fieldbyname('Mpsid').asinteger,userCode,3);
          SqlText:='Update Mps '
                  +' set MpsStatus=3 '
                  +' Where MpsId='''+IntToStr(AdoQry_Head.fieldbyname('MpsId').AsInteger)+''''
                  +' And MpsStatus=2 ';
          AdoQry_tmp.Close;
          AdoQry_tmp.SQL.Text:=SqlText;
          AdoQry_tmp.ExecSQL;
          SqlText:='Update #tmPmpsPass '
                  +' set MpsStatus=3 '
                  +' Where MpsId='''+IntToStr(AdoQry_Head.fieldbyname('MpsId').AsInteger)+''''
                  +' And MpsStatus=2 ';
          AdoQry_tmp.Close;
          AdoQry_tmp.SQL.Text:=SqlText;
          AdoQry_tmp.ExecSQL;
          AdoQry_Head.Edit;
          AdoQry_Head.fieldbyname('MpsStatus').AsInteger:=3;
          AdoQry_Head.fieldbyname('MpScheck').AsInteger:=0;
          AdoQry_Head.Post;
          I:=I+1;
          AdoQry_Head.Next;
        end
        Else
        begin
          I:=I+1;
          AdoQry_Head.Next;
        end;
      DbConnect.CommitTrans;
    Except
      If DbConnect.InTransaction Then
        DbConnect.RollBackTrans;
      DispInfo('更改数据时发生错误,数据未更改,请重试!',1);
      AdoQry_Head.BookMArk:=BookmArk;
      Abort;
    end;
  end;
  AdoQry_Head.BookMArk:=BookmArk;
  Flag:=Not Flag;
end;

procedure TFrm_Mrp_Enter_PassMps.Act_CancelCheckExecute(Sender: TObject);
var
  SqlText,BookMArk:String;
  I:Integer;
begin
  inherited;
   If AdoQry_Head.RecordCount=0 Then
    Abort;
  BookMArk:=AdoQry_Head.BookmArk;
  If DispInfo('确认取消批准选定主生产计划吗?',2)='y' Then
  begin
    DbConnect.beginTrans;
    I:=1;
    Try
      AdoQry_Head.First;
      While Not AdoQry_Head.Eof Do
        If (AdoQry_Head.fieldbyname('MpScheck').AsInteger=1)
            And (AdoQry_Head.fieldbyname('MpsStatus').AsInteger=3)
             Then
        begin
          SqlText:=' Select * From Mps Where MpsId='''+IntToStr(AdoQry_Head.fieldbyname('MpsId').AsInteger)+'''';
            //        +' And MpsStatus=3 and (MpsFinishQty=0) ';
          AdoQry_Tmp.Close;
          AdoQry_Tmp.SQL.Text:=SqlText;
          AdoQry_Tmp.Open;
          If AdoQry_Tmp.Eof Then
          begin
            If DbConnect.InTransaction Then
              DbConnect.RollBackTrans;
              DispInfo('选定的第'+IntToStr(I)+'条主生产计划已被删除,请刷新!',3);
              exit;
          end
          else
          begin
            if AdoQry_Tmp.fieldbyname('MpsStatus').asfloat <> 3 then
              begin
                If DbConnect.InTransaction Then
                  DbConnect.RollBackTrans;
                  DispInfo('选定的第'+IntToStr(I)+'条主生产计划行状态已被其它用户修改,请刷新!',3);
                  exit;
              end
            else
              if AdoQry_Tmp.fieldbyname('MpsFinishQty').AsString<>'0' then
                begin
                If DbConnect.InTransaction Then
                  DbConnect.RollBackTrans;
                  DispInfo('选定的第'+IntToStr(I)+'条主生产计划约定交货量不等于未结量,'+chr(13)+'不能取消批准!',3);
                  exit;
                end;
          end;

         { If AdoQry_Tmp.Eof Then
          begin
            If DbConnect.InTransaction Then
              DbConnect.RollBackTrans;
            DispInfo('选定的第'+IntToStr(I)+'条主生产计划行状态已被其它用户修改,请刷新!',3);
            Abort;
          end; }
          saveMpshistory(dbconnect,AdoQry_Head.fieldbyname('Mpsid').asinteger,userCode,4);
          SqlText:='Update Mps '
                  +' set MpsStatus=2 '
                  +' Where MpsId='''+IntToStr(AdoQry_Head.fieldbyname('MpsId').AsInteger)+''''
                  +' And MpsStatus=3 ';
          AdoQry_tmp.Close;
          AdoQry_tmp.SQL.Text:=SqlText;
          AdoQry_tmp.ExecSQL;
          SqlText:='Update #tmPmpsPass '
                  +' set MpsStatus=2 '
                  +' Where MpsId='''+IntToStr(AdoQry_Head.fieldbyname('MpsId').AsInteger)+''''
                  +' And MpsStatus=3 ';
          AdoQry_tmp.Close;
          AdoQry_tmp.SQL.Text:=SqlText;
          AdoQry_tmp.ExecSQL;
           AdoQry_Head.Edit;
          AdoQry_Head.fieldbyname('MpsStatus').AsInteger:=2;
          AdoQry_Head.fieldbyname('MpScheck').AsInteger:=0;
          AdoQry_Head.Post;
          I:=I+1;
        end
        Else
        begin
          I:=I+1;
          AdoQry_Head.Next;
        end;
      DbConnect.CommitTrans;
    Except
      If DbConnect.InTransaction Then
        DbConnect.RollBackTrans;
      DispInfo('更改数据时发生错误,数据未更改,请重试!',1);
      AdoQry_Head.BookMArk:=BookmArk;
      Abort;
    end;
  end;
  AdoQry_Head.BookMArk:=BookmArk;
  Flag:=Not Flag;
end;

procedure TFrm_Mrp_Enter_PassMps.DBGridEhDblClick(Sender: TObject);
begin
  inherited;
   If AdoQry_Head.RecordCount=0 Then
    Abort;
  If AdoQry_Head.fieldbyname('MpsStatus').AsInteger=2 then
    Act_CheckExecute(Act_Check)
  Else
    Act_CancelCheckExecute(Act_CancelCheck);
end;

procedure TFrm_Mrp_Enter_PassMps.DBGridEhTitleClick(Column: TColumnEh);
var
  BookMArk:String;
begin
  inherited;
  If Trim(Column.Title.Caption)<>'标记' Then
    Abort;
  If AdoQry_Head.RecordCount=0 Then
    Abort;
  BookMArk:=AdoQry_Head.BookmArk;
  If Not Flag Then
  begin
    AdoQry_Head.First;
    While Not AdoQry_Head.Eof Do
    begin
      AdoQry_Head.Edit;
      AdoQry_Head.fieldbyname('MpScheck').AsInteger:=1;
      AdoQry_Head.Post;
      AdoQry_Head.Next;
    end;
  end
  Else
  begin
    AdoQry_Head.First;
    While Not AdoQry_Head.Eof Do
    begin
      AdoQry_Head.Edit;
      AdoQry_Head.fieldbyname('MpScheck').AsInteger:=0;
      AdoQry_Head.Post;
      AdoQry_Head.Next;
    end;
  end;
  AdoQry_Head.BookmArk:=BookMArk;
  Flag:=Not Flag;
end;

procedure TFrm_Mrp_Enter_PassMps.AdoQry_HeadBeforeInsert(
  DataSet: TDataSet);
begin
  inherited;
  Abort;
end;

procedure TFrm_Mrp_Enter_PassMps.FormCreate(Sender: TObject);
begin
  inherited;
ToolButton6.Action:=act_excel;
end;

procedure TFrm_Mrp_Enter_PassMps.Act_ExcelExecute(Sender: TObject);
begin
 // inherited;
 dbgridehtoexcel(dbgrideh);
end;

procedure TFrm_Mrp_Enter_PassMps.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  inherited;
try
Executesql(AdoQry_tmp,'drop table #tmPmpsPass',1);
except
end;
end;

end.

⌨️ 快捷键说明

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