/// <summary> /// /// </summary> /// <param name="storageId"></param> /// <param name="couchConnector"></param> /// <param name="doc"></param> /// <param name="errorMessage"></param> /// <param name="liteFetch"> </param> /// <returns></returns> public static bool GetDocument( string storageId, SecuredCouchConnector couchConnector, out Document doc, out string errorMessage, bool liteFetch = false) { //Set defaults for outgoing params doc = null; errorMessage = string.Empty; if (!string.IsNullOrEmpty(storageId) && couchConnector != null) { doc = new Document_Couch(storageId); var dStorage = new DocStorage_CouchDB(); string errCode, errTxt; if (dStorage.SecuredGetDocument(couchConnector, ref doc, out errCode, out errTxt, liteFetch)) { return(true); } errorMessage = "Could not retrieve document: " + errCode + " " + errTxt; return(false); } errorMessage = "Could not retrieve document"; return(false); }
private bool InitCouchDB() { if (this.CouchServer == null) { return(false); } if (this.couchConnector != null && this.couchConnector.Error == false) { return(true); } this.couchConnector = new SecuredCouchConnector ( this.EncryptedConfig.DecryptValue(this.CouchServer.Server), this.EncryptedConfig.DecryptValue(this.CouchServer.Port), DesktopSession.SSL_PORT, this.EncryptedConfig.DecryptValue(this.CouchServer.Schema), this.EncryptedConfig.DecryptValue(this.CouchServer.DbUser), this.EncryptedConfig.DecryptValue(this.CouchServer.DbUserPwd), DesktopSession.SECURE_COUCH_CONN); if (this.couchConnector.Error) { return(false); } return(true); }
public void addDocumentToCouch(CouchVo vo, Document document, out string msg, out bool added) { added = false; msg = ""; var sErrCode = string.Empty; var sErrText = string.Empty; setCouchValues(vo); SecuredCouchConnector CouchConnectorObj = null; var dStorage = new DocStorage_CouchDB(); CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); dStorage.SecuredAddDocument(CouchConnectorObj, ref document, out sErrCode, out sErrText); msg = sErrText; if (sErrCode == "0") { added = true; //log.Debug("Added Document ID:" + document.FileId); } else { added = false; // log.Debug("Error adding doc :" + sErrText); } }
public bool getDocumentByID(string id) { var dStorage = new DocStorage_CouchDB(); Document doc = new Document_Couch(id); var errCode = string.Empty; var errTxt = string.Empty; byte[] fileData; FileStream fStream = null; var CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); dStorage.SecuredGetDocument(CouchConnectorObj, ref doc, out errCode, out errTxt); if (CouchConnectorObj.Error) { Console.WriteLine(errTxt); return(false); } else { Console.WriteLine(string.Format("Got Doc '{0}' from db '{1}' by userID '{2}'", doc.FileId, dbName, userid)); doc.GetSourceData(out fileData); if (fileData != null) { fStream = File.Create(Directory.GetCurrentDirectory() + "//" + doc.FileId + ".pdf"); fStream.Write(fileData, 0, fileData.Length); Console.WriteLine("written to file :" + Directory.GetCurrentDirectory() + "//" + doc.FileId + ".pdf"); fStream.Flush(); fStream.Close(); } return(true); } }
/// <summary> /// /// </summary> /// <param name="dA"></param> /// <param name="cC"></param> /// <param name="userID"></param> /// <param name="docInfo"></param> /// <param name="errText"></param> /// <returns></returns> public static bool AddPawnDocument( OracleDataAccessor dA, SecuredCouchConnector cC, string userID, ref PawnDocInfo docInfo, out string errText) { return(AddPawnDocument(dA, cC, userID, null, null, ref docInfo, out errText)); }
public void DeleteDocument(CouchVo sourceVO, string docID, out string msg, out bool deleted) { msg = ""; deleted = false; setCouchValues(sourceVO); var CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); deleted = CouchConnectorObj.Document_Delete(docID); msg = CouchConnectorObj.Message; }
public void GetDocument(CouchVo vo1, System.Windows.Forms.RichTextBox resultBox) { setCouchValues(vo1); if (process != null && !process.HasExited) { process.Kill(); } var dStorage = new DocStorage_CouchDB(); PawnObjects.Doc.Document doc = (PawnObjects.Doc.Document) new Document_Couch(vo1.documentID); var errCode = string.Empty; var errTxt = string.Empty; byte[] fileData; FileStream fStream = null; SecuredCouchConnector CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); Stopwatch sw = new Stopwatch(); sw.Start(); dStorage.SecuredGetDocument(CouchConnectorObj, ref doc, out errCode, out errTxt); sw.Stop(); resultBox.AppendText("\n"); resultBox.AppendText("Time Taken to get :" + sw.ElapsedMilliseconds); resultBox.AppendText("\n"); // dStorage.SecuredGetDocumentWithAttachment(CouchConnectorObj, ref doc, out errCode, out errTxt); if (CouchConnectorObj.Error) { Console.WriteLine(errTxt); resultBox.AppendText(errTxt); resultBox.AppendText("\n"); //return false; } else { resultBox.AppendText(string.Format("Got Doc '{0}' from db '{1}' by userID '{2}'", doc.FileId, dbName, userid)); resultBox.AppendText("\n"); doc.GetSourceData(out fileData); string path = FileHandler.createPDFDir(); string fileWithPath = path + "\\" + doc.FileName; if (fileData != null) { fStream = File.Create(fileWithPath); fStream.Write(fileData, 0, fileData.Length); resultBox.AppendText(("written to file :" + fileWithPath)); resultBox.AppendText("\n"); fStream.Flush(); fStream.Close(); process = Process.Start(fileWithPath); } // return true; } }
private void PrintAndStoreReport(int ticketNumber, string reportName) { DesktopSession cds = GlobalDataAccessor.Instance.DesktopSession; OracleDataAccessor dA = GlobalDataAccessor.Instance.OracleDA; SecuredCouchConnector cC = GlobalDataAccessor.Instance.CouchDBConnector; if (SecurityAccessor.Instance.EncryptConfig.ClientConfig.ClientConfiguration.PrintEnabled && cds.LaserPrinter.IsValid) { if (FileLogger.Instance.IsLogInfo) { FileLogger.Instance.logMessage(LogLevel.INFO, "CreateReportObject", "Printing {0} on printer {1}", reportName, cds.LaserPrinter); } string errMsg = PrintingUtilities.printDocument( reportObject.ReportTempFileFullName, cds.LaserPrinter.IPAddress, cds.LaserPrinter.Port, 2); if (errMsg.IndexOf("SUCCESS", StringComparison.OrdinalIgnoreCase) == -1) { if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Cannot print {0} on {1}", reportName, cds.LaserPrinter); } } } var pDoc = new CouchDbUtils.PawnDocInfo(); //Set document add calls pDoc.UseCurrentShopDateTime = true; pDoc.StoreNumber = GlobalDataAccessor.Instance.CurrentSiteId.StoreNumber; pDoc.CustomerNumber = GlobalDataAccessor.Instance.DesktopSession.ActiveCustomer.CustomerNumber; pDoc.DocumentType = Document.DocTypeNames.PDF; pDoc.DocFileName = reportObject.ReportTempFileFullName; pDoc.TicketNumber = ticketNumber; long recNumL = 0L; string errText; if (!CouchDbUtils.AddPawnDocument(dA, cC, cds.UserName, ref pDoc, out errText)) { if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Could not store Layaway Contract in document storage: {0} - FileName: {1}", errText, reportObject.ReportTempFileFullName); } BasicExceptionHandler.Instance.AddException( "Could not store Layaway Contract in document storage", new ApplicationException("Could not store receipt in document storage: " + errText)); } }
/*** * This method will be used for couch authentication functionality ***/ private static string couchLoginVerification(String docName, out string msg, out bool added, bool isAdminVerify) { added = false; msg = string.Empty; DocumentType = Document.DocTypeNames.PDF; string fileName = docName; int lastSlashIdx = fileName.LastIndexOf('\\'); string fName = fileName.Substring(lastSlashIdx + 1); var sErrCode = string.Empty; var sErrText = string.Empty; //byte[] fileBytes = File.ReadAllBytes(fileName); byte[] fileBytes = SimpleHash.convertToByteArr("This is connection test"); Document couchDocObj = (Document) new Document_Couch(fileName, fName, DocumentType); couchDocObj.SetPropertyData("jak prop1", "value"); string storageID = System.Guid.NewGuid().ToString(); GldocName = storageID; // Console.WriteLine("Added doc name :" + GldocName); SecuredCouchConnector CouchConnectorObj = null; //StorageID = "1234"; if (couchDocObj.SetSourceData(fileBytes, storageID, false)) { var dStorage = new DocStorage_CouchDB(); if (isAdminVerify) { CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, adminUserid, adminPass, isSec); dStorage.SecuredAddDocument(CouchConnectorObj, ref couchDocObj, out sErrCode, out sErrText); } else { CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); dStorage.SecuredAddDocument(CouchConnectorObj, ref couchDocObj, out sErrCode, out sErrText); } if (sErrCode == "0") { added = true; msg = "Added" + fileName; } else { added = false; msg = sErrText; } } return(storageID); }
public DSTRViewerWindow(string envStr, string usrName) { InitializeComponent(); this.initialized = false; this.curEnvString = envStr; this.curUserName = usrName; this.selectedStore = string.Empty; this.dateStorageMap = new Dictionary <long, List <PairType <string, Document> > >(); this.storeList = new List <string>(); this.selectedDate = DateTime.MinValue; this.couchConnector = null; this.selectedDocument = null; this.Finished = false; }
private string addDocumentToCouch(String docName, string storageID, out bool added) { added = false; // msg = string.Empty; //DocumentType = PawnObjects.Doc.Document.DocTypeNames.PDF; string fileName = docName; int lastSlashIdx = fileName.LastIndexOf('\\'); string fName = fileName.Substring(lastSlashIdx + 1); var sErrCode = string.Empty; var sErrText = string.Empty; if (fileBytes == null) { fileBytes = File.ReadAllBytes(fileName); } Document couchDocObj = (Document) new Document_Couch(fileName, fName, Document.DocTypeNames.PDF); couchDocObj.SetPropertyData("jak prop1", "value"); //string storageID = System.Guid.NewGuid().ToString(); // Console.WriteLine("Added doc name :" + GldocName); SecuredCouchConnector CouchConnectorObj = null; //StorageID = "1234"; if (couchDocObj.SetSourceData(fileBytes, storageID, false)) { var dStorage = new DocStorage_CouchDB(); CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); dStorage.SecuredAddDocument(CouchConnectorObj, ref couchDocObj, out sErrCode, out sErrText); if (sErrCode == "0") { added = true; //log.Info("Added Document ID:" + storageID); successCount++; } else { added = false; log.Info("Error adding doc :" + sErrText); failCount++; // msg = sErrText; } } return(storageID); }
private static string addDocumentToCouch(String docName, out string msg, out bool added, System.Windows.Forms.RichTextBox textBox) { added = false; msg = string.Empty; DocumentType = Document.DocTypeNames.PDF; string fileName = docName; int lastSlashIdx = fileName.LastIndexOf('\\'); string fName = fileName.Substring(lastSlashIdx + 1); var sErrCode = string.Empty; var sErrText = string.Empty; byte[] fileBytes = File.ReadAllBytes(fileName); Document couchDocObj = (Document) new Document_Couch(fileName, fName, DocumentType); couchDocObj.SetPropertyData("jak prop1", "value"); string storageID = System.Guid.NewGuid().ToString(); GldocName = storageID; // Console.WriteLine("Added doc name :" + GldocName); SecuredCouchConnector CouchConnectorObj = null; //StorageID = "1234"; if (couchDocObj.SetSourceData(fileBytes, storageID, false)) { var dStorage = new DocStorage_CouchDB(); CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); dStorage.SecuredAddDocument(CouchConnectorObj, ref couchDocObj, out sErrCode, out sErrText); if (sErrCode == "0") { added = true; msg = "Added" + fileName; textBox.AppendText("Document ID:" + GldocName); textBox.AppendText("\n"); } else { added = false; msg = sErrText; } } return(storageID); }
public CouchVo couchLogin(CouchVo vo1) { setCouchValues(vo1); bool result = false; string msg = string.Empty; string fileName = "C:\\Program Files\\Phase2App\\templates\\Report031620110858461303709.pdf"; string docID = null; try { docID = couchLoginVerification(fileName, out msg, out result); } catch (Exception) { vo1.errorMSG = msg; vo1.isError = result; return(vo1); } if (!result) { vo1.errorMSG = msg; vo1.isError = true; return(vo1); } Console.WriteLine("Added doc :" + docID); SecuredCouchConnector CouchConnectorObj = new SecuredCouchConnector(hostname, portName, secWebPort, dbName, userid, pass, isSec); result = CouchConnectorObj.Document_Delete(GldocName); //CouchVo vo = new CouchVo(); vo1.errorMSG = ""; if (!result) { vo1.isError = true; } return(vo1); }
/// <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); }
/// <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); }
void pic_Click(object sender, EventArgs e) { if (ADS.ActiveAudit.AuditId > 0) { //Instantiate docinfo which will return info we need to be able to //call reprint ticket. CouchDbUtils.PawnDocInfo docInfo = new CouchDbUtils.PawnDocInfo(); docInfo.DocumentType = Document.DocTypeNames.PDF; /*docInfo.SetDocumentSearchType(CouchDbUtils.DocSearchType.STORAGE); * docInfo.StoreNumber = ADS.ActiveAudit.StoreNumber; * docInfo.TicketNumber = ADS.ActiveAudit.AuditId; * int receiptNumber = 0;*/ string storageID = ((PictureBox)sender).Name.ToString(); if (!string.IsNullOrEmpty(storageID)) { //Get the accessors SecuredCouchConnector cC = GlobalDataAccessor.Instance.CouchDBConnector; //Retrieve the document data var pLoadMesg = new ProcessingMessage("* Loading Document *"); //Connect to couch and retrieve document Document doc; string errText; if (!CouchDbUtils.GetDocument( storageID, cC, out doc, out errText)) { pLoadMesg.Close(); pLoadMesg.Dispose(); this.showErrorMessage("view", errText, storageID); this.Close(); } 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", storageID); pLoadMesg.Close(); pLoadMesg.Dispose(); this.Close(); return; } //Create temporary file if (!this.createTempFile(fileData, out tmpFileName)) { this.showErrorMessage("view", "Cannot generate file data to show file", storageID); pLoadMesg.Close(); pLoadMesg.Dispose(); this.Close(); return; } pLoadMesg.Close(); pLoadMesg.Dispose(); switch (docInfo.DocumentType) { case Document.DocTypeNames.PDF: AuditDesktopSession.ShowPDFFile(tmpFileName, true); break; } } } } }
public void PrintAndStoreReport(AuditReportsObject ro, string report) { OracleDataAccessor dA = GlobalDataAccessor.Instance.OracleDA; SecuredCouchConnector cC = GlobalDataAccessor.Instance.CouchDBConnector; try { if (SecurityAccessor.Instance.EncryptConfig.ClientConfig.ClientConfiguration.PrintEnabled && ADS.LaserPrinter.IsValid) { if (FileLogger.Instance.IsLogInfo) { FileLogger.Instance.logMessage(LogLevel.INFO, "CallAuditReport", "Printing " + report + " on printer {0}", ADS.LaserPrinter); } string errMsg = PrintingUtilities.printDocument( ro.ReportTempFileFullName, ADS.LaserPrinter.IPAddress, ADS.LaserPrinter.Port, 1); if (errMsg.IndexOf("SUCCESS", StringComparison.OrdinalIgnoreCase) == -1) { if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Cannot print " + report + " on {0}", ADS.LaserPrinter); } } } var pDoc = new CouchDbUtils.PawnDocInfo(); //Set document add calls pDoc.UseCurrentShopDateTime = true; pDoc.StoreNumber = ADS.ActiveAudit.StoreNumber; pDoc.CustomerNumber = "0"; pDoc.DocumentType = Document.DocTypeNames.PDF; pDoc.DocFileName = ro.ReportTempFileFullName; pDoc.TicketNumber = ADS.ActiveAudit.AuditId; pDoc.AuxInfo = report; //pDoc.DocumentSearchType = CouchDbUtils.DocSearchType.STORE_TICKET; //pDoc.TicketNumber = layaway.TicketNumber; long recNumL = 0L; //if (long.TryParse(receiptDetailsVO.ReceiptNumber, out recNumL)) // { // pDoc.ReceiptNumber = recNumL; // } //Add this document to the pawn document registry and document storage string errText; if (!CouchDbUtils.AddPawnDocument(dA, cC, ADS.UserName, ref pDoc, out errText)) { if (FileLogger.Instance.IsLogError) { FileLogger.Instance.logMessage(LogLevel.ERROR, this, "Could not store " + report + " in document storage: {0} - FileName: {1}", errText, ro.ReportTempFileFullName); } BasicExceptionHandler.Instance.AddException( "Could not store " + report + " in document storage", new ApplicationException("Could not store " + report + " in document storage: " + errText)); } } catch (Exception ex) { } }
private void printDocButton_Click(object sender, EventArgs e) { //TODO: Finalize printing this.printDocButton.Enabled = false; //Get the accessors SecuredCouchConnector 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) { //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 bool 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 string 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 string 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) { pLoadMesg.Close(); pLoadMesg.Dispose(); this.showErrorMessage("print", "Cannot determine laser printer IP/Port"); this.Close(); return; } //Send raw text data to laser printer string resStrTxt = GenerateDocumentsPrinter.printDocument( fileData, laserIp, 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; }