public bool IsPrinterBusy(string driverName, int timeoutInSeconds) { bool ready = false; int errors = 0; ZBRGraphics graphics; ASCIIEncoding ascii; try { graphics = new ZBRGraphics(); ascii = new ASCIIEncoding(); for (int i = 0; i < timeoutInSeconds; i++) { //ascii.GetBytes() encodes the string to a sequence of bytes if (graphics.IsPrinterReady(ascii.GetBytes(driverName), out errors) != 0) { ready = true; break; } Thread.Sleep(1000); } } catch (Exception e) { ready = false; MessageBox.Show(e.ToString()); } finally { graphics = null; ascii = null; } return ready; }
public void Print(string driverName, string name, string userID, string userPicture, bool admin, out string msg) { int error; ZBRGraphics graphics = null; ASCIIEncoding ascii; msg = ""; try { int fontStyle = BOLD; graphics = new ZBRGraphics(); ascii = new ASCIIEncoding(); //Initialize Graphics if (graphics.InitGraphics(ascii.GetBytes(driverName), out error) == 0) { msg = "InitGraphics method error code: " + error.ToString(); return; } //DrawImage(location of image, X coordinate, Y coordinate, length, width, out error) if (admin == false){ //Does the user have admin? No if (graphics.DrawImage(ascii.GetBytes(Application.StartupPath + "\\Student.png"), 350, 30, 400, 50, out error) == 0) { msg = "DrawImage method error code: " + error.ToString(); return; } } else { //They do have admin if (graphics.DrawImage(ascii.GetBytes(Application.StartupPath + "\\Admin.png"), 350, 30, 400, 50, out error) == 0) { msg = "DrawImage method error code: " + error.ToString(); return; } } //DrawImage(location of image, X coordinate, Y coordinate, length, width, out error) if (graphics.DrawImage(ascii.GetBytes(userPicture), 30, 30, 200, 150, out error) == 0) { msg = "DrawImage method error code: " + error.ToString(); return; } //DrawText(X Coordinate, Y Coordinate, String, Font type, font size, fontStyle, color, out error) if (graphics.DrawText(35, 575, ascii.GetBytes(name), ascii.GetBytes("Arial"), 12, fontStyle, 0xFF0000, out error) == 0){ msg = "DrawText method error code: " + error.ToString(); return; } //DrawBarcode(X Coordinate, Y Coordinate, rotation, barcode type, width ratio, multiplier, height, text under, barcode data, out error) if (graphics.DrawBarcode(35, 500, 0, 0, 3, 6, 90, 0, ascii.GetBytes(userID), out error) == 0){ msg = "DrawBarcode method error code: " + error.ToString(); return; } if (graphics.PrintGraphics(out error) == 0) { msg = "PrintGraphics Error: " + error.ToString(); return; } } catch (Exception e) { MessageBox.Show(e.ToString()); } finally { ascii = null; if (graphics != null) { if (graphics.CloseGraphics(out error) == 0) { msg = "CloseGraphics method error code: " + error.ToString(); } graphics = null; } } }
public string GetSDKGraphicsVersion() { ZBRGraphics graphics = null; int major, minor, engLevel; string gVersion = ""; try { graphics = new ZBRGraphics(); graphics.GetSDKVer(out major, out minor, out engLevel); if (major > 0 || minor > 0 || engLevel > 0) { gVersion = major.ToString() + "." + minor.ToString() + "." + engLevel.ToString(); } } catch (Exception e) { MessageBox.Show(e.ToString()); } finally { graphics = null; } return gVersion; }
const int UNDERLINE = 0x04; //extended formatting hex stored as underline variable (used to underline text) #endregion Fields #region Methods public string GetSDKGraphicsVersion() { // method called on FrmMain.cs in order to obtain graphics version ZBRGraphics graphics = null; //creates graphics variable from the ZBRGraphics.cs class initialized to null int major, minor, engLevel; //integers to hold major, minor, and engine level DLL values of the ZBRGraphics class string gVersion = ""; //creates gVersion string initialized to an empty string, used to hold final graphics version numerical data try { graphics = new ZBRGraphics(); //creates new ZBRGraphics object and stores in graphics graphics.GetSDKVer(out major, out minor, out engLevel); //calls to the getSDKVer method of graphics, passing major, minor, and engine level variables by reference if (major > 0 || minor > 0 || engLevel > 0) { //if major, minor, or engine levels have values that's greater than their default values of 0... gVersion = major.ToString() + "." + minor.ToString() + "." + engLevel.ToString(); //convert all three values to string, concatenated with a period seperating each, and store the whole string value in gVersion variable - it will appear in label on About page } } catch (Exception e) { //exceotion 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 been used } return gVersion; //return resulting graphics DLL version string }