Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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);
        }