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

682 lines
20 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 uBland_bghConent;
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
TfrmBgh_CodeConent = 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;
StringColumn3: TStringColumn;
StringColumn4: TStringColumn;
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
BarCodeDic1,BarCodeDic2: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();
procedure F2DCodeWork_DataSend(sValue: string);
procedure F2DCodeWork_Oplien(iCode:Integer;sValue: 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
frmBgh_CodeConent: TfrmBgh_CodeConent;
implementation
{$R *.fmx}
uses uPucFun, uMain, uErrorInfo, IdGlobal; //bgweb_Service,609104 , uAlarmLed
procedure TfrmBgh_CodeConent.NumEnceWork(Avalue: string);
begin
end;
procedure TfrmBgh_CodeConent.RfidWork(Avalue: string);
begin
end;
procedure TfrmBgh_CodeConent.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 TfrmBgh_CodeConent.AddLog(sLog:string);
begin
Memo1.Lines.Add(FormatDateTime('yyyymmdd hh:mm:ss.zzz ',Now)+sLog);
Memo1.SelStart:=Length(Memo1.Text);
Memo1.SelLength:=0;
end;
procedure TfrmBgh_CodeConent.F2DCodeShowState(Avalue: string); //显示读头状态
begin
AddLog(Avalue);
end;
procedure TfrmBgh_CodeConent.F2DCodeWork_DataSend(sValue: string); //读取条码
var
sResult,sDataSavaLog:string;
begin
DbApiLog.MessageInfo('F2DCodeWork_DataSend in:'+sValue);
sDataSavaLog:= ksoap.P_ORG_CODE+','+ //廠區
TxtLotNo.Text+','+ //批号
sValue+','+ // 條碼(批號10碼+PNL3碼)
ksoap.P_PC+','+ //製程
ksoap.P_LINE+','+ //線別
ksoap.P_LINE_NUM+','+ //線別編號
'-1'+','+ // 正常板/重工板
LotNoRecord.P_TROLLEY_NUM+','+ // 台車編號
LotNoRecord.P_COPPER_MODEL+','+ // 銅箔型號
LotNoRecord.P_Buffer+','+ // 緩衝材型號
FormatDateTime('yyyymmdd hh:mm:ss',Now)+','+
vP_ID.ToString+','+
ksoap.P_Goods_Num;
DbApiLog.MessageInfo('F2DCodeWork_DataSend in1:'+sValue);
// exit;
DataSavaLog('').MessageInfo(TxtLotNo.Text+','+LotNoRecord.P_TROLLEY_NUM,sDataSavaLog); //料号
DbApiLog.MessageInfo('F2DCodeWork_DataSend in2:'+sValue);
if (length(sValue)>15) then
//开启线程,提交数据到服务器,提交不成功,就保存在本地
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
try
sDataSavaLog:= TxtLotNo.Text+','+
ksoap.P_Goods_Num+','+
'D'+','+Avalue;
DbApiLog.MessageInfo('xxcf_chk_barcode 提交内容:%s',[sDataSavaLog]);
sResult:= '';//bgweb_Service.GetServiceSoap().xxcf_chk_barcode(TxtLotNo.Text,
// ksoap.P_Goods_Num,
// 'D',Avalue);
DbApiLog.MessageInfo('xxcf_chk_barcode 返回:%s',[sResult]);
except
on e:Exception do
begin
DbApiLog.Error('xxcf_chk_barcode 错误:%s',[ChangeErrorInfo(E.Message)]);
// sError:=ChangeErrorInfo(E.Message);
end;
end;
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';
end
else
tmp:=Avalue+'提交失敗:'+sError;
WorkLog.MessageInfo(tmp);
finally
CoUninitialize;
end;
TThread.Synchronize( nil,
procedure
begin
AddLog(tmp);
end
);
end,sValue
).Start;
end;
procedure TfrmBgh_CodeConent.F2DCodeWork(Sender:TObject;sValue: string); //读取条码
var
sError: string;
procedure ReOpen2D();
begin
exit;
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 BarCodeDic1.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(50);
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;
BarCodeDic1.Add(sValue);
//开启线程,3秒后开启2D读头
ReOpen2D();
//EdtInput1.Text:= sValue;
WorkLog.MessageInfo('条码sValue:'+sValue);
// AddLog('条码读取成功5'+sValue);
F2DCodeWork_Oplien(1,sValue);
end;
procedure TfrmBgh_CodeConent.F2DCodeWork_Oplien(iCode:Integer;sValue: string); //读取条码
var
add_yn: Boolean;
begin
if (iCode=1) and (BarCodeDic2.IndexOf(sValue)<0) then
add_yn:= True;
if (iCode=2) and (BarCodeDic1.IndexOf(sValue)<0) then
add_yn:= True;
if add_yn then //判断新增
begin
with StringGrid1 do
begin
inc(iCount);
BeginUpdate;
RowCount:= RowCount+1;
Cells[0,RowCount-1]:=iCount.ToString;
if iCode=1 then
Cells[1,RowCount-1]:=sValue;
if iCode=2 then
Cells[4,RowCount-1]:=sValue;
Cells[3,RowCount-1]:='否';
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]);
end
else
begin
with StringGrid1 do
begin
BeginUpdate;
if iCode=1 then
Cells[1,RowCount-1]:=sValue;
if iCode=2 then
Cells[4,RowCount-1]:=sValue;
if Cells[1,RowCount-1]=Cells[4,RowCount-1] then
Cells[3,RowCount-1]:='是';
SelectRow(RowCount-1);
EndUpdate;
DbApiLog.MessageInfo('F2DCodeWork_DataSend 返回:'+Cells[3,RowCount-1]);
if (Cells[3,RowCount-1]='是') then
begin
F2DCodeWork_DataSend(sValue);
end;
end;
end;
end;
procedure TfrmBgh_CodeConent.F2DCodeWork2(Sender:TObject;sValue: string); //读取条码
var
sError: string;
procedure ReOpen2D();
begin
exit;
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 BarCodeDic2.IndexOf(sValue)>=0 then //判断重复
BEGIN
AddLog('条码重复'+sValue);
WorkLog.MessageInfo('条码重复'+sValue);
TxtBarCodePrompt.Text:=Format('二维码重复:%s',[sValue]);
ReOpen2D();
Exit;
END;
BarCodeDic2.Add(sValue);
//开启线程,3秒后开启2D读头
ReOpen2D();
//EdtInput1.Text:= sValue;
WorkLog.MessageInfo('条码sValue:'+sValue);
// AddLog('条码读取成功5'+sValue);
F2DCodeWork_Oplien(2,sValue);
end;
procedure TfrmBgh_CodeConent.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;
procedure TfrmBgh_CodeConent.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;
BarCodeDic1:=TStringList.Create;
BarCodeDic1.Sorted:=true;
BarCodeDic2:=TStringList.Create;
BarCodeDic2.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 TfrmBgh_CodeConent.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);
BarCodeDic1.Free;
BarCodeDic2.Free;
end;
procedure TfrmBgh_CodeConent.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 TfrmBgh_CodeConent.Rectangle20Click(Sender: TObject);
begin
if ShowInfoOKCancel('該批還沒有完成,真的要退出嗎?') then Close;
end;
procedure TfrmBgh_CodeConent.Text16Click(Sender: TObject);
begin
ShowTouchKeyBoard();
end;
procedure TfrmBgh_CodeConent.Text17Click(Sender: TObject);
begin
Close;
end;
procedure TfrmBgh_CodeConent.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;
Text9.Text:= EdtInput1.Text;
end;
finally
Text1.TextSettings.FontColor:=TAlphaColorRec.White;
end;
end;
procedure TfrmBgh_CodeConent.Text5Click(Sender: TObject);
begin
MEMO1.Lines.Clear;
end;
procedure TfrmBgh_CodeConent.Timer1Timer(Sender: TObject);
begin
Text2.Text:= GetSysTimeByFormate;
end;
procedure TfrmBgh_CodeConent.TxtBarCodePromptClick(Sender: TObject);
begin
// F2DCodeWork(F2DCode[0],'D30101860L12001'); //測試板
end;
procedure TfrmBgh_CodeConent.TxtLotNumInfoClick(Sender: TObject);
begin
// F2DCodeWork2(F2DCode[1],'D2FDXJG1D2631'); //鏡板
end;
end.