Преглед на файлове

新增一期计量,优化速度

MaiXinRong преди 6 години
родител
ревизия
b6a991654f
променени са 4 файла, в които са добавени 160 реда и са изтрити 1 реда
  1. 2 0
      DataModules/PhasePayDm.pas
  2. 2 0
      DataModules/StageDm.pas
  3. 12 1
      Units/Globals.pas
  4. 144 0
      Units/LogUtils.pas

+ 2 - 0
DataModules/PhasePayDm.pas

@@ -282,10 +282,12 @@ procedure TPhasePayData.AfterBatchOperation;
 begin
   sddPhasePay.BeforeValueChange := sddPhasePayBeforeValueChange;
   sddPhasePay.AfterValueChanged := sddPhasePayAfterValueChanged;
+  sddPhasePay.EndUpdate;
 end;
 
 procedure TPhasePayData.BeforeBatchOperation;
 begin
+  sddPhasePay.BeginUpdate;
   sddPhasePay.BeforeValueChange := nil;
   sddPhasePay.AfterValueChanged := nil;
 end;

+ 2 - 0
DataModules/StageDm.pas

@@ -495,12 +495,14 @@ end;
 
 procedure TStageData.AfterBatchOperation;
 begin
+  sddStage.EndUpdate;
   sddStage.BeforeValueChange := sddStageBeforeValueChange;
   sddStage.AfterValueChanged := sddStageAfterValueChanged;
 end;
 
 procedure TStageData.BeforeBatchOperation;
 begin
+  sddStage.BeginUpdate;
   sddStage.BeforeValueChange := nil;
   sddStage.AfterValueChanged := nil;
 end;

+ 12 - 1
Units/Globals.pas

@@ -18,6 +18,8 @@ function MemoryReportManager: TMemoryReportManager;
 
 function MeasureLog: TLogUtils;
 
+function TimeLog: TTimeLogManager;
+
 implementation
 
 var
@@ -28,6 +30,7 @@ var
   _ReportConfig: TReportConfig;
   _MemoryReportManager: TMemoryReportManager;
   _MeasureLog: TLogUtils;
+  _TimeLog: TTimeLogManager;
 
 function OpenProjectManager: TOpenProjectManager;
 begin
@@ -78,6 +81,13 @@ begin
   Result := _MeasureLog;
 end;
 
+function TimeLog: TTimeLogManager;
+begin
+  if not Assigned(_TimeLog) then
+    _TimeLog := TTimeLogManager.Create;
+  Result := _TimeLog;
+end;
+
 initialization
 
 finalization
@@ -87,5 +97,6 @@ finalization
   _ReportTemplateManager.Free;
   _ReportConfig.Free;
   _MemoryReportManager.Free;
-  _MeasureLog.Free;
+  _MeasureLog.Free;         
+  _TimeLog.Free;
 end.

+ 144 - 0
Units/LogUtils.pas

@@ -18,10 +18,46 @@ type
     procedure AppendLogTo(const ALog: string);
   end;
 
+  TTimeLog = class
+  private
+    FEndTime: TDateTime;
+    FBeginTime: TDateTime;
+    FName: string;
+  public
+    constructor Create(const AName: string);
+    procedure EndLog;
+
+    property Name: string read FName;
+    property BeginTime: TDateTime read FBeginTime;
+    property EndTime: TDateTime read FEndTime;
+  end;
+
+  TTimeLogManager = class
+  private
+    FLogFolder: string;
+    FLogFile: string;
+    FLogList: TList;
+
+    function FindTimeLog(const AName: string): TTimeLog;
+    function AddTimeLog(const AName: string): TTimeLog;
+    function GetTimeLog(const AName: string): TTimeLog;
+
+    procedure AppendLogTo(const ALog: string);
+  public
+    constructor Create;
+    destructor Destroy; override;
+
+    procedure ClearTimeLog;
+
+    procedure BeginTime(const AName: string);
+    procedure EndTime(const AName: string);
+  end;
+
 implementation
 
 uses SysUtils, UtilMethods, Math, ZhAPI;
 
+
 { TLog }
 
 procedure TLogUtils.AppendLogTo(const ALog: string);
@@ -60,4 +96,112 @@ begin
   inherited;
 end;
 
+{ TTimeLog }
+
+constructor TTimeLog.Create(const AName: string);
+begin
+  FName := AName;
+  FBeginTime := TickCount;
+end;
+
+procedure TTimeLog.EndLog;
+begin
+  FEndTime := TickCount;
+end;
+
+{ TTimeLogManager }
+
+function TTimeLogManager.AddTimeLog(const AName: string): TTimeLog;
+begin
+  Result := TTimeLog.Create(AName);
+  FLogList.Add(Result);
+end;
+
+procedure TTimeLogManager.AppendLogTo(const ALog: string);
+var
+  f: TextFile;
+begin
+  try
+    AssignFile(f, FLogFile);
+    if FileExists(FLogFile) then
+      Append(f)
+    else
+      Rewrite(f);
+    Writeln(f, ALog);
+    Flush(f);
+  finally
+    CloseFile(f);
+  end;
+end;
+
+procedure TTimeLogManager.BeginTime(const AName: string);
+var
+  vLog: TTimeLog;
+begin
+  vLog := GetTimeLog(AName);
+end;
+
+procedure TTimeLogManager.ClearTimeLog;
+begin
+  ClearObjects(FLogList);
+end;
+
+constructor TTimeLogManager.Create;
+var
+  vFormatSetting: TFormatSettings;
+begin
+  vFormatSetting.ShortDateFormat := 'yyyy/MM/dd';
+  vFormatSetting.DateSeparator := '-';
+  FLogFolder := GetAppFilePath + 'log';
+  if not DirectoryExists(FLogFolder) then
+    CreateDirectoryInDeep(FLogFolder);
+  FLogFile := FLogFolder + '\' + DateToStr(Date, vFormatSetting) + '.log';
+  FLogList := TList.Create;
+end;
+
+destructor TTimeLogManager.Destroy;
+begin
+  ClearTimeLog;
+  FLogList.Free;
+  inherited;
+end;
+
+procedure TTimeLogManager.EndTime(const AName: string);
+var
+  vLog: TTimeLog;
+begin
+  vLog := FindTimeLog(AName);
+  if Assigned(vLog) then
+  begin
+    vLog.EndLog;
+    AppendLogTo(Format('%s: %fms', [vLog.Name, vLog.EndTime - vLog.BeginTime]));
+  end
+  else
+    AppendLogTo(Format('Time Log %s not Assigned', [AName]));
+end;
+
+function TTimeLogManager.FindTimeLog(const AName: string): TTimeLog;
+var
+  i: Integer;
+begin
+  Result := nil;
+  for i := 0 to FLogList.Count - 1 do
+  begin
+    if (TTimeLog(FLogList.Items[i])).Name = AName then
+    begin
+      Result := TTimeLog(FLogList.Items[i]);
+      Break;
+    end;
+  end;
+end;
+
+function TTimeLogManager.GetTimeLog(const AName: string): TTimeLog;
+var
+  vLog: TTimeLog;
+begin
+  vLog := FindTimeLog(AName);
+  if not Assigned(vLog) then
+    vLog := AddTimeLog(AName);
+end;
+
 end.