public string GetStorageId(string selectedProduct, CouchDbUtils.PawnDocInfo docInfo, out string errString) { if (selectedProduct == null) { throw new ArgumentNullException("selectedProduct"); } List <CouchDbUtils.PawnDocInfo> pawnDocs; var lastStorageId = string.Empty; if (CouchDbUtils.GetPawnDocument(GlobalDataAccessor.Instance.OracleDA, GlobalDataAccessor.Instance.CouchDBConnector, docInfo, false, out pawnDocs, out errString)) { foreach (var doc in pawnDocs) { if (selectedProduct == CUSTOMER_BUY || selectedProduct == PURCHASE_RETURN && (doc.AuxInfo == PurchaseDocumentGenerator.PURCHASE_AUXINFOTAG || doc.AuxInfo == PurchaseDocumentIndiana.PURCHASE_AUXINFOTAG)) { lastStorageId = doc.StorageId; } if (selectedProduct == PAWN_LOAN && doc.AuxInfo == "" && doc.DocumentType == Document.DocTypeNames.PDF) { lastStorageId = doc.StorageId; //Do not break here -- allow the storage id to be //set to the last storage id for PDF files returned. //break; } if (selectedProduct == RECIEPT && doc.DocumentType == Document.DocTypeNames.RECEIPT) { lastStorageId = doc.StorageId; } if (selectedProduct == POLICE_CARD && doc.DocumentType == Document.DocTypeNames.TEXT) { lastStorageId = doc.StorageId; } if (selectedProduct == RELEASE_FINGERPRINTS && doc.DocumentType == Document.DocTypeNames.PDF) { lastStorageId = doc.StorageId; } } } return(lastStorageId); }
/// <summary> /// /// </summary> /// <param name="dA"></param> /// <param name="cC"></param> /// <param name="searchInfo"></param> /// <param name="retrieveDocFlag">If set to true, will retrieve document data from CouchDB server</param> /// <param name="documents"></param> /// <param name="errText"></param> /// <returns></returns> public static bool GetPawnDocument( OracleDataAccessor dA, SecuredCouchConnector cC, PawnDocInfo searchInfo, bool retrieveDocFlag, out List <PawnDocInfo> documents, out string errText) { errText = string.Empty; documents = new List <PawnDocInfo>(1); //Verify inputs if (dA == null || dA.Initialized == false) { errText = "GetPawnDocument: Database accessor is invalid."; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils::GetPawnDocument", errText); } return(false); } //Search type must be specified if (cC == null || searchInfo == null || string.IsNullOrEmpty(searchInfo.DocumentSearchType)) { errText = "GetPawnDocument: Couch DB Accessor info is invalid."; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils::GetPawnDocument", errText); } return(false); } //Log search type if (FileLogger.Instance.IsLogDebug) { FileLogger.Instance.logMessage(LogLevel.DEBUG, "CouchDbUtils::GetPawnDocument", "Doc search string = {0}", searchInfo.DocumentSearchType); } string srchID01 = string.Empty; string srchID02 = string.Empty; //Switch search type switch (searchInfo.DocSearchEnumType) { case DocSearchType.STORAGE: srchID01 = searchInfo.StorageId; break; case DocSearchType.RECEIPT: srchID01 = searchInfo.ReceiptNumber.ToString(); break; case DocSearchType.CUSTOMER: srchID01 = searchInfo.CustomerNumber; break; case DocSearchType.STORE_TICKET: case DocSearchType.POLICE_CARD: srchID01 = searchInfo.StoreNumber; srchID02 = searchInfo.TicketNumber.ToString(); searchInfo.DocSearchEnumType = DocSearchType.STORE_TICKET; break; case DocSearchType.RELEASE_FINGERPRINTS: srchID01 = searchInfo.StoreNumber; srchID02 = searchInfo.TicketNumber.ToString(); searchInfo.DocSearchEnumType = DocSearchType.STORE_TICKET; break; case DocSearchType.STORE_CUSTOMER: srchID01 = searchInfo.StoreNumber; srchID02 = searchInfo.CustomerNumber; break; case DocSearchType.INVALID: break; } //Ensure that at least one of the search constraints //have been specified if (string.IsNullOrEmpty(srchID01) && string.IsNullOrEmpty(srchID02)) { errText = "Not enough information specified to " + "search for document"; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils::GetPawnDocument", errText); } } //Retrieve document registry information string spErrCode, spErrText; DataTable dataTable; //string nowTime = DateTime.Now.FormatDate(); //Fix to base the time the document search is performed on the current shop date time var searchTime = ShopDateTime.Instance.FullShopDateTime.FormatDate(); if (!GetPawnDocumentRegistry( dA, srchID01, srchID02, "0", //TODO: Disabled doc chain fetch for now "0", //TODO: Disabled date range fetch for now searchInfo.DocumentSearchType, searchTime, searchTime, out dataTable, out spErrCode, out spErrText)) { errText = "GetPawnDocument: Could not retrieve document registry info. " + "Registry error code: " + spErrCode + ", error text: " + spErrText; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils::GetPawnDocument", errText); } return(false); } if (dataTable == null || dataTable.Rows == null || dataTable.Rows.Count <= 0) { errText = "GetPawnDocument: Data table returned from registry is invalid."; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils.GetPawnDocument", errText); } return(false); } foreach (DataRow dR in dataTable.Rows) { //Validate data row if (dR == null || dR.HasErrors || dR.ItemArray.Length <= 0) { continue; } //Set data from data table searchInfo.StorageId = Utilities.GetStringValue(dR["storage_id"], string.Empty); searchInfo.StoreNumber = Utilities.GetStringValue(dR["storenumber"], string.Empty); searchInfo.TicketNumber = Utilities.GetIntegerValue(dR["ticket_number"], 0); //GJL - 6/15/2010 - Column for receipt detail will now hold receipt number searchInfo.ReceiptNumber = Utilities.GetIntegerValue(dR["receiptdetail_number"], 0); searchInfo.CustomerNumber = Utilities.GetStringValue(dR["customernumber"], string.Empty); searchInfo.AuxInfo = Utilities.GetStringValue(dR["storage_auxinf"], string.Empty); searchInfo.DocumentType = (Document.DocTypeNames) Enum.Parse(typeof(Document.DocTypeNames), Utilities.GetStringValue(dR["doc_type"], "INVALID")); //If retrieve document flag is true, make the call to the couch server Document doc = null; if (retrieveDocFlag) { //Get next document from couch DB server if (!CouchDbUtils.GetDocument( searchInfo.StorageId, cC, out doc, out errText)) { errText = "GetPawnDocument: Could not get the document from the storage server."; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils::GetPawnDocument", errText); } //If the couch retrieval fails, do not add an entry to returned //document list continue; } } //Create doc info container var newInfo = new PawnDocInfo { StorageId = searchInfo.StorageId, StoreNumber = searchInfo.StoreNumber, TicketNumber = searchInfo.TicketNumber, ReceiptNumber = searchInfo.ReceiptNumber, CustomerNumber = searchInfo.CustomerNumber, AuxInfo = searchInfo.AuxInfo, DocumentType = searchInfo.DocumentType, DocumentObject = doc }; newInfo.SetDocumentSearchType(searchInfo.DocSearchEnumType); documents.Add(newInfo); } return(true); }
/// <summary> /// /// </summary> /// <param name="dA"></param> /// <param name="cC"></param> /// <param name="userID"></param> /// <param name="metaData"></param> /// <param name="auxInfo"></param> /// <param name="docInfo"></param> /// <param name="errText"></param> /// <returns></returns> public static bool AddPawnDocument( OracleDataAccessor dA, SecuredCouchConnector cC, string userID, Dictionary <string, string> metaData, string auxInfo, ref PawnDocInfo docInfo, out string errText) { errText = string.Empty; if (dA == null || dA.Initialized == false) { errText = "AddPawnDocument: Database accessor is invalid."; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils::AddPawnDocument", errText); } return(false); } if (cC == null || docInfo == null || string.IsNullOrEmpty(userID)) { errText = "AddPawnDocument: Couch DB Accessor info is invalid."; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils::AddPawnDocument", errText); } return(false); } //Generate storage id if the incoming storage id is blank if (string.IsNullOrEmpty(docInfo.StorageId)) { docInfo.StorageId = System.Guid.NewGuid().ToString(); FileLogger.Instance.logMessage(LogLevel.INFO, "Storage Id of the document to store in couch db", docInfo.StorageId); } //Validate other document info properties if (string.IsNullOrEmpty(docInfo.DocFileName)) { errText = "AddPawnDocument: Must specify a valid file name"; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils::AddPawnDocument", errText); return(false); } } //Send document to couch DB server Document doc; if (!CouchDbUtils.StoreDocument( docInfo.DocFileName, docInfo.StorageId, cC, docInfo.OverrideDocument, docInfo.DocumentType, metaData, out doc, out errText)) { errText = "AddPawnDocument: Could not add the document to the storage server." + errText; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils::AddPawnDocument", errText); } return(false); } //Store document registry info in the database //DateTime storeDate, storeTime; if (docInfo.UseCurrentShopDateTime) { DateTime sDate = ShopDateTime.Instance.ShopDate; docInfo.StorageDate = sDate.FormatDate(); docInfo.StorageTime = ShopDateTime.Instance.ShopTransactionTime; } string spErrCode, spErrText; if (!AddPawnDocumentRegistry(dA, docInfo.StorageId, docInfo.ParentStorageId, docInfo.StoreNumber, docInfo.TicketNumber, docInfo.ReceiptNumber, docInfo.CustomerNumber, docInfo.StorageDate, docInfo.StorageTime, docInfo.DocumentType.ToString(), auxInfo, userID, out spErrCode, out spErrText)) { errText = "AddPawnDocument: Could not register document. " + "Registry error code: " + spErrCode + ", error text: " + spErrText; if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, "CouchDbUtils.AddPawnDocument", errText); } return(false); } //Return true if we reach this point!! return(true); }
public bool View(DesktopSession dSession) { //Get the accessors Document doc; var cds = dSession; var cC = GlobalDataAccessor.Instance.CouchDBConnector; //Retrieve the document data var pLoadMesg = new ProcessingMessage("* Loading Document *"); //Connect to couch and retrieve document string errText; if (!CouchDbUtils.GetDocument( this.StorageId, cC, out doc, out errText)) { pLoadMesg.Close(); pLoadMesg.Dispose(); this.ShowErrorMessage("view", errText); return(true); } else if (doc != null) { pLoadMesg.Message = "* Document Loaded...Displaying *"; //Fetch data string tmpFileName; byte[] fileData; if (!doc.GetSourceData(out fileData)) { this.ShowErrorMessage("view", "Cannot retrieve file data to show file"); pLoadMesg.Close(); pLoadMesg.Dispose(); return(true); } //Create temporary file if (!this.CreateTempFile(fileData, out tmpFileName)) { this.ShowErrorMessage("view", "Cannot generate file data to show file"); pLoadMesg.Close(); pLoadMesg.Dispose(); return(true); } pLoadMesg.Close(); pLoadMesg.Dispose(); string bbyteArrayString = ByteArrayToString(fileData); char[] buf = bbyteArrayString.ToCharArray(); if (this.DocumentType == Document.DocTypeNames.RECEIPT && buf[0] == '%' && buf[1] == 'P' && buf[2] == 'D' && buf[3] == 'F') { this.DocumentType = Document.DocTypeNames.PDF; } switch (this.DocumentType) { case Document.DocTypeNames.PDF: DesktopSession.ShowPDFFile(tmpFileName, true); break; case Document.DocTypeNames.RECEIPT: //GJL - do nothing for now until complete receipt renderer var receiptR = new ReceiptRenderer(fileData); //receiptR.RichTextBoxContent = bbyteArrayString; receiptR.ShowDialog(); //MessageBox.Show("Show receipt renderer"); //Invoke View receipt rendering form break; case Document.DocTypeNames.BARCODE: MessageBox.Show("Nothing to show"); //Nothing for now) break; case Document.DocTypeNames.TEXT: MessageBox.Show("Nothing to show"); //Nothing for now) //Notepad?? break; case Document.DocTypeNames.BINARY: MessageBox.Show("Nothing to show"); //Nothing for now) //Nothing for now break; case Document.DocTypeNames.INVALID: MessageBox.Show("Nothing to show"); //Nothing for now) //Nothing for now break; } //Reset the storage id in case it's called again. //this.StorageId = ""; //Delete temporary file try { File.Delete(tmpFileName); } catch (Exception eX) { if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Could not delete file: {0} Exception: {1}", tmpFileName, eX); } } } return(false); }