using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Text;
using System.Threading;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                        Created On  : 12-Aug-2007
* Module          : Employee Master                                  Modified On : 08-Aug-2007
* Created By      : Arun Vinoth.T
* Modified By     : 
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_Emp_SpouseModify : Base.BasePage
{
    EmployeeEventData objEmployee = new EmployeeEventData();
    ResourceManager rm;
    CultureInfo ci;
    string[] spouse_name = new string[100];
    string[] spouse_DOB = new string[100];
    int rows = 0;
    int empID, No;
    protected override void Page_Load(object sender, EventArgs e)
    {
        // session checking and reset date format
        base.Page_Load(sender, e);
        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;
        if (!IsPostBack)
        {
            if (Request.QueryString["EmpID"] != null && Request.QueryString["EmpID"] != "" && Request.QueryString["No"] != null && Request.QueryString["No"] != "")
            {
                empID = Convert.ToInt32(Request.QueryString["EmpID"].ToString());
                No = Convert.ToInt32(Request.QueryString["No"].ToString());
                GetSpouseDetails(empID);
                GenerateControls();
            }
            else
            {
                Response.Clear();
                Response.Write("Fail");
                Response.End();
            }
        }
    }
    //function getting spouse details
    private void GetSpouseDetails(int empID)
    {
        if (empID != 0)
        {
            DataSet ds = new DataSet();
            ds = objEmployee.select_SpouseDetails(empID);
            rows = ds.Tables[0].Rows.Count;
            for (int i = 0; i < rows; i++)
            {
                spouse_name[i] = ds.Tables[0].Rows[i]["Name"].ToString();
                spouse_DOB[i] = ds.Tables[0].Rows[i]["DOB"].ToString();
            }
        }
    }
    //function generating controls
    private void GenerateControls()
    {
        Response.Clear();
        string id1 = "";
        string id2 = "";
        StringBuilder sb_spouse = new StringBuilder();
        sb_spouse.Append("<div id=\"tbl_spouse\" style='color:#5D5D5D'>");
        for (int i = 0; i < No; i++)
        {
            id1 = "txt_SpName" + i;
            id2 = "txt_SpouseDOB" + i;
            int j = i + 1;
            if (i < rows)
            {
                string strdob = "";
                if (spouse_DOB[i].ToString() != "")
                {
                    strdob = (Convert.ToDateTime(spouse_DOB[i].ToString())).ToString(Session["MDateFormat"].ToString());
                }
                sb_spouse.Append("<div class='row form-group'>");
                sb_spouse.Append("<div class='col-md-2'>");
                sb_spouse.Append(rm.GetString("Caption_Spouse", ci) + j + rm.GetString("OrgLevels_CompDetails_Name", ci) + "</div> <div class='col-md-3'><INPUT value='" + spouse_name[i].ToString() + "' type='Text' class='form-control' ID='" + id1 + "' onkeypress=\"return character_only(event,this)\" onchange=\"javascript:return assign_hiddenModify_spouse('1');\">");
                sb_spouse.Append("</div><div class='col-md-1'></div>");
                sb_spouse.Append("<div class='col-md-2'>");
                sb_spouse.Append(rm.GetString("Caption_Spouse", ci) + j + rm.GetString("Caption_DOB", ci) + "</div> <div class='col-md-3'> <INPUT value='" + strdob + "' type='Text' class='form-control' runat ='Server'  ID='" + id2 + "' onmouseover=\"javascript:return DynamicDatePicker('" + Convert.ToString(Session["IDateFormat"]) + "','" + id2 + "');\" onkeypress=\"return key_press_nokey(event)\" onpaste=\"return false\" onchange=\"javascript:assign_hiddenModify_spouse(this);\">");
                sb_spouse.Append("</div>");
                //sb_spouse.Append("<div class='col-md-1'>");
                //sb_spouse.Append("<input type=\"image\" src=\"../Images/dateicon.gif\" id=\"buttxt_dob" + j + "\" onclick=\"Calendar.setup({inputField     :    '" + id2 + "',ifFormat       :    '" + Convert.ToString(Session["IDateFormat"]) + "',showsTime      :    false, button         :    'buttxt_dob" + j + "',  singleClick    :    true,   step           :    1 });return false\"/>");
                //sb_spouse.Append("</div>");
                sb_spouse.Append("</div>");
            }
            else
            {
                sb_spouse.Append("<div class='row form-group'>");
                sb_spouse.Append("<div class='col-md-2'>");
                sb_spouse.Append(rm.GetString("Caption_Spouse", ci) + j + rm.GetString("OrgLevels_CompDetails_Name", ci) + "</div> <div class='col-md-3'><INPUT type='Text' class='form-control' ID='" + id1 + "' onkeypress=\"return character_only(event,this)\" onchange=\"javascript:return assign_hiddenModify_spouse('1');\">");
                sb_spouse.Append("</div><div class='col-md-1'></div>");
                sb_spouse.Append("<div class='col-md-2'>");
                sb_spouse.Append(rm.GetString("Caption_Spouse", ci) + j + rm.GetString("Caption_DOB", ci) + "</div> <div class='col-md-3'> <INPUT type='Text' class='form-control' runat ='Server'  ID='" + id2 + "' onkeypress=\"return key_press_nokey(event)\" onpaste=\"return false\" onmouseover=\"javascript:return DynamicDatePicker('" + Convert.ToString(Session["IDateFormat"]) + "','" + id2 + "');\" onchange=\"javascript:return assign_hiddenModify_spouse(this);\">");
                sb_spouse.Append("</div>");
                //sb_spouse.Append("<div class='col-md-1'>");
                //sb_spouse.Append("<input type=\"image\" src=\"../Images/dateicon.gif\" id=\"buttxt_dob" + j + "\" onclick=\"Calendar.setup({inputField     :    '" + id2 + "',ifFormat       :    '" + Convert.ToString(Session["IDateFormat"]) + "',showsTime      :    false, button         :    'buttxt_dob" + j + "',  singleClick    :    true,   step           :    1 });return false\"/>");
                //sb_spouse.Append("</div>");
                sb_spouse.Append("</div>");
            }
        }
        sb_spouse.Append("</div>");
        Response.Write(sb_spouse);
        Response.End();
    }
}
