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
+541
View File
@@ -0,0 +1,541 @@
unit uBla_yamaha_Conent;
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, FMX.Memo.Types;
type
TfBla_yamaha_Conent = 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
LotNoMid: Integer;
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();
{ Private declarations }
public
iDetailCount:Integer;
iCount:Integer;
vP_ID:Double;
vId:integer;
F2DCode:array[0..9] of T2DCode;
Rfid:TRfid;
NumEnce:TNumEnce;
LotNoRecord:TLotNoRecord;
tv_hp: Boolean;
end;
var
fBla_yamaha_Conent: TfBla_yamaha_Conent;
implementation
{$R *.fmx}
uses uPucFun, uMain; //609104 , uAlarmLed
procedure TfBla_yamaha_Conent.NumEnceWork(Avalue: string);
begin
end;
procedure TfBla_yamaha_Conent.RfidWork(Avalue: string);
begin
end;
procedure TfBla_yamaha_Conent.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 TfBla_yamaha_Conent.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 TfBla_yamaha_Conent.F2DCodeShowState(Avalue: string); //显示读头状态
begin
AddLog(Avalue);
end;
procedure TfBla_yamaha_Conent.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;
if tv_hp and (Length(sValue)= 23) and (pos('033940A',sValue)>0)
and (Str34ToInt(RightStr(sValue,4))<>LotNoMid) then
begin
AddLog('注意混批:'+sValue);
if NumEnce<>nil then
begin
NumEnce.SendStr('#011401');
// Sleep(500);
// NumEnce.SendStr('#011400');
end;
AddLog('条码读取成功24'+sValue);
ReOpen2D();
Exit;
end;
// AddLog('条码读取成功2'+sValue);
if tv_hp and (Length(TxtLotNo.Text)<>21) and (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);
if not ShowInfoOKCancel('注意混批,是否保存数据?') then
begin
ReOpen2D();
Exit;
end;
//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;
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]);
//开启线程,3秒后开启2D读头
ReOpen2D();
//EdtInput1.Text:= sValue;
WorkLog.MessageInfo('条码sValue:'+sValue);
// AddLog('条码读取成功5'+sValue);
//开启线程,提交数据到服务器,提交不成功,就保存在本地
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:='-1'; // 正常板/重工板
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='連接數據庫服務器失败') or (pos('Error sending data',sError)>0) 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;
end;
procedure TfBla_yamaha_Conent.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 TfBla_yamaha_Conent.FormCreate(Sender: TObject);
var
sDevName,sIp,sPort:string;
tmpValue, tv_hpStr:string;
i: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;
LotNoMid:= 0;
try
LotNoMid:= StrToInt(MidBStr(TxtLotNo.Text,3,8));
except
end;
ShowEndNum();
TxtVerInfo.Text:=GetBuildInfo;
Memo1.Lines.Clear;
TxtShowErrorInfo(TxtError,'');
iCount:=0;
iDetailCount:=0;
BarCodeDic:=TStringList.Create;
BarCodeDic.Sorted:=true;
tv_hpStr:=dm.MemTableReadKeyValue('主要参数','tv_hp');
tv_hp:= True;
if tv_hpStr='0' then
tv_hp:= False;
//Rectangle001.Visible:=ksoap.P_LINE='油墨印刷機';
//根据配置加载设备
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 TfBla_yamaha_Conent.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 TfBla_yamaha_Conent.Rectangle20Click(Sender: TObject);
var
s:string;
begin
//*
//3.當模具生產前測壓次數大於預警壽命950000,字體顏色變紅提示;
//4.當模具生產前測壓次數大於1000000,報警提示“模具最大使用壽命到”,無法啟動。
//5.當模具生產后測壓次數小於模具生產前測壓次數,無法輸入。
//6.當模具生產後測壓次數與生產前的測壓次數相比,新增壓次若大於100000,會有友情提示人員是否輸錯。
//点击了OK按钮后,则
if InputQuery('模具生產后測壓次數','模具生產后測壓次數:',s) then
begin
if s<>'' then //如果输入不为空则
begin
showmessage(s);
if ShowInfoOKCancel('該批還沒有完成,真的要退出嗎?') then Close;
end;
end;
end;
procedure TfBla_yamaha_Conent.Text16Click(Sender: TObject);
begin
ShowTouchKeyBoard();
end;
procedure TfBla_yamaha_Conent.Text17Click(Sender: TObject);
begin
Close;
end;
procedure TfBla_yamaha_Conent.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 TfBla_yamaha_Conent.Text5Click(Sender: TObject);
begin
MEMO1.Lines.Clear;
end;
procedure TfBla_yamaha_Conent.Timer1Timer(Sender: TObject);
begin
Text2.Text:= GetSysTimeByFormate;
end;
end.