using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Threading;
using System.Web.UI;
public partial class System_Settings_System_Branding : Base.BasePage
{
    #region "Variable Declaration"
    ResourceManager rm;
    byte[] img_Cuslogo;
    cls_Common obj_Common = new cls_Common();
    BrandingEventdata obj_Branding = new BrandingEventdata();
    int findex;
    string str_imgType, strFileName;
    string strPathName = string.Empty, strPreviewPath = string.Empty, strDestinationPath = string.Empty;
    string strTxtDataForLoad = string.Empty;
    string strClassnameForLoad = string.Empty;
    string[] delim = { "\r\n" };
    string gstrHeaderBgColorCode = string.Empty;
    bool blnStyleSheetModified;
    Cls_CheckUser objCheckUser = new Cls_CheckUser();
    DataSet ds_Checkuser = new DataSet();
    CultureInfo ci;
    #endregion
    #region PageLoad
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking
        base.Page_Load(sender, e);
        //get the culture info to set the language
        if (!Page.IsPostBack)
        {
            base.CheckPages(0);
            obj_Common.menu("Configuration", "77");
        }
        string source_Language;
        source_Language = Convert.ToString(Session["Session_ActiveLanguage"]);
        rm = new ResourceManager(source_Language, System.Reflection.Assembly.Load("App_GlobalResources"));
        ci = Thread.CurrentThread.CurrentCulture;
        site.SiteMapProvider = Convert.ToString(Session["SiteMapProvider"]);
        Session["Direction"] = rm.GetString("Direction", ci);
        LoadStrings(ci);
        btn_Save.OnClientClick = "if(Page_ClientValidate()) return confirm('" + rm.GetString("Alert_ConfirmSave", ci) + "');return false;"; ;
        //Call to a function to implement the UserRights
        UserRights();
        blnStyleSheetModified = false;
        DataSet ds_Logo = new DataSet();
        ds_Logo = obj_Branding.SelectCusLogo();
        if (ds_Logo != null && ds_Logo.Tables.Count > 0)
        {
            if (ds_Logo.Tables[0].Rows.Count > 0)
            {
                if (ds_Logo.Tables[0].Rows[0]["Cus_Image"] != System.DBNull.Value)
                {
                    hdnLogo.Value = "1";
                }
            }
        }
        if (!IsPostBack)
        {
            string strSetAlert = "";
            strSetAlert = strSetAlert + "<script language='javascript'>";
            strSetAlert = strSetAlert + "SetAlertMessages('" + rm.GetString("Alert_ConfirmDelete") + "','" + rm.GetString("Alert_Noimagefoundunabletodelete") + "');";
            strSetAlert = strSetAlert + "</script>";
            Page.RegisterStartupScript("SetAlertMessages", strSetAlert);
        }
    }
    #endregion
    #region UserDefinedFunctions
    // Getting Information from resource file and display it in label
    private void LoadStrings(CultureInfo ci)
    {
        lblHeader_Branding.Text = rm.GetString("System_Branding_Title", ci);
        lbl_IndicatesMandatoryFields.Text = rm.GetString("IndicatesMandatoryFields", ci);
        lbl_CusLogo.Text = rm.GetString("BrandingandPersonalization_CustomerLogo", ci);
        btn_Save.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Save", ci);
        btn_Delete.Text = "&nbsp;&nbsp;" + rm.GetString("btn_Delete", ci);
        RequiredFieldValidator1.ErrorMessage = rm.GetString("Alert_SelectCustomerLogo", ci);
    }
    protected void btn_Upload_Click(object sender, EventArgs e)
    {
        // Uploading Customer Logo
        if (fp_Upload.FileName != string.Empty)
        {
            findex = fp_Upload.FileName.LastIndexOf(".");
            strFileName = fp_Upload.FileName;
            str_imgType = strFileName.Substring(findex + 1).ToUpper();
            if (str_imgType == "JPEG" || str_imgType == "JPG" || str_imgType == "BMP" || str_imgType == "GIF")
            {
                img_Cuslogo = fp_Upload.FileBytes;
                obj_Branding.InsertCustomerLogo(img_Cuslogo);
                lbl_Error.Text = string.Empty;
                Response.Write("<script>alert('" + rm.GetString("Alert_Customerlogouploadedsuccessfully", ci) + "');location.replace('System_Branding.aspx');</script>");
            }
            else
            {
                base.Message(rm.GetString("Alert_PleaseselectGifJPEGJPGBMPFiles", ci));
            }
        }
    }
    protected void btn_Delete_Click(object sender, EventArgs e)
    {
        int intLogoCount = 0;
        intLogoCount = obj_Branding.DeleteLogo();
        if (intLogoCount > 0)
        {
            string str = "alert('" + rm.GetString("Alert_Customerlogodeletedsuccessfully", ci) + "');location.replace('System_Branding.aspx');";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
        }
    }
    private void UserRights()
    {
        ds_Checkuser = objCheckUser.checkRights(77, Convert.ToInt32(Session["userGroup_Id"]), "");
        if (ds_Checkuser.Tables[0].Rows.Count > 0)
        {
            if (ds_Checkuser.Tables[0].Rows[0]["deletePrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["deletePrv"]) == 1)
            {
                this.btn_Delete.Visible = true;
            }
            else
            {
                this.btn_Delete.Visible = false;
            }
            if (ds_Checkuser.Tables[0].Rows[0]["modifyPrv"] != DBNull.Value && Convert.ToInt32(ds_Checkuser.Tables[0].Rows[0]["modifyPrv"]) == 1)
            {
                this.btn_Save.Visible = true;
            }
            else
            {
                this.btn_Save.Visible = false;
            }
        }
        else
        {
            Response.Redirect("SystemLandingPage.aspx");
        }
    }
    #endregion
}