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

📄 pm_enter_passpo.pas

📁 一个MRPII系统源代码版本
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit Pm_Enter_PassPo;

Interface

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

Type
  TFrm_Pm_Enter_PassPo = Class(TFrm_Base_Check)
    AdoQry_HeadPONO: TStringField;
    AdoQry_HeadPOLINENo: TIntegerField;
    AdoQry_HeadItemCode: TStringField;
    AdoQry_HeadPOLineDATE: TDateTimeField;
    AdoQry_HeadPOQTY: TFloatField;
    AdoQry_HeadPONoFinishQty: TFloatField;
    AdoQry_HeadPOREFERENCEDPRICE: TIntegerField;
    AdoQry_HeadPOLINESTATUS: TIntegerField;
    AdoQry_HeadPoNoTaxPrice: TFloatField;
    AdoQry_HeadPONoTaxAmount: TBCDField;
    AdoQry_HeadPoTaxPrice: TFloatField;
    AdoQry_HeadPoTaxAmount: TBCDField;
    AdoQry_HeadPOStArtWorkDate: TDateTimeField;
    AdoQry_HeadVendorCode: TStringField;
    AdoQry_HeadVendorName: TStringField;
    AdoQry_HeadItemName: TStringField;
    AdoQry_HeadPoDate: TDateTimeField;
    AdoQry_HeadEmployeeCode: TStringField;
    AdoQry_HeadUomName: TStringField;
    AdoQry_HeadEmployeeFlag: TStringField;
    AdoQry_HeadItemFlag: TStringField;
    AdoQry_HeadVendorFlag: TStringField;
    Label2: TLabel;
    DBText2: TDBText;
    Label1: TLabel;
    DBText1: TDBText;
    Label3: TLabel;
    DBText3: TDBText;
    AdoQry_HeadPoLineCheck: TIntegerField;
    AdoQry_HeadSsQty: TFloatField;
    AdoQry_HeadPoRealInQty: TFloatField;
    AdoQry_HeadPoInQty: TFloatField;
    AdoQry_HeadCloseRemArk: TStringField;
    AdoQry_HeadPmCode: TIntegerField;
    AdoQry_HeadQclt: TIntegerField;
    Label4: TLabel;
    DBText4: TDBText;
    AdoQry_HeadEmployeeName2: TStringField;
    procedure Act_CancelCheckExecute(Sender: TObject);
    procedure Act_CheckExecute(Sender: TObject);
    procedure DBGridEhDblClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure DBGridEhTitleClick(Column: TColumnEh);
    procedure AdoQry_HeadBeforeInsert(DataSet: TDataSet);
    procedure Act_LookExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Act_DeleteExecute(Sender: TObject);
    procedure Act_ModifyExecute(Sender: TObject);
  private
    Flag:Boolean;
    Function  SavePoLineHistory(Status1:String):Boolean;//保存历史记录
    Function  SavePoLineHistory1(Status1:String):Boolean;//保存历史记录
    procedure CloseRecord; //关闭
    procedure OpenRecord; //打开
    procedure DeleteRecord;
    { Private declarations }
  public
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);Override;
    function getQclt(ItemCode:string):string;{ Public declarations }
    function beendilivered(pono:string;polineno:integer):boolean;
    procedure UpDatePoline(PoNo:string;PoLineNo:integer);
    { Public declarations }
  end;

var
  Frm_Pm_Enter_PassPo: TFrm_Pm_Enter_PassPo;

implementation

uses Sys_Global,Pm_Enter_PoSsParent, Pm_Enter_PassPo_D, Pm_Enter_PassPo_C,
  Mrp_Enter_MoSsParent;

