Initial commit - Delphi MES client project

This commit is contained in:
Developer
2026-05-07 20:25:34 +08:00
commit 819b4824f6
466 changed files with 1176403 additions and 0 deletions
+675
View File
@@ -0,0 +1,675 @@
unit uBlandDBJConent;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
System.ImageList, FMX.ImgList, FMX.Controls.Presentation, FMX.Edit,uTcpDevice,
FMX.Layouts, System.Rtti, FMX.Grid.Style, FMX.Memo, FMX.ScrollBox, FMX.Grid,
Winapi.Windows, uDM,uShowInfo, FMX.StdCtrls,uKsoap,uSafeLog,Winapi.ActiveX,
System.StrUtils, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, REST.Types, Data.Bind.Components, Data.Bind.ObjectScope, REST.Client,
FMX.Memo.Types;
type
TfrmBlandDBJConent = class(TForm)
Rectangle1: TRectangle;
Rectangle2: TRectangle;
Rectangle3: TRectangle;
TxtFactoryCode: TText;
Rectangle4: TRectangle;
Rectangle6: TRectangle;
Text2: TText;
ImageList1: TImageList;
Rectangle18: TRectangle;
Rectangle19: TRectangle;
Rectangle20: TRectangle;
Text7: TText;
Rectangle26: TRectangle;
Text17: TText;
Rectangle33: TRectangle;
Text3: TText;
Rectangle5: TRectangle;
Rectangle7: TRectangle;
Rectangle8: TRectangle;
Rectangle10: TRectangle;
Rectangle11: TRectangle;
Rectangle12: TRectangle;
Memo1: TMemo;
Text4: TText;
Text5: TText;
Rectangle15: TRectangle;
Rectangle16: TRectangle;
Rectangle17: TRectangle;
Rectangle22: TRectangle;
Text11: TText;
TxtEmpNo: TText;
Rectangle25: TRectangle;
Text12: TText;
TxtLotNo: TText;
Rectangle28: TRectangle;
Text13: TText;
TxtGoodsNo: TText;
Rectangle29: TRectangle;
Line1: TLine;
Rectangle30: TRectangle;
Line2: TLine;
Text14: TText;
TxtPc: TText;
Text18: TText;
TxtLine: TText;
Text20: TText;
TxtLineNum: TText;
Rectangle31: TRectangle;
Text22: TText;
TxtLotNum: TText;
Rectangle32: TRectangle;
Text26: TText;
Text29: TText;
Line3: TLine;
StringGrid1: TStringGrid;
StringColumn1: TStringColumn;
StringColumn6: TStringColumn;
Rectangle35: TRectangle;
Text21: TText;
Text16: TText;
Glyph23: TGlyph;
TxtVerInfo: TText;
Rectangle001: TRectangle;
Glyph1: TGlyph;
Text6: TText;
TxtPc11: TText;
EdtInput1: TEdit;
Rectangle23: TRectangle;
Text1: TText;
Text10: TText;
TxtError: TText;
StringColumn2: TStringColumn;
TxtBarCodePrompt: TText;
TxtLotNumInfo: TText;
Timer1: TTimer;
Rectangle9: TRectangle;
Text8: TText;
Text9: TText;
IdHTTP1: TIdHTTP;
procedure Text16Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Text5Click(Sender: TObject);
procedure Rectangle20Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure Text1Click(Sender: TObject);
procedure Text17Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TxtBarCodePromptClick(Sender: TObject);
procedure TxtLotNumInfoClick(Sender: TObject);
private
BarCodeDic:TStringList;
procedure F2DCodeWork(Sender: TObject;sValue: string);
procedure F2DCodeWork2(Sender:TObject;sValue: string); //读取条码
procedure NumEnceWork(Avalue: string);
procedure RfidWork(Avalue: string);
procedure F2DCodeShowState(Avalue: string); //显示读头状态
procedure AddLog(sLog:string);
procedure ShowEndNum();
function httpget(url: string;JsonValue:string): String;
{ Private declarations }
public
iDetailCount:Integer;
iCount:Integer;
vP_ID:Double;
vId:integer;
F2DCode:array[0..9] of T2DCode;
Rfid:TRfid;
NumEnce:TNumEnce;
LotNoRecord:TLotNoRecord;
end;
var
frmBlandDBJConent: TfrmBlandDBJConent;
implementation
{$R *.fmx}
uses uPucFun, uMain, uAlarmLed, uErrorInfo, IdGlobal; //609104
procedure TfrmBlandDBJConent.NumEnceWork(Avalue: string);
begin
end;
procedure TfrmBlandDBJConent.RfidWork(Avalue: string);
begin
end;
procedure TfrmBlandDBJConent.ShowEndNum();
begin
TxtLotNumInfo.Visible:=ksoap.P_Lot_Num-iCount<6;
if TxtLotNumInfo.Visible then
begin
if ksoap.P_Lot_Num>iCount then
TxtLotNumInfo.Text:=Format('该批次即将完成,还剩%d片,请注意换批!',[ksoap.P_Lot_Num-iCount])
else
TxtLotNumInfo.Text:='该批次已经完成,请注意换批!';
end;
end;
procedure TfrmBlandDBJConent.AddLog(sLog:string);
begin
if Memo1.Lines.Count>100 then
Memo1.Lines.Delete(0);
Memo1.Lines.Add(FormatDateTime('yyyymmdd hh:mm:ss.zzz ',Now)+sLog);
Memo1.SelStart:=Length(Memo1.Text);
Memo1.SelLength:=0;
end;
procedure TfrmBlandDBJConent.F2DCodeShowState(Avalue: string); //显示读头状态
begin
AddLog(Avalue);
end;
procedure TfrmBlandDBJConent.F2DCodeWork(Sender:TObject;sValue: string); //读取条码
var
sError: string;
procedure ReOpen2D();
begin
TThread.CreateAnonymousThread(
procedure
begin
Sleep(3000);
TThread.Synchronize( nil,
procedure
begin
if Sender<>nil then T2DCode(Sender).Open;
TxtBarCodePrompt.Text:='读码中...';
end
);
end
).Start;
end;
begin
AddLog('条码读取成功:'+sValue);
if sValue='ERROR' then
BEGIN
AddLog('条码读取出错'+sValue);
WorkLog.MessageInfo('条码读取出错'+sValue);
TxtBarCodePrompt.Text:='二维码读取出错';
ReOpen2D();
Exit;
END;
// AddLog('条码读取成功1'+sValue);
if BarCodeDic.IndexOf(sValue)>=0 then //判断重复
BEGIN
AddLog('条码重复'+sValue);
WorkLog.MessageInfo('条码重复'+sValue);
TxtBarCodePrompt.Text:=Format('二维码重复:%s',[sValue]);
ReOpen2D();
Exit;
END;
// AddLog('条码读取成功2'+sValue);
// if LeftStr(TxtLotNo.Text,8)<>LeftStr(sValue,8) then
// begin
// AddLog('注意混批:'+sValue);
// if NumEnce<>nil then
// begin
// NumEnce.SendStr('#011301');
// Sleep(500);
// NumEnce.SendStr('#011300');
// end;
// AddLog('条码读取成功23'+sValue);
// ReOpen2D();
// Exit;
// //Sleep(100);
// // NumEnce.SendStr('#011300');
// // Sleep(50);
// // NumEnce.SendStr('#011400');
// end;
// AddLog('条码读取成功3'+sValue);
if NumEnce<>nil then
begin
NumEnce.SendStr('#011101');
Sleep(500);
NumEnce.SendStr('#011100');
//Sleep(100);
// NumEnce.SendStr('#011300');
// Sleep(50);
// NumEnce.SendStr('#011400');
end;
// AddLog('条码读取成功4'+sValue);
if AlarmLed<>nil then //打开报警灯
begin
AlarmLed.SparkGreen(sError);
end;
BarCodeDic.Add(sValue);
with StringGrid1 do
begin
inc(iCount);
BeginUpdate;
RowCount:=RowCount+1;
Cells[0,RowCount-1]:=iCount.ToString;
Cells[1,RowCount-1]:=sValue;
Cells[2,RowCount-1]:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
SelectRow(RowCount-1);
EndUpdate;
inc(iDetailCount);
Text29.Text:=iCount.ToString;
end;
ShowEndNum();
TxtBarCodePrompt.Text:=Format('二维码 %d:%s',[iCount,sValue]);
//EdtInput1.Text:= sValue;
WorkLog.MessageInfo('条码sValue:'+sValue);
// AddLog('条码读取成功5'+sValue);
//开启线程,提交数据到服务器,提交不成功,就保存在本地
TThread.CreateThreadX<string>(
procedure (Avalue:string)
var
DetailRecord:TDetailRecord;
sError:string;
bResult:boolean;
tmp,tmp1:string;
begin
DetailRecord.P_ORG_CODE:=ksoap.P_ORG_CODE; //廠區
DetailRecord.P_LOT:=TxtLotNo.Text; //批号
DetailRecord.P_BC:=Avalue; // 條碼(批號10碼+PNL3碼)
DetailRecord.P_PC:=ksoap.P_PC; //製程
DetailRecord.P_LINE:=ksoap.P_LINE; //線別
DetailRecord.P_LINE_NUM:=ksoap.P_LINE_NUM; //線別編號
DetailRecord.P_LOT_TYPE:='-1'; // 正常板/重工板
DetailRecord.P_TROLLEY_NUM:=LotNoRecord.P_TROLLEY_NUM; // 台車編號
DetailRecord.P_COPPER_MODEL:=LotNoRecord.P_COPPER_MODEL; // 銅箔型號
DetailRecord.P_BUFFER_TYPE:=LotNoRecord.P_Buffer; // 緩衝材型號
DetailRecord.P_CREATION_DATE:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
DetailRecord.P_ID:=vP_ID.ToString;
CoInitialize(nil);
try
bResult:=Ksoap.Insert_cc_wip_lot_bc_history(DetailRecord,sError);
if sError='連接數據庫服務器失败' then
begin
dm.InsertDetail(vId,DetailRecord);
tmp:=Avalue+'提交失敗:連接數據庫服務器失败,暫存本地';
end;
if bResult then
begin
tmp:=Avalue+'提交成功:OK';
tmp1:= (httpget('/steel-plate/put/product/2did',
'"lineNum":"'+ksoap.P_LINE+'","lotNumber":"'+
ksoap.P_Lot+'","lotPanel":"'+
Avalue+'","processLineId":"'+
vP_ID.ToString+'"'));
AddLog(tmp1);
WorkLog.MessageInfo(tmp1);
end
else
tmp:=Avalue+'提交失敗:'+sError;
WorkLog.MessageInfo(tmp);
finally
CoUninitialize;
end;
TThread.Synchronize( nil,
procedure
begin
AddLog(tmp);
end
);
end,sValue
).Start;
//开启线程,3秒后开启2D读头
ReOpen2D();
end;
procedure TfrmBlandDBJConent.F2DCodeWork2(Sender:TObject;sValue: string); //读取条码
var
sError: string;
procedure ReOpen2D();
begin
TThread.CreateAnonymousThread(
procedure
begin
Sleep(3000);
TThread.Synchronize( nil,
procedure
begin
if Sender<>nil then T2DCode(Sender).Open;
TxtBarCodePrompt.Text:='读码中...';
end
);
end
).Start;
end;
begin
AddLog('条码2读取成功:'+sValue);
if sValue='ERROR' then
BEGIN
AddLog('条码2读取出错'+sValue);
WorkLog.MessageInfo('条码2读取出错'+sValue);
TxtBarCodePrompt.Text:='二维码2读取出错';
ReOpen2D();
Exit;
END;
// AddLog('条码读取成功4'+sValue);
if AlarmLed<>nil then //打开报警灯
begin
AlarmLed.SparkGreen(sError);
end;
//EdtInput1.Text:= sValue;
WorkLog.MessageInfo('条码2sValue:'+sValue);
// AddLog('条码读取成功5'+sValue);
//开启线程,提交数据到服务器,提交不成功,就保存在本地
TThread.CreateThreadX<string>(
procedure (Avalue:string)
var
DetailRecord:TDetailRecord;
sError:string;
bResult:boolean;
tmp:string;
begin
CoInitialize(nil);
try
try
tmp:= (httpget('/mirror-plate/put/product',
'"fixtureCodeSeq":"'+Avalue+'","lotNumber":"'+
ksoap.P_Lot+'","machineName":"'+
ksoap.P_LINE+'","machineNumber":"'
+ksoap.P_LINE_NUM+'","processCode":"'+
ksoap.P_PC+'","processLineId":"'+
vP_ID.ToString+'","trayNumber":"'+
LotNoRecord.P_TROLLEY_NUM+'","workNumber":"'+
ksoap.P_WORK_NUM+'"'));
// AddLog(tmp);
WorkLog.MessageInfo(tmp);
finally
CoUninitialize;
end;
except
on e:Exception do
begin
DbApiLog.Error('TIdHttp 错误:%s',[ChangeErrorInfo(E.Message)]);
// sError:=ChangeErrorInfo(E.Message);
end;
end;
TThread.Synchronize( nil,
procedure
begin
Text9.Text:=(StrToInt(Text9.Text)+1).ToString;
AddLog(tmp);
end
);
end,sValue
).Start;
//开启线程,3秒后开启2D读头
ReOpen2D();
end;
procedure TfrmBlandDBJConent.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if (F2DCode[0]<>nil) and (StrToInt(Text29.Text)=0) then
Text29.Text:= TxtLotNum.Text;
//退出的时候
dm.InsertQtyTime(vId.ToString,'0',Text29.Text,'-1','-1','-1','-1');
end;
function TfrmBlandDBJConent.httpget(url:string;JsonValue:string):String;
var
IdHTTP1: TIdHTTP;
jsonToSend,tmpStream : TStringStream;
surl,tmpStr : String;
begin
IdHTTP1 := TIdHttp.Create(nil);
try
IdHTTP1.HandleRedirects := True;//允许头转向
IdHTTP1.ReadTimeout := 5000;//请求超时设置
IdHTTP1.Request.ContentType := 'application/json';//设置内容类型为json
IdHTTP1.HandleRedirects:=True;
IdHTTP1.ProtocolVersion:=pv1_1;
IdHTTP1.HTTPOptions:=IdHTTP1.HTTPOptions+[hoTreat302Like303];
// Memo1.Text:=IdHTTP1.Post('http://www.*.com/User/login.aspx',StrLst,IndyTextEncoding(encUTF8));
//http.Request.CustomHeaders.Values['Authorization'] := Concat('Bearer ',这里写token信息 );
jsonToSend := TStringStream.Create('{'+UTF8Encode(JsonValue)+'}');//",name":"Peter Pan" 创建一个包含JSON数据的变量
tmpStream := TStringStream.Create('');
try
DbApiLog.MessageInfo('TIdHttp_jsonToSend:%s',[jsonToSend.DataString]);
jsonToSend.Position := 0;//将流位置置为0
surl:= 'http://home170.compeq.huizhou.gd.cn:8090'+url;
DbApiLog.MessageInfo('IdHttp_Post:%s,%s',[surl,jsonToSend.DataString]);
IdHTTP1.Post(surl, jsonToSend,tmpStream);//用MEMO控件接收POST后的数据返回
tmpStr:= UTF8Decode(tmpStream.DataString);
DbApiLog.MessageInfo('IdHttp_Post返回:%s',[tmpStr]);
finally
jsonToSend.free;
tmpStream.free;
IdHTTP1.free;//用完记得释放
end;
Result:= tmpStr;
except
on e:Exception do
begin
Result:='';
DbApiLog.Error('TIdHttp 错误:%s,%s,%s',[surl,jsonToSend.DataString,ChangeErrorInfo(E.Message)]);
// sError:=ChangeErrorInfo(E.Message);
end;
end;
end;
procedure TfrmBlandDBJConent.FormCreate(Sender: TObject);
var
sDevName,sIp,sPort:string;
tmpValue:string;
i,i_F2DCode:integer;
begin
TxtFactoryCode.Text:= FactoryCode; //厂区
TxtEmpNo.Text:=ksoap.P_WORK_NUM; //工号
TxtLotNo.Text:=ksoap.P_Lot; //批号
TxtGoodsNo.Text:=ksoap.P_Goods_Num; //料号
TxtPc.Text:=ksoap.P_PC; //制程代码
TxtLine.Text:=ksoap.P_LINE; //制程名
TxtLineNum.Text:=ksoap.P_LINE_NUM; //线别
TxtLotNum.Text:=ksoap.P_Lot_Num.tostring;
ShowEndNum();
TxtVerInfo.Text:=GetBuildInfo;
Memo1.Lines.Clear;
TxtShowErrorInfo(TxtError,'');
iCount:=0;
iDetailCount:=0;
BarCodeDic:=TStringList.Create;
BarCodeDic.Sorted:=true;
//Rectangle001.Visible:=ksoap.P_LINE='油墨印刷機';
i_F2DCode:= 0;
//根据配置加载设备
for i := 1 to 9 do
begin
tmpValue:=dm.MemTableReadKeyValue('读头','tv_line_speed'+i.ToString);
if tmpValue<>'' then
begin
if CheckParameter(tmpValue,sDevName,sIp,sPort) then
begin
if sameText(sDevName.ToLower,'keyence') then //1、2D读头 ,2、鏡板、板翹读头
begin
inc(i_F2DCode);
F2DCode[i]:=T2DCode.Create(sIp,sPort.ToInteger);
F2DCode[i].Num:=i_F2DCode;
if i_F2DCode=1 then
F2DCode[i].OnWork:=F2DCodeWork
else
F2DCode[i].OnWork:=F2DCodeWork2;
F2DCode[i].OnShowState:=F2DCodeShowState;
F2DCode[i].Connect;
TThread.CreateThreadX<Integer>(
procedure (Avalue:Integer)
begin
Sleep(1000);
TThread.Synchronize( nil,
procedure
begin
F2DCode[Avalue].Open;
end
);
end,i
).Start;
end;
if sameText(sDevName,'RFID') then //RFID
begin
Rfid:=TRfid.Create(sIp,sPort.ToInteger);
Rfid.OnWork:=RfidWork;
end;
if sameText(sDevName,'WJ95') then //采集器
begin
NumEnce:=TNumEnce.Create(sIp,sPort.ToInteger);
NumEnce.OnWork:=NumEnceWork;
end;
end;
end;
end;
//调整网格列宽
StringColumn6.Width:=StringGrid1.Width-StringColumn1.Width-25-StringColumn2.Width;
end;
procedure TfrmBlandDBJConent.FormDestroy(Sender: TObject);
var
i:integer;
begin
for i := 0 to 9 do
begin
if F2DCode[i]<>nil then
begin
F2DCode[i].Close;
Sleep(200);
FreeandNil(F2DCode[i]);
end;
end;
if Rfid<>nil then FreeandNil(Rfid);
if NumEnce<>nil then FreeandNil(NumEnce);
BarCodeDic.Free;
end;
procedure TfrmBlandDBJConent.FormShow(Sender: TObject);
begin
// AddLog(httpget('/mirror-plate/put/product',
// '"fixtureCodeSeq":"D2FDXJG1D2631","lotNumber":"'+
// ksoap.P_Lot+'","machineName":"'+
// ksoap.P_LINE+'","machineNumber":"'
// +ksoap.P_LINE_NUM+'","processCode":"'+
// ksoap.P_PC+'","processLineId":"'+
// vP_ID.ToString+'","trayNumber":"'+
// LotNoRecord.P_TROLLEY_NUM+'","workNumber":"'+
// ksoap.P_WORK_NUM+'"'));
end;
procedure TfrmBlandDBJConent.Rectangle20Click(Sender: TObject);
begin
if ShowInfoOKCancel('該批還沒有完成,真的要退出嗎?') then Close;
end;
procedure TfrmBlandDBJConent.Text16Click(Sender: TObject);
begin
ShowTouchKeyBoard();
end;
procedure TfrmBlandDBJConent.Text17Click(Sender: TObject);
begin
Close;
end;
procedure TfrmBlandDBJConent.Text1Click(Sender: TObject);
var
sError:string;
begin
sError:='';
//更换烤箱号
if Text1.TextSettings.FontColor=TAlphaColorRec.Silver then Exit;
Text1.TextSettings.FontColor:=TAlphaColorRec.Silver;
try
if ShowInfoOKCancel(Format('確定要%s嗎?',[Text6.Text])) then
begin
if not Ksoap.Thread_Check_tool_or_equip_status_f(Ksoap.P_Lot,Ksoap.P_LINE_NUM,EdtInput1.Text,'-1',sError) then
begin
TxtShowErrorInfo(TxtError,sError);
Exit;
end;
vP_ID:=Ksoap.Thread_cf_traceability_seq_f(Ksoap.P_ORG_CODE,sError);
if vP_ID=0 then //取不到ID
begin
TxtShowErrorInfo(TxtError,sError);
Exit;
end;
dm.InsertQtyTime(vId.ToString,'0',iDetailCount.ToString,'-1','-1','-1','-1');
iDetailCount:=0;
LotNoRecord.P_ID:=vP_ID;
LotNoRecord.P_TROLLEY_NUM := EdtInput1.Text;
if vP_ID=0 then
BEGIN
dm.InsertMain(vId,LotNoRecord,false);
END
ELSE
BEGIN
//直接调用API,出错再保存本地
if not Ksoap.Thread_Insert_CM_WIP_PROCESS_LINE_HISTORY_NEW(LotNoRecord,sError) then //提交主表不成功
begin
if sError='連接數據庫服務器失败' then
begin
dm.InsertMain(vId,LotNoRecord,false);
end
else
ShowError(sError);
end
else
begin
dm.InsertMain(vId,LotNoRecord,false);
dm.UpdateMainId(vId,vP_ID.ToString,True);
end;
END;
end;
finally
Text1.TextSettings.FontColor:=TAlphaColorRec.White;
end;
end;
procedure TfrmBlandDBJConent.Text5Click(Sender: TObject);
begin
MEMO1.Lines.Clear;
end;
procedure TfrmBlandDBJConent.Timer1Timer(Sender: TObject);
begin
Text2.Text:= GetSysTimeByFormate;
end;
procedure TfrmBlandDBJConent.TxtBarCodePromptClick(Sender: TObject);
begin
// F2DCodeWork(F2DCode[0],'D30101860L12001'); //測試板
end;
procedure TfrmBlandDBJConent.TxtLotNumInfoClick(Sender: TObject);
begin
// F2DCodeWork2(F2DCode[1],'D2FDXJG1D2631'); //鏡板
end;
end.