194 lines
4.9 KiB
ObjectPascal
194 lines
4.9 KiB
ObjectPascal
|
|
unit U_CustomFun;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
System.SysUtils, System.Classes, Data.DB, System.Generics.Collections,
|
|||
|
|
System.StrUtils, Datasnap.DBClient, Data.Win.ADODB;
|
|||
|
|
|
|||
|
|
type
|
|||
|
|
TProductTotals = class
|
|||
|
|
private
|
|||
|
|
FPieceCount: Integer;
|
|||
|
|
FQuantity: Double;
|
|||
|
|
public
|
|||
|
|
property PieceCount: Integer read FPieceCount write FPieceCount;
|
|||
|
|
property Quantity: Double read FQuantity write FQuantity;
|
|||
|
|
constructor Create;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
TProductNameTotalsDict = TDictionary<string, TProductTotals>;
|
|||
|
|
|
|||
|
|
function GetMergedResultsAsString(ClientDataSet: TClientDataSet): string;
|
|||
|
|
|
|||
|
|
function CustomSelCDSKey(CDS_1: TclientDataSet; Keys: TArray<string>): TArray<string>;
|
|||
|
|
|
|||
|
|
function GetLSNo1(ADOQueryTmp: TADOQuery; // ȡ<><C8A1><EFBFBD><EFBFBD>
|
|||
|
|
var mMaxNo: string; mFlag: string; mTable: string; mlen: Integer; mtype: Integer = 0): Boolean;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
//uses
|
|||
|
|
// U_printPdf, U_RTFun, U_DataLink;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
/// ////////////////////////////////////////////////
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD>ȡ<EFBFBD><C8A1>ˮ<EFBFBD><CBAE>
|
|||
|
|
// mFlag:ǰ<C7B0><D7BA>mTable:<3A><><EFBFBD><EFBFBD>
|
|||
|
|
// mlen:<3A><>ˮ<EFBFBD>ų<EFBFBD><C5B3><EFBFBD>; mtype:<3A>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 1<><31><EFBFBD><EFBFBD> 0 <20><><EFBFBD><EFBFBD>
|
|||
|
|
/// ////////////////////////////////////////////////
|
|||
|
|
function GetLSNo1(ADOQueryTmp: TADOQuery; var mMaxNo: string; mFlag: string; mTable: string; mlen: Integer; mtype: Integer = 0): Boolean;
|
|||
|
|
begin
|
|||
|
|
try
|
|||
|
|
with ADOQueryTmp do
|
|||
|
|
begin
|
|||
|
|
close;
|
|||
|
|
sql.Clear;
|
|||
|
|
sql.Add('exec Get_SY_MaxBH_copy1 ');
|
|||
|
|
sql.Add(' ' + quotedStr(mFlag));
|
|||
|
|
sql.Add(',' + quotedStr(mTable));
|
|||
|
|
sql.Add(',' + intTostr(mlen));
|
|||
|
|
sql.Add(',' + intTostr(mtype));
|
|||
|
|
// ShowMessage(SQL.Text);
|
|||
|
|
Open;
|
|||
|
|
|
|||
|
|
if Recordcount > 0 then
|
|||
|
|
begin
|
|||
|
|
mMaxNo := Trim(fieldByName('MaxBH').AsString);
|
|||
|
|
if mMaxNo <> '' then
|
|||
|
|
Result := true
|
|||
|
|
else
|
|||
|
|
Result := false;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
begin
|
|||
|
|
Result := false;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end;
|
|||
|
|
if not Result then
|
|||
|
|
raise Exception.Create(PChar('<27><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮ<EFBFBD><CBAE>(' + mFlag + ')'));
|
|||
|
|
|
|||
|
|
except
|
|||
|
|
Result := false;
|
|||
|
|
// raise Exception.Create(PChar('<27><EFBFBD><DEB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ˮ<EFBFBD><CBAE>(' + mFlag + ')'));
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
constructor TProductTotals.Create;
|
|||
|
|
begin
|
|||
|
|
FPieceCount := 0;
|
|||
|
|
FQuantity := 0.0;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function CustomSelCDSKey(CDS_1: TclientDataSet; Keys: TArray<string>): TArray<string>;
|
|||
|
|
var
|
|||
|
|
RTValues: TArray<string>;
|
|||
|
|
i, j, CurRow: Integer;
|
|||
|
|
begin
|
|||
|
|
SetLength(RTValues, Length(Keys));
|
|||
|
|
CurRow := CDS_1.recno;
|
|||
|
|
CDS_1.DisableControls;
|
|||
|
|
with CDS_1 do
|
|||
|
|
begin
|
|||
|
|
First;
|
|||
|
|
j := 0;
|
|||
|
|
while not Eof do
|
|||
|
|
begin
|
|||
|
|
if j = 0 then
|
|||
|
|
begin
|
|||
|
|
for i := 0 to Length(RTValues) - 1 do
|
|||
|
|
begin
|
|||
|
|
RTValues[i] := Trim(CDS_1.fieldbyname(Keys[i]).AsString) + ',';
|
|||
|
|
end;
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
begin
|
|||
|
|
for i := 0 to Length(RTValues) - 1 do
|
|||
|
|
begin
|
|||
|
|
RTValues[i] := RTValues[i] + Trim(CDS_1.fieldbyname(Keys[i]).AsString) + ',';
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
j := j + 1;
|
|||
|
|
|
|||
|
|
CDS_1.Next;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
CDS_1.recno := CurRow;
|
|||
|
|
CDS_1.EnableControls;
|
|||
|
|
|
|||
|
|
for i := 0 to Length(RTValues) - 1 do
|
|||
|
|
begin
|
|||
|
|
RTValues[i] := copy(RTValues[i], 1, Length(RTValues[i]) - 1);
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
Result := RTValues;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function GetMergedResultsAsString(ClientDataSet: TClientDataSet): string;
|
|||
|
|
var
|
|||
|
|
ProductNameTotalsDict: TProductNameTotalsDict;
|
|||
|
|
ProductName: string;
|
|||
|
|
PieceCount: Integer;
|
|||
|
|
Quantity: Double;
|
|||
|
|
ProductNameList: TStringList;
|
|||
|
|
ProductTotals: TProductTotals;
|
|||
|
|
I: Integer;
|
|||
|
|
begin
|
|||
|
|
ProductNameTotalsDict := TProductNameTotalsDict.Create;
|
|||
|
|
try
|
|||
|
|
ClientDataSet.IndexName := ''; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
ClientDataSet.First;
|
|||
|
|
|
|||
|
|
while not ClientDataSet.Eof do
|
|||
|
|
begin
|
|||
|
|
ProductName := ClientDataSet.FieldByName('Grade').AsString;
|
|||
|
|
PieceCount := ClientDataSet.FieldByName('Piece').AsInteger;
|
|||
|
|
Quantity := ClientDataSet.FieldByName('Qty').AsFloat;
|
|||
|
|
|
|||
|
|
if not ProductNameTotalsDict.ContainsKey(ProductName) then
|
|||
|
|
begin
|
|||
|
|
ProductTotals := TProductTotals.Create;
|
|||
|
|
ProductTotals.PieceCount := PieceCount;
|
|||
|
|
ProductTotals.Quantity := Quantity;
|
|||
|
|
ProductNameTotalsDict.Add(ProductName, ProductTotals);
|
|||
|
|
end
|
|||
|
|
else
|
|||
|
|
begin
|
|||
|
|
ProductTotals := ProductNameTotalsDict[ProductName];
|
|||
|
|
ProductTotals.PieceCount := ProductTotals.PieceCount + PieceCount;
|
|||
|
|
ProductTotals.Quantity := ProductTotals.Quantity + Quantity;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
ClientDataSet.Next;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
ProductNameList := TStringList.Create;
|
|||
|
|
try
|
|||
|
|
for ProductName in ProductNameTotalsDict.Keys do
|
|||
|
|
begin
|
|||
|
|
ProductTotals := ProductNameTotalsDict[ProductName];
|
|||
|
|
ProductNameList.Add(Format('%s: ֧<><D6A7>=%d, <20><><EFBFBD><EFBFBD>=%.2f', [ProductName, ProductTotals.PieceCount, ProductTotals.Quantity]));
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
ProductNameList.Sort;
|
|||
|
|
Result := StringReplace(ProductNameList.Text, #13#10, '; ', [rfReplaceAll]);
|
|||
|
|
finally
|
|||
|
|
ProductNameList.Free;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><D6B5>еĶ<D0B5><C4B6><EFBFBD><F3A3ACB1><EFBFBD><EFBFBD>ڴ<EFBFBD>й©
|
|||
|
|
for ProductTotals in ProductNameTotalsDict.Values do
|
|||
|
|
begin
|
|||
|
|
ProductTotals.Free;
|
|||
|
|
end;
|
|||
|
|
ProductNameTotalsDict.Clear;
|
|||
|
|
end;
|
|||
|
|
finally
|
|||
|
|
ProductNameTotalsDict.Free;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|
|||
|
|
|