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

573 lines
20 KiB
ObjectPascal
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit MixMaterialMst;
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,
DCPrijndael, DCPsha256, System.NetEncoding;
type
TMixMaterialMst = class(TwItem)
private
{ Private declarations }
FOrdDate: string;
FOrdCode: string;
FIsConfirm: string;
FDescriptions: string;
FUnitt: string;
FQty: string;
FCustName: string;
FqMatList: TList;
FqRelList: TList;
FqProcList: TList;
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TObject);// override;
destructor Destroy; override;
class function xGetStrSqlMixToMaterialList(AQuery: TFDQuery; code, prod, stDate, enDate: string): TList;
class function xGetObjsMixMaterialMstList(AQuery: TFDQuery; code, name, stDate, enDate: string): TList;
procedure xGetObjsMixMatRtpProcList(AQuery: TFDQuery);
function LoadFromQueryPtpProcList(AQuery: TFDQuery): TList;
procedure xFreeAllFqProcList;
class function xAddSqlMark(velStr: string): string;
class function LoadFromQuery(AQuery: TFDQuery): TList;
class function LoadFromSingleQuery(AQuery: TFDQuery): TList;
class function DecryptAES(const EncText, Key: string): string;//º¹È£È­..
class function xGetStrsDistinctAttr(AQuery: TFDQuery; colName: string): TStrings;
class function xAddSqlDoubleMark(velStr: String): String;
class function LoadFromStringsQuery(AQuery: TFDQuery; column: string): TStrings;
property qMatList: TList read FqMatList write FqMatList;
property qRelList: TList read FqRelList write FqRelList;
property qProcList: TList read FqProcList write FqProcList;
published
{ Published declarations }
property OrdDate: string read FOrdDate write FOrdDate;
property OrdCode: string read FOrdCode write FOrdCode;
property IsConfirm: string read FIsConfirm write FIsConfirm;
property Descriptions: string read FDescriptions write FDescriptions;
property Unitt: string read FUnitt write FUnitt;
property Qty: string read FQty write FQty;
property CustName: string read FCustName write FCustName;
end;
implementation
uses
MixMatMstR, MaterialMst,
RtpProcessInfo, RtpMaterialInfo;
{ TMixMaterialMst }
constructor TMixMaterialMst.Create(AOwner: TObject);
begin
FqMatList := TList.Create;
FqRelList := TList.Create;
FqProcList := nil;
end;
class function TMixMaterialMst.DecryptAES(const EncText, Key: string): string;
var
Cipher: TDCP_rijndael;
Hash: TDCP_sha256;
KeyHash: array[0..31] of Byte;
Decoded: string;
begin
Cipher := TDCP_rijndael.Create(nil);
Hash := TDCP_sha256.Create(nil);
try
Hash.Init;
Hash.UpdateStr(Key);
Hash.Final(KeyHash);
Decoded := TNetEncoding.Base64.Decode(EncText);
Cipher.Init(KeyHash, 256, nil);
Result := Cipher.DecryptString(Decoded);
Cipher.Burn;
finally
Hash.Free;
Cipher.Free;
end;
end;
destructor TMixMaterialMst.Destroy;
var
i: Integer;
tmpObj: TObject;
begin
if FqMatList <> nil then begin
i := 0;
while i < FqMatList.Count do begin
tmpObj := FqMatList.Items[i];
if tmpObj <> nil then tmpObj.Free;
tmpObj := nil;
FqMatList.Delete(i);
end;
FqMatList.Free; FqMatList:=nil;
end;
if FqRelList <> nil then begin
i := 0;
while i < FqRelList.Count do begin
tmpObj := FqRelList.Items[i];
if tmpObj <> nil then tmpObj.Free;
tmpObj := nil;
FqRelList.Delete(i);
end;
FqRelList.Free; FqRelList:=nil;
end;
if FqProcList <> nil then begin
i := 0;
while i < FqProcList.Count do begin
tmpObj := FqProcList.Items[i];
if tmpObj <> nil then tmpObj.Free;
tmpObj := nil;
FqProcList.Delete(i);
end;
FqProcList.Free; FqProcList:=nil;
end;
inherited;
end;
class function TMixMaterialMst.LoadFromQuery(AQuery: TFDQuery): TList;
var
i, idx, nidx, nnidx: Integer;
valName, fieName, obidVal: string;
curMix, tmpMix: TMixMaterialMst;
curRel: TMixMatMstR;
curMat: TMaterialMst;
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;
nnidx := -1;
for i := 0 to AQuery.FieldCount-1 do begin
fieName := AQuery.Fields[i].FieldName;
if Pos('_2',fieName) > 0 then begin
nnidx := 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
tmpMix := TMixMaterialMst(Result[i]);
if SameText(obidVal, tmpMix.OBID) then begin
idx := i;
Break;
end;
end;
if idx = -1 then begin
curMix := TMixMaterialMst.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 curMix.OBID := valName
else if SameText(fieName, 'Name') then curMix.Name := valName
else if SameText(fieName, 'wClassName') then curMix.wClassName := valName
else if SameText(fieName, 'CreateDate') then curMix.CreateDate := valName
else if SameText(fieName, 'CreateTime') then curMix.CreateTime := valName
else if SameText(fieName, 'CreatorID') then curMix.CreatorID := valName
else if SameText(fieName, 'IsValid') then curMix.IsValid := valName
else if SameText(fieName, 'LcStatus') then curMix.LcStatus := valName
else if SameText(fieName, 'OrdDate') then curMix.OrdDate := valName
else if SameText(fieName, 'OrdCode') then curMix.OrdCode := valName
else if SameText(fieName, 'IsConfirm') then curMix.IsConfirm := valName
else if SameText(fieName, 'Descriptions') then curMix.Descriptions := valName
else if SameText(fieName, 'Unitt') then curMix.Unitt := valName
else if SameText(fieName, 'Qty') then curMix.Qty := valName
else if SameText(fieName, 'CustName') then curMix.CustName := valName;
end;
Result.Add(curMix);
end else begin
curMix := TMixMaterialMst(Result.Items[idx]);
end;
curRel := TMixMatMstR.Create(nil);
for i := nidx to nnidx-1 do begin
fieName := StringReplace(AQuery.Fields[i].FieldName, '_1', '', [rfReplaceAll]);
valName := AQuery.Fields[i].AsString;
if SameText(fieName, 'OBID') then curRel.OBID := valName
else if SameText(fieName, 'Name') then curRel.Name := valName
else if SameText(fieName, 'wClassName') then curRel.wClassName := valName
else if SameText(fieName, 'CreateDate') then curRel.CreateDate := valName
else if SameText(fieName, 'CreateTime') then curRel.CreateTime := valName
else if SameText(fieName, 'CreatorID') then curRel.CreatorID := valName
else if SameText(fieName, 'IsValid') then curRel.IsValid := valName
else if SameText(fieName, 'Revision') then curRel.Revision := valName
else if SameText(fieName, 'LOBID') then curRel.LOBID := valName
else if SameText(fieName, 'ROBID') then curRel.ROBID := valName
else if SameText(fieName, 'LClassName') then curRel.LClassName := valName
else if SameText(fieName, 'RClassName') then curRel.RClassName := valName
else if SameText(fieName, 'Qty') then curRel.Qty := valName
else if SameText(fieName, 'QtyEnc') then begin
curRel.QtyEnc := DecryptAES(valName, 'SecretKey123');
end else if SameText(fieName, 'Unitt') then curRel.Unitt := valName
else if SameText(fieName, 'Descriptions') then curRel.Descriptions := valName
else if SameText(fieName, 'OrdNum') then curRel.OrdNum := valName;
end;
curMix.qRelList.Add(curRel);
curMat := TMaterialMst.Create(nil);
for i := nnidx to AQuery.FieldCount-1 do begin
fieName := StringReplace(AQuery.Fields[i].FieldName, '_2', '', [rfReplaceAll]);
valName := AQuery.Fields[i].AsString;
if SameText(fieName, 'OBID') then curMat.OBID := valName
else if SameText(fieName, 'Name') then curMat.Name := valName
else if SameText(fieName, 'wClassName') then curMat.wClassName := valName
else if SameText(fieName, 'CreateDate') then curMat.CreateDate := valName
else if SameText(fieName, 'CreateTime') then curMat.CreateTime := valName
else if SameText(fieName, 'CreatorID') then curMat.CreatorID := valName
else if SameText(fieName, 'IsValid') then curMat.IsValid := valName
else if SameText(fieName, 'LcStatus') then curMat.LcStatus := valName
else if SameText(fieName, 'MatCode') then curMat.MatCode := valName
else if SameText(fieName, 'Descriptions') then curMat.Descriptions := valName
else if SameText(fieName, 'MatType') then curMat.MatType := valName
else if SameText(fieName, 'CustName') then curMat.CustName := valName;
end;
curRel.LObj.Add(curMat);
AQuery.Next;
end;
end;
function TMixMaterialMst.LoadFromQueryPtpProcList(AQuery: TFDQuery): TList;
var
i, idx, nidx, nnidx: Integer;
valName, fieName, obidVal: string;
curMix, tmpMix: TMixMaterialMst;
curRel: TMixMatMstR;
curMat: TMaterialMst;
curProc: TRtpProcessInfo;
curRtp: TRtpMaterialInfo;
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;
{
nnidx := -1;
for i := 0 to AQuery.FieldCount-1 do begin
fieName := AQuery.Fields[i].FieldName;
if Pos('_2',fieName) > 0 then begin
nnidx := 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
curProc := TRtpProcessInfo(Result[i]);
if SameText(obidVal, curProc.OBID) then begin
idx := i;
Break;
end;
end;
if idx = -1 then begin
curProc := TRtpProcessInfo.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, 'SumQty') then curProc.SumQty := valName
else if SameText(fieName, 'Unitt') then curProc.Unitt := valName
else if SameText(fieName, 'WorkTime') then curProc.WorkTime := valName
else if SameText(fieName, 'Descriptions') then curProc.Descriptions := valName;
end;
Result.Add(curProc);
end else begin
curProc := TRtpProcessInfo(Result.Items[idx]);
end;
curRtp := TRtpMaterialInfo.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 curRtp.OBID := valName
else if SameText(fieName, 'Name') then curRtp.Name := valName
else if SameText(fieName, 'wClassName') then curRtp.wClassName := valName
else if SameText(fieName, 'CreateDate') then curRtp.CreateDate := valName
else if SameText(fieName, 'CreateTime') then curRtp.CreateTime := valName
else if SameText(fieName, 'CreatorID') then curRtp.CreatorID := valName
else if SameText(fieName, 'IsValid') then curRtp.IsValid := valName
else if SameText(fieName, 'LcStatus') then curRtp.LcStatus := valName
else if SameText(fieName, 'OrdNum') then curRtp.OrdNum := valName
else if SameText(fieName, 'MatCode') then curRtp.MatCode := valName
else if SameText(fieName, 'Qty') then curRtp.Qty := valName
else if SameText(fieName, 'Unitt') then curRtp.Unitt := valName
else if SameText(fieName, 'Ratio') then curRtp.Ratio := valName
else if SameText(fieName, 'Descriptions') then curRtp.Descriptions := valName
//µðÅ©¸³Æ® AESº¹È£È­..
else if SameText(fieName, 'QtyEnc') then curRtp.QtyEnc := DecryptAES(valName, 'SecretKey123')
else if SameText(fieName, 'RatioVal') then curRtp.RatioVal := valName;
{
else if SameText(fieName, 'Qty') then curRel.Qty := valName
else if SameText(fieName, 'QtyEnc') then begin
curRel.QtyEnc := DecryptAES(valName, 'SecretKey123');
end else if SameText(fieName, 'Unitt') then curRel.Unitt := valName
else if SameText(fieName, 'Descriptions') then curRel.Descriptions := valName
else if SameText(fieName, 'OrdNum') then curRel.OrdNum := valName;
}
end;
curProc.qRtpList.Add(curRtp);
{
curMat := TMaterialMst.Create(nil);
for i := nnidx to AQuery.FieldCount-1 do begin
fieName := StringReplace(AQuery.Fields[i].FieldName, '_2', '', [rfReplaceAll]);
valName := AQuery.Fields[i].AsString;
if SameText(fieName, 'OBID') then curMat.OBID := valName
else if SameText(fieName, 'Name') then curMat.Name := valName
else if SameText(fieName, 'wClassName') then curMat.wClassName := valName
else if SameText(fieName, 'CreateDate') then curMat.CreateDate := valName
else if SameText(fieName, 'CreateTime') then curMat.CreateTime := valName
else if SameText(fieName, 'CreatorID') then curMat.CreatorID := valName
else if SameText(fieName, 'IsValid') then curMat.IsValid := valName
else if SameText(fieName, 'LcStatus') then curMat.LcStatus := valName
else if SameText(fieName, 'MatCode') then curMat.MatCode := valName
else if SameText(fieName, 'Descriptions') then curMat.Descriptions := valName
else if SameText(fieName, 'MatType') then curMat.MatType := valName
else if SameText(fieName, 'CustName') then curMat.CustName := valName;
end;
curRel.LObj.Add(curMat);
}
AQuery.Next;
end;
end;
class function TMixMaterialMst.LoadFromSingleQuery(AQuery: TFDQuery): TList;
var
curMix: TMixMaterialMst;
begin
Result := TList.Create;
while not AQuery.Eof do begin
curMix := TMixMaterialMst.Create(nil);
curMix.OBID := AQuery.FieldByName('OBID').AsString;
curMix.Name := AQuery.FieldByName('Name').AsString;
curMix.wClassName := AQuery.FieldByName('wClassName').AsString;
curMix.CreateDate := AQuery.FieldByName('CreateDate').AsString;
curMix.CreateTime := FormatDateTime('hh:nn:ss', AQuery.FieldByName('CreateTime').AsDateTime);
curMix.CreatorID := AQuery.FieldByName('CreatorID').AsString;
curMix.IsValid := AQuery.FieldByName('IsValid').AsString;
curMix.LcStatus := AQuery.FieldByName('LcStatus').AsString;
curMix.OrdDate := AQuery.FieldByName('OrdDate').AsString;
curMix.OrdCode := AQuery.FieldByName('OrdCode').AsString;
curMix.IsConfirm := AQuery.FieldByName('IsConfirm').AsString;
curMix.Descriptions := AQuery.FieldByName('Descriptions').AsString;
curMix.Unitt := AQuery.FieldByName('Unitt').AsString;
curMix.Qty := AQuery.FieldByName('Qty').AsString;
curMix.CustName := AQuery.FieldByName('CustName').AsString;
Result.Add(curMix);
AQuery.Next;
end;
end;
class function TMixMaterialMst.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 TMixMaterialMst.xAddSqlDoubleMark(velStr: String): String;
begin
Result := '';
Result := '"' + velStr + '"';
end;
class function TMixMaterialMst.xAddSqlMark(velStr: string): string;
begin
Result := '';
Result := '''' + velStr + '''';
end;
procedure TMixMaterialMst.xFreeAllFqProcList;
var
i: Integer;
tmpObj: TObject;
begin
if FqProcList <> nil then begin
i := 0;
while i < FqProcList.Count do begin
tmpObj := FqProcList.Items[i];
if tmpObj <> nil then tmpObj.Free;
tmpObj := nil;
FqProcList.Delete(i);
end;
FqProcList.Free; FqProcList:=nil;
end;
end;
class function TMixMaterialMst.xGetObjsMixMaterialMstList(AQuery: TFDQuery;
code, name, stDate, enDate: string): TList;
var
sql: string;
begin
Result := nil;
sql := 'SELECT obj0.* FROM "MixMaterialMst"obj0';
sql := sql + ' WHERE obj0."IsValid"=' + xAddSqlMark('t');
if Length(Trim(code)) > 0 then sql := sql + ' AND obj0."OrdCode"=' + xAddSqlMark(code);
if Length(Trim(name)) > 0 then sql := sql + ' AND obj0."Name"=' + xAddSqlMark(name);
if Length(Trim(stDate)) > 0 then begin
sql := sql + ' AND obj0."OrdDate">=' + xAddSqlMark(stDate);
sql := sql + ' AND obj0."OrdDate"<=' + xAddSqlMark(enDate);
end;
try
AQuery.Close;
AQuery.SQL.Text := sql;
AQuery.Open;
except
on E: Exception do ShowMessage('XGetObjsMixMaterialMstList Äõ¸® ½ÇÇà ¿À·ù: ' + E.Message);
end;
Result := LoadFromSingleQuery(AQuery);
end;
procedure TMixMaterialMst.xGetObjsMixMatRtpProcList(AQuery: TFDQuery);
var
sql: string;
begin
//FqProcList := nil;
sql := 'SELECT obj2.*, obj4.* FROM "MixMaterialMst"obj0, "MixMatRtpProcR"obj1, "RtpProcessInfo"obj2, "RtpProcRtpMatR"obj3, "RtpMaterialInfo"obj4';
sql := sql + ' WHERE obj0."IsValid"=' + xAddSqlMark('t');
sql := sql + ' AND obj0."OBID"=' + xAddSqlMark(OBID);
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 + ' AND obj3."IsValid"=' + xAddSqlMark('t');
sql := sql + ' AND obj3."LOBID"=obj2."OBID"';
sql := sql + ' AND obj4."IsValid"=' + xAddSqlMark('t');
sql := sql + ' AND obj4."OBID"=obj3."ROBID"';
try
AQuery.Close;
AQuery.SQL.Text := sql;
AQuery.Open;
except
on E: Exception do ShowMessage('xGetObjsMixMatRtpProcList Äõ¸® ½ÇÇà ¿À·ù: ' + E.Message);
end;
if FqProcList <> nil then xFreeAllFqProcList;
FqProcList := LoadFromQueryPtpProcList(AQuery);
end;
class function TMixMaterialMst.xGetStrsDistinctAttr(AQuery: TFDQuery;
colName: string): TStrings;
var
sql: string;
begin
Result := nil;
sql := 'SELECT DISTINCT ' + xAddSqlDoubleMark(colName) + ' FROM "MixMaterialMst"';
sql := sql + ' WHERE "IsValid"=' + xAddSqlMark('t');
try
AQuery.Close;
AQuery.SQL.Text := sql;
AQuery.Open;
except
on E: Exception do ShowMessage('xGetStrsDistinctAttr Äõ¸® ½ÇÇà ¿À·ù: ' + E.Message);
end;
Result := LoadFromStringsQuery(AQuery, colName);
end;
class function TMixMaterialMst.xGetStrSqlMixToMaterialList(AQuery: TFDQuery;
code, prod, stDate, enDate: string): TList;
var
sql: string;
begin
Result := nil;
sql := 'SELECT obj0.*, obj1.*, obj2.* FROM "MixMaterialMst"obj0, "MixMatMstR"obj1, "MaterialMst"obj2';
sql := sql + ' WHERE obj0."IsValid"=' + xAddSqlMark('t');
if Length(Trim(code)) > 0 then sql := sql + ' AND obj0."OrdCode"=' + xAddSqlMark(code);
if Length(Trim(prod)) > 0 then sql := sql + ' AND obj0."Name"=' + xAddSqlMark(prod);
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('xGetStrSqlMixToMaterialList Äõ¸® ½ÇÇà ¿À·ù: ' + E.Message);
end;
Result := LoadFromQuery(AQuery);
end;
end.