示例#1
0
        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;
            }
        }
示例#2
0
 private bool PrinterReadyToStart(string driverName, int timeoutInSeconds)
 {
     GraphicCode graphics;
     try {
         graphics = new GraphicCode();
         return graphics.IsPrinterBusy(driverName, timeoutInSeconds); //returns true or false
     } catch (Exception e) {
         MessageBox.Show(e.ToString());
     } finally {
         graphics = null;
     }
     return false;
 }
示例#3
0
 private void GetSDKVersions()
 {
     GraphicCode graphics;
     MagneticStripCode printer;
     try {
         graphics = new GraphicCode();
         printer = new MagneticStripCode();
         graphicsSDKVersion = graphics.GetSDKGraphicsVersion();
         magneticPrinterSDKVersion = printer.GetSDKPrinterVersion();
         lblGraphicsVersion.Text = "Graphics Version: " + graphicsSDKVersion;
         lblPrinterVersion.Text = "Magnetic Printer Version: " + magneticPrinterSDKVersion;
     } catch (Exception e) {
         MessageBox.Show(e.ToString(), "Broc Screwed up the SDK Version Grabber");
     } finally {
         graphics = null;
         printer = null;
     }
 }
示例#4
0
 private bool PrinterReadyToStart(string driverName, int timeoutInSeconds)
 {
     //boolean method to test whether the printer is ready to start using driverName and timeoutInSeconds parameters
     GraphicCode graphics;//creates graphics variable from the GraphicsCode.cs class
     try {
         graphics = new GraphicCode(); //creates new GraphicCode object and stores in graphics
         return graphics.IsPrinterBusy(driverName, timeoutInSeconds); //returns true or false
     } catch (Exception e) { //exception handler
         MessageBox.Show(e.ToString());//catches and displays resulting errors to prevent program crash
     } finally { //finally block runs whether there is an exception or not
         graphics = null; //sets graphics object to null after it has finished being used
     }
     return false;
 }
示例#5
0
 private void GetSDKVersions()
 {
     GraphicCode graphics; //creates graphics variable from the GraphicsCode.cs class
     try {
         graphics = new GraphicCode(); //creates new GraphicCode object and stores in graphics
         graphicsSDKVersion = graphics.GetSDKGraphicsVersion();
         //calls the getSDKGraphicsVersion method of graphics object to determine graphics major, minor and engine level DLL versions and stores results in graphicsSDKVersion
         printerSDKVersion = graphics.GetSDKPrinterVersion();
         //calls the getSDKPrinterVersion method of graphics object to determine printer major, minor, and engine level DLL version and stores results in printerSDKVersion
         lblGraphicsVersion.Text = "Graphics Version: " + graphicsSDKVersion; //displays the information stored in graphisSDKVersion in lblGraphicsVersion on About tab
         lblPrinterVersion.Text = "Printer Version: " + printerSDKVersion; //displays the information stored in printerSDKVersion in lblPrinterVersion on About tab
     } catch (Exception e) { //exception handler
         MessageBox.Show(e.ToString(), "SDK Version Grabber had errors. Please contact an administrator."); //catches and displays resulting errors to prevent program crash
     } finally { //finally block runs whether there is an exception or not
         graphics = null; //sets graphics object to null after it has been used to obtain graphics and printer verion information
     }
 }
示例#6
0
        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);
            }
        }