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;
public partial class Masters_TA_UI_Transaction_MyProfileTrans : 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;
    string Status, Remarks, strEmailIdSanctionAuthority = "", strEmailIdReportingTo = "", EmployeeName, EmployeeEamilId, strLeaveApplicationDate, strNoOfDays, Leave_FromDate, Leave_ToDate;
    DataSet ds_RecordsCountLeaveReportingTo = new DataSet();
    DataSet ds_ReportingToSanctionAuthorityList = new DataSet();
    DataSet dsLeaveConversation = new DataSet();
    PermissionEventData objPermissionEventData = new PermissionEventData();
    LeaveApplicationEventData objLeaveApplicationEventData = new LeaveApplicationEventData();
    DataSet dsRecordsCount = new DataSet();
    protected override void Page_Load(object sender, EventArgs e)
    {
        try
        {
            base.Page_Load(sender, e);
            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("Approvals", "248");
            LoadStrings(ci);
            Session["SanctionSelected"] = "5";
            intEmpid = Convert.ToInt32(Request.QueryString["Emp_Id"]);
            if (!Page.IsPostBack)
            {
                Hidden1.Value = Convert.ToString(Session["IDateFormat"]);
                //BindingReligion();
                //fillCountriesddl();
                GetEmpDetailsbyID(intEmpid);
                
                if (Status != "Approved" && Status != "Rejected")
                {
                    ds_RecordsCountLeaveReportingTo = objLeaveApplicationEventData.GetRecordsCountLeaveReportingTo(Convert.ToInt32(Session["EmpAutoId"]));
                    if (Convert.ToInt32(ds_RecordsCountLeaveReportingTo.Tables[0].Rows[0]["RecordsCount"]) > 0)
                    {
                        rbApproved.Enabled = false;
                    }
                    dsRecordsCount = objLeaveApplicationEventData.GetRecordsCountLeaveSanction(Convert.ToInt32(Session["EmpAutoId"]));
                    //if (Convert.ToInt32(dsRecordsCount.Tables[0].Rows[0]["RecordsCount"]) > 0)
                    //{
                    //    rbPending.Enabled = false;
                    //}
                }
                ds_ReportingToSanctionAuthorityList = objLeaveApplicationEventData.GetReportingToSanctionAuthorityforID(Convert.ToInt32(Session["EmpAutoId"]));
                if (Status != "Approved" && Status != "Rejected")
                {
                    if (Convert.ToString(Session["UserGroupName"]) != "SuperAdmin")
                    {
                        if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Reporting_To"]) && Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Leave_Sanc_Authority"]))
                        {
                            rbApproved.Enabled = true;
                            //rbPending.Enabled = false;
                            rbRejected.Enabled = true;
                        }
                        else if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Reporting_To"]))
                        {
                            rbApproved.Enabled = false;
                            //rbPending.Enabled = false;
                        }
                        else if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Leave_Sanc_Authority"]))
                        {
                            rbApproved.Enabled = true;
                        }
                    }
                    else
                    {
                        rbApproved.Enabled = true;
                        //rbPending.Enabled = true;
                        rbRejected.Enabled = true;
                    }
                }
                else if (Status == "Approved")
                {
                    if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Reporting_To"]))
                    {
                        btn_Myprofile_Save.Enabled = false;
                        btn_Myprofile_Save.OnClientClick = null;
                    }
                    else if (Convert.ToString(Session["EmpAutoId"]) == Convert.ToString(ds_ReportingToSanctionAuthorityList.Tables[0].Rows[0]["Leave_Sanc_Authority"]))
                    {
                        btn_Myprofile_Save.Enabled = false;
                        btn_Myprofile_Save.OnClientClick = null;
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    private void LoadStrings(CultureInfo ci)
    {
        try
        {
            btn_Myprofile_Save.Text = "&nbsp;&nbsp;Save";
            btn_Cancel.Text = "&nbsp;&nbsp;Back";
            lbl_SwipecardNo.Text = "Card No.";
            lbl_EmployeeID.Text = "Employee Id";
            lbl_HeaderMyProfileView.Text = "MyProfile Sanction";
            lbl_Remark.Text = "Remarks";
            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 (rbApproved.Checked == true)
                Status = "Approved";
            //else if (rbPending.Checked == true)
            //    Status = "Pending";
            else if (rbRejected.Checked == true)
                Status = "Rejected";
            else
                Status = string.Empty;

            if (Status == string.Empty)
            {
                ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", "alert('" + rm.GetString("Msg_ChooseOption", ci) + "');", true);
                return;
            }
            else if (Convert.ToString(Request.QueryString["Status"]) == Status)
            {
                Message(rm.GetString("Alert_SelectAnyOtherOption", ci));
                return;
            }
            String Remarks=txt_Remark.Text;
            DataSet ds = new DataSet();
            Hashtable htable1 = new Hashtable();
            if (Status == "Rejected")
            {
                htable1.Add("@tag", "R");
                htable1.Add("@Remarks", Remarks);
                htable1.Add("@myprofileID", hdnMyProfileID.Value);
                ds = objEmployee.InsertUpdateMyProfileDetails(htable1);
            }
            else
            {
                htable1.Add("@tag", "A");
                htable1.Add("@Remarks", Remarks);
                htable1.Add("@myprofileID", hdnMyProfileID.Value);
                ds = objEmployee.InsertUpdateMyProfileDetails(htable1);
            }
           
            string strScript = string.Empty;
            strScript = strScript + "<script language='javascript'>";
            strScript = strScript + "alert('My Profile Sanction Application Saved');";
            strScript = strScript + "location.replace('TA_UI_Transaction_Sanctions.aspx?Type=MyProfile');";
            strScript = strScript + "</script>";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Alert", strScript, false);
        }
        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)
    {
        if (Convert.ToString(Request.QueryString["LevelId"]) != null)
        {
            if (Convert.ToString(Session["LevelId"]) == string.Empty)
            {
                Session["LevelId"] = Request.QueryString["LevelId"].ToString();
            }
        }
        if (Convert.ToString(Request.QueryString["Status"]) != null)
        {
            if (Convert.ToString(Session["LeaveSanctionStatus"]) == string.Empty)
            {
                Session["LeaveSanctionStatus"] = "All";
            }
        }
        Response.Redirect("../Transactions/TA_UI_Transaction_Sanctions.aspx?Type=MyProfile");
    }
    #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.GetEmployeeDetailsbyId(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", Request.QueryString["Status"]);
                htable.Add("@myprofileID", hdnMyProfileID.Value.ToString());
                ds_Empdetails = objEmployee.InsertUpdateMyProfileDetails(htable);
            }

            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]["SwipeCardNo"]!=DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["SwipeCardNo"])!="")
                            txt_EmpID.Text= Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["SwipeCardNo"]);
                        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"]) != "")
                        //{
                        //    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]["Remarks"] != DBNull.Value && Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Remarks"]) != string.Empty)
                        {
                            txt_Remark.Text = Convert.ToString(ds_Empdetails.Tables[0].Rows[0]["Remarks"]);
                        }
                        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[2].Rows[0]["isPath"]!=DBNull.Value)
                    {
                        Session["Path"] = ds_Empdetails.Tables[2].Rows[0]["isPath"].ToString();
                    }
                }
                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");
                        if (ds_Empdetails.Tables[1].Rows[0]["Status"] != DBNull.Value)
                        {
                            Status = Convert.ToString(ds_Empdetails.Tables[1].Rows[0]["Status"]);
                            if (Status == "Approved")
                                rbApproved.Checked = true;
                            //else if (Status == "pending")
                            //    rbPending.Checked = true;
                            else if (Status == "Rejected")
                                rbRejected.Checked = true;
                            rbApproved.Enabled = true;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
   
    protected void rbRejected_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = false;
       // rbPending.Checked = false;
        rbRejected.Checked = true;
    }
    protected void rbPending_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = false;
        //rbPending.Checked = true;
        rbRejected.Checked = false;
    }
    protected void rbApproved_OnCheckedChanged(object sender, EventArgs e)
    {
        rbApproved.Checked = true;
        //rbPending.Checked = false;
        rbRejected.Checked = false;
    }

    protected void btnDowload_Proof_Click(object sender, EventArgs e)
    {

        String filePath = Session["Path"].ToString();
        Download_MedicalCertificate(filePath);

    }

    private bool Download_MedicalCertificate(String GetPath)
    {
        string GetType = "SelectMedicalCertificate";
        bool fileflage = false;
       // int LeaveApplication_Id = LeaveApplication_ID;
        //DataSet dsFileDetails = objLeaveApplicationEventData.EditLeaveApplication_FileUpload(LeaveApplication_Id, GetType);
        //if (dsFileDetails.Tables[0].Rows.Count > 0)
        //{
            //string GetPath = dsFileDetails.Tables[0].Rows[0]["FilePath"].ToString();
            string filename = Path.GetFileName(GetPath);
            string FilePath = Server.MapPath("~/Transactions/LeaveApplicationUploadFiles/" + filename);
            FileInfo fileInfo = new FileInfo(FilePath);
            if (fileInfo.Exists)
            {
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=" + fileInfo.Name);
                Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.Flush();
                Response.TransmitFile(fileInfo.FullName);
                Response.End();
                fileflage = true;
            }
            else
            {
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + rm.GetString("Alert_MedicalCertificateNotAvailable", ci) + "');", true);
                fileflage = false;
            }
        //}
        return fileflage;
    }
}