public ViewPrintDocument( string docLabelName, string docStorageId, Document.DocTypeNames dType) { InitializeComponent(); this.DocumentName = docLabelName; this.DocumentType = dType; this.StorageId = docStorageId; this.hasLaserInfo = false; this.hasReceiptInfo = false; this.laserIp = string.Empty; this.receiptIp = string.Empty; this.laserPort = 0; this.receiptPort = 0; }
public ViewPrintDocument( string docLabelName, string receiptNo, string docStorageId, Document.DocTypeNames dType, CouchDbUtils.PawnDocInfo docInfo) { InitializeComponent(); this.DocumentName = docLabelName + receiptNo; this.DocumentType = dType; this.StorageId = docStorageId; this.hasLaserInfo = false; this.hasReceiptInfo = false; this.laserIp = string.Empty; this.receiptIp = string.Empty; this.laserPort = 0; this.receiptPort = 0; this.DocInfo = docInfo; }
/// <summary> /// /// </summary> /// <param name="fileName"></param> /// <param name="fileId"></param> /// <param name="couchConnector"></param> /// <param name="overrideDoc"></param> /// <param name="fileType"></param> /// <param name="docMetaData"></param> /// <param name="couchDocObj"></param> /// <param name="errorMessage"></param> /// <returns></returns> public static bool StoreDocument( string fileName, string fileId, SecuredCouchConnector couchConnector, bool overrideDoc, Document.DocTypeNames fileType, Dictionary <string, string> docMetaData, out Document couchDocObj, out string errorMessage) { couchDocObj = null; errorMessage = string.Empty; if (string.IsNullOrEmpty(fileName) || !System.IO.File.Exists(fileName) || string.IsNullOrEmpty(fileId) || couchConnector == null) { errorMessage = "Input parameters are invalid"; return(false); } var sErrCode = string.Empty; var sErrText = string.Empty; try { byte[] fileBytes = File.ReadAllBytes(fileName); int lastSlashIdx = fileName.LastIndexOf('\\'); if (lastSlashIdx == -1) { errorMessage = "Absolute file name is invalid."; return(false); } string fName = fileName.Substring(lastSlashIdx + 1); couchDocObj = new Document_Couch(fileName, fName, fileType); if (couchDocObj.SetSourceData(fileBytes, fileId, overrideDoc)) { if (CollectionUtilities.isNotEmpty(docMetaData)) { foreach (string key in docMetaData.Keys) { if (key == null) { continue; } string val; if (docMetaData.TryGetValue(key, out val)) { couchDocObj.SetPropertyData(key, val); } } } var dStorage = new DocStorage_CouchDB(); if (dStorage.SecuredAddDocument(couchConnector, ref couchDocObj, out sErrCode, out sErrText)) { errorMessage = sErrText; return(true); } errorMessage = sErrText; return(false); } } catch (Exception eX) { errorMessage = "Exception occurred while storing document: " + eX.Message + " (" + sErrCode + ", " + sErrText + ")"; } return(false); }
private void printDocButton_Click(object sender, EventArgs e) { if (productTypeList1.ComboBox.SelectedValue != null) { if (productTypeList1.ComboBox.SelectedValue.ToString() == DocumentHelper.REPRINT_TAGS) { this.Hide(); var reprintTag = new ReprintTag(); reprintTag.ShowDialog(this); this.Close(); return; } } if (_isLookup) { if (!SetStorageIDFromLookup()) { return; } } //TODO: Finalize printing this.printDocButton.Enabled = false; //Get the accessors var cC = GlobalDataAccessor.Instance.CouchDBConnector; //Retrieve the document data var pLoadMesg = new ProcessingMessage("* Printing Document *"); //Connect to couch and retrieve document Document doc; string errText; if (!CouchDbUtils.GetDocument( this.StorageId, cC, out doc, out errText)) { pLoadMesg.Close(); pLoadMesg.Dispose(); this.ShowErrorMessage("print", errText); this.Close(); } else if (doc != null) { this.DocumentType = doc.TypeName; //Fetch data byte[] fileData; if (!doc.GetSourceData(out fileData)) { pLoadMesg.Close(); pLoadMesg.Dispose(); this.ShowErrorMessage("print", "Cannot retrieve file data to print file"); this.Close(); return; } //Send byte stream to printer based on type var printSuccess = false; switch (this.DocumentType) { case Document.DocTypeNames.PDF: //If we do not have the laser printer info, get out if (!hasLaserInfo) { pLoadMesg.Close(); pLoadMesg.Dispose(); this.ShowErrorMessage("print", "Cannot determine laser printer IP/Port"); this.Close(); return; } //Send raw pdf data to printer var resStrPdf = GenerateDocumentsPrinter.printDocument(fileData, laserIp, laserPort, 1); if (!string.IsNullOrEmpty(resStrPdf) && resStrPdf.Contains("SUCCESS")) { printSuccess = true; } break; case Document.DocTypeNames.RECEIPT: //If we do not have the receipt printer info, get out if (!hasReceiptInfo) { pLoadMesg.Close(); pLoadMesg.Dispose(); this.ShowErrorMessage("print", "Cannot determine receipt printer IP/Port"); this.Close(); return; } //Send raw receipt data to receipt printer var resStrRec = GenerateDocumentsPrinter.printDocument(fileData, receiptIp, receiptPort, 1); if (!string.IsNullOrEmpty(resStrRec) && resStrRec.Contains("SUCCESS")) { printSuccess = true; } break; case Document.DocTypeNames.BARCODE: MessageBox.Show("Nothing to print"); //Nothing for now - should go to Intermec printer break; case Document.DocTypeNames.TEXT: //If we do not have the laser printer info, get out if (!hasLaserInfo && !hasIndianaPoliceCardPrinterInfo) { pLoadMesg.Close(); pLoadMesg.Dispose(); this.ShowErrorMessage("print", "Cannot determine printer IP/Port"); this.Close(); return; } //Send raw text data to laser printer var resStrTxt = GenerateDocumentsPrinter.printDocument( fileData, hasIndianaPoliceCardPrinterInfo ? indianaPoliceCardPrinterIp : laserIp, hasIndianaPoliceCardPrinterInfo ? indianaPoliceCardPrinterPort : laserPort, 1); if (!string.IsNullOrEmpty(resStrTxt) && resStrTxt.Contains("SUCCESS")) { printSuccess = true; } break; case Document.DocTypeNames.BINARY: MessageBox.Show("Nothing to print"); //Nothing for now) //Nothing for now break; case Document.DocTypeNames.INVALID: MessageBox.Show("Nothing to print"); //Nothing for now) //Nothing for now break; } pLoadMesg.Close(); pLoadMesg.Dispose(); if (!printSuccess) { this.ShowErrorMessage("print", "Reprint operation failed"); } else { MessageBox.Show("Document has successfully reprinted", "Pawn Application Message"); } } //Re-enable print button this.printDocButton.Enabled = true; }
/// <summary> /// Sets the storage id from the lookup data. /// </summary> /// <returns>True upon success.</returns> private bool SetStorageIDFromLookup() { var productsList = (System.Windows.Forms.ComboBox)productTypeList1.Controls[0]; var ticketNumber = -1; if (productsList.SelectedIndex == 0 || !int.TryParse(txtTicketNumber.Text.Trim(), out ticketNumber)) { System.Windows.Forms.MessageBox.Show( "Please ensure you have selected a product and ticket number."); return(false); } var docInfo = new CouchDbUtils.PawnDocInfo(); string errString; docInfo.StoreNumber = GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber; if (productsList.SelectedValue.ToString() == DocumentHelper.RECIEPT) { docInfo.ReceiptNumber = ticketNumber; docInfo.SetDocumentSearchType(CouchDbUtils.DocSearchType.RECEIPT); } else if (productsList.SelectedValue.ToString() == DocumentHelper.POLICE_CARD) { docInfo.ReceiptNumber = ticketNumber; docInfo.TicketNumber = ticketNumber; docInfo.SetDocumentSearchType(CouchDbUtils.DocSearchType.POLICE_CARD); } else if (productsList.SelectedValue.ToString() == DocumentHelper.RELEASE_FINGERPRINTS) { docInfo.TicketNumber = ticketNumber; docInfo.SetDocumentSearchType(CouchDbUtils.DocSearchType.RELEASE_FINGERPRINTS); } else { docInfo.TicketNumber = ticketNumber; docInfo.SetDocumentSearchType(CouchDbUtils.DocSearchType.STORE_TICKET); } //Also set the meta tag here as well as search type. if (productsList.SelectedValue.Equals(DocumentHelper.CUSTOMER_BUY) || productsList.SelectedValue.Equals(DocumentHelper.PURCHASE_RETURN)) { if (GlobalDataAccessor.Instance.CurrentSiteId.State == States.Indiana) { docInfo.AuxInfo = PurchaseDocumentIndiana.PURCHASE_AUXINFOTAG; } else { docInfo.AuxInfo = PurchaseDocumentGenerator.PURCHASE_AUXINFOTAG; } } else if (productsList.SelectedValue.Equals(DocumentHelper.PAWN_LOAN)) { PawnLoan pawnLoan; PawnAppVO pApp; CustomerVO customerVO; string errorCode; string errorText; if (!CustomerLoans.GetPawnLoan(GlobalDataAccessor.Instance.DesktopSession, Utilities.GetIntegerValue(GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber), ticketNumber, "0", StateStatus.BLNK, true, out pawnLoan, out pApp, out customerVO, out errorCode, out errorText)) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Error trying to get loan data" + errorText); MessageBox.Show("Error trying to get loan details for the number entered."); return(false); } if (pawnLoan.DateMade.Date != ShopDateTime.Instance.FullShopDateTime.Date) { FileLogger.Instance.logMessage(LogLevel.WARN, this, "Cannot reprint loan documents for " + ticketNumber.ToString() + " on a previous date"); MessageBox.Show("This document is not eligible for reprint after the loan date."); return(false); } } else if (productsList.SelectedValue.Equals(DocumentHelper.POLICE_CARD)) { this.DocumentType = Document.DocTypeNames.TEXT; } else if (productsList.SelectedValue.Equals(DocumentHelper.RECIEPT)) { this.DocumentType = Document.DocTypeNames.RECEIPT; } else if (productsList.SelectedValue.Equals(DocumentHelper.RELEASE_FINGERPRINTS)) { this.DocumentType = Document.DocTypeNames.PDF; } else { throw new NotImplementedException("This product has not been implemented yet."); } var lastStorageId = documentHelper.GetStorageId(Utilities.GetStringValue(productsList.SelectedValue, null), docInfo, out errString); if (!string.IsNullOrEmpty(lastStorageId)) { this.StorageId = lastStorageId; } else { MessageBox.Show("Could not find the document."); return(false); } return(true); }