Files
2026-05-07 20:25:34 +08:00

1505 lines
44 KiB
Plaintext
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 uMain;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Types, System.UITypes,
System.Classes, System.Variants, System.IOUtils, System.StrUtils, System.DateUtils,
System.ImageList, ActiveX, ShellAPI,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Objects,
FMX.ImgList, FMX.Controls.Presentation, FMX.Edit, FMX.Pickers, FMX.ListBox,
FMX.ComboEdit, FMX.Layouts, FMX.StdCtrls,
utcpdevice, iniFiles, uSafeLog, uKsoap, uPucFun, uPassword, uShowInfo, udm,
uFrameBase, uFrameBaseBland, uInkPrintConent, MahUSB,
uConfigManager, uBusinessServices, uLogManager;
type
TfrmMain = class(TForm)
LayoutMain: TRectangle;
Rectangle7: TRectangle;
Rectangle_MenuLeft: TRectangle;
Rectangle_MenuRight: TRectangle;
Glyph1: TGlyph;
ImageList1: TImageList;
Rectangle001: TRectangle;
Text3: TText;
TxtPc: TText;
Rec_OkSave: TRectangle;
Rectangle12: TRectangle;
Rectangle14: TRectangle;
Text7: TText;
Rec_GD: TRectangle;
Glyph4: TGlyph;
Text8: TText;
Text9: TText;
EdtEmpNo: TEdit;
Rec_code: TRectangle;
Glyph5: TGlyph;
Text10: TText;
Text11: TText;
EdtGoodsNo: TEdit;
RectangleLotNo: TRectangle;
Glyph6: TGlyph;
Text12: TText;
Text13: TText;
EdtLotNo: TEdit;
Rectangle18: TRectangle;
Glyph7: TGlyph;
Text14: TText;
TxtLineNum: TText;
Rectangle19: TRectangle;
Glyph8: TGlyph;
Text16: TText;
TxtLine: TText;
Rectangle2: TRectangle;
Rectangle3: TRectangle;
Rectangle6: TRectangle;
Rectangle4: TRectangle;
TxtFactoryCode: TText;
Text2: TText;
Rectangle5: TRectangle;
Text21: TText;
Timer1: TTimer;
Rectangle35: TRectangle;
Text49: TText;
Rectangle36: TRectangle;
TxtEmpNoError: TText;
Glyph23: TGlyph;
Text4: TText;
TxtVerInfo: TText;
TxtLotnoError: TText;
Text5: TText;
TxtOffline: TText;
TxtGoodsNoError: TText;
ComboBoxP_PC: TComboBox;
StyleBook1: TStyleBook;
GridLayout1: TGridLayout;
Rec_Menu: TRectangle;
CheckBox1: TCheckBox;
Label_NG: TLabel;
RectangleChild: TRectangle;
procedure Text7Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure Rectangle2Click(Sender: TObject);
procedure Text4Click(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure EdtEmpNoKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
procedure EdtLotNoKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
procedure EdtLotNoExit(Sender: TObject);
procedure Text5Click(Sender: TObject);
procedure AppctionError(Sender: TObject; E: Exception);
procedure ComboBoxP_PCExit(Sender: TObject);
procedure TxtVerInfoClick(Sender: TObject);
procedure EdtEmpNoChange(Sender: TObject);
procedure EdtLotNoChange(Sender: TObject);
procedure EdtEmpNoExit(Sender: TObject);
procedure EdtLotNoClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure ComboBoxP_PCChange(Sender: TObject);
procedure EdtGoodsNoExit(Sender: TObject);
procedure ComboBoxP_PCClick(Sender: TObject);
procedure EdtGoodsNoKeyUp(Sender: TObject; var Key: Word; var KeyChar: Char;
Shift: TShiftState);
private
FUsb : TUsbClass;
FLastInputTime, oldFLastInputTime: TDateTime; // 记录最后输入时间
FDataAccessService: TDataAccessService;
FProductionService: TProductionReportingService;
procedure UIDataClear;
procedure UIClear();
procedure SetMainUIParameter;
procedure SetRadioOption(sRadioList: string);
procedure ShowMainError(EmpNoError,LotNoError,GoodsNoError:string);
procedure aaaWork(Avalue: string);
function EdtLotPartnum(Value: string): Boolean;
procedure UsbIN(ASender : TObject; const ADevType,ADriverName,
AFriendlyName : string);
procedure UsbOUT(ASender : TObject; const ADevType,ADriverName,
AFriendlyName : string);
procedure comlista;
procedure CreateEmpNoExit;
procedure EdtEmpNoExitList;
procedure EdtLotNoExit1;
procedure ComboBoxP_PC_Down();
procedure HFraButClick(Sender: TObject; ButtonID: Integer);
{ Private declarations }
public
DisplayFrame:TFrameBase;
sLotNum:string; //批号的数量
sPartnumValue:string; //获取料号返回的数据
DbSoapThread:TDbSoapThread;
end;
var
frmMain: TfrmMain;
iniListName:TStrings;
implementation
{$R *.fmx}
{ 二维要代出
259->261
259-R->261-R
54-> 18K预烤
541-> 18K后烤
18B油墨印刷机->18B大气烤箱
182-B景晖手动印刷机->182-B烤箱
}
uses uSetMain, uListMoreConent, uListConent,
json_dypSave, uFrame_Dyp001, uFrame_Dyp_Setup,
uFrame_Dyp002, uFrame_Dyp003, uFrame_Dyp000, json_webservice;
procedure TfrmMain.EdtEmpNoChange(Sender: TObject);
begin
if EdtEmpNo.Text='' then TxtShowErrorInfo(TxtEmpNoError,'');
end;
procedure TfrmMain.EdtEmpNoExit(Sender: TObject); //查用户表
var
sError:string;
begin
if EdtEmpNo.Text='' then exit;
ShowMainError('','','');
TThread.CreateAnonymousThread(
procedure
var
sError:string;
begin
CoInitialize(nil);
TRY
if not FProductionService.ValidateUser(EdtEmpNo.Text) then
begin
TxtEmpNoError.TextSettings.FontColor:= $FFFF0000;
ShowMainError('用户账号错误','','');
Exit;
end;
FINALLY
CoUninitialize;
END;
end).Start;
// EdtEmpNoExitList;
end;
procedure TfrmMain.EdtGoodsNoExit(Sender: TObject);
begin
if (EdtGoodsNo.Text = '') or (ComboBoxP_PC.ItemIndex < 0) or (EdtLotNo.Text = '') then
Exit;
ShowMainError('', '', '');
// 提前获取需要在线程中使用的值,避免跨线程访问VCL控件
var LItemCode := EdtGoodsNo.Text;
var LLotNo := EdtLotNo.Text;
var LProcessIndex := ComboBoxP_PC.ItemIndex;
var LProcessNumber := '';
if LProcessIndex >= 0 then
LProcessNumber := KJSon.REST_Value(KJSon.FList_pro_process.Strings[LProcessIndex], 'number');
TThread.CreateAnonymousThread(
procedure
var
sError: string;
LNeedsSync: Boolean;
begin
CoInitialize(nil);
try
sError := '';
LNeedsSync := False;
// 检查是否满足执行条件
if (KJSon.FList_pro_process.Count > 0) and (LProcessIndex > -1) then
begin
if not FProductionService.ValidateGoodsNo(LItemCode, LProcessNumber, LLotNo) then
begin
LNeedsSync := True;
TThread.Synchronize(nil,
procedure
begin
TxtEmpNoError.TextSettings.FontColor := $FFFF0000;
ShowMainError('二维码错误或还没有检验过', '', '');
end);
Exit;
end;
end;
// 如果有错误信息,也同步显示
if sError <> '' then
begin
if not LNeedsSync then // 如果尚未同步,则需要新的同步
begin
TThread.Synchronize(nil,
procedure
begin
ShowMainError(sError, '', '');
end);
end
else
begin
// 如果已经需要同步,可以合并错误信息(根据实际需求调整)
TThread.Synchronize(nil,
procedure
begin
ShowMainError('二维码错误或还没有检验过', sError, '');
end);
end;
end;
finally
CoUninitialize;
end;
end).Start;
end;
procedure TfrmMain.EdtGoodsNoKeyUp(Sender: TObject; var Key: Word;
var KeyChar: Char; Shift: TShiftState);
begin
// 每次输入内容时,更新最后输入时间
FLastInputTime := Now;
// Text13.Text:= EdtGoodsNo.Text;
// if (EdtGoodsNo.Text.Length>10) then
// begin
// // Text13.Text:= EdtGoodsNo.Text + Key.ToString();
// Text7Click(Sender);
// end;
end;
procedure TfrmMain.EdtEmpNoExitList;
begin
if (EdtEmpNo.Text<>'') and (not TxtOffline.Visible) then //不是手工操作
TThread.CreateAnonymousThread(
procedure
var
sError:string;
I: Integer;
begin
CoInitialize(nil);
TRY
//检查工号
if KJSon.REST_pro_List(EdtEmpNo.Text,2,sError)<>'' then
begin
TxtEmpNoError.TextSettings.FontColor:= $FFFF0000;
ShowMainError(sError,'','');
Exit;
end;
// if (not Ksoap.xxcc_work_num_f(FactoryCode,EdtEmpNo.Text,TxtPc.Text,TxtLine.Text,sError)) then
// begin
// TxtEmpNoError.TextSettings.FontColor:= $FFFF0000;
// ShowMainError(sError,'','');
// Exit;
// end
// else
// begin
// TxtEmpNoError.TextSettings.FontColor:= $FF0003F3;
// ShowMainError('ok','','');
// end;
finally
CoUninitialize;
end;
end
).Start;
end;
procedure TfrmMain.EdtEmpNoKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
var
i: Boolean;
StartTime: Int64;
begin
StartTime := TThread.GetTickCount;
try
if Key = vk_Return then
begin
TxtEmpNoError.Text:='';
EdtGoodsNo.Text:='';
EdtLotNo.SetFocus;
end;
// i := (KeyChar <= #8) or (KeyChar <= #8) and (KeyChar < #48) or (KeyChar > #57);
// if i then
// KeyChar := #0;
//
// if not (KeyChar in ['0'..'9', #13]) then
// KeyChar := #0;
finally
LogManager.LogUIOperation('KeyDown', 'EdtEmpNo', TThread.GetTickCount - StartTime);
end;
end;
procedure TfrmMain.EdtLotNoKeyDown(Sender: TObject; var Key: Word; var KeyChar: Char; Shift: TShiftState);
var
StartTime: Int64;
begin
StartTime := TThread.GetTickCount;
try
if Key = vk_Return then EdtGoodsNo.SetFocus;
finally
LogManager.LogUIOperation('KeyDown', 'EdtLotNo', TThread.GetTickCount - StartTime);
end;
end;
procedure TfrmMain.aaaWork(Avalue:string);
begin
//连接数据库服务器
TThread.Synchronize(nil,
procedure
begin
TxtLineNum.Text:=Avalue;
//Form1.Memo1.Lines.Add();
end);
end;
procedure TfrmMain.UIClear();
begin
ComboBoxP_PC.Items.Clear;
try
dm.MainUI:=StrToInt(FDataAccessService.ReadProductionParams('MainUI'));
except
dm.MainUI:= 1;
end;
// EdtGoodsNo.ReadOnly:=not TxtOffline.Visible;
if FDataAccessService.ReadProductionParams('DataOpline')<>'' then
try
dm.DataOpline:=StrToInt(FDataAccessService.ReadProductionParams('DataOpline'));
except
dm.DataOpline:= 0;
end;
TRY
// KJSon.REST_pro_List('', 1, sP_KB); //查工序
if dm.MainUI=2 then //特殊处理 'VCP F线A列'=trim(TxtLine.Text)
begin
RectangleLotNo.Visible:=false;
Rec_code.Visible:=false;
Label_NG.Visible:= true;
end
else if dm.MainUI=3 then
begin
// ComboBoxP_PC_Down(); //加载数据
end
else if dm.MainUI=4 then
begin
// // 安全释放方案
// if Assigned(DisplayFrame) then // 更标准的Delphi对象检查方式
// begin
// try
// DisplayFrame.Free;
// finally
// DisplayFrame := nil; // 重要:立即置空指针
// end;
// end;
// Rec_GD.Visible:= False;
// RectangleLotNo.Visible:= False;
Label_NG.Visible:= False;
Text12.Text:= '返回工序';
DisplayFrame:=TFrame_Dyp_Setup.Create(nil);
DisplayFrame.Parent:=RectangleChild;
DisplayFrame.Align:=TAlignLayout.Top;
DisplayFrame.GridLayout:=GridLayout1;
DisplayFrame.FillDefaultValue('sPartnumValue','');
// DisplayFrame.Controls[0].BringToFront;
// RectangleChild.Controls[0].BringToFront;
WorkLog.MessageInfo('修维部1:%s ' , [DisplayFrame.Name]);
// ShowInfoOK('上传成功,正在生产中...');
// exit;
// Rectangle16.Visible:=false;
end;
except
END;
// SetMainUIParameter(); //加载界面数据
TThread.CreateAnonymousThread(
procedure
var
sError:string;
I: Integer;
begin
CoInitialize(nil);
TRY
SetMainUIParameter(); //加载界面
if DisplayFrame=nil then //其他
begin
DisplayFrame:=TFrameBaseBland.Create(nil);
DisplayFrame.Parent:=RectangleChild;
DisplayFrame.Align:=TAlignLayout.Bottom;
DisplayFrame.GridLayout:=GridLayout1;
//Text21.Text:= DisplayFrame.Name;
DisplayFrame.Initialize();
Exit;
end;
if EdtEmpNo.Visible then
EdtEmpNo.SetFocus;
finally
CoUninitialize;
end;
end
).Start;
end;
procedure TfrmMain.UIDataClear();
VAR
I:INTEGER;
sP_KB:string;
begin
WorkLog.MessageInfo('界面初始化');
TxtShowErrorInfo(TxtEmpNoError,'');
TxtShowErrorInfo(TxtLotNoError,'');
TxtShowErrorInfo(TxtGoodsNoError,'');
// EdtEmpNo.Text:='';
//EdtLotNo.Text:='';
EdtGoodsNo.Text:='';
for I :=GridLayout1.ChildrenCount-1 downto 0 do
begin
TRadioButton(GridLayout1.Children[i]).IsChecked:=false;
end;
if DisplayFrame<>nil then
begin
DisplayFrame.ClearAll;
end;
end;
procedure TfrmMain.ComboBoxP_PCChange(Sender: TObject);
var
sTemp: string;
begin
if dm.MainUI=4 then exit; //去掉维修
// ShowMainError('1','','');
if (ComboBoxP_PC.ItemIndex>-1) and (KJSon. FList_pro_process.Count>0) then
TxtLine.Text:= KJSon. REST_Value(KJSon. FList_pro_process.Strings[ComboBoxP_PC.ItemIndex], 'name'); //ComboBoxP_PC.Items.Add(KJSon. REST_Value(KJSon. FList_Str.Strings[i], 'number'));
// 安全释放方案
// if (ComboBoxP_PC.ItemIndex > -1) and (KJSon. FList_pro_process.Count>0) then begin
if Assigned(DisplayFrame) then // 更标准的Delphi对象检查方式
begin
try
DisplayFrame.Free;
finally
DisplayFrame := nil; // 重要:立即置空指针
end;
// ComboBoxP_PC.ItemIndex:= 0;
end;
// end;
//电应普
if (DisplayFrame=nil) and (ComboBoxP_PC.ItemIndex > -1) and (trim(KJSon. REST_Value(KJSon. FList_pro_process.Strings[ComboBoxP_PC.ItemIndex], 'attention'))<>'') then
begin
sTemp:= UpperCase(Trim(copy(trim(KJSon. REST_Value(KJSon. FList_pro_process.Strings[ComboBoxP_PC.ItemIndex], 'attention')),1,2)));
WorkLog.MessageInfo('DisplayFrame_sTemp: %d,%s',[ComboBoxP_PC.ItemIndex,sTemp]);
// ShowMainError('2','','');
if sTemp=UpperCase('bx') then
begin
DisplayFrame:=TFrame_Dyp001.Create(nil);
DisplayFrame.Parent:=RectangleChild;
DisplayFrame.Align:=TAlignLayout.Top;
DisplayFrame.GridLayout:=GridLayout1;
DisplayFrame.OnPanelButClick := HFraButClick;
DisplayFrame.Tag:= ComboBoxP_PC.ItemIndex;
// ShowMainError('3','','');
exit;
end;
if sTemp=UpperCase('bd') then
begin
DisplayFrame:=TFrame_Dyp002.Create(nil);
DisplayFrame.Parent:=RectangleChild;
DisplayFrame.Align:=TAlignLayout.Top;
DisplayFrame.GridLayout:=GridLayout1;
DisplayFrame.OnPanelButClick := HFraButClick;
DisplayFrame.Tag:= ComboBoxP_PC.ItemIndex;
exit;
end;
if sTemp=UpperCase('cl') then
begin
DisplayFrame:=TFrame_Dyp003.Create(nil);
DisplayFrame.Parent:=RectangleChild;
DisplayFrame.Align:=TAlignLayout.Top;
DisplayFrame.GridLayout:=GridLayout1;
DisplayFrame.OnPanelButClick := HFraButClick;
DisplayFrame.Tag:= ComboBoxP_PC.ItemIndex;
exit;
end;
if sTemp=UpperCase('nu') then //'null'
begin
DisplayFrame:=TFrame_Dyp000.Create(nil);
DisplayFrame.Parent:=RectangleChild;
DisplayFrame.Align:=TAlignLayout.Top;
DisplayFrame.GridLayout:=GridLayout1;
DisplayFrame.Tag:= ComboBoxP_PC.ItemIndex;
exit;
end;
// SetRadioOption('TOP面,BOT面');
Exit;
end;
end;
procedure TfrmMain.ComboBoxP_PCClick(Sender: TObject);
begin
if EdtLotNo.Text.Length=0 then
begin
// ShowInfoOK('工单不能为空');
TxtShowErrorInfo(TxtEmpNoError,'工单不能为空');
exit;
end;
end;
procedure TfrmMain.ComboBoxP_PCExit(Sender: TObject); //把工序给值
begin
if (ComboBoxP_PC.Count>0) and (ComboBoxP_PC.Selected<>nil) then
Text13.Text:=ComboBoxP_PC.Selected.Text;
end;
procedure TfrmMain.ComboBoxP_PC_Down();
var
i: Integer;
sTemp: String;
begin
ComboBoxP_PC.Items.Clear;
if KJSon. FList_pro_process.Count>0 then
begin
for I := 0 to KJSon. FList_pro_process.Count - 1 do
begin
sTemp:= KJSon. REST_Value(KJSon. FList_pro_process.Strings[i], 'attention').Replace('null','');
if (sTemp<>'') then sTemp:= UpperCase(Copy(sTemp, 1, 2)) + '-';
ComboBoxP_PC.Items.Add(sTemp + KJSon. REST_Value(KJSon. FList_pro_process.Strings[i], 'processName'));
end;
end;
with ComboBoxP_PC do
begin
DropDownKind := TDropDownKind.Custom;
for i := 0 to Count - 1 do
begin
ListBox.ListItems[i].TextSettings.Font.Size := 16;
ListBox.ListItems[i].StyledSettings :=ListBox.ListItems[i].StyledSettings-[TStyledSetting.Size];
end;
end;
// ShowInfoOK(inttostr(KJSon. FList_pro_process.Count));
end;
procedure TfrmMain.SetMainUIParameter();
VAR
tmpList:Tstrings;
sP_KB, sTemp: String;
i: integer;
procedure SetOption(Rectangle:TRectangle;sValue:string);
var
i:integer;
begin
if (sValue='#') then
begin
for I := 0 to Rectangle.ControlsCount-1 do
begin
if TControl(Rectangle.Controls[i]) is TGlyph then
TGlyph(Rectangle.Controls[i]).ImageIndex:=-1
else
TControl(Rectangle.Controls[i]).Visible:=false;
end;
end
else
begin
for i := 0 to Rectangle.ControlsCount-1 do
begin
if Pos('OptionLabel',Rectangle.Controls[i].Name)>0 then
TText(Rectangle.Controls[i]).Text:=sValue;
TControl(Rectangle.Controls[i]).Visible:=true;
if TControl(Rectangle.Controls[i]) is TGlyph then
TGlyph(Rectangle.Controls[i]).ImageIndex:=11;
end;
end;
end;
begin
sbaseUrl:=FDataAccessService.ReadConfigValue('tv_DirData','server_url');
if sbaseUrl='' then
sbaseUrl:= Config.GetServerURL;
FactoryCode:=FDataAccessService.ReadDeviceInfo('FACTORY_CODE');
TxtFactoryCode.Text:= FactoryCode; //string类型
// TxtPc.Text:= FDataAccessService.ReadDeviceInfo('P_PC'); //string类型
TxtLine.Text:= FDataAccessService.ReadDeviceInfo('P_LINE'); //string类型
TxtLineNum.Text:= FDataAccessService.ReadDeviceInfo('P_LINE_NUM'); //string类型
sP_KB:=FDataAccessService.ReadDeviceInfo('P_KB');
fDevRecord.FP_User:= FDataAccessService.ReadConfigValue('tv_DirData','u_user');
fDevRecord.FP_Pass:= FDataAccessService.ReadConfigValue('tv_DirData','u_pass');
try
dm.Operate:=StrToInt(FDataAccessService.ReadProductionParams('tv_Operate'));
except
dm.Operate:= 1;
end;
WorkLog.MessageInfo('设备信息:'+FactoryCode+','+TxtPc.Text+','+TxtLine.Text+','+TxtLineNum.Text+','+sP_KB);
//登录用户
if WebJSon.PostJSONWithREST_Login(fDevRecord.FP_User,fDevRecord.FP_Pass,sP_KB)='' then
begin
TxtEmpNoError.TextSettings.FontColor:= $FFFF0000;
ShowMainError(sP_KB,'','');
Exit;
end;
if dm.MainUI=4 then //维修数据加载
begin
// KJSon.REST_pro_List('', 9, sP_KB); //查工序
// if DisplayFrame<>nil then
// DisplayFrame.FillDefaultValue('sPartnumValue',''); //查工序
TxtLineNum.Text:= '修维部';
end;
end;
procedure TfrmMain.AppctionError(Sender: TObject; E: Exception);
begin
WorkLog.Error('AppctionError:'+E.Message);
ShowError('程序异常,请与技术人员联系!');
end;
procedure TfrmMain.comlista;
var
ADevType,ADriverDesc,
AFriendlyName : string;
begin
UsbOUT(nil,ADevType,ADriverDesc,AFriendlyName);
end;
procedure TfrmMain.FormCreate(Sender: TObject);
var
Filename: string;
vs,sError: string;
i:integer;
f:TStrings;
begin
FDataAccessService := TBusinessServiceFactory.GetDataAccessService();
FProductionService := TBusinessServiceFactory.GetProductionReportingService('');
//http://home09.compeq.huizhou.gd.cn/ctshopfloor/Mor/PRM/MorQuery.asp 查询 制程名称 設備統稱
Application.OnException:=AppctionError;
WorkLog.MessageInfo('');
WorkLog.MessageInfo('程序开始');
DbApiLog.MessageInfo('');
DbApiLog.MessageInfo('程序开始');
ksoap.OnLine:=true;
sError:= '';
// ksoap.Thread_ExecuteDataSet('select sysdate from dual',sError);//查时间
// Ksoap.getPartnumTime('R300000100','TIME',sError);
try
FLastInputTime := Now; // 初始化时间
oldFLastInputTime:= FLastInputTime;
// SetTime(sError);
Except
end;
TxtOffline.Visible:=false; //手工操作
dm.LoadMain();
dm.LoadDetail();
//R3003420L
//R3003420L12001
ComName:=FDataAccessService.ReadAlarmConfig('DevName');
// if ComName<>'' then
// begin
// ComType:=FDataAccessService.ReadAlarmConfig('ComType');
// if ComType='1' then //使用IO盒子控制
// begin
// AlarmCom:=TAlarmCom.Create;
// AlarmCom.open(ComName,sError);
// sleep(200);
// AlarmCom.GreenLed(sError);
// sleep(800);
// end
// else
// begin
// // ComName:= comName_a;
// // AlarmLed:=TAlarmLed.Create;
// // AlarmLed.open(ComName,sError);
// end;
// end;
iniListName:= TStringList.Create;
dm.MemTableReadTabList(iniListName);
TxtVerInfo.Text:=GetBuildInfo; //获取版本号
UIClear();
UIDataClear();
DbSoapThread:=TDbSoapThread.Create;
DbSoapThread.Start; //开始提交失败数据
end;
procedure TfrmMain.FormDestroy(Sender: TObject);
var
sError:string;
begin
WorkLog.MessageInfo('程序退出1');
// if Assigned(AlarmLed) then // 更标准的Delphi对象检查方式
// begin
// try
// AlarmLed.CloseAllLed(sError);
// AlarmLed.Free;
// finally
// AlarmLed := nil; // 重要:立即置空指针
// end;
// end;
WorkLog.MessageInfo('程序退出2');
if Assigned(DbSoapThread) then // 更标准的Delphi对象检查方式
begin
try
DbSoapThread.Free;
finally
DbSoapThread := nil; // 重要:立即置空指针
end;
end;
WorkLog.MessageInfo('程序退出3');
if Assigned(DisplayFrame) then // 更标准的Delphi对象检查方式
begin
try
DisplayFrame.Free;
finally
DisplayFrame := nil; // 重要:立即置空指针
end;
end;
WorkLog.MessageInfo('程序退出4');
if Assigned(iniListName) then // 更标准的Delphi对象检查方式
begin
try
iniListName.Free;
finally
iniListName := nil; // 重要:立即置空指针
end;
end;
WorkLog.MessageInfo('程序退出5');
if Assigned(FUsb) then // 更标准的Delphi对象检查方式
begin
try
FUsb.Free;
finally
FUsb := nil; // 重要:立即置空指针
end;
end;
// if AlarmLed<>nil then AlarmLed.CloseAllLed(sError);
// if DbSoapThread<>nil then DbSoapThread.Terminate;
// WorkLog.MessageInfo('程序退出3');
// if AlarmLed<>nil then AlarmLed.Free;
// WorkLog.MessageInfo('程序退出4');
// if DisplayFrame<>nil then DisplayFrame.Free;
// WorkLog.MessageInfo('程序退出');
// DbApiLog.MessageInfo('程序退出');
// iniListName.Free;
// WorkLog.MessageInfo('程序退出5');
// FreeAndNil(FUsb);
// WorkLog.MessageInfo('程序退出6');
if Assigned(FDataAccessService) then
begin
try
FDataAccessService.Free;
finally
FDataAccessService := nil;
end;
end;
if Assigned(FProductionService) then
begin
try
FProductionService.Free;
finally
FProductionService := nil;
end;
end;
end;
procedure TfrmMain.CreateEmpNoExit;
begin
// if (EdtEmpNo.Text<>'') and (not TxtOffline.Visible) then //不是手工操作
TThread.CreateAnonymousThread(
procedure
var
sError:string;
I: Integer;
begin
CoInitialize(nil);
TRY
// if (not Ksoap.xxcc_work_num_f(FactoryCode,EdtEmpNo.Text,TxtPc.Text,TxtLine.Text,sError)) then
// begin
// TxtEmpNoError.TextSettings.FontColor:= $FFFF0000;
// ShowMainError(sError,'','');
// Exit;
// end
// else
// begin
// TxtEmpNoError.TextSettings.FontColor:= $FF0003F3;
// ShowMainError('ok','','');
// end;
finally
CoUninitialize;
end;
end
).Start;
end;
procedure TfrmMain.FormShow(Sender: TObject);
var
StartTime: Int64;
begin
StartTime := TThread.GetTickCount;
try
if FUsb=nil then
begin
FUsb := TUsbClass.Create;
FUsb.OnUsbInsertion := UsbIN;
FUsb.OnUsbRemoval := UsbOUT;
comlista;
CreateEmpNoExit;
end;
finally
LogManager.LogFormShow('MainForm', TThread.GetTickCount - StartTime);
end;
end;
procedure TfrmMain.HFraButClick(Sender: TObject; ButtonID: Integer);
var
Frame: TFramebase;
begin
WorkLog.MessageInfo('HFraButClick%s ' , [fDevRecord.P_ORG_CODE]);
Frame := Sender as TFramebase;
EdtGoodsNo.Text:= fDevRecord.P_ORG_CODE;
if Copy(fDevRecord.P_DIE_NAME,1,3)='不合格' then
begin
Label_NG.Text:='NG';
Label_NG.FontColor:= TAlphaColor($eeff0000);
end
else
begin
Label_NG.Text:='OK';
Label_NG.FontColor:= TAlphaColor($ee06b75b);
end;
if ButtonID=8 then
Text7Click(self);
end;
procedure TfrmMain.Rectangle2Click(Sender: TObject);
begin
FrmPassword:= TFrmPassword.Create(nil);
try
FrmPassword.Position:=TFormPosition.MainFormCenter;
if FrmPassword.ShowModal=mrOk then
begin
dm.MemTableReadTabList(iniListName);
frmSetMain:= TfrmSetMain.Create(nil);
try
frmSetMain.Position:=TFormPosition.MainFormCenter;
frmSetMain.TxtFactoryCode.Text:=FactoryCode; //厂区
frmSetMain.ShowModal;
TxtOffline.Visible:=frmSetMain.CheckBox1.IsChecked;
ksoap.OnLine:=not TxtOffline.Visible;
// if ksoap.OnLine then
// EdtGoodsNo.StyleLookup:='EdtGoodsNoStyle1'
// else
// EdtGoodsNo.StyleLookup:='';
//重新加载参数信息
SetMainUIParameter();
finally
frmSetMain.Free;
end;
end;
finally
FrmPassword.Free;
end;
end;
procedure TfrmMain.Text4Click(Sender: TObject);
begin
ShowTouchKeyBoard();
end;
procedure TfrmMain.Text5Click(Sender: TObject);
begin
UIDataClear();
end;
procedure TfrmMain.ShowMainError(EmpNoError,LotNoError,GoodsNoError:string);
begin
TThread.Synchronize(nil,
procedure
begin
TxtShowErrorInfo(TxtEmpNoError,EmpNoError);
TxtShowErrorInfo(TxtLotNoError,LotNoError);
if LotNoError<>'' then EdtLotNo.SetFocus;
TxtShowErrorInfo(TxtGoodsNoError,GoodsNoError);
// EdtGoodsNo.Text:='';//料号为空
end);
end;
procedure TfrmMain.Text7Click(Sender: TObject);
var
sError:string;
sFixture_Code:string;
begin
// showmessage('aa');
// WorkLog.MessageInfo('login点击');
//防止连续点击多次
if Text7.TextSettings.FontColor=TAlphaColorRec.Silver then
begin
WorkLog.MessageInfo('重复点击');
Exit;
end;
// showmessage('aa1');
Text7.TextSettings.FontColor:=TAlphaColorRec.Silver;
try
TxtShowErrorInfo(TxtEmpNoError,'');
if EdtEmpNo.Text='' then
begin
TxtShowErrorInfo(TxtEmpNoError,'工号不能为空');
TxtShowErrorInfo(TxtLotnoError,'');
TxtShowErrorInfo(TxtGoodsNoError,'');
EdtEmpNo.SetFocus;
Exit;
end;
if Rec_GD.Visible and (EdtLotNo.Text='') then //检查工号
begin
TxtShowErrorInfo(TxtEmpNoError,'');
TxtShowErrorInfo(TxtLotnoError,'工单不能为空');
TxtShowErrorInfo(TxtGoodsNoError,'');
EdtLotno.SetFocus;
Exit;
end;
// showmessage('aa11');
if Rec_code.Visible then
begin
// showmessage('aa111');
EdtGoodsNo.Text:= EdtGoodsNo.Text.Replace(';','');
EdtGoodsNo.Text:= EdtGoodsNo.Text.Replace(',','');
if EdtGoodsNo.Text='' then
begin
TxtShowErrorInfo(TxtEmpNoError,'');
TxtShowErrorInfo(TxtLotnoError,'');
TxtShowErrorInfo(TxtGoodsNoError,'条码不能为空');
EdtLotno.SetFocus;
Exit;
end;
// showmessage('aa1111');
// if ((Rectangle16.Visible) and (EdtGoodsNo.Text='')) then //批号带不出料号
// begin
// TxtShowErrorInfo(TxtEmpNoError,'');
// TxtShowErrorInfo(TxtLotnoError,'');
// TxtShowErrorInfo(TxtGoodsNoError,'料號不能為空');
// EdtLotno.SetFocus;
// Exit;
// end;
end;
// showmessage('aa2');
if not TxtOffline.Visible then //不是手工操作
begin
WorkLog.MessageInfo('开始提交数据到服务器...');
fDevRecord.P_BC:= EdtEmpNo.Text; //工号
fDevRecord.P_LOT:= EdtLotNo.Text; //单号
WorkLog.MessageInfo('提交+%d,%d,%d',[ComboBoxP_PC.ItemIndex,ComboBoxP_PC.Count,KJson.FList_pro_process.Count]);
if (ComboBoxP_PC.ItemIndex> -1) and (KJson.FList_pro_process.Count> 0) then
begin
fDevRecord.P_LINE_index:= ComboBoxP_PC.ItemIndex; //线别序号
fDevRecord.P_LINE_id:= StrToInt(KJson.REST_Value(KJson.FList_pro_process.Strings[ComboBoxP_PC.ItemIndex],'id')); //线别ID
// fDevRecord.P_LINE:= (KJson.REST_Value(KJson.FList_pro_process.Strings[ComboBoxP_PC.ItemIndex],'number')); //线别编号
fDevRecord.P_LINE_name:= (KJson.REST_Value(KJson.FList_pro_process.Strings[ComboBoxP_PC.ItemIndex],'processName')); //线别名称
end;
fDevRecord.P_ORG_CODE:= EdtGoodsNo.Text; //二维码
fDevRecord.P_COPPER_MODEL:= EdtGoodsNo.Text; //二维码ID
WorkLog.MessageInfo('提交数据main: ' +
'工号=' + fDevRecord.P_BC + ', ' +
'单号=' + fDevRecord.P_LOT + ', ' +
'线别id=' + IntToStr(fDevRecord.P_LINE_id) + ', ' +
'线别名称=' + fDevRecord.P_LINE_name + ', ' +
'料号=' + fDevRecord.P_ORG_CODE);
WorkLog.MessageInfo('EdtGoodsNo: %s',[EdtGoodsNo.Text]);
//去掉维修,第一个工序
if (dm.MainUI<>4) and (ComboBoxP_PC.ItemIndex=0)
and ((fDevRecord.P_ORG_CODE='') or (fDevRecord.P_ORG_CODE_id='')) then
begin
TxtShowErrorInfo(TxtEmpNoError,'');
TxtShowErrorInfo(TxtLotnoError,'');
TxtShowErrorInfo(TxtGoodsNoError,'条码和ID不能为空');
EdtLotno.SetFocus;
Exit;
end;
// 提交生产数据到服务层
if not FProductionService.SubmitProductionData(
fDevRecord.P_BC, // 工号
fDevRecord.P_LOT, // 单号
IntToStr(fDevRecord.P_LINE_id), // 工序ID
fDevRecord.P_ORG_CODE) then // 二维码
begin
TxtShowErrorInfo(TxtEmpNoError,'');
TxtShowErrorInfo(TxtLotnoError,'');
TxtShowErrorInfo(TxtGoodsNoError,'数据提交失败');
Exit;
end;
// //检查工号
// if (not KJSon.Thread_xxcc_work_num_f(FactoryCode,EdtEmpNo.Text,TxtPc.Text,TxtLine.Text,sError)) then
// begin
// TxtShowErrorInfo(TxtEmpNoError,sError);
// TxtShowErrorInfo(TxtLotnoError,'');
// TxtShowErrorInfo(TxtGoodsNoError,'');
// Exit;
// end;
WorkLog.MessageInfo('提交数据main1:' + sError);
// //检查批号
// if RectangleLotNo.Visible then
// begin
// if (not Ksoap.Thread_XXCC_LOT_PC_F(EdtLotno.Text,TxtLineNum.Text,'1',sError)) then
// begin
// TxtShowErrorInfo(TxtEmpNoError,'');
// TxtShowErrorInfo(TxtLotNoError,sError);
// TxtShowErrorInfo(TxtGoodsNoError,'');
// Exit;
// end;
//
// sFixture_Code:=DisplayFrame.GetFixture_Code; //取治具ID
//
// //獲取治工具或者設備的狀態
// if not Ksoap.Thread_Check_tool_or_equip_status_f(EdtLotNo.Text,TxtLineNum.Text,sFixture_Code,'-1',sError) then
// begin
// ShowMainError('',sError,'');
// Exit;
// end;
// end;
end
else
begin
WorkLog.MessageInfo('提交数据:2');
ksoap.P_ORG_CODE:=FactoryCode; //廠區
ksoap.P_WORK_NUM:=EdtEmpNo.Text; //工號
ksoap.P_PC:=TxtPc.Text; //製程
ksoap.P_LINE:=TxtLine.Text; //線別
ksoap.P_LINE_NUM:=TxtLineNum.Text; //線別編號
ksoap.P_Goods_Num:=EdtGoodsNo.Text; //料号
ksoap.P_Lot:=EdtLotNo.Text; //批号
ksoap.P_Lot_Num:=0;
ksoap.Fixture_Code:=DisplayFrame.GetFixture_Code;
// TxtShowErrorInfo(TxtEmpNoError,'工號进入');
end;
// Text21.Text:= DisplayFrame.Name;
WorkLog.MessageInfo('提交数据main2:%s', [sError]);
if (DisplayFrame<>nil) and (DisplayFrame.DoExec) then UIDataClear;
finally
Text7.TextSettings.FontColor:=TAlphaColorRec.White;
end;
end;
procedure TfrmMain.Timer1Timer(Sender: TObject);
begin
Text2.Text:= GetSysTimeByFormate;
//判断整点,就上传日志
dm.Tim_Timer(Text2.Text);
// 判断如果当前时间减去最后输入时间大于等于1秒 20260426
if (SecondsBetween(Now, FLastInputTime) >= 1) and (oldFLastInputTime<FLastInputTime) then
begin
// 如果需要检查编辑框是否为空
if Trim(EdtGoodsNo.Text).Length >6 then
begin
// 执行Text7Click
Text7Click(Sender);
// 重置时间,避免重复触发
FLastInputTime := Now;
oldFLastInputTime:= FLastInputTime;
end;
end;
end;
procedure TfrmMain.TxtVerInfoClick(Sender: TObject);
begin
// exit;
// frmListConent:=TfrmListConent.Create(nil); //多个读头
// try
// frmListConent.ShowModal;
// finally
// frmListConent.Free;
// end;
{ frmInkPrinterConent:=TfrmInkPrinterConent.Create(nil);
try
frmInkPrinterConent.ShowModal;
finally
frmInkPrinterConent.Free;
end; }
// frmListMoreConent:=TfrmListMoreConent.Create(nil); //多个批号
// try
// frmListMoreConent.ShowModal;
// finally
// frmListMoreConent.Free;
// end;
end;
procedure TfrmMain.UsbIN(ASender: TObject; const ADevType, ADriverName,
AFriendlyName: string);
var
sError:String;
begin
WorkLog.MessageInfo('USB Inserted - Device Type = ' + ADevType + #13#10 +
'Driver Name = ' + ADriverName + #13+#10 +
'Friendly Name = ' + AFriendlyName);
// if (dm.MemTableReadKeyValue('报警灯','DevName')<>'') and (Pos('340',AFriendlyName)>0) then
// begin
// dm.MemTableWriteKeyValue('报警灯','DevName',ADriverName);
// if AlarmLed<>nil then
// begin
// AlarmLed.open(ADriverName,sError);
// sleep(100);
// AlarmLed.YellowLed(sError);
// end;
// end;
end;
procedure TfrmMain.UsbOUT(ASender: TObject; const ADevType, ADriverName,
AFriendlyName: string);
begin
WorkLog.MessageInfo('USB Removed - Device Type = ' + ADevType + #13#10 +
'Driver Name = ' + ADriverName + #13+#10 +
'Friendly Name = ' + AFriendlyName);
end;
procedure TfrmMain.SetRadioOption(sRadioList:string);
VAR
i:integer;
tmpList:TStrings;
begin
if sRadioList='' then Exit;
// if (GridLayout1<>nil) and (GridLayout1.ChildrenCount>0) then //检测TOP面,BOT面
// begin
// while GridLayout1.ChildrenCount>0 do //有选项没显示,返回也为真
// begin
// GridLayout1.Children.Items[0].Destroy;
// end;
// end;
// WorkLog.Debug(Format('iLayerValue1:%s',[IntToStr(GridLayout1.ChildrenCount)]));
tmpList:=TStringlist.Create;
try
tmplist.DelimitedText:=sRadioList;
if tmpList.Count>10 then Exit;
if tmplist.Count>GridLayout1.ChildrenCount then //创建
begin
for i := 0 to tmplist.Count-GridLayout1.ChildrenCount-1 do
begin
WITH TRadioButton.Create(SELF) DO
BEGIN
PARENT:=GridLayout1;
GroupName:='a';
Height:=34;
END;
end;
end;
if tmplist.Count<GridLayout1.ChildrenCount then //隐藏
begin
for I :=GridLayout1.ChildrenCount-1 downto 0 do
begin
TRadioButton(GridLayout1.Children[i]).IsChecked:=false;
if i>=tmplist.Count then
TRadioButton(GridLayout1.Children[i]).Visible:=false
else
TRadioButton(GridLayout1.Children[i]).Text:=tmplist.Strings[i];
end;
if tmplist.Count>0 then
GridLayout1.ItemWidth:=GridLayout1.Width / tmplist.Count;
end
else //数量相同
begin
for I := 0 to GridLayout1.ChildrenCount-1 do
begin
TRadioButton(GridLayout1.Children[i]).IsChecked:=false;
TRadioButton(GridLayout1.Children[i]).Text:=tmplist.Strings[i];
TRadioButton(GridLayout1.Children[i]).Visible:=true;
end;
if GridLayout1.ChildrenCount>0 then
GridLayout1.ItemWidth:=GridLayout1.Width / GridLayout1.ChildrenCount;
end;
finally
tmpList.Free;
end;
WorkLog.Debug(Format('iLayerValue2:%s',[IntToStr(GridLayout1.ChildrenCount)]));
end;
procedure TfrmMain.EdtLotNoChange(Sender: TObject);
begin
if EdtLotNo.Text='' then TxtShowErrorInfo(TxtLotnoError,'');
EdtLotNo.Text:= Trim(EdtLotNo.Text.ToUpper);
end;
procedure TfrmMain.EdtLotNoClick(Sender: TObject);
begin
ShowTouchKeyBoard();
end;
function TfrmMain.EdtLotPartnum(Value: string): Boolean;
begin
Result:= False;
if Value<>'' then
begin
if ComboBoxP_PC.Items.IndexOf(Value)<0 then
// ComboBoxP_PC.Items.Add(sPc);
begin
TxtShowErrorInfo(TxtLotNoError,'该批当前站在'+Value);
end
else
begin
COMBOBOXp_PC.ItemIndex:=ComboBoxP_PC.Items.IndexOf(Value);
TxtPc.Text:=Value;
ksoap.P_PC:=TxtPc.Text; //製程
Result:= True;
end;
end;
end;
procedure TfrmMain.EdtLotNoExit(Sender: TObject); //离开单号处理
var
sError:string;
begin
//检查单号
if EdtLotNo.Text='' then exit;
ShowMainError('','','');
TThread.CreateAnonymousThread(
procedure
var
sError:string;
begin
CoInitialize(nil);
TRY
ComboBoxP_PC.Items.Clear;
// 获取工单信息
var WorkOrderInfo := FProductionService.GetWorkOrderInfo(EdtLotNo.Text);
if not Assigned(WorkOrderInfo) then
begin
TxtEmpNoError.TextSettings.FontColor:= $FFFF0000;
ShowMainError('没有找到单号','','');
Exit;
end;
// 获取工序列表
var ProcessList := FProductionService.GetProcessList(EdtLotNo.Text);
if Assigned(ProcessList) and (ProcessList.Count > 0) then
begin
// 这里可以将ProcessList转换为KJSon.FList_pro_process的格式
// 或者修改ComboBoxP_PC_Down方法以使用新的数据源
KJSon. REST_pro_List(EdtLotNo.Text, 1, sError); // 暂时保留原调用,后续可完全迁移
ComboBoxP_PC_Down();
end;
FINALLY
CoUninitialize;
END;
end).Start;
end;
procedure TfrmMain.EdtLotNoExit1; //离开二维码处理
var
sLayerValue,sDefaulValue:string;
// sFixture_Code:string;
begin
if (EdtEmpNo.Text<>'') and (EdtLotNo.Text<>'') then //不是手工操作
TThread.CreateAnonymousThread(
procedure
var
sError:string;
sGoodsNo,sNum,sPc:string;
begin
CoInitialize(nil);
TRY
// ShowInfoOK('连接数据库中...');
if not EdtLotPartnum(sPc) then
begin
Exit;
end;
//检查批号
if (not Ksoap.XXCC_LOT_PC_F(EdtLotno.Text,TxtLineNum.Text,'1',sError)) then
begin
ShowMainError('',sError,'');
if (EdtLotno.Text<>'R30034200L') then
Exit;
end;
//得料号
if not Ksoap.getPartnum(EdtLotNo.Text,'',sGoodsNo,sNum,sPc,sPartnumValue,sError) then
begin
ShowMainError('',sError,'');
Exit;
end;
//获取缺省值
if DisplayFrame.DefaultXN and not Ksoap.return_default_values_f(sDefaulValue,sError) then
begin
ShowMainError('','Ksoap.return_default_values_f'+sError,'');
Exit;
end;
//根据料号,设置正反面板材
if not Ksoap.xxcf_get_layer_f(sGoodsNo,sLayerValue,sError) then
begin
ShowMainError('','',sError);
Exit;
end;
if sLayerValue<>'' then //面次
begin
SetRadioOption(sLayerValue);
WorkLog.Debug(Format('sLayerValue:%s',[sLayerValue]));
end;
// //原物料編號
// if (DisplayFrame<>nil) and ((DisplayFrame.ClassType=TFrame_maoqie) or (DisplayFrame.ClassType=TFrame_pingdao) or (DisplayFrame.ClassType=TFrame_yandao)) then
// begin
// DisplayFrame.F2DCodeCreate();
// end;
//参数带入,根据参数设置PLC
if (DisplayFrame.Name='FrameAutoYLBland') then
begin
//get_barcode_param_f
if (not Ksoap.xx_get_barcode_param_f(FactoryCode,EdtLotNo.Text,'yfynj',TxtLineNum.Text,sError)) then
begin
TThread.Synchronize(nil,
procedure
begin
TxtShowErrorInfo(TxtLotNoError,sError);
end);
Exit;
end;
end;
finally
CoUninitialize;
end;
TThread.Synchronize(nil,
procedure
begin
// EdtGoodsNo.Text:=sGoodsNo;
sLotNum:=sNum;
DisplayFrame.sLotNum:= sNum;
TxtShowErrorInfo(TxtLotNoError,'');
DisplayFrame.FillDefaultValue(sPartnumValue,sDefaulValue);
SetRadioOption(sDefaulValue);
//
// //根据批号,带出料号与当前制程,自动增加填写当前制程
// if sPc<>'' then
// begin
// if ComboBoxP_PC.Items.IndexOf(sPc)<0 then
// // ComboBoxP_PC.Items.Add(sPc);
// begin
// TxtShowErrorInfo(TxtLotNoError,'該批當前站在'+sPc);
// end
// else
// begin
// COMBOBOXp_PC.ItemIndex:=ComboBoxP_PC.Items.IndexOf(sPc);
// TxtPc.Text:=sPc;
// ksoap.P_PC:=TxtPc.Text; //製程
// end;
// end;
//设置PLC相关参数
end);
end
).Start;
end;
end.