Files
dyp/backup_ansi/uFrame_Dyp001.pas
2026-05-07 20:25:34 +08:00

335 lines
12 KiB
ObjectPascal
Raw Permalink 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 uFrame_Dyp001;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
System.ImageList, FMX.ImgList, FMX.Controls.Presentation, FMX.Edit,
FMX.Objects,uFrameBase,uShowInfo,uKsoap,uPucFun, FMX.Memo.Types,
FMX.ScrollBox, FMX.Memo, DateUtils;
type
TFrame_Dyp001 = class(TFrameBase)
Rectangle88: TRectangle;
Option1: TRectangle;
Glyph9: TGlyph;
Edit_CaiZhi_Label: TText;
Text19: TText;
Edit_CaiZhi: TEdit;
Option2: TRectangle;
Glyph2: TGlyph;
Edit_banhou_Label: TText;
Text6: TText;
Edit_banhou: TEdit;
Option3: TRectangle;
Glyph3: TGlyph;
Edit_jiexi_Label: TText;
Text23: TText;
Edit_jiexi: TEdit;
Option4: TRectangle;
Glyph12: TGlyph;
Edit_xiankuang_Label: TText;
Text28: TText;
Edit_xiankuang: TEdit;
Option7: TRectangle;
Glyph13: TGlyph;
Edit_rongchadada_Label: TText;
Text30: TText;
Edit_rongchadada: TEdit;
ImageList1: TImageList;
Option6: TRectangle;
Glyph1: TGlyph;
Edit_rongchaxiao_Label: TText;
Text2: TText;
Edit_rongchaxiao: TEdit;
Option5: TRectangle;
Glyph4: TGlyph;
Edit_jianju_Label: TText;
Text4: TText;
Edit_jianju: TEdit;
TxtError: TText;
Timer1: TTimer;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
Rectangle1: TRectangle;
Glyph5: TGlyph;
Edit1_Label: TText;
Text3: TText;
Edit1: TEdit;
Rectangle2: TRectangle;
Glyph6: TGlyph;
Edit2_Label: TText;
Text7: TText;
Edit2: TEdit;
Rectangle3: TRectangle;
procedure Edit_CaiZhiClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
private
iLine: integer;
{ Private declarations }
public
procedure FillDefaultValue(sPartnumValue,sDefaultTxt:string);override; //填写默认值
function DoExec():boolean;override; //判断输入是否有效,执行插入主表,或打开窗体
function CheckValid(var sTxt:string):boolean;override;
end;
implementation
{$R *.fmx}
uses uDM, json_webservice, uSafeLog;
function TFrame_Dyp001.CheckValid(var sTxt:string):boolean; //返回面次数据
var
aa:Extended;
begin
Result:=false;
if Trim(Edit_CaiZhi.Text)='' then begin Error(Edit_CaiZhi,TxtError,Edit_CaiZhi_Label.Text+'不能为空');Exit;end;
if Trim(Edit_rongchaxiao.Text)='' then begin Error(Edit_rongchaxiao,TxtError,Edit_rongchaxiao_Label.Text+'不能为空');Exit;end;
if Trim(Edit_banhou.Text)='' then begin Error(Edit_banhou,TxtError,Edit_banhou_Label.Text+'不能为空');Exit;end;
if Trim(Edit_jiexi.Text)='' then begin Error(Edit_jiexi,TxtError,Edit_jiexi_Label.Text+'不能为空');Exit;end;
if Trim(Edit_xiankuang.Text)='' then begin Error(Edit_xiankuang,TxtError,Edit_xiankuang_Label.Text+'不能为空');Exit;end;
// if Trim(Edit_rongchadada.Text)='' then begin Error(Edit_rongchadada,TxtError,Edit_rongchadada_Label.Text+'不能为空');Exit;end;
// if Trim(Edit1.Text)='' then begin Error(Edit1,TxtError,Edit1.Text+'不能为空');Exit;end;
// if Trim(Edit2.Text)='' then begin Error(Edit2,TxtError,Edit2.Text+'不能为空');Exit;end;
if Trim(Edit_jianju.Text)='' then begin Error(Edit_jianju,TxtError,Edit_jianju_Label.Text+'不能为空');Exit;end;
if not TryStrToFloat(Edit_CaiZhi.Text,aa) then begin Error(Edit_CaiZhi,TxtError,Edit_CaiZhi_Label.Text+'类型错误,请重新输入');Exit;end;
if not TryStrToFloat(Edit_banhou.Text,aa) then begin Error(Edit_banhou,TxtError,Edit_banhou_Label.Text+'类型错误,请重新输入');Exit;end;
if not TryStrToFloat(Edit_jiexi.Text,aa) then begin Error(Edit_jiexi,TxtError,Edit_jiexi_Label.Text+'类型错误,请重新输入');Exit;end;
if not TryStrToFloat(Edit_xiankuang.Text,aa) then begin Error(Edit_xiankuang,TxtError,Edit_xiankuang_Label.Text+'类型错误,请重新输入');Exit;end;
// if not TryStrToFloat(Edit_rongchaxiao.Text,aa) then begin Error(Edit_rongchaxiao,TxtError,Edit_rongchaxiao_Label.Text+'类型错误,请重新输入');Exit;end;
// if not TryStrToFloat(Edit_rongchadada.Text,aa) then begin Error(Edit_rongchadada,TxtError,Edit_rongchadada_Label.Text+'类型错误,请重新输入');Exit;end;
// if not TryStrToFloat(Edit1.Text,aa) then begin Error(Edit1,TxtError,Edit1_Label.Text+'类型错误,请重新输入');Exit;end;
// if not TryStrToFloat(Edit2.Text,aa) then begin Error(Edit2,TxtError,Edit2_Label.Text+'类型错误,请重新输入');Exit;end;
Result:=true;
if Result then Error(Edit_CaiZhi,TxtError,'');
end;
procedure TFrame_Dyp001.FillDefaultValue(sPartnumValue,sDefaultTxt:string);
var
tmpList:TStrings;
begin
if sDefaultTxt='' then Exit;
// tmpList:=TStringList.Create;
try
// tmpList.DelimitedText:= ReplaceStrWork(sDefaultTxt);
// if tmpList.Count>13 then
begin
Edit_CaiZhi.Text:=GetJSONValue(sDefaultTxt, '温度');//GetRightPart(tmpList.Strings[7],'');
Edit_banhou.Text:=GetJSONValue(sDefaultTxt, '距离');//GetRightPart(tmpList.Strings[8],'');
Edit_jiexi.Text:=GetJSONValue(sDefaultTxt, '回波时间');//GetRightPart(tmpList.Strings[9],'');
Edit_rongchaxiao.Text:=GetJSONValue(sDefaultTxt, '底噪');//GetRightPart(tmpList.Strings[11],'');
Edit_jianju.Text:=GetJSONValue(sDefaultTxt, '卡关');//GetRightPart(tmpList.Strings[4],':');
Edit_xiankuang.Text:=GetJSONValue(sDefaultTxt, '幅值');//GetRightPart(tmpList.Strings[13],'');
Edit_rongchadada.Text:=GetJSONValue(sDefaultTxt, '入水盲区');//GetRightPart(tmpList.Strings[12],'');
Edit2.Text:=GetJSONValue(sDefaultTxt, '出水盲区');//GetRightPart(tmpList.Strings[12],'');
Edit1.Text:=GetJSONValue(sDefaultTxt, '盲区差值');//GetRightPart(tmpList.Strings[12],'');
end;
fDevRecord.P_ORG_CODE:= (GetJSONValue(sDefaultTxt, 'SN码'));
fDevRecord.P_ORG_CODE_id:= GetJSONValue(sDefaultTxt, 'ID');
fDevRecord.P_DIE_NAME:= Edit_jianju.Text; //是否合格
if Assigned(FOnButtonClick) then
FOnButtonClick(Self); // 将Frame自身作为Sender传递
if self.Tag=4 then
begin
Option7.Visible:= False;
Rectangle2.Visible:= False;
Rectangle1.Visible:= False;
end;
{tmpList.DelimitedText:=sPartnumValue;
if tmpList.Count>5 then //这里根据料号返回信息填写缺省值
Edit_banhou.Text:=tmpList.Strings[5];}
finally
// tmpList.Free;
end;
end;
function GetLatestFileInDir(const DirPath: string): string;
var
SearchRec: TSearchRec;
LatestTime: TDateTime;
CurrentTime: TDateTime;
begin
Result := '';
LatestTime := MinDateTime; // 初始化为最小日期
if FindFirst(IncludeTrailingPathDelimiter(DirPath) + 'bx-*.txt', faAnyFile, SearchRec) = 0 then
begin
repeat
if (SearchRec.Name <> '.') and (SearchRec.Name <> '..') then
begin
CurrentTime := FileDateToDateTime(SearchRec.Time);
if CompareDateTime(CurrentTime, LatestTime) > 0 then
begin
LatestTime := CurrentTime;
Result := IncludeTrailingPathDelimiter(DirPath) + SearchRec.Name;
end;
end;
until FindNext(SearchRec) <> 0;
FindClose(SearchRec);
end;
end;
procedure TFrame_Dyp001.Timer1Timer(Sender: TObject);
var
sFPhat: String;
y, iLen: Integer;
tmpList:TStrings;
fileStream: TFileStream; // 用于以只读方式打开文件
procedure ListfillValue(sDefaultTxt:string);
var
// tmpList:TStrings;
ii: Integer;
begin
if sDefaultTxt='' then Exit;
// tmpList:=TStringList.Create;
// try
// tmpList.Delimiter:= ',';
// tmpList.DelimitedText:= ReplaceStrWork(sDefaultTxt);
// Memo1.Lines.Clear;
//
// // for ii := 0 to tmpList.Count-1 do
// // Memo1.Lines.Add(tmpList.Strings[ii]);
//
// finally
// tmpList.Free;
// end;
JSonProcessSensorData:= FormatDataToJSON(sDefaultTxt);
end;
begin
inherited;
sFPhat:= GetLatestFileInDir(dm.MemTableReadKeyValue('tv_DirData','locad_dir')); //本地文件目录
if FileExists(sFPhat) then
begin
tmpList:= TStringList.Create;
fileStream := TFileStream.Create(sFPhat, fmOpenRead or fmShareDenyWrite); // 只读且禁止写入
with tmpList do
try
tmpList.LoadFromStream(fileStream); // 从流加载内容
// LoadFromFile(sFPhat);
iLen := Count;
if iLen>iLine then
begin
// if OpenDialog1.Execute then
Memo1.BeginUpdate;
try
if tmpList.Count>0 then
for y := tmpList.Count downto 1 do
if (tmpList.Strings[y-1]<>'') then
begin
// ListfillValue(tmpList.Strings[y-1]);
// Memo1.Text:= tmpList.Strings[y-1];
JSonProcessSensorData:= FormatDataToJSON(tmpList.Strings[y-1]);
FillDefaultValue('', JSonProcessSensorData);
break;
end;
//Memo1.Lines.Assign(tmpList); // 关键修改:将当前TStringList内容复制到Memo
finally
Memo1.EndUpdate;
end;
iLine := tmpList.Count;
end;
finally
fileStream.Free; // 释放文件流
Free;
end;
end
else
WorkLog.MessageInfo('sFPhat:%s ' , [sFPhat]);
end;
function TFrame_Dyp001.DoExec():boolean;
var
LotNoRecord:TLotNoRecord;
vId:Integer;
sTxt:string;
sError:string;
vP_ID:Double;
begin
Result:=false;
if CheckValid(sTxt) then //上传数据
begin
LotNoRecord:=TLotNoRecord.Create('-1'); //初始化记录
LotNoRecord.P_LOT:=ksoap.P_Lot;
LotNoRecord.P_LOT_TYPE:='正常板';
LotNoRecord.P_Enable:='Y';
LotNoRecord.P_ID:=0;
LotNoRecord.P_ORG_CODE:=ksoap.P_ORG_CODE; //廠區
LotNoRecord.P_NUM:=ksoap.P_WORK_NUM; //工號
LotNoRecord.P_PC:=ksoap.P_PC; //製程
LotNoRecord.P_LINE:=ksoap.P_LINE; //線別
LotNoRecord.P_LINE_NUM:=ksoap.P_LINE_NUM; //線別編號
if Edit_CaiZhi.Text<>'' then
LotNoRecord.P_DIE_USE_NUM:=StrToFloat(Edit_CaiZhi.Text); //温度
if Edit_banhou.Text<>'' then
LotNoRecord.P_LINE_SPEED:=StrToFloat(Edit_banhou.Text); //距离
if Edit_jiexi.Text<>'' then
LotNoRecord.P_ELE_CUR_DENSITY:=StrToFloat(Edit_jiexi.Text); //回波时间
if Edit_xiankuang.Text<>'' then
LotNoRecord.P_ELE_AREA1:=StrToFloat(Edit_xiankuang.Text); //幅值
if Edit_rongchadada.Text<>'' then
LotNoRecord.P_PRODUCT_PRESSURE:=StrToFloat(Edit_rongchadada.Text); //入水盲区
if Edit_rongchaxiao.Text<>'' then
LotNoRecord.P_COM_TEMPERATURE:=StrToFloat(Edit_rongchaxiao.Text); //底噪
if edit2.Text<>'' then
LotNoRecord.P_SIDE:=edit2.Text; //出水盲区
if edit1.Text<>'' then
LotNoRecord.P_SHORT_CIRCUIT:=edit1.Text; //盲区差值
LotNoRecord.P_DIE_NAME:=(Edit_jianju.Text); //是否合格
LotNoRecord.P_CREATION_DATE:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
sError:='';
// vP_ID:=KJSon.Thread_cf_traceability_seq_f(ksoap.P_ORG_CODE,sError);
LotNoRecord.P_ID:=vP_ID;
//直接调用API,出错再保存本地
if not KJSon.Thread_Insert_CM_WIP_PROCESS_LINE_HISTORY_NEW(LotNoRecord,sError) then //提交主表不成功
begin
if sError='連接數據庫服務器失败' then
begin
dm.InsertMain(vId,LotNoRecord,true);
ShowInfoOK('数据库连接失败,已暂存本地,可以继生产');
Result:=true;
end
else
ShowError(sError);
end
else
begin
ShowInfoOK('数据上传成功, 可以继生产');
Result:=true;
end;
end;
end;
procedure TFrame_Dyp001.Edit_CaiZhiClick(Sender: TObject);
begin
inherited;
ShowTouchKeyBoard();
end;
end.