private void MatchExDevice() { MainForm.SetFiscalId(txtFiscalId.Text); #if CPP PrinterWrapper.DeviceInfo serverInfo = new PrinterWrapper.DeviceInfo(); serverInfo.IP = GetIPAddress(); #else DeviceInfo serverInfo = new DeviceInfo(); serverInfo.IP = System.Net.IPAddress.Parse(GetIPAddress()); serverInfo.IPProtocol = IPProtocol.IPV4; #endif serverInfo.Brand = "HUGIN"; serverInfo.Model = "HUGIN COMPACT"; serverInfo.Port = Convert.ToInt32(txtTcpPort.Text); serverInfo.TerminalNo = txtFiscalId.Text.PadLeft(8, '0'); serverInfo.Version = new FileInfo(System.Reflection.Assembly.GetExecutingAssembly().Location).LastWriteTime.ToShortDateString(); serverInfo.SerialNum = CreateMD5(GetMBId()).Substring(0, 8); #if CPP if (conn) { try { if (!printer.Connect(serverInfo, fiscalId, "")) { throw new OperationCanceledException(FormMessage.UNABLE_TO_MATCH); } } catch (Exception ex) { throw ex; } CPResponse.Bridge = this; } #else if (conn.IsOpen) { try { printer = new CompactPrinter(); printer.FiscalRegisterNo = fiscalId; try { //Optional if (!String.IsNullOrEmpty(System.Configuration.ConfigurationSettings.AppSettings["LogDirectory"])) { printer.LogDirectory = System.Configuration.ConfigurationSettings.AppSettings["LogDirectory"]; } //Optional . printer.LogerLevel = int.Parse(System.Configuration.ConfigurationSettings.AppSettings["LogLevel"]); } catch (System.Exception ex) { } #if NEBIM_MODE if (!printer.Connect(conn.ToObject(), serverInfo)) #else if (!printer.Connect(conn.ToObject(), serverInfo, System.Configuration.ConfigurationSettings.AppSettings["LicenseKey"])) #endif { throw new OperationCanceledException(FormMessage.UNABLE_TO_MATCH); } } catch (Exception ex) { throw ex; } CPResponse.Bridge = this; #if CPP conn2.Bridge = this; #endif } #endif }
private void btnConnect_Click(object sender, EventArgs e) { #if CPP string errPrefix = FormMessage.CONNECTION_ERROR + ": "; try { if (!conn) { this.Log(FormMessage.CONNECTING + "... (" + FormMessage.PLEASE_WAIT + ")"); printer = new PrinterWrapper.CompactPrinterWrapper(); if (tabConn.SelectedTab == tabComPort) { conn = printer.SerialConnect(cmbPorts.Text, int.Parse(txtBaudrate.Text)); } else { conn = printer.TCPConnect(txtTCPIP.Text, int.Parse(txtTcpPort.Text)); } errPrefix = FormMessage.MATCHING_ERROR + ": "; } else { conn = false; this.Log(FormMessage.DISCONNECTED); btnConnect.Text = FormMessage.CONNECT; return; } } catch (System.Exception ex) { conn = false; this.Log(FormMessage.OPERATION_FAILS + ": " + errPrefix + ex.Message); } if (conn) { btnConnect.Text = FormMessage.DISCONNECT; MatchExDevice(); this.Log(FormMessage.CONNECTED); } else { btnConnect.Text = FormMessage.CONNECT; this.Log(FormMessage.CONNECTION_ERROR); } #else string errPrefix = FormMessage.CONNECTION_ERROR + ": "; try { if (this.Connection == null) { if (tabConn.SelectedTab == tabComPort) { this.Connection = new SerialConnection(cmbPorts.Text, int.Parse(txtBaudrate.Text)); } else { int port = Convert.ToInt32(txtTcpPort.Text); this.Connection = new TCPConnection(txtTCPIP.Text, port); } this.Log(FormMessage.CONNECTING + "... (" + FormMessage.PLEASE_WAIT + ")"); this.Connection.Open(); errPrefix = FormMessage.MATCHING_ERROR + ": "; MatchExDevice(); MainForm.SetFiscalId(txtFiscalId.Text); btnConnect.Text = FormMessage.DISCONNECT; this.Log(FormMessage.CONNECTED); } else { this.Connection.Close(); this.Connection = null; btnConnect.Text = FormMessage.CONNECT; this.Log(FormMessage.DISCONNECTED); } } catch (System.Exception ex) { this.Log(FormMessage.OPERATION_FAILS + ": " + errPrefix + ex.Message); if (conn != null) { btnConnect.Text = FormMessage.DISCONNECT; } } #endif }