|
@@ -0,0 +1,100 @@
|
|
|
+unit OtherMeasureOnceDm;
|
|
|
+
|
|
|
+interface
|
|
|
+
|
|
|
+uses
|
|
|
+ SysUtils, Classes, sdDB, sdProvider, ADODB;
|
|
|
+
|
|
|
+type
|
|
|
+ TOtherMeasureOnceData = class(TDataModule)
|
|
|
+ sdpOnce: TsdADOProvider;
|
|
|
+ sddOnce: TsdDataSet;
|
|
|
+ sdvOnce: TsdDataView;
|
|
|
+ procedure sddOnceAfterAddRecord(ARecord: TsdDataRecord);
|
|
|
+ private
|
|
|
+ FProjectData: TObject;
|
|
|
+
|
|
|
+ function GetNewID: Integer;
|
|
|
+ function GetNewSerialNo: Integer;
|
|
|
+ public
|
|
|
+ constructor Create(AProjectData: TObject);
|
|
|
+ destructor Destroy; override;
|
|
|
+
|
|
|
+ procedure Open(AConnection: TADOConnection);
|
|
|
+ procedure Close;
|
|
|
+ procedure Save;
|
|
|
+ end;
|
|
|
+
|
|
|
+implementation
|
|
|
+
|
|
|
+uses
|
|
|
+ ProjectData;
|
|
|
+
|
|
|
+{$R *.dfm}
|
|
|
+
|
|
|
+{ TOtherMeasureOnceData }
|
|
|
+
|
|
|
+procedure TOtherMeasureOnceData.Close;
|
|
|
+begin
|
|
|
+ sddOnce.Close;
|
|
|
+end;
|
|
|
+
|
|
|
+constructor TOtherMeasureOnceData.Create(AProjectData: TObject);
|
|
|
+begin
|
|
|
+ inherited Create(nil);
|
|
|
+ FProjectData := AProjectData;
|
|
|
+end;
|
|
|
+
|
|
|
+destructor TOtherMeasureOnceData.Destroy;
|
|
|
+begin
|
|
|
+ inherited;
|
|
|
+end;
|
|
|
+
|
|
|
+function TOtherMeasureOnceData.GetNewID: Integer;
|
|
|
+var
|
|
|
+ idx: TsdIndex;
|
|
|
+begin
|
|
|
+ idx := sddOnce.FindIndex('idxID');
|
|
|
+ if idx.RecordCount > 0 then
|
|
|
+ Result := idx.Records[idx.RecordCount - 1].ValueByName('ID').AsInteger + 1
|
|
|
+ else
|
|
|
+ Result := 1;
|
|
|
+end;
|
|
|
+
|
|
|
+function TOtherMeasureOnceData.GetNewSerialNo: Integer;
|
|
|
+var
|
|
|
+ idx: TsdIndex;
|
|
|
+begin
|
|
|
+ idx := sddOnce.FindIndex('idxSerial');
|
|
|
+ if idx.RecordCount > 0 then
|
|
|
+ Result := idx.Records[idx.RecordCount - 1].ValueByName('SerialNo').AsInteger + 1
|
|
|
+ else
|
|
|
+ Result := 1;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TOtherMeasureOnceData.Open(AConnection: TADOConnection);
|
|
|
+begin
|
|
|
+ sdpOnce.Connection := AConnection;
|
|
|
+ sddOnce.Open;
|
|
|
+ if not Assigned(sddOnce.FindIndex('idxID')) then
|
|
|
+ sddOnce.AddIndex('idxID', 'ID');
|
|
|
+ if not Assigned(sddOnce.FindIndex('idxSerial')) then
|
|
|
+ sddOnce.AddIndex('idxSerial', 'SerialNo');
|
|
|
+ sdvOnce.Open;
|
|
|
+ sdvOnce.IndexName := 'idxSerial';
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TOtherMeasureOnceData.Save;
|
|
|
+begin
|
|
|
+ sddOnce.Save;
|
|
|
+end;
|
|
|
+
|
|
|
+procedure TOtherMeasureOnceData.sddOnceAfterAddRecord(
|
|
|
+ ARecord: TsdDataRecord);
|
|
|
+begin
|
|
|
+ ARecord.ValueByName('ID').AsInteger := GetNewID;
|
|
|
+ ARecord.ValueByName('SerialNo').AsInteger := GetNewSerialNo;
|
|
|
+ ARecord.ValueByName('CreatePhaseID').AsInteger := TProjectData(FProjectData).PhaseIndex;
|
|
|
+end;
|
|
|
+
|
|
|
+end.
|