private bool ConnectToPrinter(ref ZXPSampleCode z, ref Job job, string deviceName) { try { if (!z.Connect(ref job)) { Cursor.Current = Cursors.Default; MessageBox.Show("Unable to open device [" + deviceName + "]"); DisconnectFromPrinter(ref z, ref job); } else { return(true); } } catch (Exception ex) { MessageBox.Show("ConnectToPrinter threw exception: " + ex.Message); } return(false); }
private void btnConnectToPrinter_Click(object sender, EventArgs e) { ZXPSampleCode z = null; Job job = null; try { Cursor = Cursors.WaitCursor; btnRun.Enabled = false; lbStatus.Visible = true; lbStatus.Text = "Connecting to printer"; Refresh(); Application.DoEvents(); job = new Job(); z = new ZXPSampleCode(this.cboPrn.Text); if (z.Connect(ref job)) { // Displays versions this.lblVersions.Text = z.GetVersions(); if (!z.IsZXP7) { // Loads card types based on type of sample type _cardTypeList = new ArrayList(); CardTypesInit(ref z, this.cboPrn.Text); cboCardTypeInit(); } else { cboCardType.Enabled = false; } btnRun.Enabled = true; } else { MessageBox.Show("Could not open connection to printer " + cboPrn.Text, "Warning"); } } catch (Exception ex) { MessageBox.Show("btnConnectToPrinter_Click exception: " + ex.Message); } finally { if (z != null) { z.Disconnect(ref job); } z = null; lbStatus.Visible = false; Cursor = Cursors.Default; } }