private void btnPrintID_Click(object sender, EventArgs args) { string message = ""; GraphicCode graphics = null; lblStatus.Text = ""; Refresh(); Application.DoEvents(); try { if (cbPrinters.SelectedIndex < 0) { message = "No printer selected."; return; } if (!IsPrinterAvailable(cbPrinters.Text)) { message = "Printer is not available."; return; } //need to check first if all forms are filled out //do later graphics = new GraphicCode(); graphics.Print(cbPrinters.Text, txtFirstName + " " + txtLastName, "1", userSelectedFilePath, cbAdmin.Checked, out message); if (message == "") { PrinterReadyToStart(cbPrinters.Text, 60); lblStatus.Text = "Printing the ID"; } } catch (Exception e) { message += e.Message; MessageBox.Show(e.ToString()); } finally { if (message != "") { lblStatus.Text = message; } graphics = null; } }
private void btnPrintID_Click(object sender, EventArgs args) { //click event for Print ID button on Add User tab string message = ""; //string variable message initialized to an empty string GraphicCode graphics = null; //creates graphics variable from the GraphicsCode.cs class initialized to null lblStatus.Text = ""; //on Add User tab - initializes Status label text property to an empty string Refresh(); //call the base class's refresh method so the control and its child controls are invalidated and redrawn Application.DoEvents(); //Application provides static methods and properties to manage an application. Begins running a standard application message loop on the... //...current thread, which enables the form to receive Windows messages to allow it to appear responsive and have interaction with the user try { if (cbPrinters.SelectedIndex < 0) {//check the selected index of printers dropdown box on Add User tab, if less than 0... message = "No printer selected."; //store string "No printer selected" in message variable return; //return results displaying message that no printer is selected } if (!IsPrinterAvailable(cbPrinters.Text)) { //check text of cbPrinters drop-down, if the not of printers available... message = "Printer is not available."; //store string "Printer is not available" in message variable return; //return results displaying message that no printer is available } string nullMessage = ""; //Holds what we return to the user if (txtFirstName.Text == "") { //If first name field is empty nullMessage += "No data has been entered for First Name.\n"; } if (txtLastName.Text == "") { //If last name field is empty nullMessage += "No data has been entered for Last Name.\n"; } if (txtStreet.Text == "") { //If street field is empty nullMessage += "No data has been entered for Street.\n"; } if (txtCity.Text == "") { //If city field is empty nullMessage += "No data has been entered for City.\n"; } if (cbState.Text == "") { //If state field is empty nullMessage += "No State has been selected.\n"; } if (txtZip.Text == "") { //If zip field is empty nullMessage += "No data has been entered for Zip Code.\n"; } if (txtPhone.Text == "") { //If phone field is empty nullMessage += "No data has been entered for Phone Number.\n"; } if (userSelectedFilePath == "") { //If user image field is empty nullMessage += "No image has been selected.\n"; } if (nullMessage != "") { //If null message is set MessageBox.Show(nullMessage); } else { //If null message was not set graphics = new GraphicCode(); //creates new GraphicCode object and stores in graphics //call Print method of graphics object and pass (string driverName, string name, string userID, string userPicture, bool admin, bool back, string[] disclaimerSplit, out string msg) graphics.Print(cbPrinters.Text, txtFirstName.Text + " " + txtLastName.Text, (Database.newUser() + 1).ToString(), userSelectedFilePath, cbAdmin.Checked, out message); if (message == "") { //if message string is empty, nothing is determined to have prevented the printer from functioning PrinterReadyToStart(cbPrinters.Text, 60); //call to PrinterReadyToStart method passing user selected printer driver user selected from drop-down list on Add User tab, and 60 second timeout value lblStatus.Text = "Printing the ID"; //change Status label on Add User tab to display "Printing the ID" } string isAdmin; //Is the user an admin format string. if (cbAdmin.Checked == true) { isAdmin = "1"; //Is admin } else { isAdmin = "0"; //Is not admin } //Adds the user to the database(first name, last name, street, city, state, zip, phone number, user image, is an admin) Database.addUser(txtFirstName.Text, txtLastName.Text, txtStreet.Text, txtCity.Text, cbState.Text, txtZip.Text, txtPhone.Text, userSelectedFilePath, isAdmin); Console.WriteLine("add query was ran"); //Messagebox to wait for the user to press okay before trying to write data to the card DialogResult result = MessageBox.Show("Press okay and wait for the orange light on the EZWriter, then slide your card.", "Confirmation", MessageBoxButtons.OK); if (result == DialogResult.OK) { //Picked ok MagneticStripCode.writeCardData(Database.newUser().ToString()); //Writes card data } else { Database.deleteUser(Database.newUser().ToString()); //Delete user that was added MessageBox.Show("User was not created. Please retry."); } } } catch (Exception e) { //exception handler message += e.Message; //add the value of e.message to message string MessageBox.Show(e.ToString()); //use a message box to display the results of exception variable e as a string } finally { //finally block runs whether there is an exception or not if (message != "") { //if message string variable has changed to anything other than the initialized empty string... lblStatus.Text = message; //set the Status label to display the contents of message string } graphics = null; //sets graphics object to null after it has finished being used FrmMain_Load(sender, args); } }