private void viewDocButton_Click(object sender, EventArgs e) { //Ensure that the button is not clicked twice this.viewDocButton.Enabled = false; //Get the accessors var cds = GlobalDataAccessor.Instance.DesktopSession; var 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( this.StorageId, cC, out doc, out errText)) { pLoadMesg.Close(); pLoadMesg.Dispose(); this.showErrorMessage("view", errText); 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"); 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"); pLoadMesg.Close(); pLoadMesg.Dispose(); this.Close(); return; } pLoadMesg.Close(); pLoadMesg.Dispose(); 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 ReceiptRenderer receiptR = new ReceiptRenderer(fileData); //Desktop.PrintQueue.ReceiptRenderer receiptR = new Desktop.PrintQueue.ReceiptRenderer(fileData); //receiptDataRetrieved = receiptR.ExecuteServicePawnLoanForReceiptRenderer(this.DocInfo); //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; } //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); } } } //Re-enable show button this.viewDocButton.Enabled = 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); }