ad_enter_depreciation.pas

来自「一个MRPII系统源代码版本」· PAS 代码 · 共 185 行

PAS
185
字号
unit Ad_Enter_Depreciation;

Interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Base_Condition, Db, AdODB, StdCtrls,Sys_Global;

Type
  TFrm_Ad_Enter_Depreciation = Class(TFrm_Base_Condition)
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    Edit2: TEdit;
    procedure btn_okClick(Sender: TObject);
    procedure btn_CancelClick(Sender: TObject);
  private
    { Private declarations }
    Function  ISDepreciation(R_AdoQry:TAdoQuery;R_StrDepreciationMonth:String):Integer;//计提月份
  public
    { Public declarations }
    procedure InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
  end;

var
  Frm_Ad_Enter_Depreciation: TFrm_Ad_Enter_Depreciation;

implementation

{$R *.DFM}
procedure TFrm_Ad_Enter_Depreciation.InitForm(AdOConnection:TAdOConnection;ReadOnly:Boolean);
var StrSqlText:String;
begin
  inherited;
  Caption:='计提折旧';
  AdoQry_Tmp.Connection:=AdOConnection;
  StrSqlText:='Select Top 1 * '+
                     'From Ad_MonthCheckout '+
                     'Order By YearMonth DESC';
  ExecuteSql(AdoQry_Tmp,StrSqltext,0);
  Edit2.Text:=AdoQry_Tmp.fieldbyname('YearMonth').AsString;
  Edit1.Text:=Copy(DateToStr(Date),1,7);


end;


Function  TFrm_Ad_Enter_Depreciation.ISDepreciation(R_AdoQry:TAdoQuery;R_StrDepreciationMonth:String):Integer;//计提月份
var StrSqlText:String;
    StrStartUseMonth:String;
    StrLastCheckoutMonth:String;
    IntCheckoutYear:Integer;
    IntCheckoutMonth:Integer;
    IntDepreciationYear:Integer;
    IntDepreciationMonth:Integer;
begin
  StrSqlText:='Select * '+
                     'From Ad_Param '+
                     'Where ParamCode=''StartUseAd'' And ParamValueN=1';
  ExecuteSql(R_AdoQry,StrSqltext,0);
  IF R_AdoQry.RecordCount=0 Then
  begin
    Result:=0;  //模块没有正式启用
    Exit;
  end;

  StrStartUseMonth:=R_AdoQry.fieldbyname('ParamValueC').AsString;
  IF StrStartUseMonth>R_StrDepreciationMonth  Then
  begin
     Result:=1;
     Exit; //计提月份小于模块启用月份
  end;

  StrSqlText:='Select * '+
                     'From Ad_MonthCheckout '+
                     'Where YearMonth='+R_StrDepreciationMonth+' ';
  ExecuteSql(R_AdoQry,StrSqltext,0);
  IF R_AdoQry.RecordCount=1 Then
  begin
    Result:=2;     //已月结了
    Exit;
  end;

  StrSqlText:='Select Top 1 * '+
                     'From Ad_MonthCheckout '+
                     'Order By YearMonth DESC';
  ExecuteSql(R_AdoQry,StrSqltext,0);
  StrLastCheckoutMonth:=R_AdoQry.fieldbyname('YearMonth').AsString;
  IF StrLastCheckoutMonth<>'' Then
  begin
    IntCheckoutYear:=StrToInt(Copy(StrLastCheckoutMonth,1,4));
    IntCheckoutMonth:=StrToInt(Copy(StrLastCheckoutMonth,6,2));
    IntDepreciationYear:=StrToInt(Copy(R_StrDepreciationMonth,1,4));
    IntDepreciationMonth:=StrToInt(Copy(R_StrDepreciationMonth,6,2));
    Case IntDepreciationYear-IntCheckoutYear Of
       0: begin
            If IntDepreciationMonth-IntCheckoutMonth<>1 Then
               Result:=3;     //跨月份了
               Exit;
          end;
       1: begin
            IF (IntDepreciationMonth=1) And (IntCheckoutMonth=12) Then
               Result:=3;     //跨月份了
               Exit;
          end;
       Else begin
              Result:=3;     //跨月份了
              Exit;
            end;
    end;
  end
  Else begin
    IF R_StrDepreciationMonth<>StrStartUseMonth Then
      begin
         Result:=3;     //跨月份了
         Exit;
      end;
  end;
  StrSqlText:='Select * '+
                      'From Ad_Depreciation '+
                      'Where DepreciationMonth='''+R_StrDepreciationMonth+'''';
  ExecuteSql(R_AdoQry,StrSqltext,0);
  IF R_AdoQry.RecordCount>0 Then
     Result:=4;
end;

procedure TFrm_Ad_Enter_Depreciation.btn_okClick(Sender: TObject);
var  StrDepreciationMonth:String;
     StrSqlText:String;
     AdODBConnect:TAdOConnection;
begin
  inherited;
  StrDepreciationMonth:=Edit1.Text;
  Case ISDepreciation(AdoQry_Tmp,StrDepreciationMonth) Of
    0: begin
         DispInfo('固定资产模块没有正式启用',1);
         Abort;
     end;
    1: begin
         DispInfo('计提月份小于模块启用月份',1);
         Abort;
     end;
    2: begin
         DispInfo('此月份已月结,不能计提折旧',1);
         Abort;
     end;
    3: begin
         DispInfo('不能跨月份计提折旧',1);
         Abort;
     end;
    4: begin
         IF DispInfo(StrDepreciationMonth+'月份已计提折旧,您是否重新计提折旧',2)='n' Then
            Abort;
     end;
     Else  begin
         IF DispInfo('您真的想对'+StrDepreciationMonth+'月份计提折旧吗?',2)='n' Then
            Abort;
           end;
  end;

  StrSqlText:='Exec Prod_Ad_Depreciation '''+StrDepreciationMonth+'''';
  AdODBConnect:=AdoQry_Tmp.Connection;
  AdODBConnect.beginTrans;
  Try
    ExecuteSql(AdoQry_Tmp,StrSqlText,1);
    AdODBConnect.CommitTrans;
    DispInfo('计提折旧成功',3);
  Except
    AdODBConnect.RollBackTrans;
    DispInfo('计提折旧失败,稍后请重试',1);
  end;



end;

procedure TFrm_Ad_Enter_Depreciation.btn_CancelClick(Sender: TObject);
begin
  inherited;
  Close;
end;


end.

⌨️ 快捷键说明

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