using System;
using System.Data;
using System.Globalization;
using System.Resources;
using System.Text;
using System.Threading;
/****************************************************************************************************************************
* Project Name    : TimeCheck                                         Started Date  : 12-Aug-2007
* Module          : Shift Pattern                                     Last Modified : 18-May-2007
* Programmer      : Janakaraj.P
* Current Storage : \\Angler56\Projects\Inprogress\SCREEN1206\code\Time_AttendanceApp
* BackUp          :
****************************************************************************************************************************/
public partial class Masters_TA_UI_Master_ShiftRemote : Base.BasePage
{
    ShiftPatternEventData objShiftPattern = new ShiftPatternEventData();
    DataSet ds_Shift = new DataSet();
    ResourceManager rm;
    CultureInfo ci;
    cls_Common objCommon = new cls_Common();
    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;
        string pattern = Convert.ToString(Request.QueryString["Pattern"]);
        ds_Shift = filldataset();
        if (pattern == "Daily")
            DailyPattern();
        if (pattern == "Weekly")
            CreateWeeklyTable();
        if (pattern == "Fortnightly")
            CreateForNigthTable();
        if (pattern == "Monthly")
            createMonthlyTable();
        if (!IsPostBack)
        {
            objCommon.menu("ShiftMaster", "69");
        }
    }
    private void DailyPattern()
    {
        StringBuilder strDaily = new StringBuilder();
        strDaily.Append("<table>");
        strDaily.Append("<tr>");
        strDaily.Append("<td class='td'>");
        strDaily.Append("Number of Days");
        strDaily.Append("</td>");
        strDaily.Append("<td class='td'>");
        strDaily.Append("<select id='sel_daily' class='dlist' onchange='AjaxDvia(" + rm.GetString("Alert_Errorretrievingdata", ci) + ");'>");
        strDaily.Append("<option >-Select-</option>");
        strDaily.Append("<option value='1'>1</option>");
        strDaily.Append("<option value='2'>2</option>");
        strDaily.Append("<option value='3'>3</option>");
        strDaily.Append("<option value='4'>4</option>");
        strDaily.Append("<option value='5'>5</option>");
        strDaily.Append("<option value='6'>6</option>");
        strDaily.Append("</select>");
        strDaily.Append("</td>");
        strDaily.Append("</tr>");
        Response.Clear();
        Response.Write(strDaily);
        Response.End();
    }
    private void CreateWeeklyTable()
    {
        StringBuilder strWeely = new StringBuilder();
        strWeely.Append("<table>");
        for (int i = 1; i <= 7; i++)
        {
            string id = "ddl_WeeklyPattern" + i;
            strWeely.Append("<tr>");
            strWeely.Append("<td class='td' width='30%'>Day " + i + " </td> ");
            //strWeely.Append("&nbsp;&nbsp;");
            strWeely.Append("<td width='50%'> <select id='" + id + "' name='" + id + "' class='dlist'>");
            for (int j = 0; j < ds_Shift.Tables[0].Rows.Count; j++)
            {
                strWeely.Append("<option value=" + Convert.ToInt16(ds_Shift.Tables[0].Rows[j]["Shift_Id"]) + ">" + Convert.ToString(ds_Shift.Tables[0].Rows[j]["Shift_Name"]) + "</option> ");
            }
            strWeely.Append("</select></td>");
            strWeely.Append("</tr>");
        }
        strWeely.Append("</table>");
        Response.Write(strWeely);
        Response.End();
    }
    private void CreateForNigthTable()
    {
        StringBuilder strForthnight = new StringBuilder();
        strForthnight.Append("<table cellpadding='0' cellspacing='0' width='400px'>");
        strForthnight.Append("<tr> <td class='td'></td> <td class='td'></td> <td class='td'></td></tr> ");
        for (int k = 1; k <= 5; k++)
        {
            strForthnight.Append("<tr>");
            strForthnight.Append("<td class='td'>");
            for (int i = 1; i <= 3; i++)
            {
                string id = "ddl_ForthNight" + i;
                strForthnight.Append("<td class='td'>Day " + i * k + " </td> ");
                //strForthnight.Append("&nbsp;&nbsp;");
                strForthnight.Append("<td> <select id='" + id + "' name='" + id + "' class='dlist'>");
                for (int j = 0; j < ds_Shift.Tables[0].Rows.Count; j++)
                {
                    strForthnight.Append("<option value=" + Convert.ToInt16(ds_Shift.Tables[0].Rows[j]["Shift_Id"]) + ">" + Convert.ToString(ds_Shift.Tables[0].Rows[j]["Shift_Name"]) + "</option> ");
                }
                strForthnight.Append("</select> </td>");
            }
            strForthnight.Append("</td>");
            strForthnight.Append("</tr>");
        }
        strForthnight.Append("</table>");
        Response.Write(strForthnight);
        Response.End();
    }
    private void createMonthlyTable()
    {
        StringBuilder strMonthly = new StringBuilder();
        strMonthly.Append("<table cellpadding='0' cellspacing='0' width='400px'>");
        strMonthly.Append("<tr> <td class='td'></td> <td class='td'></td> <td class='td'></td></tr> ");
        for (int k = 1; k <= 10; k++)
        {
            strMonthly.Append("<tr>");
            strMonthly.Append("<td class='td'>");
            for (int i = 1; i <= 3; i++)
            {
                string id = "ddl_Monthly" + i;
                strMonthly.Append("<td class='td'>Day " + i * k + " </td> ");
                strMonthly.Append("<td> <select id='" + id + "' class='dlist'>");
                for (int j = 0; j < ds_Shift.Tables[0].Rows.Count; j++)
                {
                    strMonthly.Append("<option value=" + Convert.ToInt16(ds_Shift.Tables[0].Rows[j]["Shift_Id"]) + ">" + Convert.ToString(ds_Shift.Tables[0].Rows[j]["Shift_Name"]) + "</option> ");
                }
                strMonthly.Append("</select> </td>");
            }
            strMonthly.Append("</td>");
            strMonthly.Append("</tr>");
        }
        strMonthly.Append("</table>");
        Response.Write(strMonthly);
        Response.End();
    }
    public DataSet filldataset()
    {
        DataSet ds;
        string strusergroup = string.Empty;
        ds = objShiftPattern.SelectShift(Convert.ToString(Session["UserGroupName"]), Convert.ToString(Session["LevelRights"]), 0);
        return ds;
    }
}
