internal static DataSet ProvidePermissionsAndLimits(string costCenterId, string userId, string limitsOn)
        {
            DataSet dsPermissionsLimits;
            string  sqlQuery = string.Format("exec GetPermissionsAndLimits {0},'{1}','{2}'", costCenterId, userId, limitsOn);

            using (OsaDirectEAManager.Database database = new OsaDirectEAManager.Database())
            {
                DbCommand cmdCostCenterName = database.GetSqlStringCommand(sqlQuery);
                dsPermissionsLimits = database.ExecuteDataSet(cmdCostCenterName);
            }
            return(dsPermissionsLimits);
        }
        public static DataSet GetCostCenterName(string costCenterID)
        {
            DataSet costCenterName;
            string  sqlQuery = "select COSTCENTER_NAME from M_COST_CENTERS where COSTCENTER_ID = '" + costCenterID + "'";

            using (OsaDirectEAManager.Database dbcostCenterName = new OsaDirectEAManager.Database())
            {
                DbCommand cmdCostCenterName = dbcostCenterName.GetSqlStringCommand(sqlQuery);
                costCenterName = dbcostCenterName.ExecuteDataSet(cmdCostCenterName);
            }
            return(costCenterName);
        }
        internal static string ProvideUserCostcenter(string userAccountId, string userCostCenter)
        {
            using (OsaDirectEAManager.Database database = new OsaDirectEAManager.Database())
            {
                string sqlQuery = string.Format("exec GetUserCostCenter {0},{1}", userAccountId, userCostCenter);

                DataSet dsUserDetails = database.ExecuteDataSet(database.GetSqlStringCommand(sqlQuery));

                if (dsUserDetails.Tables[0].Rows.Count > 0)
                {
                    userCostCenter = dsUserDetails.Tables[0].Rows[0]["CostCenter"].ToString();
                }
                database.Connection.Close();
            }
            return(userCostCenter);
        }
        /// <summary>
        /// Gets the print user preferred cost center.
        /// </summary>
        /// <param name="printUserAccountID">The print user account ID.</param>
        /// <returns></returns>
        public static string GetPrintUserPreferredCostCenter(int printUserAccountID)
        {
            string preferredCostCenter = string.Empty;

            using (OsaDirectEAManager.Database database = new OsaDirectEAManager.Database())
            {
                string sqlQuery = string.Format("select USR_COSTCENTER, USR_SOURCE from M_USERS where USR_ACCOUNT_ID ='{0}' order by USR_SOURCE", printUserAccountID);

                DataSet dsUserDetails = database.ExecuteDataSet(database.GetSqlStringCommand(sqlQuery));

                if (dsUserDetails.Tables[0].Rows.Count > 0)
                {
                    preferredCostCenter = dsUserDetails.Tables[0].Rows[0]["USR_COSTCENTER"].ToString();
                }
                database.Connection.Close();
            }
            return(preferredCostCenter);
        }
        public static int GetPrintUserAccountID(string printUser)
        {
            int printUserAccountID = 0;

            using (OsaDirectEAManager.Database database = new OsaDirectEAManager.Database())
            {
                string sqlQuery = string.Format("select USR_ACCOUNT_ID, USR_SOURCE from M_USERS where USR_ID ='{0}' order by USR_SOURCE", printUser);

                DataSet dsUserDetails = database.ExecuteDataSet(database.GetSqlStringCommand(sqlQuery));

                if (dsUserDetails.Tables[0].Rows.Count > 0)
                {
                    printUserAccountID = int.Parse(dsUserDetails.Tables[0].Rows[0]["USR_ACCOUNT_ID"].ToString());
                }
                database.Connection.Close();
            }
            return(printUserAccountID);
        }
        /// <summary>
        /// Determines whether [is valid user] [the specified userid].
        /// </summary>
        /// <remarks>
        /// Sequence Diagram:<br/>
        /// <img src="SequenceDiagrams/SD_DataManager.Controller.Users.IsValidUser.jpg" />
        /// </remarks>
        /// <param name="userid">Userid.</param>
        /// <param name="password">Password.</param>
        /// <param name="userAccountIdInDb">User account id in db.</param>
        /// <returns>string</returns>
        public static DataSet IsValidUser(string userId, string password)
        {
            DataSet dsUser = new DataSet();

            dsUser.Locale = CultureInfo.InvariantCulture;
            string sqlQuery = string.Format(CultureInfo.CurrentCulture, "select * from M_USERS where (USR_ID=N'{0}' or USR_PIN = N'{0}' or USR_CARD_ID=N'{0}')", userId.Replace("'", "''"));

            if (string.IsNullOrEmpty(userId))
            {
                return(null);
            }
            if (string.IsNullOrEmpty(password))
            {
            }
            using (OsaDirectEAManager.Database dbValidUser = new OsaDirectEAManager.Database())
            {
                DbCommand cmdValidUser = dbValidUser.GetSqlStringCommand(sqlQuery);
                dsUser = dbValidUser.ExecuteDataSet(cmdValidUser);
            }
            return(dsUser);
        }
        /// <summary>
        /// Records to log.
        /// </summary>
        /// <param name="deviceIP">Device IP.</param>
        /// <param name="deviceMacAddress">Device mac address.</param>
        /// <param name="userAccountId">User account id.</param>
        /// <param name="jobNo">Job no.</param>
        /// <param name="jobMode">Job mode.</param>
        /// <param name="jobComputer">Job computer.</param>
        /// <param name="startDate">Start date.</param>
        /// <param name="endDate">End date.</param>
        /// <param name="colorMode">Color mode.</param>
        /// <param name="monochromeSheetCount">The monochrome sheet count.</param>
        /// <param name="colorSheetCount">The color sheet count.</param>
        /// <param name="jobStatus">Job status.</param>
        /// <param name="paperSize">Size of the paper.</param>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="duplexMode">Duplex Mode.</param>
        /// <param name="costCenter">The cost center.</param>
        /// <param name="costCenterName">Name of the cost center.</param>
        /// <remarks>
        /// Sequence Diagram:<br/>
        ///     <img src="SequenceDiagrams/SD_DataManager.Controller.Jobs.RecordToLog.jpg"/>
        /// </remarks>
        public static bool RecordToLog(string deviceIP, string deviceMacAddress, string userAccountId, string jobNo, string jobMode, string jobComputer, string startDate, string endDate, string colorMode, string monochromeSheetCount, string colorSheetCount, string jobStatus, string paperOriginalSize, string paperSize, string fileName, string duplexMode, string costCenter, string costCenterName, string limitsOn, int osaJobCount, string serverIPAddress, string serverLocation, string serverTokenID)
        {
            string dbString              = string.Empty;
            string storeName             = string.Empty;
            string storeInformation      = OsaDirectEAManager.Helper.UserAccount.ExternalStore.Info(out storeName, out dbString);
            string StorePath             = GetStoreAssemblypath();
            string storeAssemblyLocation = Path.Combine(StorePath, storeName, storeName + ".dll");
            string serialNumber          = userAccountId;
            string transcationType       = jobMode;
            string amountTotal           = "0";
            bool   returnValue           = false;
            string userNameExternal      = string.Empty;

            if (jobMode.ToLower() == "copy" || jobMode.ToLower() == "scanner")
            {
                if (colorMode.ToLower() != "monochrome")
                {
                    colorSheetCount      = monochromeSheetCount;
                    monochromeSheetCount = string.Empty;
                }
            }

            if (jobMode == "FAX-PRINT" || jobMode == "FAX-SEND")
            {
                jobMode = "FAX";
            }

            if (jobMode == "FAX-RECEIVE")
            {
                jobMode = "FAX RECEIVE";
            }

            if (jobMode == "DOC-FILING-PRINT")
            {
                jobMode = "Doc Filing Print";
            }

            if (jobMode == "DOC-FILING")
            {
                jobMode = "Doc Filing Scan";
            }

            if (!string.IsNullOrEmpty(colorSheetCount) && !string.IsNullOrEmpty(monochromeSheetCount))
            {
                colorMode = "AUTO";
            }
            else if (string.IsNullOrEmpty(colorSheetCount) && !string.IsNullOrEmpty(monochromeSheetCount))
            {
                colorMode = "MONOCHROME";
            }
            else if (!string.IsNullOrEmpty(colorSheetCount) && string.IsNullOrEmpty(monochromeSheetCount))
            {
                colorMode = "FULL-COLOR";
            }

            if (string.IsNullOrEmpty(paperSize))
            {
                paperSize = "A4";
            }

            string[] paperSizeReverse = paperSize.Split('_');
            if (paperSizeReverse.Length > 1)
            {
                paperSize = paperSizeReverse[0].ToString();
            }

            if (string.IsNullOrEmpty(monochromeSheetCount))
            {
                monochromeSheetCount = "0";
            }
            if (string.IsNullOrEmpty(colorSheetCount))
            {
                colorSheetCount = "0";
            }

            if (string.IsNullOrEmpty(duplexMode))
            {
                duplexMode = "1SIDED";
            }
            if (jobMode == "FAX")
            {
                try
                {
                    int.Parse(userAccountId);
                }
                catch
                {
                    userAccountId = "-500";
                }
            }
            try
            {
                if (!string.IsNullOrEmpty(storeName))
                {
                    Object[] argsUserName        = { dbString, userAccountId };
                    Object   stoteResultUserName = CustomAccount.DynaInvoke.InvokeMethod(storeAssemblyLocation, "ExternalStore.Accounts", "UserName", argsUserName);
                    if (stoteResultUserName != null)
                    {
                        userNameExternal = stoteResultUserName.ToString();
                    }
                }

                string sqlQuery    = string.Format("exec RecordJobEvent '{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', '{8}', '{9}', '{10}', '{11}', '{12}', '{13}', '{14}', '{15}', '{16}','{17}', '{18}','{19}','{20}','{21}','{22}' ", deviceIP, deviceMacAddress, userAccountId, jobNo, jobMode, jobComputer, startDate, endDate, colorMode, monochromeSheetCount, colorSheetCount, jobStatus, paperOriginalSize, paperSize, fileName, duplexMode, limitsOn, osaJobCount, costCenter, serverIPAddress, serverLocation, serverTokenID, userNameExternal);
                string sqlResult   = string.Empty;
                string totalAmount = "0";
                using (OsaDirectEAManager.Database database = new OsaDirectEAManager.Database())
                {
                    DbCommand dbCommand        = database.GetSqlStringCommand(sqlQuery);
                    DataSet   drJobUsedUpdated = database.ExecuteDataSet(dbCommand);
                    if (drJobUsedUpdated.Tables.Count > 0 && drJobUsedUpdated != null)
                    {
                        returnValue = bool.Parse(drJobUsedUpdated.Tables[0].Rows[0]["JOB_USED_UPDATED"].ToString());
                        try
                        {
                            totalAmount = drJobUsedUpdated.Tables[1].Rows[0]["jobPriceTotal"].ToString();
                        }
                        catch (Exception ex)
                        {
                            totalAmount = "0";
                        }
                    }
                }
                if (string.IsNullOrEmpty(sqlResult))
                {
                    returnValue = true;
                }



                if (!string.IsNullOrEmpty(storeName))
                {
                    if (jobStatus.ToLower() == "finished" || jobStatus.ToLower() == "suspend" || jobStatus.ToLower() == "suspended")
                    {
                        amountTotal = totalAmount;
                        float    transcationAmount = float.Parse(amountTotal.ToString());
                        string   transcationMisc   = fileName;
                        string   operatorID        = deviceIP;
                        int      status            = 0;
                        Object[] args        = { dbString, serialNumber, transcationType, transcationAmount, transcationMisc, operatorID, status };
                        Object   stoteResult = CustomAccount.DynaInvoke.InvokeMethod(storeAssemblyLocation, "ExternalStore.Accounts", "RecordJobLog", args);
                        if (stoteResult != null)
                        {
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                returnValue = false;
            }
            return(returnValue);
        }