protected void Page_Load(object sender, EventArgs e)
        {
            AppCode.ApplicationHelper.ClearSqlPools();
            if (string.IsNullOrEmpty(Session["UserID"] as string))
            {
                Response.Redirect("AccountingLogOn.aspx?AutoLogOff=Y", true);
            }

            if (!IsPostBack)
            {
                //Displays the Balance of the User for each job type.
                string userID     = Session["UserSystemID"] as string;
                string userName   = Session["UserID"] as string;
                string userSource = Session["UserSource"] as string;
                string domainName = Session["DomainName"] as string;
                deviceModel = Session["OSAModel"] as string;

                ApplyThemes();

                #region deviceModel == "Wide-SVGA"
                if (deviceModel == Constants.DEVICE_MODEL_DEFAULT)  //|| deviceModel == "Wide-SVGA"
                {
                    ImageButtonPrintColor.ImageUrl = "../App_Themes/Blue/Wide-SVGA/Images/Print_Icon_Color.png";
                    ImageButtonPrintColor.Width    = 56;
                    ImageButtonPrintColor.Height   = 53;

                    ImageButtonPrintBW.ImageUrl = "../App_Themes/Blue/Wide-SVGA/Images/Print_Icon_BW.png";
                    ImageButtonPrintBW.Width    = 56;
                    ImageButtonPrintBW.Height   = 53;

                    ImageButtonCopyColor.ImageUrl = "../App_Themes/Blue/Wide-SVGA/Images/Copy_Icon_Color.png";
                    ImageButtonCopyColor.Width    = 55;
                    ImageButtonCopyColor.Height   = 54;

                    ImageButtonCopyBW.ImageUrl = "../App_Themes/Blue/Wide-SVGA/Images/Copy_Icon_BW.png";
                    ImageButtonCopyBW.Width    = 55;
                    ImageButtonCopyBW.Height   = 54;

                    ImageButtonScanColor.ImageUrl = "../App_Themes/Blue/Wide-SVGA/Images/Scan_Icon_Color.png";
                    ImageButtonScanColor.Width    = 68;
                    ImageButtonScanColor.Height   = 44;

                    ImageButtonScanBW.ImageUrl = "../App_Themes/Blue/Wide-SVGA/Images/Scan_Icon_BW.png";
                    ImageButtonScanBW.Width    = 68;
                    ImageButtonScanBW.Height   = 44;

                    ImageButtonFaxColor.ImageUrl = "../App_Themes/Blue/Wide-SVGA/Images/Fax_Icon_Color.png";
                    ImageButtonFaxColor.Width    = 61;
                    ImageButtonFaxColor.Height   = 55;

                    ImageButtonFaxBW.ImageUrl = "../App_Themes/Blue/Wide-SVGA/Images/Fax_Icon_BW.png";
                    ImageButtonFaxBW.Width    = 61;
                    ImageButtonFaxBW.Height   = 55;

                    ImageButtonMiniStatement.ImageUrl = "../App_Themes/Blue/Wide-SVGA/Images/Ministatement_Icon.png";
                    ImageButtonMiniStatement.Width    = 52;
                    ImageButtonMiniStatement.Height   = 47;

                    ImageButtonRecharge.ImageUrl = "../App_Themes/Blue/Wide-SVGA/Images/Recharge_Icon.png";
                    ImageButtonRecharge.Width    = 59;
                    ImageButtonRecharge.Height   = 40;
                }
                #endregion

                #region deviceModel == "Wide-XGA"
                else if (deviceModel == Constants.DEVICE_MODEL_WIDE_XGA)  //|| deviceModel == "Wide-XGA"
                {
                    ImageButtonPrintColor.ImageUrl = "../App_Themes/Blue/Wide-XGA/Images/Print_Icon_Color.png";
                    ImageButtonPrintColor.Width    = 76;
                    ImageButtonPrintColor.Height   = 72;

                    ImageButtonPrintBW.ImageUrl = "../App_Themes/Blue/Wide-XGA/Images/Print_Icon_BW.png";
                    ImageButtonPrintBW.Width    = 76;
                    ImageButtonPrintBW.Height   = 72;

                    ImageButtonCopyColor.ImageUrl = "../App_Themes/Blue/Wide-XGA/Images/Copy_Icon_Color.png";
                    ImageButtonCopyColor.Width    = 74;
                    ImageButtonCopyColor.Height   = 74;

                    ImageButtonCopyBW.ImageUrl = "../App_Themes/Blue/Wide-XGA/Images/Copy_Icon_BW.png";
                    ImageButtonCopyBW.Width    = 74;
                    ImageButtonCopyBW.Height   = 74;

                    ImageButtonScanColor.ImageUrl = "../App_Themes/Blue/Wide-XGA/Images/Scan_Icon_Color.png";
                    ImageButtonScanColor.Width    = 85;
                    ImageButtonScanColor.Height   = 55;

                    ImageButtonScanBW.ImageUrl = "../App_Themes/Blue/Wide-XGA/Images/Scan_Icon_BW.png";
                    ImageButtonScanBW.Width    = 85;
                    ImageButtonScanBW.Height   = 55;

                    ImageButtonFaxColor.ImageUrl = "../App_Themes/Blue/Wide-XGA/Images/Fax_Icon_Color.png";
                    ImageButtonFaxColor.Width    = 80;
                    ImageButtonFaxColor.Height   = 71;

                    ImageButtonFaxBW.ImageUrl = "../App_Themes/Blue/Wide-XGA/Images/Fax_Icon_BW.png";
                    ImageButtonFaxBW.Width    = 80;
                    ImageButtonFaxBW.Height   = 71;

                    ImageButtonMiniStatement.ImageUrl = "../App_Themes/Blue/Wide-XGA/Images/Ministatement_Icon.png";
                    ImageButtonMiniStatement.Width    = 72;
                    ImageButtonMiniStatement.Height   = 69;

                    ImageButtonRecharge.ImageUrl = "../App_Themes/Blue/Wide-XGA/Images/Recharge_Icon.png";
                    ImageButtonRecharge.Width    = 75;
                    ImageButtonRecharge.Height   = 49;
                }
                #endregion

                #region deviceModel == "Wide-VGA"
                else if (deviceModel == Constants.DEVICE_MODEL_OSA) //deviceModel == "Wide-VGA"
                {
                    ImageButtonPrintColor.ImageUrl = "../App_Themes/Blue/Wide-VGA/Images/Print_Icon_Color.png";
                    ImageButtonPrintColor.Width    = 44;
                    ImageButtonPrintColor.Height   = 41;

                    ImageButtonPrintBW.ImageUrl = "../App_Themes/Blue/Wide-VGA/Images/Print_Icon_BW.png";
                    ImageButtonPrintBW.Width    = 44;
                    ImageButtonPrintBW.Height   = 41;

                    ImageButtonCopyColor.ImageUrl = "../App_Themes/Blue/Wide-VGA/Images/Copy_Icon_Color.png";
                    ImageButtonCopyColor.Width    = 37;
                    ImageButtonCopyColor.Height   = 38;

                    ImageButtonCopyBW.ImageUrl = "../App_Themes/Blue/Wide-VGA/Images/Copy_Icon_BW.png";
                    ImageButtonCopyBW.Width    = 37;
                    ImageButtonCopyBW.Height   = 38;

                    ImageButtonScanColor.ImageUrl = "../App_Themes/Blue/Wide-VGA/Images/Scan_Icon_Color.png";
                    ImageButtonScanColor.Width    = 46;
                    ImageButtonScanColor.Height   = 30;

                    ImageButtonScanBW.ImageUrl = "../App_Themes/Blue/Wide-VGA/Images/Scan_Icon_BW.png";
                    ImageButtonScanBW.Width    = 46;
                    ImageButtonScanBW.Height   = 30;

                    ImageButtonFaxColor.ImageUrl = "../App_Themes/Blue/Wide-VGA/Images/Fax_Icon_Color.png";
                    ImageButtonFaxColor.Width    = 43;
                    ImageButtonFaxColor.Height   = 38;

                    ImageButtonFaxBW.ImageUrl = "../App_Themes/Blue/Wide-VGA/Images/Fax_Icon_BW.png";
                    ImageButtonFaxBW.Width    = 43;
                    ImageButtonFaxBW.Height   = 38;

                    ImageButtonMiniStatement.ImageUrl = "../App_Themes/Blue/Wide-VGA/Images/Ministatement_Icon.png";
                    ImageButtonMiniStatement.Width    = 37;
                    ImageButtonMiniStatement.Height   = 38;

                    ImageButtonRecharge.ImageUrl = "../App_Themes/Blue/Wide-VGA/Images/Recharge_Icon.png";
                    ImageButtonRecharge.Width    = 43;
                    ImageButtonRecharge.Height   = 29;
                }
                #endregion

                else
                {
                    Response.Redirect("../PSPModel/JobList.aspx");
                }


                // Add Details in to Database
                string mfpaddress  = Request.Params["REMOTE_ADDR"] as string;
                string miniBalance = DataManagerDevice.ProviderDevice.ApplicationSettings.ProvideSetting("Minimum Balance");
                if (!string.IsNullOrEmpty(miniBalance))
                {
                    minimumBalance = decimal.Parse(miniBalance);
                }
                accBalance = Helper.UserAccount.GetBalance(userID);

                string updateLoginDetails = DataManagerDevice.Controller.Device.UpdateTimeOutDetails(Session["UserSystemID"] as string, mfpaddress);

                string applicationTimeOut = string.Empty;
                if (Session["ApplicationTimeOut"] == null)
                {
                    applicationTimeOut            = DataManagerDevice.ProviderDevice.ApplicationSettings.ProvideSetting("Time out");
                    Session["ApplicationTimeOut"] = applicationTimeOut;
                }
                else
                {
                    applicationTimeOut = Session["ApplicationTimeOut"] as string;
                }

                HiddenFieldIntervalTime.Value = applicationTimeOut;

                if (!string.IsNullOrEmpty(userID))
                {
                    AccUser.Text = "" + userName;
                    string path            = Server.MapPath("~/");
                    string currencySetting = DataManagerDevice.ProviderDevice.ApplicationSettings.currencySettings(path);
                    AccBal.Text   = currencySetting + " " + Helper.UserAccount.GetBalance(userID).ToString("0.00");
                    AccBalBW.Text = currencySetting + " " + Helper.UserAccount.GetBalance(userID).ToString("0.00");
                }

                //Check the balance of the user and then display for each job type, how many pages the user can execute
                string mfpIP      = Request.Params["REMOTE_ADDR"] as string;
                string costProfId = string.Empty;

                //string mfpGrpId = string.Empty;
                //string getMfpGroupId = "select GRUP_ID from T_GROUP_MFPS where MFP_IP='" + mfpIP + "'";
                //using (AppLibrary.Database dbGrpDet = new AppLibrary.Database())
                //{
                //    try
                //    {
                //        DbCommand cmdGrpDetails = dbGrpDet.GetSqlStringCommand(getMfpGroupId);
                //        DataSet grpId = dbGrpDet.ExecuteDataSet(cmdGrpDetails);
                //        mfpGrpId = Convert.ToString(grpId.Tables[0].Rows[0].ItemArray[0]);
                //    }
                //    catch { }
                //}

                string getCostProfId = "SELECT COST_PROFILE_ID FROM T_ASSGIN_COST_PROFILE_MFPGROUPS WHERE MFP_GROUP_ID = '" + mfpIP + "'";
                using (AppLibrary.Database dbCostProfDetails = new AppLibrary.Database())
                {
                    try
                    {
                        DbCommand cmdCostDetails = dbCostProfDetails.GetSqlStringCommand(getCostProfId);
                        grpId = dbCostProfDetails.ExecuteDataSet(cmdCostDetails);
                        if (grpId != null && grpId.Tables[0].Rows.Count > 0)
                        {
                            costProfId = Convert.ToString(grpId.Tables[0].Rows[0].ItemArray[0]);

                            string getPrintPriceCmd = "select PRICE_PERUNIT_COLOR, PRICE_PERUNIT_BLACK from T_PRICES where PRICE_PROFILE_ID = '" + costProfId + "' and JOB_TYPE = 'Print' and PAPER_SIZE in('A4','A3','A4R','LETTER','LEGAL','LEDGER')";
                            string getCopyPriceCmd  = "select PRICE_PERUNIT_COLOR, PRICE_PERUNIT_BLACK from T_PRICES where PRICE_PROFILE_ID = '" + costProfId + "' and JOB_TYPE = 'Copy' and PAPER_SIZE in('A4','A3','A4R','LETTER','LEGAL','LEDGER')";
                            string getScanPriceCmd  = "select PRICE_PERUNIT_COLOR, PRICE_PERUNIT_BLACK from T_PRICES where PRICE_PROFILE_ID = '" + costProfId + "' and JOB_TYPE = 'Scan' and PAPER_SIZE in('A4','A3','A4R','LETTER','LEGAL','LEDGER')";
                            string getFaxPriceCmd   = "select PRICE_PERUNIT_COLOR, PRICE_PERUNIT_BLACK from T_PRICES where PRICE_PROFILE_ID = '" + costProfId + "' and JOB_TYPE = 'Fax' and PAPER_SIZE in('A4','A3','A4R','LETTER','LEGAL','LEDGER')";

                            //string getPrintPriceCmd = "select PRICE_PERUNIT_COLOR, PRICE_PERUNIT_BLACK from T_PRICES where PRICE_PROFILE_ID = '" + costProfId + "' and JOB_TYPE = 'Print' and PAPER_SIZE = 'A4'";
                            //string getScanPriceCmd = "select PRICE_PERUNIT_COLOR, PRICE_PERUNIT_BLACK from T_PRICES where PRICE_PROFILE_ID = '" + costProfId + "' and JOB_TYPE = 'Scan' and PAPER_SIZE = 'A4'";
                            //string getCopyPriceCmd = "select PRICE_PERUNIT_COLOR, PRICE_PERUNIT_BLACK from T_PRICES where PRICE_PROFILE_ID = '" + costProfId + "' and JOB_TYPE = 'Copy' and PAPER_SIZE = 'A4'";
                            //string getFaxPriceCmd = "select PRICE_PERUNIT_COLOR, PRICE_PERUNIT_BLACK from T_PRICES where PRICE_PROFILE_ID = '" + costProfId + "' and JOB_TYPE = 'Fax' and PAPER_SIZE = 'A4'";


                            DbCommand cmdPrintPrice = dbCostProfDetails.GetSqlStringCommand(getPrintPriceCmd);
                            DataSet   PrintPriceDet = dbCostProfDetails.ExecuteDataSet(cmdPrintPrice);

                            if (PrintPriceDet != null && PrintPriceDet.Tables[0].Rows.Count > 0)
                            {
                                colorPrintPrice = Convert.ToInt32(PrintPriceDet.Tables[0].Rows[0].ItemArray[0]);
                                bwPrintPrice    = Convert.ToInt32(PrintPriceDet.Tables[0].Rows[0].ItemArray[1]);
                            }

                            DbCommand cmdScanPrice = dbCostProfDetails.GetSqlStringCommand(getScanPriceCmd);
                            DataSet   scanPriceDet = dbCostProfDetails.ExecuteDataSet(cmdScanPrice);

                            if (scanPriceDet != null && scanPriceDet.Tables[0].Rows.Count > 0)
                            {
                                colorScanPrice = Convert.ToInt32(scanPriceDet.Tables[0].Rows[0].ItemArray[0]);
                                bwScanPrice    = Convert.ToInt32(scanPriceDet.Tables[0].Rows[0].ItemArray[1]);
                            }

                            DbCommand cmdCopyPrice = dbCostProfDetails.GetSqlStringCommand(getCopyPriceCmd);
                            DataSet   copyPriceDet = dbCostProfDetails.ExecuteDataSet(cmdCopyPrice);

                            if (copyPriceDet != null && copyPriceDet.Tables[0].Rows.Count > 0)
                            {
                                colorCopyPrice = Convert.ToInt32(copyPriceDet.Tables[0].Rows[0].ItemArray[0]);
                                bwCopyPrice    = Convert.ToInt32(copyPriceDet.Tables[0].Rows[0].ItemArray[1]);
                            }

                            DbCommand cmdFaxPrice = dbCostProfDetails.GetSqlStringCommand(getFaxPriceCmd);
                            DataSet   FaxPriceDet = dbCostProfDetails.ExecuteDataSet(cmdFaxPrice);

                            if (FaxPriceDet != null && FaxPriceDet.Tables[0].Rows.Count > 0)
                            {
                                colorFaxPrice = Convert.ToInt32(FaxPriceDet.Tables[0].Rows[0].ItemArray[0]);
                                bwFaxPrice    = Convert.ToInt32(FaxPriceDet.Tables[0].Rows[0].ItemArray[1]);
                            }

                            string UserId = Session["UserSystemID"] as string;
                            string path   = Server.MapPath("~/");

                            accBalance = Helper.UserAccount.GetBalance(UserId);
                            if (accBalance <= 0)
                            {
                                ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "ShowMessage(0);", true);
                                LabelErrorMessage.Text = "You have low balance";
                            }
                        }
                        else
                        {
                            ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID, "ShowMessage(0);", true);
                            if (grpId.Tables[0].Rows.Count <= 0 && AccBal.Text == "0")
                            {
                                LabelErrorMessage.Text = "Please assign Cost Profile to MFP and Add Balance ";
                            }
                            else if (grpId.Tables[0].Rows.Count <= 0)
                            {
                                LabelErrorMessage.Text = "This MFP is not assigned to Cost Profile";
                            }
                            else if (AccBal.Text == "0")
                            {
                                LabelErrorMessage.Text = "You have low balance.";
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }

            string printFileCount   = string.Empty;
            string printfileCountBW = string.Empty;

            ProvideNumberOfFiles(out printFileCount, out printfileCountBW);
            hiddenfieldPrintFileCount.Value   = printFileCount;
            hiddenfieldPrintFileCountBW.Value = printfileCountBW;
            //LabelFileCount.Text = printfileCountBW;
            GetUIControlsDetails(printFileCount);
            try
            {
                sessionTimeOut = DataManagerDevice.ProviderDevice.ApplicationSettings.ProvideSetting("Time out");
            }
            catch
            { }

            CheckUserMinimiumBalance(minimumBalance, accBalance);
        }