SmartFactory_NEOL/SOURCE/Lib/base - 20260114_old/ProductPlan.pas
2026-09-04 14:06:10 +09:00

248 lines
9.7 KiB
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit ProductPlan;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
wItem, OrderMst,
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
TProductPlan = class(TwItem)
private
{ Private declarations }
FOrdNum: string;
FOrdCode: string;
FConnPerson: string;
FDescriptions: string;
FMachName: string;
FPlanDate: string;
FStartMachDate: string;
FFinMachDate: string;
FqMyOrd: TOrderMst;
protected
{ Protected declarations }
public
{ Public declarations }
property qMyOrd: TOrderMst read FqMyOrd write FqMyOrd;
constructor Create(AOwner: TObject);
destructor Destroy; override;
class function xAddSqlMark(velStr: string): string;
function xAddSqlDoubleMark(velStr: String): String;
function xGetStrInsertQuery: string;
class function xGetStrSqlPlanToOrderMstList(AQuery: TFDQuery; status, mach, cust, stDate, enDate: string): TList;
class function LoadFromQueryToPlanOrder(AQuery: TFDQuery): TList;
// class function LoadFromQuery(AQuery: TFDQuery): TList;
published
{ Published declarations }
property OrdNum: string read FOrdNum write FOrdNum;
property OrdCode: string read FOrdCode write FOrdCode;
property ConnPerson: string read FConnPerson write FConnPerson;
property Descriptions: string read FDescriptions write FDescriptions;
property MachName: string read FMachName write FMachName;
property PlanDate: string read FPlanDate write FPlanDate;
property StartMachDate: string read FStartMachDate write FStartMachDate;
property FinMachDate: string read FFinMachDate write FFinMachDate;
end;
implementation
{ TProductPlan }
constructor TProductPlan.Create(AOwner: TObject);
begin
wClassName := 'ProductPlan';
CreateDate := FormatDateTime('yyyy-MM-dd',Now);
CreateTime := FormatDateTime('HH:nn:ss',Now);
IsValid := 't';
FqMyOrd := nil;
end;
destructor TProductPlan.Destroy;
begin
inherited;
end;
class function TProductPlan.LoadFromQueryToPlanOrder(AQuery: TFDQuery): TList;
var
i, idx, nidx: Integer;
valName, fieName, obidVal: string;
curPlan, tmpPlan: TProductPlan;
curOrd: TOrderMst;
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
tmpPlan := TProductPlan(Result[i]);
if SameText(obidVal, tmpPlan.OBID) then begin
idx := i;
Break;
end;
end;
if idx = -1 then begin
curPlan := TProductPlan.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 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, 'OrdCode') then curPlan.OrdCode := valName
else if SameText(fieName, 'ConnPerson') then curPlan.ConnPerson := valName
else if SameText(fieName, 'Descriptions') then curPlan.Descriptions := valName
else if SameText(fieName, 'MachName') then curPlan.MachName := valName
else if SameText(fieName, 'planDate') then curPlan.planDate := valName
else if SameText(fieName, 'StartMachDate') then curPlan.StartMachDate := valName
else if SameText(fieName, 'FinMachDate') then curPlan.FinMachDate := valName;
end;
Result.Add(curPlan);
end else begin
curPlan := TProductPlan(Result.Items[idx]);
end;
curOrd := TOrderMst.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 curOrd.OBID := valName
else if SameText(fieName, 'Name') then curOrd.Name := valName
else if SameText(fieName, 'wClassName') then curOrd.wClassName := valName
else if SameText(fieName, 'CreateDate') then curOrd.CreateDate := valName
else if SameText(fieName, 'CreateTime') then curOrd.CreateTime := valName
else if SameText(fieName, 'CreatorID') then curOrd.CreatorID := valName
else if SameText(fieName, 'IsValid') then curOrd.IsValid := valName
else if SameText(fieName, 'LcStatus') then curOrd.LcStatus := valName
else if SameText(fieName, 'OrdNum') then curOrd.OrdNum := valName
else if SameText(fieName, 'OrdDate') then curOrd.OrdDate := valName
else if SameText(fieName, 'CustName') then curOrd.CustName := valName
else if SameText(fieName, 'ConnPerson') then curOrd.ConnPerson := valName
else if SameText(fieName, 'DeliveryDate') then curOrd.DeliveryDate := valName
else if SameText(fieName, 'Warehouse') then curOrd.Warehouse := valName
else if SameText(fieName, 'Qty') then curOrd.Qty := valName
else if SameText(fieName, 'Unitt') then curOrd.Unitt := valName
else if SameText(fieName, 'UnitPrice') then curOrd.UnitPrice := valName
else if SameText(fieName, 'Amount') then curOrd.Amount := valName
else if SameText(fieName, 'Descriptions') then curOrd.Descriptions := valName
else if SameText(fieName, 'ProcStatus') then curOrd.ProcStatus := valName
else if SameText(fieName, 'ScheDay') then curOrd.ScheDay := valName
else if SameText(fieName, 'ProcDesc') then curOrd.ProcDesc := valName
else if SameText(fieName, 'ProcName') then curOrd.ProcName := valName
else if SameText(fieName, 'ProcCost') then curOrd.ProcCost := valName
else if SameText(fieName, 'OutInfo') then curOrd.OutInfo := valName
else if SameText(fieName, 'OrdCode') then curOrd.OrdCode := valName
else if SameText(fieName, 'MatKind') then curOrd.MatKind := valName
else if SameText(fieName, 'Manufact') then curOrd.Manufact := valName
else if SameText(fieName, 'EtcAmo') then curOrd.EtcAmo := valName
else if SameText(fieName, 'PurDate') then curOrd.PurDate := valName
else if SameText(fieName, 'PurCust') then curOrd.PurCust := valName
else if SameText(fieName, 'PurUnitPrice') then curOrd.PurUnitPrice := valName
else if SameText(fieName, 'PurQty') then curOrd.PurQty := valName
else if SameText(fieName, 'PurAmo') then curOrd.PurAmo := valName
else if SameText(fieName, 'PurDesc') then curOrd.PurDesc := valName
else if SameText(fieName, 'IsAddInfo') then curOrd.IsAddInfo := valName
else if SameText(fieName, 'ProdCode') then curOrd.ProdCode := valName
else if SameText(fieName, 'OutDay') then curOrd.OutDay := valName
else if SameText(fieName, 'TaxDay') then curOrd.TaxDay := valName
else if SameText(fieName, 'InAmoDay') then curOrd.InAmoDay := valName
else if SameText(fieName, 'ScheDay') then curOrd.ScheDay := valName;
end;
curPlan.qMyOrd := curOrd;
AQuery.Next;
end;
end;
function TProductPlan.xAddSqlDoubleMark(velStr: String): String;
begin
Result := '';
Result := '"' + velStr + '"';
end;
class function TProductPlan.xAddSqlMark(velStr: string): string;
begin
Result := '';
Result := '''' + velStr + '''';
end;
function TProductPlan.xGetStrInsertQuery: string;
begin
Result := '';
Result := 'INSERT INTO ' + xAddSqlDoubleMark(ClassName);
end;
class function TProductPlan.xGetStrSqlPlanToOrderMstList(AQuery: TFDQuery;
status, mach, cust, stDate, enDate: string): TList;
var
sql: string;
begin
Result := nil;
sql := 'SELECT obj0.*, obj2.* FROM "ProductPlan"obj0, "OrderMstProdPlanR"obj1, "OrderMst"obj2';
sql := sql + ' WHERE obj0."IsValid"=' + xAddSqlMark('t');
if Length(Trim(status)) > 0 then begin
if SameText('<27>Ϸ<EFBFBD>',status) then begin
sql := sql + ' AND obj0."LcStatus"=' + xAddSqlMark(status);
end else if SameText('<27>̿Ϸ<CCBF>',status) then begin
sql := sql + ' AND obj0."LcStatus"<>' + xAddSqlMark('<27>Ϸ<EFBFBD>');
end;
end;
if Length(Trim(mach)) > 0 then sql := sql + ' AND obj0."MachName"=' + xAddSqlMark(mach);
if Length(Trim(stDate)) > 0 then begin
sql := sql + ' AND obj0."PlanDate">=' + xAddSqlMark(stDate);
sql := sql + ' AND obj0."PlanDate"<=' + xAddSqlMark(enDate);
end;
sql := sql + ' AND obj1."IsValid"=' + xAddSqlMark('t');
sql := sql + ' AND obj1."ROBID"=obj0."OBID"';
sql := sql + ' AND obj2."IsValid"=' + xAddSqlMark('t');
sql := sql + ' AND obj2."OBID"=obj1."LOBID"';
if Length(Trim(cust)) > 0 then sql := sql + ' AND obj2."CustName"=' + xAddSqlMark(cust);
sql := sql + ' ORDER BY obj0."OrdNum"';
try
AQuery.Close;
AQuery.SQL.Text := sql;
AQuery.Open;
except
on E: Exception do ShowMessage('xGetStrSqlPlanToOrderMstList <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>: ' + E.Message);
end;
Result := LoadFromQueryToPlanOrder(AQuery);
end;
end.