/// <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);
        }
        /// <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);
        }