using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;

public partial class TA_UI_Master_MyProfileView : Base.BasePage
{
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objCommon = new cls_Common();
    EmployeeEventData objEmployee = new EmployeeEventData();
    string strGender;
    int intEmpid;
    int intCountry = 0;
    int intState = 0;
    int intNativeplace = 0;
    DataSet ds_Empdetails;
    protected override void Page_Load(object sender, EventArgs e)
    {
        try
        {
            base.Page_Load(sender, e);
            //grvMyProfile.Styles.CssFilePath = Convert.ToString(Session["GridCSS"]);
            GC.Collect();
            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;
            objCommon.menu("EmployeeMaster", "18");
            LoadStrings(ci);
            intEmpid = Convert.ToInt32(Request.QueryString["Emp_Id"]);
            if (!Page.IsPostBack)
            {
                Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
                BindingReligion();
                fillCountriesddl();
                GetEmpDetailsbyID(intEmpid);
                //Session["MyProfileDB"] = null;
            }
            else
            {
                if (Session["MyProfileDB"] != null)
                {
                    DataSet ds = (DataSet)Session["MyProfileDB"];
                    //grvMyProfile.DataSource = ds.Tables[2];
                    //grvMyProfile.DataBind();
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        try
        {
            btn_Myprofile_Save.Text = "&nbsp;&nbsp;Save";
            btn_Cancel.Text = "&nbsp;&nbsp;Cancel";
            lbl_SwipecardNo.Text = "Card No.";
            lbl_HeaderMyProfileView.Text = "MyProfile View";
            lbl_BloodGroup.Text = rm.GetString("EmployeeMaster_BloodGroup", ci);
            lbl_City.Text = rm.GetString("Masters_Generic_City", ci);
            lbl_ContactAddress.Text = rm.GetString("EmployeeMaster_ContactAddress", ci);
            lbl_Country.Text = rm.GetString("Masters_Generic_Country", ci);
            lbl_DateofBirth.Text = rm.GetString("EmployeeMaster_DateOfBirth", ci);
            lbl_DateofBirthAsPerRec.Text = rm.GetString("EmployeeMaster_DateOfBirthAsPerRecord", ci);
            lbl_District.Text = rm.GetString("EmployeeMaster_District", ci);
            lbl_EmailID.Text = rm.GetString("EmployeeMaster_EmailId", ci);
            lbl_EmployeeFirstName.Text = rm.GetString("email_EmployeeName", ci);
            lbl_FathersName.Text = rm.GetString("EmployeeMaster_FathersName", ci);
            lbl_LastName.Text = rm.GetString("EmployeeMaster_LastName", ci);
            lbl_Maritalstatus.Text = rm.GetString("EmployeeMaster_MaritalStatus", ci);
            lbl_MiddleName.Text = rm.GetString("EmployeeMaster_MiddleName", ci);
            lbl_MobileNumber.Text = rm.GetString("EmployeeMaster_MobileNumber", ci);
            lbl_MothersName.Text = rm.GetString("EmployeeMaster_MothersName", ci);
            lbl_Nationality.Text = rm.GetString("EmployeeMaster_Nationality", ci);
            lbl_PermanentAddress.Text = rm.GetString("EmployeeMaster_PermanentAddress", ci);
            lbl_PersonalMailID.Text = rm.GetString("EmployeeMaster_PersionalMailId", ci);
            lbl_PhoneNumber.Text = rm.GetString("EmployeeMaster_PhoneNumber", ci);
            lbl_Religion.Text = rm.GetString("EmployeeMaster_Religion", ci);
            lbl_State.Text = rm.GetString("Masters_Generic_State", ci);
            rbtn_Married.Text = rm.GetString("rbtn_EmployeeMaster_Married", ci);
            rbtn_Single.Text = rm.GetString("rbtn_EmployeeMaster_Single", ci);
            ddl_Country.Items[0].Text = rm.GetString("Select", ci);
            ddl_State.Items[0].Text = rm.GetString("Select", ci);
            ddl_City.Items[0].Text = rm.GetString("Select", ci);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void btn_Myprofile_Save_Click(object sender, EventArgs e)
    {
        try
        {

            if (fu_proofDoc.HasFile)
            {
                string extension = "";
                int MaxFileSize = 5242880; //5 MB;
                string fileExtension = System.IO.Path.GetExtension(fu_proofDoc.FileName);
                if (!(fileExtension.Contains(".jpeg") || fileExtension.Contains(".jpg") || fileExtension.Contains(".pdf") || fileExtension.Contains(".doc") || fileExtension.Contains(".docx")))
                {
                    ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Please Upload only PDF,DOC,JPEG.JPG extension file format');", true);
                    return;
                }
                else
                {
                    int fileSize = fu_proofDoc.PostedFile.ContentLength;
                    if (fileSize == 0 || fileSize > MaxFileSize)
                    {
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Maximum upload file size is 5MB.');", true);
                        return;
                    }
                    else
                    {
                        try
                        {
                            extension = Path.GetExtension(fu_proofDoc.PostedFile.FileName);
                            DirectoryInfo isDirectExists = new DirectoryInfo(Server.MapPath("~/Transactions/LeaveApplicationUploadFiles"));
                            if (!isDirectExists.Exists)
                            {
                                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('The Application doest not contain Leave Application Upload Files folder, please create it');", true);
                                return;
                            }
                        }
                        catch (Exception ex)
                        {
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('File Could not be uploaded');", true);
                            return;
                        }
                    }
                }
               
                string newMaritalStatus = "";
                if (rbtn_Single.Checked)
                {
                    newMaritalStatus = "Single";
                }
                if (rbtn_Married.Checked)
                {
                    newMaritalStatus = "Married";
                }
                if (Convert.ToString(txt_EmpFirstName.Text) != Convert.ToString(Session["My_fstNme"]) ||
                    Convert.ToString(txt_MiddleName.Text) != Convert.ToString(Session["My_mNme"]) ||
                    Convert.ToString(txt_LastName.Text) != Convert.ToString(Session["My_lstNme"]) ||
                    Convert.ToString(txt_ContactAddress.Text) != Convert.ToString(Session["My_ConAddr"]) ||
                    Convert.ToString(txt_PermanentAddress.Text) != Convert.ToString(Session["My_PermAddr"]) ||
                    Convert.ToString(newMaritalStatus) != Convert.ToString(Session["My_Mstate"]) ||
                    Convert.ToString(txt_PhoneNo) != Convert.ToString(Session["My_PhnNo"]) ||
                    Convert.ToString(txt_MobileNo.Text) != Convert.ToString(Session["My_mobileNo"])
                    )
                {
                    int intCountry = 0, intState = 0, intNativeplace = 0, intEmployee_Id = 0;
                    int Religion = Convert.ToInt32(ddlReligion.SelectedValue);
                    if (Session["country"] != null)
                        intCountry = Convert.ToInt32(Session["country"]);
                    if (Session["state"] != null)
                        intState = Convert.ToInt32(Session["state"]);
                    if (Session["city"] != null)
                        intNativeplace = Convert.ToInt32(Session["city"]);
                    string strMstatus, Strdistrict, StrReligion = string.Empty;
                    string strSwipecardNo = txt_SwipeCardNo.Text.Trim();//txt_SwipeCardNo.Text.Trim();
                    Strdistrict = txt_District.Text.ToString();
                    intEmployee_Id = Convert.ToInt32(Request.QueryString["Emp_Id"]);
                    strMstatus = CheckMstatus(rbtn_Single, rbtn_Married);
                    string serverpath = string.Empty;
                    string finalfile = string.Empty;
                    if (1 == 1)
                    {
                        serverpath = Server.MapPath("~/Transactions/LeaveApplicationUploadFiles/") + "myprf_" + intEmpid + "_" + DateTime.Now.ToString("ddMMyyyy_hhmmss") + extension;
                        finalfile = AppendFileNumberIfExists(serverpath, extension);
                        fu_proofDoc.SaveAs(finalfile);
                    }
                    Hashtable htable = new Hashtable();
                    if (hdnMyProfileID.Value == "0")
                        htable.Add("@tag", "I");
                    else
                    {
                        htable.Add("@tag", "U");
                        htable.Add("@myprofileID", hdnMyProfileID.Value.ToString());
                    }

                    htable.Add("@Employee_Id", intEmployee_Id);
                    htable.Add("@SwipeCardNo", strSwipecardNo);
                    htable.Add("@Employee_FirstName", txt_EmpFirstName.Text.ToString().Trim());
                    htable.Add("@Employee_MiddleName", txt_MiddleName.Text.ToString().Trim());
                    htable.Add("@Employee_LastName", txt_LastName.Text.ToString());
                    htable.Add("@Father_name", txt_FatherName.Text.ToString().Trim());
                    htable.Add("@Mother_name", txt_MotherName.Text.ToString().Trim());
                    htable.Add("@DateofBirth", txt_dob.Text.ToString().Trim());
                    htable.Add("@DateofBirth_Record", txt_dobrecord.Text.ToString().Trim());
                    htable.Add("@Blood_Group", txt_BloodGroup.Text.ToString().Trim());
                    htable.Add("@EmailId", txt_EmailID.Text.ToString().Trim());
                    htable.Add("@Personal_mailid", txt_PerEmailId.Text.ToString().Trim());
                    htable.Add("@Contact_Address", txt_ContactAddress.Text.ToString().Trim());
                    htable.Add("@Permanent_Address", txt_PermanentAddress.Text.ToString().Trim());
                    htable.Add("@Phone_Number", txt_PhoneNo.Text.ToString().Trim());
                    htable.Add("@Mobile_Number", txt_MobileNo.Text.ToString().Trim());
                    htable.Add("@Marital_status", strMstatus);
                    htable.Add("@Nationality", txt_Nationality.Text.ToString().Trim());
                    htable.Add("@Religion", Religion);
                    htable.Add("@Country", intCountry);
                    htable.Add("@State", intState);
                    htable.Add("@City", intNativeplace);
                    htable.Add("@District", Strdistrict);
                    htable.Add("@Status", "Pending");
                    htable.Add("@Path",finalfile);
                    objEmployee.InsertUpdateMyProfileDetails(htable);
                    

                    if (Convert.ToString(Session["MyProfileURL"]).ToUpper() == "/MASTERS/TA_UI_MASTER_MYPROFILEVIEW.ASPX")
                    {
                        Session["MyProfileURL"] = "/Dashboard.aspx";
                    }
                    string str = "alert('My Profile Saved Successfully');location.replace('" + Convert.ToString(Session["MyProfileURL"]) + "');";
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "alertBox", str, true);
                }
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('Upload the required document to update my profile details in the system.');", true);
                return;
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    #region"Function returns EmployeeGender"
    private string CheckGender(RadioButton r1, RadioButton r2)
    {
        string Gender = "";
        if (r1.Checked == true)
            Gender = "Male";
        if (r2.Checked)
            Gender = "Female";
        return Gender;
    }
    #endregion
    #region"Function returns Employee Marital status"
    private string CheckMstatus(RadioButton r1, RadioButton r2)
    {
        string mstatus = "";
        if (r1.Checked == true)
            mstatus = "Single";
        if (r2.Checked == true)
            mstatus = "Married";
        return mstatus;
    }
    #endregion
    protected void btn_Cancel_Click(object sender, EventArgs e)
    {
        try
        {
            if (Convert.ToString(Session["MyProfileURL"]).ToUpper() == "/MASTERS/TA_UI_MASTER_MYPROFILEVIEW.ASPX")
            {
                Session["MyProfileURL"] = "/Dashboard.aspx";
            }
            Response.Redirect(Convert.ToString(Session["MyProfileURL"]), false);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    #region BindingEmployeeCategoryandType.
    private void BindingReligion()
    {
        DataSet dsReligion = new DataSet();
        dsReligion = objEmployee.SelectReligion();
        if (dsReligion != null)
        {
            if (dsReligion.Tables[0].Rows.Count > 0)
            {
                ddlReligion.DataSource = dsReligion;
                ddlReligion.DataTextField = "Name";
                ddlReligion.DataValueField = "Id";
                ddlReligion.DataBind();
            }
            dsReligion.Dispose();
        }
        foreach (ListItem item in ddlReligion.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    #region "Fills Country dropdowns"
    private void fillCountriesddl()
    {
        DataSet ds_country = new DataSet();
        ds_country = objEmployee.SelectCountries();
        ddl_Country.Items.Clear();
        if (ds_country != null)
        {
            if (ds_country.Tables[0].Rows.Count > 0)
            {
                ddl_Country.DataSource = ds_country;
                ddl_Country.DataTextField = "Title";
                ddl_Country.DataValueField = "ID";
                ddl_Country.DataBind();
            }
            ddl_Country.Items.Insert(0, new ListItem("-Select-", "0"));
        }
        foreach (ListItem item in ddl_Country.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    #region "FillStates"
    private void fillStateddl(int country)
    {
        DataSet ds_state = new DataSet();
        ds_state = objEmployee.SelectStates(country);
        if (ds_state != null)
        {
            if (ds_state.Tables[0].Rows.Count > 0)
            {
                ddl_State.DataSource = ds_state;
                ddl_State.DataTextField = "Title";
                ddl_State.DataValueField = "ID";
                ddl_State.DataBind();
            }
            ds_state.Dispose();
        }
        foreach (ListItem item in ddl_State.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    #region FillCity
    private void fillCityddl(int state)
    {
        DataSet ds_city = new DataSet();
        ds_city = objEmployee.SelectCities(state);
        if (ds_city != null)
        {
            if (ds_city.Tables[0].Rows.Count > 0)
            {
                ddl_City.DataSource = ds_city;
                ddl_City.DataTextField = "Title";
                ddl_City.DataValueField = "ID";
                ddl_City.DataBind();
            }
            ds_city.Dispose();
        }
        foreach (ListItem item in ddl_City.Items)
        {
            item.Attributes.Add("title", item.Text);
        }
    }
    #endregion
    protected void ddl_Country_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            int countryId;
            countryId = 0;
            fillStateddl(countryId);
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private void GetEmpDetailsbyID(int Empid)
    {
        try
        {
            ds_Empdetails = new DataSet();
            ds_Empdetails = objEmployee.Select_EmployeeDetailsbyId(Empid);
            if (ds_Empdetails != null)
            {
                if (ds_Empdetails.Tables[0].Rows.Count > 0)
                {
                    if (ds_Empdetails.Tables[0].Rows[0]["myprofileID"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["myprofileID"]) != string.Empty)
                    {
                        hdnMyProfileID.Value = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["myprofileID"]);
                    }
                    else
                    {
                        hdnMyProfileID.Value = "0";
                    }
                }
            }
            if (hdnMyProfileID.Value != "0")
            {
                Hashtable htable = new Hashtable();
                htable.Add("@tag", "E");
                htable.Add("@Status", "Pending");
                htable.Add("@myprofileID", hdnMyProfileID.Value.ToString());
                ds_Empdetails = objEmployee.InsertUpdateMyProfileDetails(htable);
            }
            DataSet ds = new DataSet();
            Hashtable htable1 = new Hashtable();
            htable1.Add("@tag", "E");
            htable1.Add("@Employee_Id", Convert.ToInt32(Request.QueryString["Emp_Id"]));
            ds = objEmployee.InsertUpdateMyProfileDetails(htable1);
            //grvMyProfile.DataSource = ds.Tables[2];
            //grvMyProfile.DataBind();
            Session["MyProfileDB"] = ds;

            if (ds_Empdetails != null)
            {
                if (ds_Empdetails.Tables.Count > 0)
                {
                    if (ds_Empdetails.Tables[0].Rows.Count > 0)
                    {
                        if (ds_Empdetails.Tables[0].Rows[0]["Employee_FirstName"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_FirstName"]) != "")
                            txt_EmpFirstName.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_FirstName"]);
                        if (ds_Empdetails.Tables[0].Rows[0]["Employee_MiddleName"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_MiddleName"]) != "")
                            txt_MiddleName.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_MiddleName"]);
                        if (ds_Empdetails.Tables[0].Rows[0]["Employee_LastName"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_LastName"]) != "")
                            txt_LastName.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Employee_LastName"]);
                        if (ds_Empdetails.Tables[0].Rows[0]["Father_name"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Father_name"]) != "")
                            txt_FatherName.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Father_name"]);
                        if (ds_Empdetails.Tables[0].Rows[0]["Mother_name"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Mother_name"]) != "")
                            txt_MotherName.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Mother_name"]);
                        DateTime date1 = new DateTime();
                        DateTime date2 = new DateTime();

                        if (ds_Empdetails.Tables[0].Rows[0]["DateofBirth"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["DateofBirth"]) != "" && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["DateofBirth"]) != "1900-01-01 00:00:00.000")
                        {
                            date1 = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["DateofBirth"]);
                            txt_dob.Text = date1.ToString(Convert.ToString(Session["MDateFormat"]));
                        }
                        if (ds_Empdetails.Tables[0].Rows[0]["DateofBirth_Record"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["DateofBirth_Record"]) != "")
                        {
                            date2 = Convert.ToDateTime(ds_Empdetails.Tables[0].Rows[0]["DateofBirth_Record"]);
                            txt_dobrecord.Text = date2.ToString(Convert.ToString(Session["MDateFormat"]));
                        }
                        if (ds_Empdetails.Tables[0].Rows[0]["Blood_Group"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Blood_Group"]) != "")
                            txt_BloodGroup.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Blood_Group"]);
                        if (ds_Empdetails.Tables[0].Rows[0]["EmailId"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["EmailId"]) != "")
                            txt_EmailID.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["EmailId"]);
                        if (ds_Empdetails.Tables[0].Rows[0]["Contact_Address"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Contact_Address"]) != "")
                            txt_ContactAddress.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Contact_Address"]);
                        if (ds_Empdetails.Tables[0].Rows[0]["Permanent_Address"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Permanent_Address"]) != "")
                            txt_PermanentAddress.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Permanent_Address"]);
                        if (ds_Empdetails.Tables[0].Rows[0]["Phone_Number"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Phone_Number"]) != "")
                            txt_PhoneNo.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Phone_Number"]);
                        if (ds_Empdetails.Tables[0].Rows[0]["Mobile_Number"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Mobile_Number"]) != "")
                            txt_MobileNo.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Mobile_Number"]);
                        string strMstatus = "";
                        if (ds_Empdetails.Tables[0].Rows[0]["Marital_status"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Marital_status"]) != "")
                        {
                            strMstatus = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Marital_status"]);
                            if (strMstatus == rbtn_Single.Text && strMstatus != null)
                            {
                                rbtn_Single.Checked=true;
                            }
                            else if(strMstatus==rbtn_Married.Text && strMstatus!=null)
                            {
                                rbtn_Married.Checked = true;
                            }

                        }
                        if (ds_Empdetails.Tables[0].Rows[0]["Nationality"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Nationality"]) != "")
                        {
                            txt_Nationality.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Nationality"]);
                        }
                        if (ds_Empdetails.Tables[0].Rows[0]["ReligionId"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["ReligionId"]) != "")
                        {
                            if (ddlReligion.Items.FindByValue(Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["ReligionId"])).Enabled)
                            {
                                ddlReligion.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["ReligionId"]);
                            }
                        }
                        if (ds_Empdetails.Tables[0].Rows[0]["Personal_mailid"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Personal_mailid"]) != "")
                        {
                            txt_PerEmailId.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Personal_mailid"]);
                        }
                        if (ds_Empdetails.Tables[0].Rows[0]["SwipeCardNo"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["SwipeCardNo"]) != string.Empty)
                        {
                            txt_SwipeCardNo.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["SwipeCardNo"]);
                        }
                        if (ds_Empdetails.Tables[0].Rows[0]["District"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["District"]) != string.Empty)
                        {
                            txt_District.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["District"]);
                        }
                        if (ds_Empdetails.Tables[0].Rows[0]["myprofileID"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["myprofileID"]) != string.Empty)
                        {
                            hdnMyProfileID.Value = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["myprofileID"]);
                        }
                        else
                        {
                            hdnMyProfileID.Value = "0";
                        }

                        fillCountriesddl();
                        string strcountry = string.Empty;
                        string strState = string.Empty;
                        string strCity = string.Empty;
                        if (ds_Empdetails.Tables[0].Rows[0]["country"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["country"]) != "")
                        {
                            ddl_Country.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["country"]);
                            strcountry = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["country"]);
                            if (strcountry != "0")
                            {
                                intCountry = Convert.ToInt32(ddl_Country.SelectedValue);
                                Session["country"] = ddl_Country.SelectedValue;
                                fillStateddl(intCountry);
                                if (ds_Empdetails.Tables[0].Rows[0]["state"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["state"]) != "")
                                {
                                    ddl_State.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["state"]);
                                    strState = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["state"]);
                                    if (strState != "0")
                                    {
                                        intState = Convert.ToInt32(ddl_State.SelectedValue);
                                        Session["state"] = ddl_State.SelectedValue;
                                        fillCityddl(intState);
                                        if (ds_Empdetails.Tables[0].Rows[0]["Native_Place"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Native_Place"]) != "")
                                        {
                                            ddl_City.SelectedValue = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Native_Place"]);
                                            strCity = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Native_Place"]);
                                            if (strCity != "0")
                                            {
                                                intNativeplace = Convert.ToInt32(ddl_City.SelectedValue);
                                                Session["city"] = ddl_City.SelectedValue;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if (ds_Empdetails.Tables.Count > 1)
                {
                    if (ds_Empdetails.Tables[1].Rows.Count > 0)
                    {
                        if (ds_Empdetails.Tables[1].Rows[0]["Employee_FirstName"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Employee_FirstName"]) == "1")
                                txt_EmpFirstName.Style.Add("border-color", "#FF0000");
                            else
                                txt_EmpFirstName.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Employee_MiddleName"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Employee_MiddleName"]) == "1")
                                txt_MiddleName.Style.Add("border-color", "#FF0000");
                            else
                                txt_MiddleName.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Employee_LastName"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Employee_LastName"]) == "1")
                                txt_LastName.Style.Add("border-color", "#FF0000");
                            else
                                txt_LastName.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Father_name"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Father_name"]) == "1")
                                txt_FatherName.Style.Add("border-color", "#FF0000");
                            else
                                txt_FatherName.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Mother_name"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Mother_name"]) == "1")
                                txt_MotherName.Style.Add("border-color", "#FF0000");
                            else
                                txt_MotherName.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["DateofBirth"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["DateofBirth"]) == "1")
                                txt_dob.Style.Add("border-color", "#FF0000");
                            else
                                txt_dob.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["DateofBirth_Record"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["DateofBirth_Record"]) == "1")
                                txt_dobrecord.Style.Add("border-color", "#FF0000");
                            else
                                txt_dobrecord.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Blood_Group"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Blood_Group"]) == "1")
                                txt_BloodGroup.Style.Add("border-color", "#FF0000");
                            else
                                txt_BloodGroup.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["EmailId"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["EmailId"]) == "1")
                                txt_EmailID.Style.Add("border-color", "#FF0000");
                            else
                                txt_EmailID.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Contact_Address"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Contact_Address"]) == "1")
                                txt_ContactAddress.Style.Add("border-color", "#FF0000");
                            else
                                txt_ContactAddress.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Permanent_Address"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Permanent_Address"]) == "1")
                                txt_PermanentAddress.Style.Add("border-color", "#FF0000");
                            else
                                txt_PermanentAddress.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Phone_Number"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Phone_Number"]) == "1")
                                txt_PhoneNo.Style.Add("border-color", "#FF0000");
                            else
                                txt_PhoneNo.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Mobile_Number"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Mobile_Number"]) == "1")
                                txt_MobileNo.Style.Add("border-color", "#FF0000");
                            else
                                txt_MobileNo.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Marital_status"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Marital_status"]) == "1")
                                rbtn_Married.Style.Add("border-color", "#FF0000");
                            else
                                rbtn_Married.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Nationality"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Nationality"]) == "1")
                                txt_Nationality.Style.Add("border-color", "#FF0000");
                            else
                                txt_Nationality.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["ReligionId"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["ReligionId"]) == "1")
                                ddlReligion.Style.Add("border-color", "#FF0000");
                            else
                                ddlReligion.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Personal_mailid"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Personal_mailid"]) == "1")
                                txt_PerEmailId.Style.Add("border-color", "#FF0000");
                            else
                                txt_PerEmailId.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["SwipeCardNo"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["SwipeCardNo"]) == "1")
                                txt_SwipeCardNo.Style.Add("border-color", "#FF0000");
                            else
                                txt_SwipeCardNo.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["District"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["District"]) == "1")
                                txt_District.Style.Add("border-color", "#FF0000");
                            else
                                txt_District.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["country"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["country"]) == "1")
                                ddl_Country.Style.Add("border-color", "#FF0000");
                            else
                                ddl_Country.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["state"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["state"]) == "1")
                                ddl_State.Style.Add("border-color", "#FF0000");
                            else
                                ddl_State.Style.Add("border-color", "#d2d6de");
                        if (ds_Empdetails.Tables[1].Rows[0]["Native_Place"] != DBNull.Value)
                            if (Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Native_Place"]) == "1")
                                ddl_City.Style.Add("border-color", "#FF0000");
                            else
                                ddl_City.Style.Add("border-color", "#d2d6de");
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void hh_Click(object sender, EventArgs e)
    {
        string pageName = Path.GetFullPath(Request.Path);
        string path = HttpContext.Current.Request.Url.AbsolutePath;
    }
    private string AppendFileNumberIfExists(string file, string ext)
    {
        // If the file exists, then do stuff. Otherwise, we just return the original file name.
        if (File.Exists(file))
        {
            string folderPath = Path.GetDirectoryName(file); // The path to the file. No sense in dealing with this unecessarily. 
            string fileName = Path.GetFileNameWithoutExtension(file); // The file name with no extension. 
            string extension = string.Empty; // The file extension. 
                                             // This lets us pass in an empty string for the file extension if required. i.e. It just makes this function a bit more versatile. 
            if (ext == string.Empty)
            {
                extension = Path.GetExtension(file);
            }
            else
            {
                extension = ext;
            }

            // at this point, find out if the fileName ends in a number, then get that number.
            int fileNumber = 0; // This stores the number as a number for us. 
                                // need a regex here - \(([0-9]+)\)$
            Regex r = new Regex(@"\(([0-9]+)\)$"); // This matches the pattern we are using, i.e. ~(#).ext
            Match m = r.Match(fileName); // We pass in the file name with no extension.
            string addSpace = " "; // We'll add a space when we don't have our pattern in order to pad the pattern.
            if (m.Success)
            {
                addSpace = string.Empty; // We have the pattern, so we don't add a space - it has already been added. 
                string s = m.Groups[1].Captures[0].Value; // This is the single capture that we are looking for. Stored as a string.
                                                          // set fileNumber to the new number.
                fileNumber = int.Parse(s); // Convert the number to an int.
                                           // remove the numbering from the string as we're constructing it again below.
                fileName = fileName.Replace("(" + s + ")", "");
            }

            // Start looping. 
            do
            {
                fileNumber += 1; // Increment the file number that we have above. 
                file = Path.Combine(folderPath, // Combine it all.
                                        String.Format("{0}{3}({1}){2}", // The pattern to combine.
                                                                  fileName,         // The file name with no extension. 
                                                                  fileNumber,       // The file number.
                                                                  extension,        // The file extension.
                                                                  addSpace));       // A space if needed to pad the initial ~(#).ext pattern.
            }
            while (File.Exists(file)); // As long as the file name exists, keep looping. 
        }
        return file;
    }
}
