Files
dyp/pas/uInkPrintConent - 副本.pas
T
2026-05-07 20:25:34 +08:00

640 lines
18 KiB
ObjectPascal
Raw 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 uInkPrintConent;
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;
type
TfrmInkPrinterConent = 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;
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);
private
tv_hp: Boolean;
BarCodeDic:TStringList;
procedure F2DCodeWork(Sender: TObject;sValue: string);
procedure NumEnceWork(Avalue: string);
procedure RfidWork(Avalue: string);
procedure F2DCodeShowState(Avalue: string); //显示读头状态
procedure AddLog(sLog:string);
procedure ShowEndNum();
function F2CodeBoolean(sValue: String): boolean;
procedure F2DCodeOpline1(Sender: TObject; sValue: string);
procedure F2DCodeOpline2(Sender: TObject; sValue: string);
procedure ReOpen2D(Sender: TObject);
{ 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
frmInkPrinterConent: TfrmInkPrinterConent;
implementation
{$R *.fmx}
uses uPucFun, uMain;
procedure TfrmInkPrinterConent.NumEnceWork(Avalue: string);
begin
end;
procedure TfrmInkPrinterConent.RfidWork(Avalue: string);
begin
end;
procedure TfrmInkPrinterConent.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 TfrmInkPrinterConent.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 TfrmInkPrinterConent.F2DCodeShowState(Avalue: string); //显示读头状态
begin
AddLog(Avalue);
end;
function TfrmInkPrinterConent.F2CodeBoolean(sValue: String):boolean;
begin
Result:= False;
if not tv_hp then
begin
Result:= True;
Exit;
end;
//混批
if (Length(sValue)<20) and (LeftStr(TxtLotNo.Text,8)<>LeftStr(sValue,8)) then
begin
Exit;
//Sleep(100);
// NumEnce.SendStr('#011300');
// Sleep(50);
// NumEnce.SendStr('#011400');
end
else
begin
end;
Result:= True;
end;
procedure TfrmInkPrinterConent.ReOpen2D(Sender:TObject);
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;
procedure TfrmInkPrinterConent.F2DCodeOpline1(Sender:TObject;sValue: string); //处理情况一
begin
// worklog.Warn('正常102NumEnce');
BarCodeDic.Add(sValue);
// worklog.Warn('正常102BarCodeDic.Add');
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;
// worklog.Warn('正常102StringGrid1');
ShowEndNum();
// worklog.Warn('正常102ShowEndNum');
TxtBarCodePrompt.Text:=Format('二维码 %d:%s',[iCount,sValue]);
//开启线程,3秒后开启2D读头
ReOpen2D(Sender);
// EdtInput1.Text:= sValue;
// worklog.Warn('正常102ReOpen2D');
//开启线程,提交数据到服务器,提交不成功,就保存在本地
TThread.CreateThreadX<string>(
procedure (Avalue:string)
var
DetailRecord:TDetailRecord;
sError:string;
bResult:boolean;
tmp: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:='正常'; //正常/重工
DetailRecord.P_TROLLEY_NUM:='-1';
DetailRecord.P_COPPER_MODEL:='-1';
DetailRecord.P_BUFFER_TYPE:='-1';
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
tmp:=Avalue+'提交成功:OK'
else
begin
tmp:=Avalue+'提交失敗:'+sError;
end;
WorkLog.MessageInfo(tmp);
finally
CoUninitialize;
end;
TThread.Synchronize( nil,
procedure
begin
AddLog(tmp);
end
);
end,sValue
).Start;
// worklog.Warn('正常102Start');
end;
procedure TfrmInkPrinterConent.F2DCodeOpline2(Sender:TObject;sValue: string); //处理情况二
begin
// EdtInput1.Text:= sValue;
// worklog.Warn('正常102ReOpen2D');
//开启线程,提交数据到服务器,提交不成功,就保存在本地
TThread.CreateThreadX<string>(
procedure (Avalue:string)
var
DetailRecord:TDetailRecord;
sError:string;
bResult:boolean;
tmp: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:='正常'; //正常/重工
DetailRecord.P_TROLLEY_NUM:='-1';
DetailRecord.P_COPPER_MODEL:='-1';
DetailRecord.P_BUFFER_TYPE:='-1';
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
tmp:=Avalue+'提交成功:OK'
else
begin
tmp:=Avalue+'提交失敗:'+sError;
end;
WorkLog.MessageInfo(tmp);
finally
CoUninitialize;
end;
TThread.Synchronize( nil,
procedure
begin
AddLog(tmp);
if bResult then //提交成功
begin
// worklog.Warn('正常102NumEnce');
BarCodeDic.Add(sValue);
// worklog.Warn('正常102BarCodeDic.Add');
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;
// worklog.Warn('正常102StringGrid1');
ShowEndNum();
// worklog.Warn('正常102ShowEndNum');
TxtBarCodePrompt.Text:=Format('二维码 %d:%s',[iCount,sValue]);
//开启线程,3秒后开启2D读头
ReOpen2D(Sender);
end;
end
);
end,sValue
).Start;
// worklog.Warn('正常102Start');
end;
procedure TfrmInkPrinterConent.F2DCodeWork(Sender:TObject;sValue: string); //读取条码
begin
// WorkLog.MessageInfo('条码读取:'+self.Name);
if sValue='ERROR' then
BEGIN
AddLog('条码读取出错'+sValue);
WorkLog.MessageInfo('条码读取出错'+sValue);
TxtBarCodePrompt.Text:='二维码读取出错';
ReOpen2D(Sender);
Exit;
END;
if BarCodeDic.IndexOf(sValue)>=0 then //判断重复
BEGIN
AddLog('条码重复'+sValue);
WorkLog.MessageInfo('条码重复'+sValue);
TxtBarCodePrompt.Text:=Format('二维码重复:%s',[sValue]);
ReOpen2D(Sender);
Exit;
END;
//混批
if not F2CodeBoolean(sValue) then
begin
AddLog('注意混批301'+sValue);
if (NumEnce<>nil) and (Sender<>nil) then
begin
if (T2DCode(Sender).Num=4) then
begin
NumEnce.SendStr8('#0111101');
Sleep(1000);
NumEnce.SendStr8('#0111100');
worklog.Warn('混批101#0111101,'+intToStr(T2DCode(Sender).Num));
end
else
begin
NumEnce.SendStr8('#0111501');
Sleep(1000);
NumEnce.SendStr8('#0111500');
worklog.Warn('混批102#0111501,'+intToStr(T2DCode(Sender).Num));
end;
end;
ReOpen2D(Sender);
Exit;
//Sleep(100);
// NumEnce.SendStr('#011300');
// Sleep(50);
// NumEnce.SendStr('#011400');
end;
AddLog('正常101'+sValue);
if (NumEnce<>nil) and (Sender<>nil) then
begin
if (T2DCode(Sender).Num=4) then
begin
NumEnce.SendStr8('#0111001');
Sleep(1000);
NumEnce.SendStr8('#0111000');
// worklog.Warn('正常101#0111001,'+intToStr(T2DCode(Sender).Num));
end
else
begin
NumEnce.SendStr8('#0111401');
Sleep(1000);
NumEnce.SendStr8('#0111400');
// worklog.Warn('正常102#0111401,'+intToStr(T2DCode(Sender).Num));
end;
//Sleep(100);
// NumEnce.SendStr('#011300');
// Sleep(50);
// NumEnce.SendStr('#011400');
end;
if DM.DataOpline=1 then
F2DCodeOpline2(Sender,sValue)
else
F2DCodeOpline1(Sender,sValue);
end;
procedure TfrmInkPrinterConent.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 TfrmInkPrinterConent.FormCreate(Sender: TObject);
var
sDevName,sIp,sPort:string;
tmpValue, tv_hpStr:string;
i:integer;
begin
TxtFactoryCode.Text:=ksoap.P_ORG_CODE+'區'; //厂区
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='油墨印刷機';
tv_hpStr:=dm.MemTableReadKeyValue('主要参数','tv_hp');
tv_hp:= True;
if tv_hpStr='0' then
tv_hp:= False;
//根据配置加载设备
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 //2D读头
begin
F2DCode[i]:=T2DCode.Create(sIp,sPort.ToInteger);
F2DCode[i].Num:=i;
F2DCode[i].OnWork:=F2DCodeWork;
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 TfrmInkPrinterConent.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 TfrmInkPrinterConent.Rectangle20Click(Sender: TObject);
begin
if ShowInfoOKCancel('該批還沒有完成,真的要退出嗎?') then Close;
end;
procedure TfrmInkPrinterConent.Text16Click(Sender: TObject);
begin
ShowTouchKeyBoard();
end;
procedure TfrmInkPrinterConent.Text17Click(Sender: TObject);
begin
Close;
end;
procedure TfrmInkPrinterConent.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 TfrmInkPrinterConent.Text5Click(Sender: TObject);
begin
MEMO1.Lines.Clear;
end;
procedure TfrmInkPrinterConent.Timer1Timer(Sender: TObject);
begin
Text2.Text:= GetSysTimeByFormate;
end;
end.