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

337 lines
10 KiB
ObjectPascal
Raw Blame History

unit ProcessMst;
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
TProcessMst = class(TwItem)
private
{ Private declarations }
FOrdNum: string;
FDescriptions: string;
FManufact: string;
FqDetList: TList;
protected
{ Protected declarations }
public
{ Public declarations }
property qDetList: TList read FqDetList write FqDetList;
constructor Create(AOwner: TObject);// override;
destructor Destroy; override;
class function xAddSqlMark(velStr: string): string;
class function xGetStrSqlProcessToDetailList(AQuery: TFDQuery; manuStr, procStr: string): TList;
class function LoadFromQuery(AQuery: TFDQuery): TList;
class function xGetStrsProcessMstDistinct(AQuery: TFDQuery; colName: string): TStrings;
class function xAddSqlDoubleMark(velStr: String): String;
class function LoadFromStringsQuery(AQuery: TFDQuery; column: string): TStrings;
function xGetRelsProcessMstDetailR(AQuery: TFDQuery): TList;
function RelsLoadFromQuery(AQuery: TFDQuery): TList;
class function xGetStrProcessMstLastCount(AQuery: TFDQuery; column: string): string;
published
{ Published declarations }
property OrdNum: string read FOrdNum write FOrdNum;
property Descriptions: string read FDescriptions write FDescriptions;
property Manufact: string read FManufact write FManufact;
end;
implementation
uses
ProcessDetail, ProcessMstDetailR;
{ TProcessMst }
constructor TProcessMst.Create(AOwner: TObject);
begin
//inherited Create;
// FClassName := 'area';
// FOBID := QuerySet.qCreateGetUniqueString(FClassName);
// FIsValid := '1';
// FCreateDate := FormatDateTime('yyyy-MM-dd',Now);
// FCreateTime := FormatDateTime('HH:mm:ss',Now);
FqDetList := TList.Create;
end;
destructor TProcessMst.Destroy;
var
i, j: Integer;
tmpStrs: TStrings;
tmpList, delList, strList: TList;
tmpObj: TObject;
begin
if FqDetList <> nil then begin
i := 0;
while i < FqDetList.Count do begin
tmpObj := FqDetList.Items[i];
if tmpObj <> nil then tmpObj.Free;
tmpObj := nil;
FqDetList.Delete(i);
end;
FqDetList.Free; FqDetList:=nil;
end;
{
if FqShopGroup <> nil then begin
i := 0;
while FqShopGroup.Count > i do begin
tmpStrs := TStrings(FqShopGroup.Objects[i]);
j := 0;
while tmpStrs.Count > j do begin
tmpList := TList(tmpStrs.Objects[j]);
while tmpList.Count > 0 do begin
tmpList.Delete(0);
end;
tmpList.Free;
Inc(j);
end;
tmpStrs.Free;
Inc(i);
end;
FqShopGroup.Free; FqShopGroup:=nil;
end;
}
inherited;
end;
class function TProcessMst.LoadFromQuery(AQuery: TFDQuery): TList;
var
i, j, k, idx, cnt, nidx: Integer;
claName, valName, fieName, obidStr, obidVal, valClass, valClass1: string;
curProc, tmpProc: TProcessMst;
curDet: TProcessDetail;
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
tmpProc := TProcessMst(Result[i]);
if SameText(obidVal, tmpProc.OBID) then begin
idx := i;
Break;
end;
end;
if idx = -1 then begin
curProc := TProcessMst.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 curProc.OBID := valName
else if SameText(fieName, 'Name') then curProc.Name := valName
else if SameText(fieName, 'wClassName') then curProc.wClassName := valName
else if SameText(fieName, 'CreateDate') then curProc.CreateDate := valName
else if SameText(fieName, 'CreateTime') then curProc.CreateTime := valName
else if SameText(fieName, 'CreatorID') then curProc.CreatorID := valName
else if SameText(fieName, 'IsValid') then curProc.IsValid := valName
else if SameText(fieName, 'LcStatus') then curProc.LcStatus := valName
else if SameText(fieName, 'OrdNum') then curProc.OrdNum := valName
else if SameText(fieName, 'Descriptions') then curProc.Descriptions := valName
else if SameText(fieName, 'Manufact') then curProc.Manufact := valName;
end;
Result.Add(curProc);
end else begin
curProc := TProcessMst(Result.Items[idx]);
end;
curDet := TProcessDetail.Create(nil);
for i := nidx to AQuery.FieldCount-1 do begin
//fieName := AQuery.Fields[i].FieldName;
//fieName := StringReplace(fieName, '_1', '', [rfReplaceAll]);
fieName := StringReplace(AQuery.Fields[i].FieldName, '_1', '', [rfReplaceAll]);
valName := AQuery.Fields[i].AsString;
if SameText(fieName, 'OBID') then curDet.OBID := valName
else if SameText(fieName, 'Name') then curDet.Name := valName
else if SameText(fieName, 'wClassName') then curDet.wClassName := valName
else if SameText(fieName, 'CreateDate') then curDet.CreateDate := valName
else if SameText(fieName, 'CreateTime') then curDet.CreateTime := valName
else if SameText(fieName, 'CreatorID') then curDet.CreatorID := valName
else if SameText(fieName, 'IsValid') then curDet.IsValid := valName
else if SameText(fieName, 'LcStatus') then curDet.LcStatus := valName
else if SameText(fieName, 'OrdNum') then curDet.OrdNum := valName
else if SameText(fieName, 'Descriptions') then curDet.Descriptions := valName
else if SameText(fieName, 'Kind') then curDet.Kind := valName;
end;
curProc.qDetList.Add(curDet);
AQuery.Next;
end;
end;
class function TProcessMst.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;
function TProcessMst.RelsLoadFromQuery(AQuery: TFDQuery): TList;
var
curRel: TProcessMstDetailR;
begin
Result := TList.Create;
AQuery.First;
while not AQuery.Eof do begin
curRel := TProcessMstDetailR.Create(nil);
curRel.OBID := AQuery.FieldByName('OBID').AsString;
curRel.Name := AQuery.FieldByName('Name').AsString;
curRel.wClassName := AQuery.FieldByName('wClassName').AsString;
curRel.CreateDate := AQuery.FieldByName('CreateDate').AsString;
curRel.CreateTime := FormatDateTime('hh:nn:ss', AQuery.FieldByName('CreateTime').AsDateTime);
curRel.CreatorID := AQuery.FieldByName('CreatorID').AsString;
curRel.IsValid := AQuery.FieldByName('IsValid').AsString;
curRel.Revision := AQuery.FieldByName('Revision').AsString;
curRel.LOBID := AQuery.FieldByName('LOBID').AsString;
curRel.ROBID := AQuery.FieldByName('ROBID').AsString;
curRel.LClassName := AQuery.FieldByName('LClassName').AsString;
curRel.RClassName := AQuery.FieldByName('RClassName').AsString;
curRel.RunningNum := IntToStr(AQuery.FieldByName('RunningNum').AsInteger);
Result.Add(curRel);
AQuery.Next;
end;
end;
class function TProcessMst.xAddSqlDoubleMark(velStr: String): String;
begin
Result := '';
Result := '"' + velStr + '"';
end;
class function TProcessMst.xAddSqlMark(velStr: string): string;
begin
Result := '';
Result := '''' + velStr + '''';
end;
function TProcessMst.xGetRelsProcessMstDetailR(AQuery: TFDQuery): TList;
var
sql: string;
begin
Result := nil;
sql := 'SELECT * FROM "ProcessMstDetailR"';
sql := sql + ' WHERE "IsValid"=' + xAddSqlMark('t');
sql := sql + ' AND "LOBID"=' + xAddSqlMark(OBID);
sql := sql + ' ORDER BY "RunningNum"';
try
AQuery.Close;
AQuery.SQL.Text := sql;
AQuery.Open;
except
on E: Exception do ShowMessage('xGetRelsProcessMstDetailR <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>: ' + E.Message);
end;
Result := RelsLoadFromQuery(AQuery);
end;
class function TProcessMst.xGetStrProcessMstLastCount(AQuery: TFDQuery;
column: string): string;
var
count: Integer;
sql: string;
tmpRes: TStrings;
begin
Result := '';
sql := 'SELECT COUNT(*) FROM "ProcessMst"';
sql := sql + ' WHERE "IsValid"=' + xAddSqlMark('t');
try
AQuery.Close;
AQuery.SQL.Text := sql;
AQuery.Open;
except
on E: Exception do ShowMessage('xGetStrProcessMstLastCount <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>: ' + E.Message);
end;
tmpRes := LoadFromStringsQuery(AQuery, column);
if tmpRes.Count > 0 then begin
count := StrToIntDef(tmpRes.Strings[0],0);
count := count + 1;
Result := IntToStr(count);
end;
tmpRes.Free;
end;
class function TProcessMst.xGetStrsProcessMstDistinct(AQuery: TFDQuery;
colName: string): TStrings;
var
sql: string;
begin
Result := nil;
sql := 'SELECT DISTINCT ' + xAddSqlDoubleMark(colName) + ' FROM "ProcessMst"';
sql := sql + ' WHERE "IsValid"=' + xAddSqlMark('t');
try
AQuery.Close;
AQuery.SQL.Text := sql;
AQuery.Open;
except
on E: Exception do ShowMessage('xGetStrsProcessMstDistinct <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>: ' + E.Message);
end;
Result := LoadFromStringsQuery(AQuery, colName);
end;
class function TProcessMst.xGetStrSqlProcessToDetailList(AQuery: TFDQuery;
manuStr, procStr: string): TList;
var
sql: string;
begin
Result := nil;
sql := 'SELECT obj0.*, obj2.* FROM "ProcessMst"obj0, "ProcessMstDetailR"obj1, "ProcessDetail"obj2';
sql := sql + ' WHERE obj0."IsValid"=' + xAddSqlMark('t');
if Length(Trim(manuStr)) > 0 then sql := sql + ' AND obj0."Manufact"=' + xAddSqlMark(manuStr);
if Length(Trim(procStr)) > 0 then sql := sql + ' AND obj0."Name"=' + xAddSqlMark(procStr);
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", obj1."RunningNum"';
try
AQuery.Close;
AQuery.SQL.Text := sql;
AQuery.Open;
except
on E: Exception do ShowMessage('xGetStrSqlProcessToDetailList <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>: ' + E.Message);
end;
Result := LoadFromQuery(AQuery);
end;
end.