269 lines
9.1 KiB
ObjectPascal
269 lines
9.1 KiB
ObjectPascal
unit PurchaseMst;
|
||
|
||
interface
|
||
|
||
uses
|
||
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
||
wItem,
|
||
FireDAC.Stan.Intf,
|
||
FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf,
|
||
FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,
|
||
FireDAC.Stan.Param, FireDAC.DatS, FireDAC.DApt.Intf, FireDAC.DApt,
|
||
FireDAC.Phys.PGDef, FireDAC.VCLUI.Wait, FireDAC.Comp.UI, FireDAC.Phys.PG,
|
||
Data.DB, FireDAC.Comp.DataSet, FireDAC.Comp.Client
|
||
;
|
||
|
||
type
|
||
TPurchaseMst = class(TwItem)
|
||
private
|
||
{ Private declarations }
|
||
FOrdNum: string;
|
||
FOrdCode: string;
|
||
FCustName: string;
|
||
FOrdDate: string;
|
||
FDeliveryDate: string;
|
||
FWarehouse: string;
|
||
FConnPerson: string;
|
||
FQty: string;
|
||
FUnitt: string;
|
||
FUnitPrice: string;
|
||
FAmount: string;
|
||
FDescriptions: string;
|
||
FPurInfo: string;
|
||
FInDate: string;
|
||
FTaxDate: string;
|
||
FAmountDate: string;
|
||
|
||
FqPlanList: TList;
|
||
protected
|
||
{ Protected declarations }
|
||
public
|
||
{ Public declarations }
|
||
property qPlanList: TList read FqPlanList write FqPlanList;
|
||
|
||
constructor Create(AOwner: TObject);// override;
|
||
destructor Destroy; override;
|
||
|
||
class function xAddSqlMark(velStr: string): string;
|
||
class function xGetStrSqlPurchaseToPlanList(AQuery: TFDQuery; cust, stDate, enDate: string): TList;
|
||
class function LoadFromQuery(AQuery: TFDQuery): TList;
|
||
|
||
class function xGetPurchaseMstLastNumber(AQuery: TFDQuery; column: string): string;
|
||
class function LoadFromStringsQuery(AQuery: TFDQuery; column: string): TStrings;
|
||
published
|
||
{ Published declarations }
|
||
property OrdNum: string read FOrdNum write FOrdNum;
|
||
property OrdCode: string read FOrdCode write FOrdCode;
|
||
property CustName: string read FCustName write FCustName;
|
||
property OrdDate: string read FOrdDate write FOrdDate;
|
||
property DeliveryDate: string read FDeliveryDate write FDeliveryDate;
|
||
property Warehouse: string read FWarehouse write FWarehouse;
|
||
property ConnPerson: string read FConnPerson write FConnPerson;
|
||
property Qty: string read FQty write FQty;
|
||
property Unitt: string read FUnitt write FUnitt;
|
||
property UnitPrice: string read FUnitPrice write FUnitPrice;
|
||
property Amount: string read FAmount write FAmount;
|
||
property Descriptions: string read FDescriptions write FDescriptions;
|
||
property PurInfo: string read FPurInfo write FPurInfo;
|
||
property InDate: string read FInDate write FInDate;
|
||
property TaxDate: string read FTaxDate write FTaxDate;
|
||
property AmountDate: string read FAmountDate write FAmountDate;
|
||
end;
|
||
|
||
implementation
|
||
|
||
uses
|
||
PurchasePlan;
|
||
|
||
{ TPurchaseMst }
|
||
|
||
constructor TPurchaseMst.Create(AOwner: TObject);
|
||
begin
|
||
FqPlanList := TList.Create;
|
||
end;
|
||
|
||
destructor TPurchaseMst.Destroy;
|
||
var
|
||
i: Integer;
|
||
tmpObj: TObject;
|
||
begin
|
||
if FqPlanList <> nil then begin
|
||
i := 0;
|
||
while i < FqPlanList.Count do begin
|
||
tmpObj := FqPlanList.Items[i];
|
||
if tmpObj <> nil then tmpObj.Free;
|
||
tmpObj := nil;
|
||
FqPlanList.Delete(i);
|
||
end;
|
||
FqPlanList.Free; FqPlanList:=nil;
|
||
end;
|
||
|
||
inherited;
|
||
end;
|
||
|
||
class function TPurchaseMst.LoadFromQuery(AQuery: TFDQuery): TList;
|
||
var
|
||
i, idx, nidx: Integer;
|
||
valName, fieName, obidVal: string;
|
||
curPur, tmpPur: TPurchaseMst;
|
||
curPlan: TPurchasePlan;
|
||
begin
|
||
Result := TList.Create;
|
||
|
||
AQuery.First;
|
||
//<2F>ߺ<EFBFBD> <20>÷<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ã<><C3A3>..
|
||
nidx := -1;
|
||
for i := 0 to AQuery.FieldCount-1 do begin
|
||
fieName := AQuery.Fields[i].FieldName;
|
||
if Pos('_1',fieName) > 0 then begin
|
||
nidx := i;
|
||
Break;
|
||
end;
|
||
end;
|
||
|
||
AQuery.First;
|
||
while not AQuery.Eof do begin
|
||
obidVal := AQuery.FieldByName('OBID').AsString;
|
||
//<2F>ߺ<EFBFBD> <20><>ü ã<><C3A3>..
|
||
idx := -1;
|
||
for i := 0 to Result.Count - 1 do begin
|
||
tmpPur := TPurchaseMst(Result[i]);
|
||
if SameText(obidVal, tmpPur.OBID) then begin
|
||
idx := i;
|
||
Break;
|
||
end;
|
||
end;
|
||
|
||
if idx = -1 then begin
|
||
curPur := TPurchaseMst.Create(nil);
|
||
for i := 0 to nidx-1 do begin
|
||
fieName := AQuery.Fields[i].FieldName;
|
||
valName := AQuery.Fields[i].AsString;
|
||
if SameText(fieName, 'OBID') then curPur.OBID := valName
|
||
else if SameText(fieName, 'Name') then curPur.Name := valName
|
||
else if SameText(fieName, 'wClassName') then curPur.wClassName := valName
|
||
else if SameText(fieName, 'CreateDate') then curPur.CreateDate := valName
|
||
else if SameText(fieName, 'CreateTime') then curPur.CreateTime := valName
|
||
else if SameText(fieName, 'CreatorID') then curPur.CreatorID := valName
|
||
else if SameText(fieName, 'IsValid') then curPur.IsValid := valName
|
||
else if SameText(fieName, 'LcStatus') then curPur.LcStatus := valName
|
||
|
||
else if SameText(fieName, 'OrdNum') then curPur.OrdNum := valName
|
||
else if SameText(fieName, 'OrdCode') then curPur.OrdCode := valName
|
||
else if SameText(fieName, 'CustName') then curPur.CustName := valName
|
||
else if SameText(fieName, 'OrdDate') then curPur.OrdDate := valName
|
||
else if SameText(fieName, 'DeliveryDate') then curPur.DeliveryDate := valName
|
||
else if SameText(fieName, 'Warehouse') then curPur.Warehouse := valName
|
||
else if SameText(fieName, 'ConnPerson') then curPur.ConnPerson := valName
|
||
else if SameText(fieName, 'Qty') then curPur.Qty := valName
|
||
else if SameText(fieName, 'Unitt') then curPur.Unitt := valName
|
||
else if SameText(fieName, 'UnitPrice') then curPur.UnitPrice := valName
|
||
else if SameText(fieName, 'Amount') then curPur.Amount := valName
|
||
else if SameText(fieName, 'Descriptions') then curPur.Descriptions := valName
|
||
else if SameText(fieName, 'PurInfo') then curPur.PurInfo := valName
|
||
else if SameText(fieName, 'InDate') then curPur.InDate := valName
|
||
else if SameText(fieName, 'TaxDate') then curPur.TaxDate := valName
|
||
else if SameText(fieName, 'AmountDate') then curPur.AmountDate := valName;
|
||
end;
|
||
Result.Add(curPur);
|
||
end else begin
|
||
curPur := TPurchaseMst(Result.Items[idx]);
|
||
end;
|
||
|
||
curPlan := TPurchasePlan.Create(nil);
|
||
for i := nidx to AQuery.FieldCount-1 do begin
|
||
fieName := StringReplace(AQuery.Fields[i].FieldName, '_1', '', [rfReplaceAll]);
|
||
valName := AQuery.Fields[i].AsString;
|
||
if SameText(fieName, 'OBID') then curPlan.OBID := valName
|
||
else if SameText(fieName, 'Name') then curPlan.Name := valName
|
||
else if SameText(fieName, 'wClassName') then curPlan.wClassName := valName
|
||
else if SameText(fieName, 'CreateDate') then curPlan.CreateDate := valName
|
||
else if SameText(fieName, 'CreateTime') then curPlan.CreateTime := valName
|
||
else if SameText(fieName, 'CreatorID') then curPlan.CreatorID := valName
|
||
else if SameText(fieName, 'IsValid') then curPlan.IsValid := valName
|
||
else if SameText(fieName, 'LcStatus') then curPlan.LcStatus := valName
|
||
else if SameText(fieName, 'OrdNum') then curPlan.OrdNum := valName
|
||
else if SameText(fieName, 'Qty') then curPlan.Qty := valName
|
||
else if SameText(fieName, 'Unitt') then curPlan.Unitt := valName
|
||
else if SameText(fieName, 'UnitPrice') then curPlan.UnitPrice := valName
|
||
else if SameText(fieName, 'Amount') then curPlan.Amount := valName;
|
||
end;
|
||
curPur.qPlanList.Add(curPlan);
|
||
|
||
AQuery.Next;
|
||
end;
|
||
end;
|
||
|
||
class function TPurchaseMst.LoadFromStringsQuery(AQuery: TFDQuery;
|
||
column: string): TStrings;
|
||
var
|
||
valStr: string;
|
||
begin
|
||
Result := TStringList.Create;
|
||
while not AQuery.Eof do begin
|
||
valStr := AQuery.FieldByName(column).AsString;
|
||
Result.Add(valStr);
|
||
|
||
AQuery.Next;
|
||
end;
|
||
end;
|
||
|
||
class function TPurchaseMst.xAddSqlMark(velStr: string): string;
|
||
begin
|
||
Result := '';
|
||
Result := '''' + velStr + '''';
|
||
end;
|
||
|
||
class function TPurchaseMst.xGetPurchaseMstLastNumber(AQuery: TFDQuery;
|
||
column: string): string;
|
||
var
|
||
sql: string;
|
||
resStrs: TStrings;
|
||
begin
|
||
Result := '';
|
||
sql := 'SELECT COUNT(*) FROM "PurchaseMst"';
|
||
try
|
||
AQuery.Close;
|
||
AQuery.SQL.Text := sql;
|
||
AQuery.Open;
|
||
except
|
||
on E: Exception do ShowMessage('xGetPurchaseMstLastNumber <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>: ' + E.Message);
|
||
end;
|
||
resStrs := LoadFromStringsQuery(AQuery, column);
|
||
if resStrs.Count > 0 then begin
|
||
Result := resStrs.Strings[0];
|
||
end;
|
||
resStrs.Free;
|
||
end;
|
||
|
||
class function TPurchaseMst.xGetStrSqlPurchaseToPlanList(AQuery: TFDQuery; cust,
|
||
stDate, enDate: string): TList;
|
||
var
|
||
sql: string;
|
||
begin
|
||
Result := nil;
|
||
sql := 'SELECT obj0.*, obj2.* FROM "PurchaseMst"obj0, "PurchaseMstPlanR"obj1, "PurchasePlan"obj2';
|
||
sql := sql + ' WHERE obj0."IsValid"=' + xAddSqlMark('t');
|
||
if Length(Trim(cust)) > 0 then sql := sql + ' AND obj0."CustName"=' + xAddSqlMark(cust);
|
||
if Length(Trim(stDate)) > 0 then begin
|
||
sql := sql + ' AND obj0."OrdDate">=' + xAddSqlMark(stDate);
|
||
sql := sql + ' AND obj0."OrdDate"<=' + xAddSqlMark(enDate);
|
||
end;
|
||
sql := sql + ' AND obj1."IsValid"=' + xAddSqlMark('t');
|
||
sql := sql + ' AND obj1."LOBID"=obj0."OBID"';
|
||
sql := sql + ' AND obj2."IsValid"=' + xAddSqlMark('t');
|
||
sql := sql + ' AND obj2."OBID"=obj1."ROBID"';
|
||
|
||
try
|
||
AQuery.Close;
|
||
AQuery.SQL.Text := sql;
|
||
AQuery.Open;
|
||
except
|
||
on E: Exception do ShowMessage('xGetPurchaseToPlanList <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>: ' + E.Message);
|
||
end;
|
||
Result := LoadFromQuery(AQuery);
|
||
end;
|
||
|
||
end.
|
||
|