{$R *.DFM}
procedure TFrm_Pm_Enter_PassPo.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
begin
  Application.ProcessMessages;
  Inherited;

  SelectFromSql:=' Select Distinct PoLine.*,Po.*,Vendor.VendorName,Item.ItemName,Item.PmCode,Item.QcLt,Employee.EmployeeName,Uom.UomName,'
                +' Employee.EmployeeCode+'''+' '+'''+Employee.EmployeeName As EmployeeFlag,'
                +' Item.ItemCode+'''+' '+'''+Item.ItemName As ItemFlag, '
                +' Vendor.VendorCode+'''+' '+'''+Vendor.VendorName As VendorFlag '
                +' From PoLine '
                +' Join Po On Po.PoNo=PoLine.PoNo '
                +' Join Item On PoLine.ItemCode=Item.ItemCode '
                +' And ((POLineStatus=5) Or (POLineStatus=6)) '
                +' Left Join Vendor On Po.VendorCode=Vendor.VendorCode '
                +' Left Join Employee On Employee.EmployeeCode=Po.EmployeeCode '
                +' Join Uom On Uom.UomCode=Item.UomCode ' ;

  ConditionUserDefine:=' (Po.PoNo  In (Select po.PoNo From Po join PoLine on Po.PoNo=PoLine.PoNo) and (po.PoSpecial=0) and (PoLine.POlinestatus in (5,6)))';
  Condition :='POLineStatus=5 ' ;
  OrderByFields:='EmployeeCode,PoNo';
  GetData;
  {Frm_Sys_Condition:=TFrm_Pm_Enter_PassPo_C.Create(Self);
  ConditionUserDefine:=' (Po.PoNo  In (Select po.PoNo From Po join PoLine on Po.PoNo=PoLine.PoNo) and (po.PoSpecial=0) and (PoLine.POlinestatus in (5,6)))';
  OrderByFields:='EmployeeCode,PoNo';
  Act_Filter.Execute;}
  Application.ProcessMessages;
  Flag:=False;
end;

Function TFrm_Pm_Enter_PassPo.SavePoLineHistory(Status1:String):Boolean;
var
  SqlText:String;
begin
  Try
    SqlText:='Insert PoLineHistory '
            +' (PoNo,PoLineNo,ItemCode,POLineDate,PoStArtWorkDate,POQty,POTaxPrice,POTaxAmount,PONoTaxPrice,'
            +' PONoTaxAmount,PONoFinishQty,POReferencedPrice,POLineStatus,PolChgEmployeeCode,PolChgTime,PolChgType)'
            +'Values('
            +''''+AdoQry_Head.fieldbyname('PoNo').AsString+''''+','
            +''''+IntToStr(AdoQry_Head.fieldbyname('PoLineNo').AsInteger)+''''+','
            +''''+AdoQry_Head.fieldbyname('ItemCode').AsString+''''+','
            +''''+DatetimeToStr(AdoQry_Head.fieldbyname('PoLineDate').AsDateTime)+''''+','
            +''''+DatetimeToStr(AdoQry_Head.fieldbyname('PoStArtWorkDate').AsDateTime)+''''+','
            +''''+FloatToStr(AdoQry_Head.fieldbyname('PoQty').AsFloat)+''''+','
            +''''+FloatToStr(AdoQry_Head.fieldbyname('POTaxPrice').AsFloat)+''''+','
            +''''+FloatToStr(AdoQry_Head.fieldbyname('POTaxAmount').AsFloat)+''''+','
            +''''+FloatToStr(AdoQry_Head.fieldbyname('PONoTaxPrice').AsFloat)+''''+','
            +''''+FloatToStr(AdoQry_Head.fieldbyname('PONoTaxAmount').AsFloat)+''''+','
            +''''+FloatToStr(AdoQry_Head.fieldbyname('PONoFinishQty').AsFloat)+''''+','
            +''''+IntToStr(AdoQry_Head.fieldbyname('POReferencedPrice').AsInteger)+''''+','
            +''''+IntToStr(AdoQry_Head.fieldbyname('POLineStatus').AsInteger)+''''+','
            +''''+UserCode+''''+','
            +'GetDate(),' ;
            if Status1='Edit' then
              SqlText:=SqlText+''''+'更改行状态'+''''+')'
            else
              if Status1='Delete' then
                SqlText:=SqlText+''''+'删除记录'+''''+')';
    AdoQry_Tmp.Close;
    AdoQry_Tmp.SQL.Text:=SqlText;
    AdoQry_Tmp.ExecSQL;
    Result:=True;
  Except
    Result:=False;
  end;
end;

procedure TFrm_Pm_Enter_PassPo.OpenRecord;
var
  SqlText,BookMArk:String;
  I:Integer;
begin
  BookMArk:=AdoQry_Head.BookmArk;
  DbConnect.beginTrans;
  AdoQry_Head.First;
  I:=1;
  Try
    While Not AdoQry_Head.Eof Do
      If (AdoQry_Head.fieldbyname('PoLineCheck').AsInteger=1)
        And (AdoQry_Head.fieldbyname('PoLineStatus').AsInteger=5) Then
       begin
         SqlText:=' Select * From PoLine '
              +' Where PoNo='''+AdoQry_Head.fieldbyname('PoNo').AsString+''''
              +' And PoLineNo='''+IntToStr(AdoQry_Head.fieldbyname('PoLineNo').AsInteger)+'''';
             // +' And PoLineStatus=5';
         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('PoLineStatus').AsInteger<> 5 then
             begin
               If DbConnect.InTransaction Then
                 DbConnect.RollBackTrans;
                 DispInfo('选定的第'+IntToStr(I)+'条采购订单记录行状态已被其它用户修改,请刷新!',3);
                 exit;
             end;
         end;
        { If AdoQry_Tmp.Eof Then
         begin
           If DbConnect.InTransaction Then
             DbConnect.RollBackTrans;
           DispInfo('选定的第'+IntToStr(I)+'条采购订单记录行状态已被其它用户修改,请刷新!',3);
           Abort;
         end;}
         SavePoLineHistory('Edit');
         SqlText:=' Update PoLine '
                 +' set PoLineStatus=6'
                 +' Where PoLine.PoNo='''+AdoQry_Head.fieldbyname('PoNo').AsString+''''
                 +' And PoLine.PoLineNo='''+AdoQry_Head.fieldbyname('PoLineNo').AsString+''''
                 +' And PoLine.PoLineStatus=5';
         AdoQry_Tmp.Close;
         AdoQry_Tmp.SQL.Text:=SqlText;
         AdoQry_Tmp.ExecSQL;
         AdoQry_Head.Edit;
         AdoQry_Head.fieldbyname('PoLineStatus').AsInteger:=6;
         AdoQry_Head.fieldbyname('PoLineCheck').AsInteger:=0;
         AdoQry_Head.Post;
         if  AdoQry_Head.fieldbyname('PmCode').AsInteger=2 then
         begin
           SqlText:='Delete OpItemList where pono='''+AdoQry_Head.fieldbyname('pono').AsString+''' '
                   +' and polineno='''+AdoQry_Head.fieldbyname('polineno').AsString+''' ';
           AdoQry_Tmp.Close;
           AdoQry_Tmp.SQL.Text:=SqlText;
           AdoQry_Tmp.ExecSQL;
           IF Not AutoBuildopListOrder(DbConnect,Trim(AdoQry_Head.fieldbyname('pono').AsString),Trim(AdoQry_Head.fieldbyname('ItemCode').AsString),IntToStr(AdoQry_Head.fieldbyname('PoLineNo').AsInteger),
             'Add','Po',AdoQry_Head.fieldbyname('PoQty').Asfloat) Then  //自动产生领料单
           Abort;
         end;
         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;
      AdoQry_Head.BookMArk:=BookmArk;
      DispInfo('更改数据时发生错误,数据未更改,请重试!',1);
      Abort;
  end;
  AdoQry_Head.BookMArk:=BookmArk;
  Flag:=Not Flag;
end;


procedure TFrm_Pm_Enter_PassPo.CloseRecord;
var
  SqlText,BookMArk:String;
  I:Integer;
begin
  BookMArk:=AdoQry_Head.BookmArk;
  I:=1;
  AdoQry_Head.First;
  DbConnect.beginTrans;
  Try
    While Not AdoQry_Head.Eof Do
    begin
     {If AdoQry_Head.fieldbyname('PoNoFinishQty').AsFloat<AdoQry_Head.fieldbyname('POQTY').AsFloat Then
      begin
        I:=I+1;
        AdoQry_Head.Next;
        Continue;
      end;}
      If (AdoQry_Head.fieldbyname('PoLineCheck').AsInteger=1)
        And (AdoQry_Head.fieldbyname('PoLineStatus').AsInteger=6) Then
       begin
         SqlText:=' Select * From PoLine '
              +' Where PoNo='''+AdoQry_Head.fieldbyname('PoNo').AsString+''''
              +' And PoLineNo='''+IntToStr(AdoQry_Head.fieldbyname('PoLineNo').AsInteger)+'''';
//              +' And PoLineStatus=6  and (PoQty=PoNoFinishQty )';
         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('PoLineStatus').asfloat<> 6 then
             begin
               If DbConnect.InTransaction Then
                 DbConnect.RollBackTrans;
                 DispInfo('选定的第'+IntToStr(I)+'条采购订单记录行状态已被其它用户修改,请刷新!',3);
                 exit;
             end
           else
             if AdoQry_Tmp.fieldbyname('PoQty').AsString<>AdoQry_Tmp.fieldbyname('PoNoFinishQty').AsString then
               begin
               If DbConnect.InTransaction Then
                 DbConnect.RollBackTrans;
                 DispInfo('选定的第'+IntToStr(I)+'条采购订单记录约定交货量不等于未结量,'+chr(13)+'不能取消批准!',3);
                 exit;
               end
           else if beendilivered(AdoQry_Head.fieldbyname('pono').asstring,AdoQry_Head.fieldbyname('polineno').asinteger) then
                       begin
                        If DbConnect.InTransaction Then
                          DbConnect.RollBackTrans;
                          DispInfo('选定的第'+IntToStr(I)+'条采购订单行已生产领料,不可取消批准!',3);
                          exit;
                       end;

         end;
          sqlText:=' Select Count(ItemCode) as aa from opItemList '
                   +' where PoRealQty>0 and pono='''+AdoQry_Head.fieldbyname('Pono').asstring+''' '
                   +' and polineno='''+AdoQry_Head.fieldbyname('Polineno').asstring+'''';
          AdoQry_tmp.Close;
          AdoQry_tmp.SQL.clear;
          AdoQry_tmp.SQL.Text := sqltext;
          AdoQry_tmp.Open ;
          if AdoQry_tmp.fieldbyname('aa').asinteger>0 then
          begin
            If DbConnect.InTransaction Then
                 DbConnect.RollBackTrans;
                 DispInfo('选定的第'+IntToStr(I)+'条采购订单记录的子项已领料,'+chr(13)+'不能取消批准!',3);
                 Abort;
          end;
         //
         SavePoLineHistory('Edit');
         SqlText:=' Update PoLine '
                 +' set PoLineStatus=5'
                 +' Where PoLine.PoNo='''+AdoQry_Head.fieldbyname('PoNo').AsString+''''
                 +' And PoLine.PoLineNo='''+AdoQry_Head.fieldbyname('PoLineNo').AsString+''''
                 +' And PoLine.PoLineStatus=6';
         AdoQry_Tmp.Close;
         AdoQry_Tmp.SQL.Text:=SqlText;
         AdoQry_Tmp.ExecSQL;
         AdoQry_Head.Edit;
         AdoQry_Head.fieldbyname('PoLineStatus').AsInteger:=5;
         AdoQry_Head.fieldbyname('PoLineCheck').AsInteger:=0;
         AdoQry_Head.Post;
         I:=I+1;
         AdoQry_Head.Next;
       end
       Else
       begin
         I:=I+1;
         AdoQry_Head.Next;
       end;
     end;
    DbConnect.CommitTrans;
  Except
    If DbConnect.InTransaction Then
      DbConnect.RollBackTrans;
      DispInfo('更改数据时发生错误,数据未更改,请重试!',1);
      AdoQry_Head.BookMArk:=BookmArk;
      Abort;
    end;
  AdoQry_Head.BookMArk:=BookmArk;

⌨️ 快捷键说明

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