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

1224 lines
33 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 uListMoreConent;
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,uKsoap,
FMX.Layouts, System.Rtti, FMX.Grid.Style, FMX.Memo, FMX.ScrollBox, FMX.Grid,
FMX.StdCtrls, FMX.ListBox, FMX.TabControl,uShowInfo,uTCPDevice,uSafeLog,Winapi.ActiveX,
SysTem.StrUtils, FMX.Memo.Types;
type
TfrmListMoreConent = class(TForm)
Rectangle1: TRectangle;
Rectangle2: TRectangle;
Rectangle3: TRectangle;
TxtFactoryCode: TText;
Rectangle4: TRectangle;
Rectangle6: TRectangle;
Text2: TText;
Rectangle18: TRectangle;
Rectangle26: TRectangle;
Text17: TText;
Rectangle33: TRectangle;
Rectangle5: TRectangle;
Rectangle16: TRectangle;
Text11: TText;
Text13: TText;
TxtEmpNo: TText;
Line1: TLine;
Line2: TLine;
TxtPc: TText;
Text18: TText;
TxtLine: TText;
Timer1: TTimer;
Rectangle11: TRectangle;
Rectangle14: TRectangle;
Rectangle001: TRectangle;
StringGrid1: TStringGrid;
StringColumn1: TStringColumn;
StringColumn2: TStringColumn;
StringColumn3: TStringColumn;
StringColumn4: TStringColumn;
StringColumn5: TStringColumn;
StringColumn6: TStringColumn;
StringColumn7: TStringColumn;
GlyphColumn1: TGlyphColumn;
Rectangle13: TRectangle;
Text21: TText;
Text3: TText;
Glyph23: TGlyph;
ImageList1: TImageList;
TxtVerInfo: TText;
Rectangle9: TRectangle;
TxtLineNum: TText;
Text7: TText;
Text1: TText;
Text8: TText;
EditLotNo: TEdit;
Rectangle8: TRectangle;
Rectangle10: TRectangle;
Rectangle7: TRectangle;
Rectangle12: TRectangle;
Text4: TText;
Rectangle15: TRectangle;
Text5: TText;
Memo1: TMemo;
StyleBook1: TStyleBook;
TxtLotNoError: TText;
Rectangle17: TRectangle;
Rectangle19: TRectangle;
Rectangle20: TRectangle;
TxtPc11: TText;
EdtInput1: TEdit;
TxtInput1Error: TText;
Rectangle23: TRectangle;
StringGrid2: TStringGrid;
StringColumn8: TStringColumn;
StringColumn9: TStringColumn;
Rectangle21: TRectangle;
StringGrid3: TStringGrid;
StringColumn10: TStringColumn;
StringColumn11: TStringColumn;
EdtInput2: TEdit;
Text6: TText;
Text9: TText;
Text29: TLabel;
Label1: TLabel;
Rectangle22: TRectangle;
TxtLotNumInfo: TText;
StringGrid4: TStringGrid;
StringColumn12: TStringColumn;
StringColumn13: TStringColumn;
StringColumn14: TStringColumn;
StringColumn15: TStringColumn;
TabControl1: TTabControl;
TabItem1: TTabItem;
TabItem2: TTabItem;
StringColumn16: TStringColumn;
Rectangle25: TRectangle;
Rectangle27: TRectangle;
CheckBox1: TCheckBox;
procedure Rectangle28Click(Sender: TObject);
procedure Rectangle21Click(Sender: TObject);
procedure StringGrid1DrawColumnCell(Sender: TObject; const Canvas: TCanvas;
const Column: TColumn; const Bounds: TRectF; const Row: Integer;
const Value: TValue; const State: TGridDrawStates);
procedure Text3Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure StringGrid1DrawColumnHeader(Sender: TObject;
const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF);
procedure FormResize(Sender: TObject);
procedure StringGrid1CellClick(const Column: TColumn; const Row: Integer);
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Single);
procedure StringGrid1Tap(Sender: TObject; const Point: TPointF);
procedure Text5Click(Sender: TObject);
procedure Text4Click(Sender: TObject);
procedure EditLotNoKeyDown(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
procedure EdtInput2KeyDown(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
procedure EdtInput1KeyDown(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
procedure FormDestroy(Sender: TObject);
procedure TabItem1Click(Sender: TObject);
procedure TabItem2Click(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure Button1Click(Sender: TObject);
procedure Text10Click(Sender: TObject);
procedure Text12Click(Sender: TObject);
procedure CheckBox1Change(Sender: TObject);
private
tv_hp: Boolean;
iDetailCount:Integer;
IsFirst:boolean;
vP_ID:Double;
F2DCode:T2DCode;
Rfid:TRfid;
NumEnce:TNumEnce;
iCount:Integer;
BarCodeDic:TStringList;
Ord_Avalue: String;
Ord_iCord2D: Integer;
Ord_iRfid: Integer;
RfidLen: boolean;
CheckBoxCode: Boolean;
procedure Clear();
procedure ShowEndNum();
procedure MainData();
procedure ListDataIn(sValue:string);
procedure ReOpen2D();
procedure AddRow(sLotNo,sGoodsNo,sLotNoNum:string);
procedure DelRow(const iRow:Integer);
procedure F2DCodeWork(Sender: TObject;sValue:string);
procedure NumEnceWork(Avalue: string);
procedure RfidWork(Avalue: string);
procedure AddLog(sLog:string);
procedure F2DCodeShowState(Avalue: string);
procedure ShowLotNoError(LotNoError: string);
function F2CodeBoolean(sValue: String): boolean;
procedure LogGridAdd;
procedure LogGridToFile;
procedure AddWork(sValue: string);
public
end;
var
frmListMoreConent: TfrmListMoreConent;
implementation
{$R *.fmx}
uses uPucFun, uDM, uMain, uLostDummy;
procedure TfrmListMoreConent.CheckBox1Change(Sender: TObject);
begin
CheckBoxCode:= CheckBox1.IsChecked;
end;
procedure TfrmListMoreConent.Clear();
begin
TxtLotNumInfo.Text:= '';
Text29.Text:= '0';
Label1.Text:= '0';
EdtInput1.Text:= '';
EdtInput2.Text:= '';
Memo1.Lines.Clear;
iCount:= 0;
StringGrid2.RowCount:= 0;
StringGrid3.RowCount:= 0;
end;
procedure TfrmListMoreConent.ShowEndNum();
begin
if StringGrid1.RowCount=0 then exit;
// if StrToInt(StringGrid1.Cells[4,0])=0 then
// Clear();
TxtLotNumInfo.Visible:=StrToInt(StringGrid1.Cells[3,0])-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 TfrmListMoreConent.ListDataIn(sValue:string);
begin
if length(EdtInput2.Text)<10 then //去掉异常的
EdtInput2.Text:= '';
//开启线程,提交数据到服务器,提交不成功,就保存在本地
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:=StringGrid1.Cells[1,0]; //批號
DetailRecord.P_BC:=sValue; // 條碼(批號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:=EdtInput2.Text; //台車編號
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 StringGrid4.RowCount>0 then
StringGrid4.Cells[4,StringGrid4.RowCount-1]:= sError;
if sError='連接數據庫服務器失败' then
begin
// dm.InsertDetail(vId,DetailRecord);
tmp:=Avalue+'提交失敗:連接數據庫服務器失败,暫存本地';
end;
if bResult then
tmp:=Avalue+'提交成功:OK'
else
begin
// dm.InsertDetail(vId,DetailRecord);
tmp:=Avalue+'提交失敗:'+sError;
end;
WorkLog.MessageInfo(tmp);
DataLog.MessageInfo('明细表:%s,%s,%s',[vP_ID.ToString,sValue,EdtInput2.Text]);
finally
CoUninitialize;
end;
TThread.Synchronize( nil,
procedure
begin
AddLog(tmp);
//最後一片刪除當前批號
if StrToInt(StringGrid1.Cells[3,0])=StrToInt(StringGrid1.Cells[5,0]) then
begin
Clear();
delrow(0);
end;
EdtInput1.Text:= '';
EdtInput2.Text:= '';
end
);
end,sValue
).Start;
end;
procedure TfrmListMoreConent.ReOpen2D();
begin
TThread.CreateAnonymousThread(
procedure
begin
Sleep(1000);
TThread.Synchronize( nil,
procedure
begin
if F2DCode<>nil then F2DCode.Open;
//TxtBarCodePrompt.Text:='读码中...';
end
);
end
).Start;
end;
procedure TfrmListMoreConent.F2DCodeWork(Sender: TObject;sValue:string);
begin
if StringGrid4.RowCount>0 then
StringGrid4.Cells[1,StringGrid4.RowCount-1]:= sValue;
if StringGrid1.RowCount=0 then exit;
if sValue='ERROR' then
BEGIN
AddLog('条码读取出错'+sValue);
//WorkLog.MessageInfo('条码读取出错'+sValue);
//TxtBarCodePrompt.Text:='二维码读取出错';
// ReOpen2D();
Exit;
END;
if BarCodeDic.IndexOf(sValue)>=0 then //判断重复
BEGIN
AddLog('条码重复'+sValue);
WorkLog.MessageInfo('条码重复'+sValue);
// TxtBarCodePrompt.Text:=Format('二维码重复:%s',[sValue]);
// ReOpen2D();
Exit;
END;
//混批
if not F2CodeBoolean(sValue) then
begin
AddLog('注意混批301'+sValue);
TxtLotNumInfo.Text:= '注意混批:'+sValue;
if (NumEnce<>nil) and (Sender<>nil) then
begin
if (T2DCode(Sender).Num=4) then
begin
NumEnce.SendStr('#0111101');
Sleep(500);
NumEnce.SendStr('#0111100');
AddLog('混批101#0111101,'+intToStr(T2DCode(Sender).Num));
end
else
begin
NumEnce.SendStr('#0111501');
Sleep(500);
NumEnce.SendStr('#0111500');
AddLog('混批102#0111501,'+intToStr(T2DCode(Sender).Num));
end;
end;
// ReOpen2D();
// Exit;
//Sleep(100);
// NumEnce.SendStr('#011300');
// Sleep(50);
// NumEnce.SendStr('#011400');
end;
BarCodeDic.Add(sValue);
AddWork(sValue);
end;
procedure TfrmListMoreConent.AddWork(sValue:string);
begin
inc(iCount);
if StringGrid1.RowCount>0 then
with StringGrid1 do
begin
BeginUpdate;
Cells[5,0]:=IntToStr(iCount);
Cells[4,0]:=IntToStr(StrToInt(Cells[3,0])-StrToInt(Cells[5,0]));
Cells[6,0]:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
EndUpdate;
end;
with StringGrid3 do
begin
if CheckBoxCode then
begin
BeginUpdate;
RowCount:=RowCount+1;
// Cells[0,RowCount-1]:=iCount.ToString;
Cells[0,RowCount-1]:=sValue;
Cells[1,RowCount-1]:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
SelectRow(RowCount-1);
EndUpdate;
end;
inc(iDetailCount);
Text29.Text:=iCount.ToString;
end;
ShowEndNum();
EdtInput1.Text:=sValue;//Format('二维码 %d:%s',[iCount,sValue]);
WorkLog.MessageInfo('条码数据:'+sValue);
//开启线程,3秒后开启2D读头
// ReOpen2D();
//第一片加入主表
if StrToInt(StringGrid1.Cells[5,0])=1 then
begin
MainData();
end;
if EdtInput2.Text<>'' then
begin
ListDataIn(EdtInput1.Text);
AddLog('提交數據:'+EdtInput1.Text);
WorkLog.Debug('提交數據:%s',[EdtInput1.Text]);
EdtInput1.Text:='';
end;
end;
function TfrmListMoreConent.F2CodeBoolean(sValue: String):boolean;
begin
Result:= False;
if StringGrid1.RowCount=0 then Exit;
if not tv_hp then
begin
Result:= True;
Exit;
end;
//混批
if (Length(sValue)<20) and (LeftStr(StringGrid1.Cells[1,0],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 TfrmListMoreConent.F2DCodeShowState(Avalue: string); //显示读头状态
begin
AddLog(Avalue);
end;
procedure TfrmListMoreConent.ShowLotNoError(LotNoError:string);
begin
TThread.Synchronize(nil,
procedure
begin
TxtLotNoError.Text:=LotNoError;
if LotNoError<>'' then EditLotNo.SetFocus;
end);
end;
procedure TfrmListMoreConent.EditLotNoKeyDown(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
var
sPartnumValue:string;
begin
if StringGrid1.Cells[1,StringGrid1.RowCount-1]=EditLotNo.Text then //重复
begin
TxtShowErrorInfo(TxtLotNoError,'批號重複輸入');
end
else
if (Key = $0D) and (EditLotNo.Text<>'') then
begin
TThread.CreateAnonymousThread(
procedure
var
sError:string;
sGoodsNo,sNum,sPc:string;
begin
CoInitialize(nil);
TRY
//检查批号
if (not Ksoap.XXCC_LOT_PC_F(EditLotNo.Text,TxtLineNum.Text,'1',sError)) then
begin
ShowLotNoError(sError);
Exit;
end;
//得料号
if not Ksoap.getPartnum(EditLotNo.Text,'',sGoodsNo,sNum,sPc,sPartnumValue,sError) then
begin
ShowLotNoError(sError);
Exit;
end;
finally
CoUninitialize;
end;
TThread.Synchronize(nil,
procedure
begin
AddRow(EditLotNo.Text,sGoodsNo,sNum);
ShowLotNoError('');
EditLotNo.Text:='';
//调整网格列宽
// StringColumn1.Width:=30;
StringColumn2.Width:=100;
StringColumn3.Width:=130;
// StringColumn4.Width:=50;
// StringColumn5.Width:=50;
// StringColumn6.Width:=50;
// StringColumn7.Width:=50;
// GlyphColumn1.Width:=50;
end);
end
).Start;
end;
end;
//添加主表
procedure TfrmListMoreConent.MainData();
var
sError:string;
LotNoRecord:TLotNoRecord;
vId:Integer;
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; //線別編號
LotNoRecord.P_CREATION_DATE:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
sError:='';
vP_ID:=Ksoap.Thread_cf_traceability_seq_f(ksoap.P_ORG_CODE,sError);
LotNoRecord.P_ID:=vP_ID;
DataLog.MessageInfo('主表:%s,%s,%s,%s,%s',[vP_ID.ToString,ksoap.P_ORG_CODE,ksoap.P_WORK_NUM,ksoap.P_PC,ksoap.P_LINE_NUM]);
if vP_ID=0 then
BEGIN
dm.InsertMain(vId,LotNoRecord,true);
ShowInfoOK('連接數據庫服務器失敗數據暫存本地,正在生產中...', False);
// Result:=true;
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,true);
ShowInfoOK('連接數據庫服務器失敗數據暫存本地,正在生產中...', False);
// Result:=true;
end
else
ShowError(sError);
end
END;
end;
procedure TfrmListMoreConent.EdtInput1KeyDown(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
var
sError:string;
DetailRecord:TDetailRecord;
vId:Integer;
begin
Exit;
if (Key = 13) and (StringGrid1.RowCount>0) then
begin
// F2DCodeWork(Sender,EdtInput1.Text);
// Exit;
// EdtInput2.Text := StringGrid1.Cells[1,0];
with StringGrid3 do
begin
if Cells[0,RowCount-1]=EdtInput1.Text then //重复
begin
TxtShowErrorInfo(TxtInput1Error,'條碼重複輸入');
end
else
begin
// if NumEnce<>nil then
// begin
// NumEnce.SendStr('#011301');
// NumEnce.SendStr('#011401');
// Sleep(100);
// NumEnce.SendStr('#011300');
// NumEnce.SendStr('#011400');
// end;
TxtShowErrorInfo(TxtInput1Error,'');
BeginUpdate;
RowCount:=RowCount+1;
Cells[0,RowCount-1]:=EdtInput1.Text;
Cells[1,RowCount-1]:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
SelectRow(RowCount-1);
EndUpdate;
inc(iCount);
// Text29.Text:=iCount.ToString;
//Ksoap.Insert_cc_wip_lot_bc_history(TxtLotNo.Text,EdtInput1.Text,'A#','正常板','-1','-1','-1',vP_Id.ToString,'',sError);
if IsFirst then //第一次,插入主
begin
MainData();
IsFirst:=false;
end;
DetailRecord.P_ORG_CODE:=ksoap.P_ORG_CODE; //廠區
DetailRecord.P_LOT:=StringGrid1.Cells[1,0];//TxtLotNo.Text;
DetailRecord.P_BC:=EdtInput1.Text; // 條碼(批號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:='0';
dm.InsertDetail(vId,DetailRecord);
end;
end;
EdtInput1.Text:='';
EdtInput1.SetFocus;
end;
if StringGrid4.Row>0 then
ExportToExcel(StringGrid1.Cells[1,0]+'-'+FormatDateTime('yyyymmddhhmmss',Now),StringGrid4);
end;
procedure TfrmListMoreConent.EdtInput2KeyDown(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
begin
exit;
if Key = 13 then
begin
RfidWork(EdtInput2.Text);
Exit;
with StringGrid2 do
begin
if Cells[0,RowCount-1]=EdtInput2.Text then //重复
begin
TxtShowErrorInfo(TxtInput1Error,'條碼2重複輸入');
end
else
begin
TxtShowErrorInfo(TxtInput1Error,'');
BeginUpdate;
RowCount:=RowCount+1;
Cells[0,RowCount-1]:=EdtInput2.Text;
Cells[1,RowCount-1]:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
SelectRow(RowCount-1);
EndUpdate;
//dm.InsertLotNo(); //
end;
end;
EdtInput2.Text:='';
EdtInput2.SetFocus;
end;
end;
procedure TfrmListMoreConent.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
LogGridToFile();
end;
procedure TfrmListMoreConent.FormCreate(Sender: TObject);
var
sDevName,sIp,sPort:string;
tmpValue, tv_hpStr:string;
i:integer;
begin
TxtFactoryCode.Text:=FactoryCode; //厂区
TxtEmpNo.Text:=ksoap.P_WORK_NUM; //工号
TxtPc.Text:=ksoap.P_PC; //制程代码
TxtLine.Text:=ksoap.P_LINE; //制程名
TxtLineNum.Text:=ksoap.P_LINE_NUM; //线别
CheckBoxCode:= True;
TabControl1.Visible:= False;
TxtVerInfo.Text:=GetBuildInfo;
Memo1.Visible:=false;
Memo1.Width:=400;
Memo1.Lines.Clear;
iCount:= 0;
Ord_iCord2D:= 0;
Ord_iRfid:= 0;
BarCodeDic:=TStringList.Create;
BarCodeDic.Sorted:=true;
Clear();
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,'keyence') then //2D读头
begin
F2DCode:=T2DCode.Create(sIp,sPort.ToInteger);
F2DCode.OnWork:=F2DCodeWork;
F2DCode.OnShowState:=F2DCodeShowState;
F2DCode.Connect;
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;
TxtShowErrorInfo(TxtInput1Error,'');
// TxtShowErrorInfo(TxtInput2Error,'');
//调整网格列宽
// StringColumn9.Width:=StringGrid2.Width-StringColumn8.Width-25;
// StringColumn11.Width:=StringGrid3.Width-StringColumn10.Width-25;
IsFirst:=True;
end;
procedure TfrmListMoreConent.FormDestroy(Sender: TObject);
var
i:integer;
begin
for i := 0 to 9 do
begin
if F2DCode<>nil then
begin
F2DCode.Close;
Sleep(200);
FreeandNil(F2DCode);
end;
end;
if Rfid<>nil then FreeandNil(Rfid);
if NumEnce<>nil then FreeandNil(NumEnce);
BarCodeDic.Free;
end;
procedure TfrmListMoreConent.FormMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Single);
begin
Memo1.Visible:=false;
end;
procedure TfrmListMoreConent.FormResize(Sender: TObject);
begin
StringColumn2.Width:=(Rectangle33.Width-StringColumn1.Width-StringColumn4.Width-
StringColumn5.Width-StringColumn6.Width-GlyphColumn1.Width-40) /3;
StringColumn3.Width:=StringColumn2.Width;
StringColumn7.Width:=StringColumn2.Width;
end;
procedure TfrmListMoreConent.Rectangle21Click(Sender: TObject);
begin
Close;
end;
procedure TfrmListMoreConent.Rectangle28Click(Sender: TObject);
begin
Close;
end;
procedure TfrmListMoreConent.StringGrid1CellClick(const Column: TColumn;
const Row: Integer);
begin
if Column=GlyphColumn1 then
begin
if Row=0 then
begin
if ShowInfoOKCancel('真的要结批吗?') then //结批
begin
delrow(Row);
end;
end
else
begin
if ShowInfoOKCancel('真的要删除该批号数据吗?') then //结批
begin
delrow(Row);
end;
end;
end;
end;
procedure TfrmListMoreConent.StringGrid1DrawColumnCell(Sender: TObject;
const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF;
const Row: Integer; const Value: TValue; const State: TGridDrawStates);
var
Size: TSizeF;
MyBitmap:TBitmap;
Rect:TRectF;
begin
if Column=GlyphColumn1 then
begin
Canvas.BeginScene();
Size:=TSize.Create(128,40);
MyBitmap:=Imagelist1.Bitmap(Size,0);
Rect:=Bounds;
Rect.Top:=Rect.Top+4;
Rect.Bottom:=Rect.Bottom-4;
Canvas.DrawBitmap(MyBitmap,MyBitmap.BoundsF,Rect,1);
Canvas.Font.Style:=[TFontStyle.fsBold];
Canvas.Font.Size:=14;
if Row=0 then
begin
Canvas.FillText(Bounds,'結批',true,1,[TFillTextFlag.RightToLeft],TTextAlign.Center, TTextAlign.Center);
end
else
begin
Canvas.FillText(Bounds,'刪除',true,1,[TFillTextFlag.RightToLeft],TTextAlign.Center, TTextAlign.Center);
end;
Canvas.EndScene;
end;
end;
procedure TfrmListMoreConent.StringGrid1DrawColumnHeader(Sender: TObject;
const Canvas: TCanvas; const Column: TColumn; const Bounds: TRectF);
var
Rect:TRectF;
begin
Rect:=Bounds;
Rect.left:=Rect.left+1;
Rect.Right:=Rect.Right-1;
Rect.Bottom:=Rect.Bottom-1;
Canvas.BeginScene();
Canvas.ClearRect(Rect,TAlphaColors.White);
Canvas.Font.Size:=16;
Canvas.Fill.Color:=TAlphaColors.Black;
Canvas.FillText(Bounds,Column.Header,true,1,[TFillTextFlag.RightToLeft],TTextAlign.Center, TTextAlign.Center);
Canvas.EndScene();
end;
procedure TfrmListMoreConent.StringGrid1Tap(Sender: TObject;
const Point: TPointF);
begin
Memo1.Visible:=false;
end;
procedure TfrmListMoreConent.TabItem1Click(Sender: TObject);
begin
Memo1.Visible:= TabItem1.Visible;
TabControl1.Width:= 450;
end;
procedure TfrmListMoreConent.TabItem2Click(Sender: TObject);
begin
StringGrid4.Visible:= TabItem2.Visible;
TabControl1.Width:= 520;
end;
procedure TfrmListMoreConent.Text10Click(Sender: TObject);
begin
//
FrmLostDummy:= TFrmLostDummy.Create(nil);
try
FrmLostDummy.Position:=TFormPosition.MainFormCenter;
if FrmLostDummy.ShowModal=mrOk then
begin
AddRow('LOST','LOST',FrmLostDummy.edit4.Text);
end;
finally
FrmLostDummy.Free;
end;
end;
procedure TfrmListMoreConent.Text12Click(Sender: TObject);
begin
FrmLostDummy:= TFrmLostDummy.Create(nil);
try
FrmLostDummy.Position:=TFormPosition.MainFormCenter;
if FrmLostDummy.ShowModal=mrOk then
begin
AddRow('Dummy','Dummy',FrmLostDummy.edit4.Text);
end;
finally
FrmLostDummy.Free;
end;
end;
procedure TfrmListMoreConent.Text3Click(Sender: TObject);
begin
ShowTouchKeyBoard();
end;
procedure TfrmListMoreConent.Text4Click(Sender: TObject);
begin
memo1.Lines.Clear;
end;
procedure TfrmListMoreConent.Text5Click(Sender: TObject);
begin
//打开日志
TabControl1.Visible:=not TabControl1.Visible;
TabControl1.Height:= self.Height-100;
Memo1.Visible:= TabControl1.Visible;
end;
procedure TfrmListMoreConent.Timer1Timer(Sender: TObject);
begin
Text2.Text:= GetSysTimeByFormate;
end;
procedure TfrmListMoreConent.AddRow(sLotNo,sGoodsNo,sLotNoNum:string); //在末尾追加
begin
with StringGrid1 do
begin
BeginUpdate;
RowCount:= RowCount + 1;
Cells[0,RowCount-1]:=(RowCount).ToString;
Cells[1,RowCount-1]:=sLotNo;
Cells[2,RowCount-1]:=sGoodsNo;
Cells[3,RowCount-1]:=sLotNoNum;
Cells[4,RowCount-1]:=sLotNoNum;
Cells[5,RowCount-1]:='0';
Cells[6,RowCount-1]:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
SelectRow(RowCount);
EndUpdate;
end;
end;
procedure TfrmListMoreConent.Button1Click(Sender: TObject);
begin
LogGridToFile();
end;
procedure TfrmListMoreConent.DelRow(const iRow:Integer);
var
i,j:Integer;
begin
with StringGrid1 do
begin
BeginUpdate;
for i := iRow to RowCount-1 do
begin
for j := 0 to ColumnCount-1 do
begin
Cells[j,i]:= Cells[j,i+1];
Cells[0,i]:=(i+1).ToString;
end;
end;
if RowCount>iRow then
RowCount:=RowCount-1;
EndUpdate;
end;
end;
//
//function ChrList(Avalue:string):String;
//var
// i: integer;
//begin
// if Avalue='' then Exit;
// for I := 1 to Length(Avalue) do
// begin
// if i mod 2 = 0 then
// begin
// Result:= Result+Chr(StrToInt(Copy(Avalue,i-1,2)));
// end;
// end;
//
//end;
procedure TfrmListMoreConent.NumEnceWork(Avalue: string);
var
iCord2D: Integer;
iRfid, i: Integer;
sDataList: string;
vDataList: array [0 .. 14] of Integer;
begin
try
WorkLog.MessageInfo('采集器值:' + Avalue);
if StringGrid1.RowCount = 0 then
exit;
TxtPc11.Text := (Avalue);
if Ord_Avalue = Avalue then //去掉重復的
begin
Exit;
end;
Ord_Avalue := Avalue;
sDataList := Avalue.Replace('>', '').Replace(',', ''); // WorkLog.MessageInfo('采集器값1:'+sDataList);
for I := 0 to 14 do
if Length(sDataList) > i then
try
vDataList[i] := StrToInt(sDataList[i + 1]);
except
on E: Exception do
begin
WorkLog.Error('转换数字出错: %s, 原始数据: %s', [E.Message, sDataList]);
vDataList[i] := 0; // 设置默认值
end;
end;
iCord2D := vDataList[14]; //右邊第一位
iRfid := vDataList[13]; //右邊第二位
if Ord_iCord2D <> iCord2D then //2D感應器處理
begin
Ord_iCord2D := iCord2D;
if (iCord2D = 1) then
begin
if StrToInt(StringGrid1.Cells[4, 0]) = StrToInt(StringGrid1.Cells[3, 0]) then //第一片
begin
// if StrToInt(StringGrid1.Cells[4,0])=0 then
Clear();
end;
Label1.Text := IntToStr(StrToInt(Label1.Text) + 1);
LogGridAdd();
// EdtInput1.Text:='';
if CheckBoxCode then
begin
ReOpen2D();
WorkLog.Debug('ReOpen2D:%s',[IntToStr(iCord2D)]);
end
else
begin
AddWork('');
WorkLog.Debug('AddWork:%s',[IntToStr(iCord2D)]);
end;
end
else
begin
if EdtInput1.Text <> '' then
begin
ListDataIn(EdtInput1.Text);
AddLog('提交數據:'+EdtInput1.Text);
WorkLog.Debug('ListDataIn:%s,',[IntToStr(iCord2D),EdtInput1.Text]);
EdtInput1.Text:='';
end;
end;
end;
if Ord_iRfid <> iRfid then //采集器處理
begin
Ord_iRfid := iRfid;
if (iRfid = 1) then
begin
WorkLog.Debug('RfidData:%s',[IntToStr(iRfid)]);
if iCord2D = 0 then
begin
LogGridAdd(); //没有感应到板子
end;
TThread.CreateAnonymousThread(
procedure
begin
CoInitialize(nil);
TRY
Rfid.ReadData();
finally
CoUninitialize;
end;
end
).Start;
end;
end;
except
on E: Exception do
begin
WorkLog.Error('采集器处理出错: %s', [E.Message]);
end;
end;
end;
procedure TfrmListMoreConent.LogGridToFile();
begin
if StringGrid4.RowCount>300 then
begin
ExportToExcel(StringGrid1.Cells[1,0]+'-'+FormatDateTime('yyyymmddhhmmss',Now),StringGrid4);
StringGrid4.BeginUpdate;
StringGrid4.RowCount:= 0;
StringGrid4.EndUpdate;
end;
end;
procedure TfrmListMoreConent.LogGridAdd();
begin
if StringGrid4.RowCount>300 then
begin
LogGridToFile();
end;
with StringGrid4 do
begin
BeginUpdate;
RowCount:= RowCount + 1;
Cells[0,RowCount-1]:=(RowCount).ToString;
Cells[1,RowCount-1]:='';
Cells[2,RowCount-1]:='';
Cells[3,RowCount-1]:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
Cells[4,RowCount-1]:='';
SelectRow(RowCount);
EndUpdate;
end;
end;
procedure TfrmListMoreConent.RfidWork(Avalue: string);
begin
EdtInput2.Text:= Avalue;
WorkLog.MessageInfo('Rfid值:'+Avalue);
if (StringGrid4.RowCount>0) AND (length(Avalue)>6) then
StringGrid4.Cells[2,StringGrid4.RowCount-1]:= Avalue;
if StringGrid1.RowCount=0 then exit;
RfidLen:= Avalue.Length>8;
if not RfidLen then
begin
if Ord_iRfid=1 then
begin
TThread.CreateAnonymousThread(
procedure
begin
CoInitialize(nil);
TRY
Rfid.ReadData();
finally
CoUninitialize;
end;
end
).Start;
end;
StringGrid4.Cells[2,StringGrid4.RowCount-1]:= '';
exit;//去掉不对的
end;
with StringGrid2 do
begin
if Cells[0,RowCount-1]=EdtInput2.Text then //重复
begin
TxtShowErrorInfo(TxtInput1Error,'條碼2重複輸入');
end
else
begin
//开启线程,提交数据到服务器,提交不成功,就保存在本地
TThread.CreateThreadX<string>(
procedure (Avalue:string)
var
sError:string;
bResult:boolean;
tmp:string;
begin
CoInitialize(nil);
try
//獲取治工具或者設備的狀態
if not Ksoap.Thread_Check_tool_or_equip_status_f(StringGrid1.Cells[1,0],TxtLineNum.Text,Avalue,'-1',sError) then
begin
TxtLotNumInfo.Text:= (sError);
Exit;
end;
finally
CoUninitialize;
end;
TThread.Synchronize( nil,
procedure
begin
AddLog(tmp);
TxtShowErrorInfo(TxtInput1Error,'');
BeginUpdate;
RowCount:=RowCount+1;
Cells[0,RowCount-1]:=EdtInput2.Text;
Cells[1,RowCount-1]:=FormatDateTime('yyyymmdd hh:mm:ss',Now);
SelectRow(RowCount-1);
EndUpdate;
FRfidLog.MessageInfo(EdtInput2.Text+' '+FormatDateTime('yyyymmdd hh:mm:ss',Now));
//dm.InsertLotNo(); //
end
);
end,Avalue
).Start;
end;
end;
end;
procedure TfrmListMoreConent.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;
end.