SmartFactory_NEOL/SOURCE/Agent,Kiosk/Lib/base - 20260114_old/WeeklyScheMst.pas
2026-09-04 14:08:41 +09:00

193 lines
6.1 KiB
ObjectPascal

unit WeeklyScheMst;
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
TWeeklyScheMst = class(TwItem)
private
{ Private declarations }
FOrdNum: string;
FWeeklyNum: string;
FScheDate: 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 xGetObjsWeeklyScheMstList(AQuery: TFDQuery; stDate, enDate: string): TList;
class function xAddSqlMark(velStr: string): string;
class function LoadFromQuery(AQuery: TFDQuery): TList;
procedure xFreeAllList(var objList: TList);
published
{ Published declarations }
property OrdNum: string read FOrdNum write FOrdNum;
property WeeklyNum: string read FWeeklyNum write FWeeklyNum;
property ScheDate: string read FScheDate write FScheDate;
end;
implementation
uses
WeeklyPlan;
{ TWeeklyScheMst }
constructor TWeeklyScheMst.Create(AOwner: TObject);
begin
FqPlanList := TList.Create;
end;
destructor TWeeklyScheMst.Destroy;
begin
if FqPlanList <> nil then xFreeAllList(FqPlanList);
inherited;
end;
class function TWeeklyScheMst.LoadFromQuery(AQuery: TFDQuery): TList;
var
i, idx, nidx: Integer;
valName, fieName, obidVal: string;
curSche, tmpSche: TWeeklyScheMst;
curPlan: TWeeklyPlan;
begin
Result := TList.Create;
AQuery.First;
//Áߺ¹ Ä÷³ ½ÃÀÛÁöÁ¡ ã±â..
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;
//Áߺ¹ °´Ã¼ ã±â..
idx := -1;
for i := 0 to Result.Count - 1 do begin
tmpSche := TWeeklyScheMst(Result[i]);
if SameText(obidVal, tmpSche.OBID) then begin
idx := i;
Break;
end;
end;
if idx = -1 then begin
curSche := TWeeklyScheMst.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 curSche.OBID := valName
else if SameText(fieName, 'Name') then curSche.Name := valName
else if SameText(fieName, 'wClassName') then curSche.wClassName := valName
else if SameText(fieName, 'CreateDate') then curSche.CreateDate := valName
else if SameText(fieName, 'CreateTime') then curSche.CreateTime := valName
else if SameText(fieName, 'CreatorID') then curSche.CreatorID := valName
else if SameText(fieName, 'IsValid') then curSche.IsValid := valName
else if SameText(fieName, 'LcStatus') then curSche.LcStatus := valName
else if SameText(fieName, 'OrdNum') then curSche.OrdNum := valName
else if SameText(fieName, 'WeeklyNum') then curSche.WeeklyNum := valName
else if SameText(fieName, 'ScheDate') then curSche.ScheDate := valName;
end;
Result.Add(curSche);
end else begin
curSche := TWeeklyScheMst(Result.Items[idx]);
end;
curPlan := TWeeklyPlan.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, 'ThisWeek') then curPlan.ThisWeek := valName
else if SameText(fieName, 'NextWeek') then curPlan.NextWeek := valName;
end;
curSche.qPlanList.Add(curPlan);
AQuery.Next;
end;
end;
class function TWeeklyScheMst.xAddSqlMark(velStr: string): string;
begin
Result := '';
Result := '''' + velStr + '''';
end;
procedure TWeeklyScheMst.xFreeAllList(var objList: TList);
var
i: Integer;
tmpObj: TObject;
begin
if objList <> nil then begin
i := 0;
while i < objList.Count do begin
tmpObj := objList.Items[i];
if tmpObj <> nil then tmpObj.Free;
tmpObj := nil;
objList.Delete(i);
end;
objList.Free; objList:=nil;
end;
end;
class function TWeeklyScheMst.xGetObjsWeeklyScheMstList(AQuery: TFDQuery;
stDate, enDate: string): TList;
var
sql: string;
begin
Result := nil;
sql := 'SELECT obj0.*, obj2.* FROM "WeeklyScheMst"obj0, "WeeklySchePlanR"obj1, "WeeklyPlan"obj2';
sql := sql + ' WHERE obj0."IsValid"=' + xAddSqlMark('t');
if Length(Trim(stDate)) > 0 then begin
sql := sql + ' AND obj0."ScheDate">=' + xAddSqlMark(stDate);
sql := sql + ' AND obj0."ScheDate"<=' + 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"';
sql := sql + ' ORDER BY obj0."OrdNum", obj2."OrdNum" DESC';
try
AQuery.Close;
AQuery.SQL.Text := sql;
AQuery.Open;
except
on E: Exception do ShowMessage('xGetObjsWeeklyScheMstList Äõ¸® ½ÇÇà ¿À·ù: ' + E.Message);
end;
Result := LoadFromQuery(AQuery);
end;
end.