This is a migrated thread and some comments may be shown as answers.

Sorting of columns and Enabling and Disabling Linkbutton in gridtemplate columns of telerik radgrid

1 Answer 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Naveen kumar
Top achievements
Rank 1
Naveen kumar asked on 01 Nov 2012, 09:02 AM
Hi All,
       I have the following code and attached a screen shot in the grid the column headers should be sorted as 1 2 3 4 etc and for the text values like holiday and absent the link should be disabled.I need it to be resolved as soon as possible.
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using Telerik.Web;
using Telerik.Web.UI;
using System.Data.SqlClient;
using MSI.Emailing;
using AttendenceManagement.Business_Layer;
 
namespace AttendenceManagement.Controls
{
    public partial class AttendenceDetailsGrid : System.Web.UI.UserControl
    {
        AttendenceDetailsDAO objAttendenceDetailsDAO = new AttendenceDetailsDAO();
        AttendenceDetailsEntities objAttendenceDetailsEntities = new AttendenceDetailsEntities();
        public string EmpId = "0MSI1132";
        protected void Page_Load(object sender, EventArgs e)
        {
            rdpTo.MaxDate = DateTime.Now;
            rcbxEmployee.EmptyMessage = "";
            if (!IsPostBack)
            {
                rdpTo.SelectedDate = DateTime.Now.AddDays(-1);
                rdpFrom.SelectedDate = DateTime.Now.AddMonths(-1);
                objAttendenceDetailsEntities.EmployeId = EmpId;
                lblFromdatewithyear.Text = rdpFrom.SelectedDate.Value.Date.ToShortDateString();
                lblTodatewithyear.Text = rdpTo.SelectedDate.Value.Date.ToShortDateString();
                objAttendenceDetailsEntities.FromDate = Convert.ToDateTime(rdpFrom.SelectedDate);
                objAttendenceDetailsEntities.ToDate = Convert.ToDateTime(rdpTo.SelectedDate);
                LoadAttendenceGrid();
                LoadRadCboxEmployee();
            }
        }
 
        protected void rbtnSelect_Click(object sender, EventArgs e)
        {
 
            ArrayList checkedItems = new ArrayList();
            checkedItems = GetCheckedItems();
            ArrayList arrlist = new ArrayList();
 
            foreach (RadComboBoxItem item in checkedItems)
            {
                arrlist.Add(item.Text);
            }
 
            string[] strEmpId = arrlist.ToArray(typeof(string)) as string[];
            string strEmployeeId = string.Join(",", strEmpId);
 
            rgAttendenceDetails.Columns.Clear();
            lblFromdatewithyear.Text = rdpFrom.SelectedDate.Value.Date.ToShortDateString();
            lblTodatewithyear.Text = rdpTo.SelectedDate.Value.Date.ToShortDateString();
            objAttendenceDetailsEntities.EmployeId = strEmployeeId;
            objAttendenceDetailsEntities.FromDate = Convert.ToDateTime(rdpFrom.SelectedDate);
            objAttendenceDetailsEntities.ToDate = Convert.ToDateTime(rdpTo.SelectedDate);
            LoadAttendenceGrid();
        }
 
        protected void rgAttendenceDetails_ItemCommand(object sender, GridCommandEventArgs e)
        {
            string strEmployeeID;
            string strDate;
 
            if (e.CommandName == "AttendenceCheck")
            {
                if (e.Item is GridDataItem)
                {
                    GridDataItem item = (GridDataItem)e.Item;
                    strEmployeeID = item["Emp_ID"].Text;
                    rtxtEmployeeName.Text = strEmployeeID;
                    strDate = e.CommandArgument.ToString();
                    rtxtDate.Text = strDate;
                    rwdAttendenceDetails.VisibleOnPageLoad = true;
                    objAttendenceDetailsEntities.EmployeId = strEmployeeID;
                    objAttendenceDetailsEntities.Date = Convert.ToDateTime(strDate);
                    LoadAttendenceGridPopUp();
                }
            }
        }
 
        protected void rgAttendenceDetails_ItemDataBound(object sender, GridItemEventArgs e)
        {
 
        }
 
        protected void rbOk_Click(object sender, EventArgs e)
        {
            objAttendenceDetailsEntities.EmployeId = EmpId;
            objAttendenceDetailsEntities.Date = Convert.ToDateTime(rtxtDate.Text);
            objAttendenceDetailsEntities.RequestComment = rtbxComments.Text;
            objAttendenceDetailsEntities.ResponseComment = "";
            objAttendenceDetailsEntities.TypeId = Convert.ToInt32(rcbxType.SelectedValue);
            objAttendenceDetailsEntities.Status = "";
            objAttendenceDetailsDAO.SaveStatusDetails(objAttendenceDetailsEntities);
        }
 
        protected void rbSendMail_Click(object sender, EventArgs e)
        {
            Emailclass objEmailclass = new Emailclass();
            string[] cc = { "naveen.kacham@mediaus.com" };
            objEmailclass.SendMailMessage("naveen.kacham@mediaus.com", cc, "TestingMail", "Testing");
        }
 
        protected void rbClose_Click(object sender, EventArgs e)
        {
            rwdAttendenceDetails.VisibleOnPageLoad = false;
        }
 
 
        protected void rgMyAttendenceDetails_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
            //rgMyAttendenceDetails.DataSource = new int[] { };
        }
 
        private void LoadAttendenceGrid()
        {
            string[] strEmplId = objAttendenceDetailsEntities.EmployeId.Split(',');
 
            DataSet dataSet = new DataSet();
            dataSet = objAttendenceDetailsDAO.GetFullAttendenceDetails(objAttendenceDetailsEntities);
            dataSet.Tables[0].DefaultView.Sort = "Att_Date";
            rgAttendenceDetails.AutoGenerateColumns = false;
            rgAttendenceDetails.MasterTableView.AutoGenerateColumns = false;
 
            DataTable dtAttendence = new DataTable();
            DataColumn dc = new DataColumn();
            DataColumn dcCol2 = new DataColumn();
            GridBoundColumn boundColumn = new GridBoundColumn();
            //GridBoundColumn bndcolPresent = new GridBoundColumn();
            //GridBoundColumn bndcolLeave = new GridBoundColumn();
            //GridBoundColumn bndcolHoliday = new GridBoundColumn();
            //GridBoundColumn bndcolCompOff = new GridBoundColumn();
            //GridBoundColumn bndcolTempId = new GridBoundColumn();
            //GridBoundColumn bndcolWorkFromHome = new GridBoundColumn();
            //GridBoundColumn bndcolRegular = new GridBoundColumn();
            //GridBoundColumn bndcolAbsent = new GridBoundColumn();
            //GridButtonColumn lnkbtnLeave = new GridButtonColumn();
            //GridButtonColumn lnkbtnHoliday = new GridButtonColumn();
            //GridButtonColumn lnkbtnCompOff = new GridButtonColumn();
            //GridButtonColumn lnkbtnTempId = new GridButtonColumn();
            //GridButtonColumn lnkbtnWorkFromHome = new GridButtonColumn();
            //GridButtonColumn lnkbtnRegular = new GridButtonColumn();
            //GridButtonColumn lnkbtnAbsent = new GridButtonColumn();
 
            GridTemplateColumn tempcolPresentType = new GridTemplateColumn();
            GridTemplateColumn tempcolLeaveType = new GridTemplateColumn();
            GridTemplateColumn tempcolHolidayType = new GridTemplateColumn();
            GridTemplateColumn tempcolCompOffType = new GridTemplateColumn();
            GridTemplateColumn tempcolTempIdType = new GridTemplateColumn();
            GridTemplateColumn tempcolWorkHomeType = new GridTemplateColumn();
            GridTemplateColumn tempcolRegularType = new GridTemplateColumn();
            GridTemplateColumn tempcolAbsentType = new GridTemplateColumn();
 
 
 
            for (int iLength = 0; iLength < strEmplId.Length; iLength++)
            {
                DataRow[] dr = dataSet.Tables[0].Select("Emp_ID='" + strEmplId[iLength] + "'");
 
                DataRow drRow = dtAttendence.NewRow();
 
                if (dr.Length + 1 != dtAttendence.Columns.Count)
                {
                    boundColumn = new GridBoundColumn();
                    boundColumn.HeaderText = "Employee Id";
                    boundColumn.DataField = "Emp_ID";
                    boundColumn.UniqueName = "Emp_ID";
                    dc.ColumnName = "Emp_ID";
                    dtAttendence.Columns.Add(dc);
                    rgAttendenceDetails.MasterTableView.Columns.Add(boundColumn);
                }
                drRow[dc.ColumnName] = dr[iLength]["Emp_ID"].ToString();
 
                for (int i = 0; i < dr.Length; i++)
                {
                    if (dr.Length + 1 != dtAttendence.Columns.Count)
                    {
                        dcCol2 = new DataColumn();
                        dtAttendence.Columns.Add(dcCol2);
                        dcCol2.ColumnName = dr[i]["Att_Date"].ToString();
                    }
 
                    string AttendenceType = dr[i]["Details"].ToString();
 
                    if (AttendenceType == AttendenceDetailsDAO.AttendenceType.Present.ToString())
                    {
                        //bndcolPresent = new GridBoundColumn();
                        //bndcolPresent.HeaderText = dr[i]["Day"].ToString();
                        //bndcolPresent.UniqueName = dcCol2.ColumnName;
                        //bndcolPresent.DataField = dcCol2.ColumnName;
                        //rgAttendenceDetails.MasterTableView.Columns.Add(bndcolPresent);
                        //bndcolPresent.ItemStyle.BackColor = Color.FromName("White");
                        //bndcolPresent.ItemStyle.ForeColor = Color.Black;
 
                        tempcolPresentType = new GridTemplateColumn();
                        tempcolPresentType.HeaderText = dr[i]["Day"].ToString();
                        string strcolName = dcCol2.ColumnName;
                        tempcolPresentType.ItemTemplate = new MyTemplate(strcolName, "false", ListItemType.Item);
                        tempcolPresentType.UniqueName = dcCol2.ColumnName;
                        tempcolPresentType.DataField = dcCol2.ColumnName;
                        tempcolPresentType.ItemStyle.BackColor = Color.FromName("White");
                        tempcolPresentType.ItemStyle.ForeColor = Color.Black;
 
                        if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                        {
                            rgAttendenceDetails.MasterTableView.Columns.Add(tempcolPresentType);
                        }
                        drRow[dr[i]["Att_Date"].ToString()] = dr[i]["Details"].ToString();
                    }
                    else if (AttendenceType == AttendenceDetailsDAO.AttendenceType.Leave.ToString())
                    {
                        TimeSpan tsWorkedHours = TimeSpan.Parse(dr[i]["WorkedHours"].ToString());
 
                        if (tsWorkedHours == TimeSpan.Zero)
                        {
                            //bndcolLeave = new GridBoundColumn();
                            //bndcolLeave.HeaderText = dr[i]["Day"].ToString();
                            //bndcolLeave.UniqueName = dcCol2.ColumnName;
                            //bndcolLeave.DataField = dcCol2.ColumnName;
                            //rgAttendenceDetails.MasterTableView.Columns.Add(bndcolLeave);
                            //bndcolLeave.ItemStyle.BackColor = Color.FromName("#FFFF99");
                            //bndcolLeave.ItemStyle.ForeColor = Color.Black;
 
                            tempcolLeaveType = new GridTemplateColumn();
                            tempcolLeaveType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolLeaveType.ItemTemplate = new MyTemplate(strcolName, "false", ListItemType.Item);
                            tempcolLeaveType.UniqueName = dcCol2.ColumnName;
                            tempcolLeaveType.DataField = dcCol2.ColumnName;
                            tempcolLeaveType.ItemStyle.BackColor = Color.FromName("#FFFF99");
                            tempcolLeaveType.ItemStyle.ForeColor = Color.Black;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolLeaveType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["Details"].ToString();
                        }
                        else
                        {
                            //lnkbtnLeave = new GridButtonColumn();
                            //lnkbtnLeave.ButtonType = GridButtonColumnType.LinkButton;
                            //lnkbtnLeave.HeaderText = dr[i]["Day"].ToString();
                            //lnkbtnLeave.UniqueName = dcCol2.ColumnName;
                            //lnkbtnLeave.DataTextField = dcCol2.ColumnName;
                            //lnkbtnLeave.ItemStyle.BackColor = Color.FromName("#FFFF99");
                            //lnkbtnLeave.ItemStyle.ForeColor = Color.Blue;
                            //lnkbtnLeave.CommandName = "AttendenceCheck";
                            //lnkbtnLeave.CommandArgument = dr[i]["Att_Date"].ToString();
                            //rgAttendenceDetails.MasterTableView.Columns.Add(lnkbtnLeave);
 
                            tempcolLeaveType = new GridTemplateColumn();
                            tempcolLeaveType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolLeaveType.ItemTemplate = new MyTemplate(strcolName, "true", ListItemType.Item);
                            tempcolLeaveType.UniqueName = dcCol2.ColumnName;
                            tempcolLeaveType.DataField = dcCol2.ColumnName;
                            tempcolLeaveType.ItemStyle.BackColor = Color.FromName("#FFFF99");
                            tempcolLeaveType.ItemStyle.ForeColor = Color.Blue;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolLeaveType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["WorkedHours"].ToString().Remove(5);
                        }
                    }
                    else if (AttendenceType == AttendenceDetailsDAO.AttendenceType.Holiday.ToString() || AttendenceType == AttendenceDetailsDAO.AttendenceType.RestrictedHoliday.ToString())
                    {
                        TimeSpan tsWorkedHours = TimeSpan.Parse(dr[i]["WorkedHours"].ToString());
 
                        if (tsWorkedHours == TimeSpan.Zero)
                        {
                            //bndcolHoliday = new GridBoundColumn();
                            //bndcolHoliday.HeaderText = dr[i]["Day"].ToString();
                            //bndcolHoliday.UniqueName = dcCol2.ColumnName;
                            //bndcolHoliday.DataField = dcCol2.ColumnName;
                            //bndcolHoliday.ItemStyle.BackColor = Color.FromName("#31849B");
                            //bndcolHoliday.ItemStyle.ForeColor = Color.Black;
                            //rgAttendenceDetails.MasterTableView.Columns.Add(bndcolHoliday);
 
                            tempcolHolidayType = new GridTemplateColumn();
                            tempcolHolidayType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolHolidayType.ItemTemplate = new MyTemplate(strcolName, "false", ListItemType.Item);
                            tempcolHolidayType.UniqueName = dcCol2.ColumnName;
                            tempcolHolidayType.DataField = dcCol2.ColumnName;
                            tempcolHolidayType.ItemStyle.BackColor = Color.FromName("#31849B");
                            tempcolHolidayType.ItemStyle.ForeColor = Color.Black;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolHolidayType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["Details"].ToString();
                        }
                        else
                        {
                            //lnkbtnHoliday = new GridButtonColumn();
                            //lnkbtnHoliday.ButtonType = GridButtonColumnType.LinkButton;
                            //lnkbtnHoliday.HeaderText = dr[i]["Day"].ToString();
                            //lnkbtnHoliday.UniqueName = dcCol2.ColumnName;
                            //lnkbtnHoliday.DataTextField = dcCol2.ColumnName;
                            //rgAttendenceDetails.MasterTableView.Columns.Add(lnkbtnHoliday);
                            //lnkbtnHoliday.ItemStyle.BackColor = Color.FromName("#31849B");
                            //lnkbtnHoliday.ItemStyle.ForeColor = Color.Blue;
                            //lnkbtnHoliday.CommandName = "AttendenceCheck";
                            //lnkbtnHoliday.CommandArgument = dr[i]["Att_Date"].ToString();
 
                            tempcolHolidayType = new GridTemplateColumn();
                            tempcolHolidayType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolHolidayType.ItemTemplate = new MyTemplate(strcolName, "true", ListItemType.Item);
                            tempcolHolidayType.UniqueName = dcCol2.ColumnName;
                            tempcolHolidayType.DataField = dcCol2.ColumnName;
                            tempcolHolidayType.ItemStyle.BackColor = Color.FromName("#31849B");
                            tempcolHolidayType.ItemStyle.ForeColor = Color.Blue;
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolHolidayType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["WorkedHours"].ToString().Remove(5);
                        }
                    }
                    else if (AttendenceType == AttendenceDetailsDAO.AttendenceType.CompOFF.ToString())
                    {
                        TimeSpan tsWorkedHours = TimeSpan.Parse(dr[i]["WorkedHours"].ToString());
 
                        if (tsWorkedHours == TimeSpan.Zero)
                        {
                            //bndcolCompOff = new GridBoundColumn();
                            //bndcolCompOff.HeaderText = dr[i]["Day"].ToString();
                            //bndcolCompOff.UniqueName = dcCol2.ColumnName;
                            //bndcolCompOff.DataField = dcCol2.ColumnName;
                            //rgAttendenceDetails.MasterTableView.Columns.Add(bndcolCompOff);
                            //bndcolCompOff.ItemStyle.BackColor = Color.FromName("#E6B9B8");
                            //bndcolCompOff.ItemStyle.ForeColor = Color.Black;
 
                            tempcolCompOffType = new GridTemplateColumn();
                            tempcolCompOffType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolCompOffType.ItemTemplate = new MyTemplate(strcolName, "false", ListItemType.Item);
                            tempcolCompOffType.UniqueName = dcCol2.ColumnName;
                            tempcolCompOffType.DataField = dcCol2.ColumnName;
                            tempcolCompOffType.ItemStyle.BackColor = Color.FromName("#E6B9B8");
                            tempcolCompOffType.ItemStyle.ForeColor = Color.Black;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolCompOffType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["Details"].ToString();
                        }
                        else
                        {
                            //lnkbtnCompOff = new GridButtonColumn();
                            //lnkbtnCompOff.ButtonType = GridButtonColumnType.LinkButton;
                            //lnkbtnCompOff.HeaderText = dr[i]["Day"].ToString();
                            //lnkbtnCompOff.UniqueName = dcCol2.ColumnName;
                            //lnkbtnCompOff.DataTextField = dcCol2.ColumnName;
                            //lnkbtnCompOff.ItemStyle.BackColor = Color.FromName("#E6B9B8");
                            //lnkbtnCompOff.ItemStyle.ForeColor = Color.Blue;
                            //lnkbtnCompOff.CommandName = "AttendenceCheck";
                            //lnkbtnCompOff.CommandArgument = dr[i]["Att_Date"].ToString();
                            //rgAttendenceDetails.MasterTableView.Columns.Add(lnkbtnCompOff);
 
                            tempcolCompOffType = new GridTemplateColumn();
                            tempcolCompOffType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolCompOffType.ItemTemplate = new MyTemplate(strcolName, "true", ListItemType.Item);
                            tempcolCompOffType.UniqueName = dcCol2.ColumnName;
                            tempcolCompOffType.DataField = dcCol2.ColumnName;
                            tempcolCompOffType.ItemStyle.BackColor = Color.FromName("#E6B9B8");
                            tempcolCompOffType.ItemStyle.ForeColor = Color.Blue;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolCompOffType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["WorkedHours"].ToString().Remove(5);
                        }
                    }
                    else if (AttendenceType == AttendenceDetailsDAO.AttendenceType.TemporaryId.ToString())
                    {
                        TimeSpan tsWorkedHours = TimeSpan.Parse(dr[i]["WorkedHours"].ToString());
 
                        if (tsWorkedHours == TimeSpan.Zero)
                        {
                            //bndcolTempId = new GridBoundColumn();
                            //bndcolTempId.HeaderText = dr[i]["Day"].ToString();
                            //bndcolTempId.UniqueName = dcCol2.ColumnName;
                            //bndcolTempId.DataField = dcCol2.ColumnName;
                            //bndcolTempId.ItemStyle.BackColor = Color.FromName("#538ED5");
                            //bndcolTempId.ItemStyle.ForeColor = Color.Black;
                            //rgAttendenceDetails.MasterTableView.Columns.Add(bndcolTempId);
 
                            tempcolTempIdType = new GridTemplateColumn();
                            tempcolTempIdType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolTempIdType.ItemTemplate = new MyTemplate(strcolName, "false", ListItemType.Item);
                            tempcolTempIdType.UniqueName = dcCol2.ColumnName;
                            tempcolTempIdType.DataField = dcCol2.ColumnName;
                            tempcolTempIdType.ItemStyle.BackColor = Color.FromName("#538ED5");
                            tempcolTempIdType.ItemStyle.ForeColor = Color.Black;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolTempIdType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["Details"].ToString();
                        }
                        else
                        {
                            //lnkbtnTempId = new GridButtonColumn();
                            //lnkbtnTempId.ButtonType = GridButtonColumnType.LinkButton;
                            //lnkbtnTempId.HeaderText = dr[i]["Day"].ToString();
                            //lnkbtnTempId.UniqueName = dcCol2.ColumnName;
                            //lnkbtnTempId.DataTextField = dcCol2.ColumnName;
                            //lnkbtnTempId.ItemStyle.BackColor = Color.FromName("#538ED5");
                            //lnkbtnTempId.ItemStyle.ForeColor = Color.Blue;
                            //lnkbtnTempId.CommandName = "AttendenceCheck";
                            //lnkbtnTempId.CommandArgument = dr[i]["Att_Date"].ToString();
                            //rgAttendenceDetails.MasterTableView.Columns.Add(lnkbtnTempId);
 
                            tempcolTempIdType = new GridTemplateColumn();
                            tempcolTempIdType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolTempIdType.ItemTemplate = new MyTemplate(strcolName, "true", ListItemType.Item);
                            tempcolTempIdType.UniqueName = dcCol2.ColumnName;
                            tempcolTempIdType.DataField = dcCol2.ColumnName;
                            tempcolTempIdType.ItemStyle.BackColor = Color.FromName("#538ED5");
                            tempcolTempIdType.ItemStyle.ForeColor = Color.Blue;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolTempIdType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["WorkedHours"].ToString().Remove(5);
                        }
                    }
                    else if (AttendenceType == AttendenceDetailsDAO.AttendenceType.WorkFromHome.ToString())
                    {
                        TimeSpan tsWorkedHours = TimeSpan.Parse(dr[i]["WorkedHours"].ToString());
 
                        if (tsWorkedHours == TimeSpan.Zero)
                        {
                            //bndcolWorkFromHome = new GridBoundColumn();
                            //bndcolWorkFromHome.HeaderText = dr[i]["Day"].ToString();
                            //bndcolWorkFromHome.UniqueName = dcCol2.ColumnName;
                            //bndcolWorkFromHome.DataField = dcCol2.ColumnName;
                            //bndcolWorkFromHome.ItemStyle.BackColor = Color.FromName("#33CC33");
                            //bndcolWorkFromHome.ItemStyle.ForeColor = Color.Black;
                            //rgAttendenceDetails.MasterTableView.Columns.Add(bndcolWorkFromHome);
 
                            tempcolWorkHomeType = new GridTemplateColumn();
                            tempcolWorkHomeType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolWorkHomeType.ItemTemplate = new MyTemplate(strcolName, "false", ListItemType.Item);
                            tempcolWorkHomeType.UniqueName = dcCol2.ColumnName;
                            tempcolWorkHomeType.DataField = dcCol2.ColumnName;
                            tempcolWorkHomeType.ItemStyle.BackColor = Color.FromName("#33CC33");
                            tempcolWorkHomeType.ItemStyle.ForeColor = Color.Black;
 
                            if (dr.Length + 1 != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolWorkHomeType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["Details"].ToString();
                        }
                        else
                        {
                            //lnkbtnWorkFromHome = new GridButtonColumn();
                            //lnkbtnWorkFromHome.ButtonType = GridButtonColumnType.LinkButton;
                            //lnkbtnWorkFromHome.HeaderText = dr[i]["Day"].ToString();
                            //lnkbtnWorkFromHome.UniqueName = dcCol2.ColumnName;
                            //lnkbtnWorkFromHome.DataTextField = dcCol2.ColumnName;
                            //lnkbtnWorkFromHome.ItemStyle.BackColor = Color.FromName("#33CC33");
                            //lnkbtnWorkFromHome.ItemStyle.ForeColor = Color.Blue;
                            //lnkbtnWorkFromHome.CommandName = "AttendenceCheck";
                            //lnkbtnWorkFromHome.CommandArgument = dr[i]["Att_Date"].ToString();
                            //rgAttendenceDetails.MasterTableView.Columns.Add(lnkbtnWorkFromHome);
 
                            tempcolWorkHomeType = new GridTemplateColumn();
                            tempcolWorkHomeType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolWorkHomeType.ItemTemplate = new MyTemplate(strcolName, "true", ListItemType.Item);
                            tempcolWorkHomeType.UniqueName = dcCol2.ColumnName;
                            tempcolWorkHomeType.DataField = dcCol2.ColumnName;
                            tempcolWorkHomeType.ItemStyle.BackColor = Color.FromName("#33CC33");
                            tempcolWorkHomeType.ItemStyle.ForeColor = Color.Blue;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolWorkHomeType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["WorkedHours"].ToString().Remove(5);
                        }
                    }
                    else if (AttendenceType == AttendenceDetailsDAO.AttendenceType.Regular.ToString())
                    {
                        TimeSpan tsWorkedHours = TimeSpan.Parse(dr[i]["WorkedHours"].ToString());
 
                        if (tsWorkedHours == TimeSpan.Zero)
                        {
                            //bndcolRegular = new GridBoundColumn();
                            //bndcolRegular.HeaderText = dr[i]["Day"].ToString();
                            //bndcolRegular.UniqueName = dcCol2.ColumnName;
                            //bndcolRegular.DataField = dcCol2.ColumnName;
                            //bndcolRegular.ItemStyle.BackColor = Color.FromName("#996633");
                            //bndcolRegular.ItemStyle.ForeColor = Color.Black;
                            //rgAttendenceDetails.MasterTableView.Columns.Add(bndcolRegular);
 
                            tempcolRegularType = new GridTemplateColumn();
                            tempcolRegularType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolRegularType.ItemTemplate = new MyTemplate(strcolName, "false", ListItemType.Item);
                            tempcolRegularType.UniqueName = dcCol2.ColumnName;
                            tempcolRegularType.DataField = dcCol2.ColumnName;
                            tempcolRegularType.ItemStyle.BackColor = Color.FromName("#996633");
                            tempcolRegularType.ItemStyle.ForeColor = Color.Black;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolRegularType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["Details"].ToString();
                        }
                        else
                        {
                            //lnkbtnRegular = new GridButtonColumn();
                            //lnkbtnRegular.ButtonType = GridButtonColumnType.LinkButton;
                            //lnkbtnRegular.HeaderText = dr[i]["Day"].ToString();
                            //lnkbtnRegular.UniqueName = dcCol2.ColumnName;
                            //lnkbtnRegular.DataTextField = dcCol2.ColumnName;
                            //lnkbtnRegular.ItemStyle.BackColor = Color.FromName("#996633");
                            //lnkbtnRegular.ItemStyle.ForeColor = Color.Blue;
                            //lnkbtnRegular.CommandName = "AttendenceCheck";
                            //lnkbtnRegular.CommandArgument = dr[i]["Att_Date"].ToString();
                            //rgAttendenceDetails.MasterTableView.Columns.Add(lnkbtnRegular);
 
                            tempcolRegularType = new GridTemplateColumn();
                            tempcolRegularType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolRegularType.ItemTemplate = new MyTemplate(strcolName, "true", ListItemType.Item);
                            tempcolRegularType.UniqueName = dcCol2.ColumnName;
                            tempcolRegularType.DataField = dcCol2.ColumnName;
                            tempcolRegularType.ItemStyle.BackColor = Color.FromName("#996633");
                            tempcolRegularType.ItemStyle.ForeColor = Color.Blue;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolRegularType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["WorkedHours"].ToString().Remove(5);
                        }
                    }
                    else if (AttendenceType == AttendenceDetailsDAO.AttendenceType.Absent.ToString())
                    {
                        TimeSpan tsWorkedHours = TimeSpan.Parse(dr[i]["WorkedHours"].ToString());
 
                        if (tsWorkedHours != TimeSpan.Zero)
                        {
                            //lnkbtnAbsent = new GridButtonColumn();
                            //lnkbtnAbsent.ButtonType = GridButtonColumnType.LinkButton;
                            //lnkbtnAbsent.HeaderText = dr[i]["Day"].ToString();
                            //lnkbtnAbsent.UniqueName = dcCol2.ColumnName;
                            //lnkbtnAbsent.DataTextField = dcCol2.ColumnName;
                            //lnkbtnAbsent.ItemStyle.BackColor = Color.FromName("#C00000");
                            //lnkbtnAbsent.ItemStyle.ForeColor = Color.Blue;
                            //lnkbtnAbsent.CommandName = "AttendenceCheck";
                            //lnkbtnAbsent.CommandArgument = dr[i]["Att_Date"].ToString();
                            //rgAttendenceDetails.MasterTableView.Columns.Add(lnkbtnAbsent);
 
                            tempcolAbsentType = new GridTemplateColumn();
                            tempcolAbsentType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolAbsentType.ItemTemplate = new MyTemplate(strcolName, "true", ListItemType.Item);
                            tempcolAbsentType.UniqueName = dcCol2.ColumnName;
                            tempcolAbsentType.DataField = dcCol2.ColumnName;
                            tempcolAbsentType.ItemStyle.BackColor = Color.FromName("#C00000");
                            tempcolAbsentType.ItemStyle.ForeColor = Color.Blue;
 
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolAbsentType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["WorkedHours"].ToString().Remove(5);
                        }
                        else
                        {
                            //bndcolAbsent = new GridBoundColumn();
                            //bndcolAbsent.HeaderText = dr[i]["Day"].ToString();
                            //bndcolAbsent.UniqueName = dr[i]["Att_Date"].ToString();
                            //bndcolAbsent.DataField = dr[i]["Att_Date"].ToString();
                            //bndcolAbsent.ItemStyle.BackColor = Color.FromName("#C00000");
                            //bndcolAbsent.ItemStyle.ForeColor = Color.Black;
                            //rgAttendenceDetails.MasterTableView.Columns.Add(bndcolAbsent);
 
                            tempcolAbsentType = new GridTemplateColumn();
                            tempcolAbsentType.HeaderText = dr[i]["Day"].ToString();
                            string strcolName = dcCol2.ColumnName;
                            tempcolAbsentType.ItemTemplate = new MyTemplate(strcolName, "false", ListItemType.Item);
                            tempcolAbsentType.UniqueName = dcCol2.ColumnName;
                            tempcolAbsentType.DataField = dcCol2.ColumnName;
                            tempcolAbsentType.ItemStyle.BackColor = Color.FromName("#C00000");
                            tempcolAbsentType.ItemStyle.ForeColor = Color.Black;
                            if (dr.Length != rgAttendenceDetails.Columns.Count - 1)
                            {
                                rgAttendenceDetails.MasterTableView.Columns.Add(tempcolAbsentType);
                            }
                            drRow[dr[i]["Att_Date"].ToString()] = dr[i]["Details"].ToString();
                        }
                    }
                }
                dtAttendence.Rows.Add(drRow);
 
            }
 
            rgAttendenceDetails.DataSource = dtAttendence;
            rgAttendenceDetails.DataBind();
        }
 
        private ArrayList GetCheckedItems()
        {
            ArrayList checkedItems = new ArrayList();
 
            foreach (RadComboBoxItem item in rcbxEmployee.Items)
            {
                CheckBox checkBox = (CheckBox)item.FindControl("chkEmployee");
 
                if (checkBox.Checked)
                {
                    checkedItems.Add(item);
                }
            }
            return checkedItems;
        }
 
        private void LoadRadCmboxType()
        {
            List<AttendenceDetailsEntities> objAttendenceDetailsEntitiesList = null;
            objAttendenceDetailsEntities = null;
            objAttendenceDetailsEntitiesList = objAttendenceDetailsDAO.GetTypes();
            rcbxType.DataSource = objAttendenceDetailsEntitiesList;
            rcbxType.DataValueField = "TypeId";
            rcbxType.DataTextField = "TypeName";
            rcbxType.DataBind();
        }
 
        private void LoadRadCboxEmployee()
        {
            List<AttendenceDetailsEntities> objAttendenceDetailsEntitiesList = null;
            objAttendenceDetailsEntities.EmployeId = EmpId;
            objAttendenceDetailsEntitiesList = objAttendenceDetailsDAO.GetEmployeeName(objAttendenceDetailsEntities);
            rcbxEmployee.DataSource = objAttendenceDetailsEntitiesList;
            rcbxEmployee.DataTextField = "EmployeId";
            this.rcbxEmployee.DataBind();
        }
 
        private void LoadAttendenceGridPopUp()
        {
            DataSet AttdataSet = new DataSet();
            AttdataSet = objAttendenceDetailsDAO.GetAttPunchedInandOutDtls(objAttendenceDetailsEntities);
            DataTable dtAttendence = new DataTable();
            DataRow drAttendence = null;
 
            dtAttendence.Columns.Add("PunchIn", typeof(string));
            dtAttendence.Columns.Add("PunchOut", typeof(string));
            dtAttendence.Columns.Add("PunchIn2", typeof(string));
            dtAttendence.Columns.Add("PunchOut2", typeof(string));
            dtAttendence.Columns.Add("PunchIn3", typeof(string));
            dtAttendence.Columns.Add("PunchOut3", typeof(string));
            dtAttendence.Columns.Add("PunchIn4", typeof(string));
            dtAttendence.Columns.Add("PunchOut4", typeof(string));
 
            drAttendence = dtAttendence.NewRow();
 
            for (int i = 0; i < AttdataSet.Tables[0].Rows.Count; i++)
            {
                if (i == 0)
                {
                    drAttendence["PunchIn"] = AttdataSet.Tables[0].Rows[i]["Punch_In"].ToString().Remove(5);
                    drAttendence["PunchOut"] = AttdataSet.Tables[0].Rows[i]["Punch_Out"].ToString().Remove(5);
                }
                else if (i == 1)
                {
                    drAttendence["PunchIn2"] = AttdataSet.Tables[0].Rows[i]["Punch_In"].ToString().Remove(5);
                    drAttendence["PunchOut2"] = AttdataSet.Tables[0].Rows[i]["Punch_Out"].ToString().Remove(5);
                }
                else if (i == 2)
                {
                    drAttendence["PunchIn3"] = AttdataSet.Tables[0].Rows[i]["Punch_In"].ToString().Remove(5);
                    drAttendence["PunchOut3"] = AttdataSet.Tables[0].Rows[i]["Punch_Out"].ToString().Remove(5);
                }
                else if (i == 3)
                {
                    drAttendence["PunchIn4"] = AttdataSet.Tables[0].Rows[i]["Punch_In"].ToString().Remove(5);
                    drAttendence["PunchOut4"] = AttdataSet.Tables[0].Rows[i]["Punch_Out"].ToString().Remove(5);
                }
            }
            dtAttendence.Rows.Add(drAttendence);
            rgMyAttendenceDetails.DataSource = dtAttendence;
            rgMyAttendenceDetails.DataBind();
            LoadRadCmboxType();
        }
 
        private class MyTemplate : ITemplate, IBindableTemplate
        {
            protected LinkButton lnkButton;
            protected LiteralControl lControl;
            private string colname;
            private string controlType;
            private ListItemType lstItemType;
            private string controlId;
            private string literalId;
            private string lnkbuttonId;
 
            public MyTemplate(string CName, string ctlType, ListItemType type)
            {
                this.colname = CName;
                this.controlType = ctlType; ;
                this.lstItemType = type;
                literalId = "lbl_" + type.ToString() + "_" + CName;
                lnkbuttonId = "lnk_" + type.ToString() + "_" + CName;
            }
 
            public void InstantiateIn(System.Web.UI.Control container)
            {
                switch (lstItemType)
                {
                    case ListItemType.Item:
                        if (controlType == "true")
                        {
                            lnkButton = new LinkButton();
                            controlId = "lnk_" + lstItemType.ToString() + "_" + colname;
                            lnkButton.ID = controlId;
                            lnkButton.Enabled = true;
                            lnkButton.CommandName = "AttendenceCheck";
                            lnkButton.DataBinding += new EventHandler(lnkButton_DataBinding);
                            container.Controls.Add(lnkButton);
                        }
                        else if (controlType == "false")
                        {
                            lnkButton = new LinkButton();
                            controlId = "lnk_" + lstItemType.ToString() + "_" + colname;
                            lnkButton.ID = controlId;
                            lnkButton.Enabled = false;
                            lnkButton.DataBinding += new EventHandler(lnkButton_DataBinding);
                            container.Controls.Add(lnkButton);
                        }
                        break;
                }
            }
 
            public void lnkButton_DataBinding(object sender, EventArgs e)
            {
                LinkButton lnk = (LinkButton)sender;
                GridDataItem container = (GridDataItem)lnk.NamingContainer;
                lnk.Text = ((DataRowView)container.DataItem)[colname].ToString();
            }
 
            //public void lControl_DataBinding(object sender, EventArgs e)
            //{
            //    LiteralControl ltlControl = (LiteralControl)sender;
            //    GridDataItem container = (GridDataItem)ltlControl.NamingContainer;
            //    ltlControl.Text = ((DataRowView)container.DataItem)[colname].ToString();
            //}
 
            public System.Collections.Specialized.IOrderedDictionary ExtractValues(System.Web.UI.Control container)
            {
                OrderedDictionary od = new OrderedDictionary();
 
                od.Add("ProviderName", ((LinkButton)((GridDataItem)container).FindControl(controlId)).Text);
 
                return od;
            }
        }
    }
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using MSI.DataAccess;
using Entities;
using MSI.Logging;
using System.Reflection;
using System.ComponentModel;
 
namespace AttendenceManagement.Business_Layer
{
    public class AttendenceDetailsDAO
    {
        //DataAccess objects Declared to set connection to Database.
        MSI.DataAccess.DataAccess objDataAccess = new MSI.DataAccess.DataAccess();
        Entities.DataAccess objdAccess = new Entities.DataAccess();
        LoggingClass objLoggingClass = new LoggingClass();
 
        /// <summary>
        ///Method Required to Declare Enums for Constants.
        /// </summary>
        public enum AttendenceType
        {
            [DescriptionAttribute("P")]
            Present = 1,
            [DescriptionAttribute("A")]
            Absent = 2,
            [DescriptionAttribute("H")]
            Holiday,
            [DescriptionAttribute("RH")]
            RestrictedHoliday,
            [DescriptionAttribute("C")]
            CompOFF,
            [DescriptionAttribute("L")]
            Leave,
            [DescriptionAttribute("T")]
            TemporaryId,
            [DescriptionAttribute("WH")]
            WorkFromHome,
            [DescriptionAttribute("R")]
            Regular
        }
 
 
 
        /// <summary>
        /// Method Requried to represent String Enums.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string GetEnumDescription(Enum value)
        {
            FieldInfo fi = value.GetType().GetField(value.ToString());
 
            DescriptionAttribute[] attributes =
                (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false);
 
            if (attributes != null && attributes.Length > 0)
                return attributes[0].Description;
            else
                return value.ToString();
        }
        /// <summary>
        /// Method to Reterive Attendence Details for an Employee for a given date.
        /// </summary>
        /// <param name="objAttDtls"></param>
        /// <returns></returns>
        public DataSet GetAttendenceDetails(AttendenceDetailsEntities objAttDtls)
        {
            try
            {
                SqlParameter[] sqlParameter = new SqlParameter[3];
                sqlParameter[0] = new SqlParameter("@FromDate", SqlDbType.Date);
                sqlParameter[0].Value = objAttDtls.FromDate;
                sqlParameter[1] = new SqlParameter("@ToDate", SqlDbType.Date);
                sqlParameter[1].Value = objAttDtls.ToDate;
                sqlParameter[2] = new SqlParameter("@EmpId", SqlDbType.NVarChar);
                sqlParameter[2].Value = objAttDtls.EmployeId;
                DataSet dataSet = new DataSet();
                dataSet = objDataAccess.GetDataSet("Attendence_SEL", sqlParameter);
                return dataSet;
            }
            catch (Exception ex)
            {
                objLoggingClass.WriteToErrorLog(ex.Message);
                throw ex;
            }
        }
 
        /// <summary>
        /// Method to Reterive Attendence Details by Concatenating Hours and Minutes.
        /// </summary>
        /// <param name="objAttDtls"></param>
        /// <returns></returns>
        public DataSet GetFullAttendenceDetails(AttendenceDetailsEntities objAttDtls)
        {
            DataSet configdataSet = new DataSet();
            configdataSet = GetConfigurationDetails();
            DataSet dataSet = new DataSet();
            TimeSpan tsWorkHoursDay;
            DataSet daTemp = new DataSet();
            daTemp = GetAttendenceDetails(objAttDtls);
            daTemp.Tables[0].Columns.Add("WorkedHours");
            daTemp.Tables[0].Columns.Add("Details");
            daTemp.Tables[0].Columns.Add("Day");
            DataSet dsLeaveType = new DataSet();
            dsLeaveType = GetLeaveTypeDetails(objAttDtls);
            string[] strarryEmpId = objAttDtls.EmployeId.Split(',');
 
            try
            {
                for (int iLength = 0; iLength <strarryEmpId.Length; iLength++)
                {
                    for (DateTime currDate = objAttDtls.FromDate.Date; currDate <= objAttDtls.ToDate.Date; currDate = currDate.AddDays(1))
                    {
                        //daTemp.Tables[0].DefaultView.Table.Select("Att_Date="+currDate.ToString());
                        string curdate = currDate.ToString("yyyy-MM-dd");
                        DataRow[] dr = daTemp.Tables[0].Select("Att_Date=#" + curdate + "# and Emp_ID='" + strarryEmpId[iLength].ToString() + "'");
                        //daTemp.Tables[0].DefaultView.RowFilter = "Att_Date=#"+curdate+"#";
                        DataRow[] drLeaveType = dsLeaveType.Tables[0].Select("Date=#" + curdate + "# and Emp_ID='" + strarryEmpId[iLength].ToString() + "'");
 
                        if (dr.Length != 0)
                        {
                            string strHoursWorked = Convert.ToString(dr[0]["Hours_worked"]);
                            string strMinsWorked = Convert.ToString(dr[0]["Minutes_worked"]);
                            string strAttType = Convert.ToString(dr[0]["Att_Type"]);
                            string strWorkHoursDay;
                            if (strHoursWorked != "" && strMinsWorked != "")
                            {
                                strWorkHoursDay = strHoursWorked + ":" + strMinsWorked;
                                tsWorkHoursDay = TimeSpan.Parse(strWorkHoursDay);
                            }
                            else
                            {
                                tsWorkHoursDay = TimeSpan.Zero;
                            }
 
                            string strConfigWorkHoursDay = Convert.ToString(configdataSet.Tables[0].Rows[0]["workHourDay"]);
                            TimeSpan tsConfigWorkHoursDay = TimeSpan.Parse(strConfigWorkHoursDay);
                            dr[0]["Day"] = currDate.Day;
                            dr[0]["WorkedHours"] = tsWorkHoursDay;
                            objAttDtls.Date = currDate;
                            
                            if (tsWorkHoursDay >= tsConfigWorkHoursDay)
                            {
                                dr[0]["Details"] = AttendenceType.Present;
                            }
                            else if (currDate.DayOfWeek.ToString() == "Sunday" || currDate.DayOfWeek.ToString() == "Saturday")
                            {
                                dr[0]["Details"] = AttendenceType.Holiday;
                            }
                            else if (strAttType == "TempID")
                            {
                                dr[0]["Details"] = AttendenceType.TemporaryId;
                            }
                            else if (strAttType == "WH")
                            {
                                dr[0]["Details"] = AttendenceType.WorkFromHome;
                            }
                            else if (strAttType == "Regular")
                            {
                                dr[0]["Details"] = AttendenceType.Regular;
                            }
                            else if (drLeaveType.Length != 0)
                            {
                                string strLeaveType = Convert.ToString(drLeaveType[0]["LeaveType"]);
                                if (strLeaveType == "CompOff")
                                {
                                    dr[0]["Details"] = AttendenceType.CompOFF;
                                }
                                else if (strLeaveType == "Leave")
                                {
                                    dr[0]["Details"] = AttendenceType.Leave;
                                }
                                else if (strLeaveType == "RH")
                                {
                                    dr[0]["Details"] = AttendenceType.RestrictedHoliday;
                                }
                                else if (strLeaveType == "Holiday")
                                {
                                    dr[0]["Details"] = AttendenceType.Holiday;
                                }
                            }
                            else
                            {
                                dr[0]["Details"] = AttendenceType.Absent;
                            }
 
                        }
                        else
                        {
                            DataRow drtemp = daTemp.Tables[0].NewRow();
                            drtemp["Emp_ID"] = strarryEmpId[iLength].ToString();
                            drtemp["Att_Date"] = curdate;
                            drtemp["Day"] = currDate.Day;
                            drtemp["WorkedHours"] = "00:00:00";
                            if (currDate.DayOfWeek.ToString() == "Sunday" || currDate.DayOfWeek.ToString() == "Saturday")
                            {
                                drtemp["Details"] = AttendenceType.Holiday;
 
                            }
                            else if (drLeaveType.Length != 0)
                            {
                                string strLeaveType = Convert.ToString(drLeaveType[0]["LeaveType"]);
                                if (strLeaveType == "CompOff")
                                {
                                    drtemp["Details"] = AttendenceType.CompOFF;
                                }
                                else if (strLeaveType == "Leave")
                                {
                                    drtemp["Details"] = AttendenceType.Leave;
                                }
                                else if (strLeaveType == "RH")
                                {
                                    drtemp["Details"] = AttendenceType.RestrictedHoliday;
                                }
                                else if (strLeaveType == "Holiday")
                                {
                                    drtemp["Details"] = AttendenceType.Holiday;
                                }
                            }
                            else
                            {
                                drtemp["Details"] = AttendenceType.Absent.ToString();
                            }
                            daTemp.Tables[0].Rows.Add(drtemp);
                        }
                    }
 
                }
                return daTemp;
            }
            catch (Exception ex)
            {
                objLoggingClass.WriteToErrorLog(ex.Message);
                throw ex;
            }
        }
 
        /// <summary>
        /// Method to Reterive Configuration Details.
        /// </summary>
        /// <returns></returns>
        public DataSet GetConfigurationDetails()
        {
            try
            {
                SqlParameter[] sqlParameter = new SqlParameter[0];
                DataSet configdataSet = new DataSet();
                configdataSet = objDataAccess.GetDataSet("ConfigurationSettings_Sel", sqlParameter);
                return configdataSet;
            }
            catch (Exception ex)
            {
                objLoggingClass.WriteToErrorLog(ex.Message);
                throw ex;
            }
        }
 
        /// <summary>
        /// Method to Reterive the Leave Type Details.
        /// </summary>
        /// <param name="objAttDtls"></param>
        /// <returns></returns>
        public DataSet GetLeaveTypeDetails(AttendenceDetailsEntities objAttDtls)
        {
            try
            {
                SqlParameter[] sqlParameter = new SqlParameter[3];
                sqlParameter[0] = new SqlParameter("@FromDate", SqlDbType.Date);
                sqlParameter[0].Value = objAttDtls.FromDate;
                sqlParameter[1] = new SqlParameter("@Todate", SqlDbType.Date);
                sqlParameter[1].Value = objAttDtls.ToDate;
                sqlParameter[2] = new SqlParameter("@EmpId", SqlDbType.NVarChar);
                sqlParameter[2].Value = objAttDtls.EmployeId;
                DataSet dataSet = new DataSet();
                dataSet = objDataAccess.GetDataSet("LeaveType_sel", sqlParameter);
                return dataSet;
 
            }
            catch (Exception ex)
            {
                objLoggingClass.WriteToErrorLog(ex.Message);
                throw ex;
            }
        }
 
        /// <summary>
        /// Method to Reterive the Attendence Punched In and Out Detials
        /// </summary>
        /// <param name="objAttDtls"></param>
        /// <returns></returns>
        public DataSet GetAttPunchedInandOutDtls(AttendenceDetailsEntities objAttDtls)
        {
            try
            {
                SqlParameter[] sqlParameter = new SqlParameter[2];
                sqlParameter[0] = new SqlParameter("@EmpId", SqlDbType.NVarChar);
                sqlParameter[0].Value = objAttDtls.EmployeId;
                sqlParameter[1] = new SqlParameter("@Date", SqlDbType.Date);
                sqlParameter[1].Value = objAttDtls.Date;
                DataSet dataSet = new DataSet();
                dataSet = objDataAccess.GetDataSet("AttendenceDetails_SEL", sqlParameter);
                return dataSet;
            }
            catch (Exception ex)
            {
                objLoggingClass.WriteToErrorLog(ex.Message);
                throw ex;
            }
        }
 
        /// <summary>
        /// Method To Reterive Type Details and Bind it to Type Combobox.
        /// </summary>
        /// <returns></returns>
        public List<AttendenceDetailsEntities> GetTypes()
        {
            List<AttendenceDetailsEntities> objAttendenceDetailsEntitiesList = null;
            AttendenceDetailsEntities objAttendenceDetailsEntities = null;
 
            try
            {
                SqlParameter[] sqlParameter = new SqlParameter[0];
                DataSet typedataSet = new DataSet();
                typedataSet = objDataAccess.GetDataSet("Types_SEL", sqlParameter);
                if (typedataSet != null && typedataSet.Tables.Count > 0 && typedataSet.Tables[0].Rows.Count > 0)
                {
                    objAttendenceDetailsEntitiesList = new List<AttendenceDetailsEntities>();
                    //for a blank entry
                    objAttendenceDetailsEntities = new AttendenceDetailsEntities();
                    objAttendenceDetailsEntities.TypeId = 0;
                    objAttendenceDetailsEntities.TypeName = "";
                    objAttendenceDetailsEntitiesList.Add(objAttendenceDetailsEntities);
 
                    foreach (DataRow row in typedataSet.Tables[0].Rows)
                    {
                        objAttendenceDetailsEntities = new AttendenceDetailsEntities();
                        objAttendenceDetailsEntities.TypeId = Convert.ToInt32(row["TypeId"]);
                        objAttendenceDetailsEntities.TypeName = Convert.ToString(row["TypeName"]);
                        objAttendenceDetailsEntitiesList.Add(objAttendenceDetailsEntities);
                    }
                }
                return objAttendenceDetailsEntitiesList;
            }
            catch (Exception ex)
            {
                objLoggingClass.WriteToErrorLog(ex.Message);
                throw ex;
            }
        }
 
        /// <summary>
        /// Method To Reterive Employee Details and Bind it to Employee Combobox.
        /// </summary>
        /// <returns></returns>
        public List<AttendenceDetailsEntities> GetEmployeeName(AttendenceDetailsEntities objAttendenceDetailsEntities)
        {
            List<AttendenceDetailsEntities> objAttendenceDetailsEntitiesList = null;           
 
            try
            {
                SqlParameter[] sqlParameter = new SqlParameter[1];
                sqlParameter[0] = new SqlParameter("@Emp_ID", SqlDbType.NVarChar);
                sqlParameter[0].Value = objAttendenceDetailsEntities.EmployeId;
                DataSet typedataSet = new DataSet();
                typedataSet = objDataAccess.GetDataSet("Employee_SEL", sqlParameter);
                if (typedataSet != null && typedataSet.Tables.Count > 0 && typedataSet.Tables[0].Rows.Count > 0)
                {
                    objAttendenceDetailsEntitiesList = new List<AttendenceDetailsEntities>();
                    //for a blank entry
                    objAttendenceDetailsEntities = new AttendenceDetailsEntities();
                    objAttendenceDetailsEntities.EmployeId = "";
                    objAttendenceDetailsEntitiesList.Add(objAttendenceDetailsEntities);
 
                    foreach (DataRow row in typedataSet.Tables[0].Rows)
                    {
                        objAttendenceDetailsEntities = new AttendenceDetailsEntities();
                        objAttendenceDetailsEntities.EmployeId = Convert.ToString(row["Emp_ID"]);
                        objAttendenceDetailsEntitiesList.Add(objAttendenceDetailsEntities);
                    }
                }
                return objAttendenceDetailsEntitiesList;
 
            }
            catch (Exception ex)
            {
                objLoggingClass.WriteToErrorLog(ex.Message);
                throw ex;
            }
        }
        /// <summary>
        /// Method To Save Status Details To DataBase.
        /// </summary>
        /// <param name="objAttendenceDetailsEntities"></param>
        public void SaveStatusDetails(AttendenceDetailsEntities objAttendenceDetailsEntities)
        {
            try
            {
                SqlParameter[] sqlParameter = new SqlParameter[6];
                sqlParameter[0] = new SqlParameter("@EmpId", SqlDbType.VarChar);
                sqlParameter[0].Value = objAttendenceDetailsEntities.EmployeId;
                sqlParameter[1] = new SqlParameter("@Date", SqlDbType.Date);
                sqlParameter[1].Value = objAttendenceDetailsEntities.Date;
                sqlParameter[2] = new SqlParameter("@RequestComment", SqlDbType.VarChar);
                sqlParameter[2].Value = objAttendenceDetailsEntities.RequestComment;
                sqlParameter[3] = new SqlParameter("@ResponseComment", SqlDbType.VarChar);
                sqlParameter[3].Value = objAttendenceDetailsEntities.ResponseComment;
                sqlParameter[4] = new SqlParameter("@TypeId", SqlDbType.Int);
                sqlParameter[4].Value = objAttendenceDetailsEntities.TypeId;
                sqlParameter[5] = new SqlParameter("@Status", SqlDbType.VarChar);
                sqlParameter[5].Value = objAttendenceDetailsEntities.Status;
 
                objDataAccess.SaveData("Status_INS", sqlParameter);
            }
            catch (Exception ex)
            {
                objLoggingClass.WriteToErrorLog(ex.Message);
                throw ex;
            }
        }
    }
}
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="AttendenceDetails.ascx.cs"
    Inherits="AttendenceManagement.Controls.AttendenceDetailsGrid" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<link href="../CSS/AttendenceStyle.css" rel="stylesheet" type="text/css" />
<link href="../CSS/TelerikCustomSkins/Grid.css" rel="stylesheet" type="text/css" />
 
<script type="text/javascript">
    function stopPropagation(e) {
        e.cancelBubble = true;
 
        if (e.stopPropagation) {
            e.stopPropagation();
        }
    }
 
</script>
 
<div class="divMainContent">
    <div class="divPickerLabel">
        <div class="divPicker">
            <div class="divFromDate">
                <asp:Label ID="lblFromDate" runat="server" Text="From"></asp:Label>
                <telerik:RadDatePicker ID="rdpFrom" runat="server" CssClass="rtxtFromStyle" Width="125px">
                </telerik:RadDatePicker>
            </div>
            <div class="divToDate">
                <asp:Label ID="lblToDate" runat="server" Text="To">
                </asp:Label>
                <telerik:RadDatePicker ID="rdpTo" runat="server" CssClass="rtxtToStyle" Width="125px">
                </telerik:RadDatePicker>
            </div>
            <div class="divSelectEmployee">
                <asp:Label ID="lblSelectEmployee" runat="server" Text="Select Employee" Visible="True"></asp:Label>
                <telerik:RadComboBox ID="rcbxEmployee" runat="server" CssClass="rcbxEmployeeStyle"
                    HighlightTemplatedItems="true" Visible="True" Width="125px">
                    <ItemTemplate>
                        <asp:CheckBox ID="chkEmployee" runat="server" onclick="stopPropagation(event);" Text="" />
                        <%# DataBinder.Eval(Container,"Text")%>
                    </ItemTemplate>
                </telerik:RadComboBox>
                <telerik:RadButton ID="rbtnSelect" runat="server" Text="Select" OnClick="rbtnSelect_Click"
                    CssClass="rbtnSelectStyle">
                </telerik:RadButton>
            </div>
            <div class="divbtnSelect">
            </div>
        </div>
        <div class="divfromdatetodatelbl">
            <asp:Label ID="lblAttendenceDetaisFrom" runat="server" Text="Attendence Details From"></asp:Label>
            <asp:Label ID="lblFromdatewithyear" runat="server"></asp:Label>
            <asp:Label ID="lblTo" runat="server" Text="To"></asp:Label>
            <asp:Label ID="lblTodatewithyear" runat="server"></asp:Label>
        </div>
    </div>
    <div class="divlegend">
        <asp:Panel ID="pnllegend" runat="server" BackColor="Gray" Width="160px" Height="192px">
            <div class="divStatus">
                <telerik:RadTextBox ID="rtxtPresent" runat="server" Text="P" BackColor="White" Width="25px"
                    BorderStyle="None">
                </telerik:RadTextBox>
                <asp:Label ID="lblPresent" runat="server" Text="Present" ForeColor="White"></asp:Label></div>
            <div class="divStatus" style="position: relative; margin: 0px 0px 0px 5px;">
                <telerik:RadTextBox ID="rtxtLeave" runat="server" Text="L" BackColor="#FFFF99" Width="25px"
                    BorderStyle="None">
                </telerik:RadTextBox>
                <asp:Label ID="lblLeave" runat="server" Text="Leave" ForeColor="White"></asp:Label></div>
            <div class="divStatus">
                <telerik:RadTextBox ID="rtxtAbsent" runat="server" Text="A" BackColor="#C00000" Width="25px"
                    BorderStyle="None">
                </telerik:RadTextBox>
                <asp:Label ID="lblAbsent" runat="server" Text="Absent" ForeColor="White"></asp:Label></div>
            <div class="divStatus">
                <telerik:RadTextBox ID="rtxtHoliday" runat="server" Text="H" BackColor="#31849B"
                    Width="25px" BorderStyle="None">
                </telerik:RadTextBox>
                <asp:Label ID="lblHoilday" runat="server" Text="Holiday" ForeColor="White"></asp:Label></div>
            <div class="divStatus">
                <telerik:RadTextBox ID="rtxtCompoff" runat="server" Text="C" BackColor="#E6B9B8"
                    Width="25px" BorderStyle="None">
                </telerik:RadTextBox>
                <asp:Label ID="lblCompoff" runat="server" Text="CompOff" ForeColor="White"></asp:Label></div>
            <div class="divStatus">
                <telerik:RadTextBox ID="rtxtTemporaryId" runat="server" Text="T" BackColor="#538ED5"
                    Width="25px" BorderStyle="None">
                </telerik:RadTextBox>
                <asp:Label ID="lblTemporaryId" runat="server" Text="TemporaryId" ForeColor="White"></asp:Label>
            </div>
            <div class="divStatus">
                <telerik:RadTextBox ID="rtxtWorkFromHome" runat="server" Text="WH" BackColor="#33CC33"
                    Width="25px" BorderStyle="None">
                </telerik:RadTextBox>
                <asp:Label ID="lblWorkFromHome" runat="server" Text="WorkFromHome" ForeColor="White"></asp:Label>
            </div>
             <div class="divStatus">
                <telerik:RadTextBox ID="rtxtRegular" runat="server" Text="R" BackColor="#996633"
                    Width="25px" BorderStyle="None">
                </telerik:RadTextBox>
                <asp:Label ID="lblRegular" runat="server" Text="Regular" ForeColor="White"></asp:Label>
            </div>
        </asp:Panel>
    </div>
</div>
<div class="divrGrid">
    <telerik:RadGrid ID="rgAttendenceDetails" runat="server" GridLines="Both" AutoGenerateColumns="false"
        ShowHeader="true" ShowFooter="true" EnableEmbeddedSkins="false" OnItemCommand="rgAttendenceDetails_ItemCommand"
        OnItemDataBound="rgAttendenceDetails_ItemDataBound" Skin="Internal" CssClass="RadGridStyle">
        <HeaderStyle VerticalAlign="Middle" HorizontalAlign="Center" CssClass="RadGridStyle" />
        <MasterTableView AutoGenerateColumns="false" EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="true"
            ShowHeader="true" ShowFooter="true" CssClass="RadGridStyle">
            <NoRecordsTemplate>
                <div>
                    <asp:Literal ID="ltlNoRecords" runat="server" Text="No Records"></asp:Literal>
                </div>
            </NoRecordsTemplate>
        </MasterTableView>
    </telerik:RadGrid>
</div>
<div>
    <telerik:RadWindowManager ID="rwmAttendenceDetails" runat="server" ShowContentDuringLoad="false"
        VisibleStatusbar="false" ReloadOnShow="true" Modal="true" VisibleTitlebar="false"
        Behaviors="Close" EnableViewState="false" EnableEmbeddedSkins="false">
        <Windows>
            <telerik:RadWindow ID="rwdAttendenceDetails" runat="server" ShowContentDuringLoad="true"
                VisibleStatusbar="false" Modal="true" EnableShadow="true" VisibleTitlebar="false"
                VisibleOnPageLoad="false" Behaviors="Close" Overlay="true" BorderWidth="0" BorderStyle="None"
                Height="500px" Width="800px">
                <ContentTemplate>
                    <asp:Panel ID="pnlWindow" runat="server">
                        <div class="divClose">
                            <telerik:RadButton ID="rbClose" runat="server" ButtonType="LinkButton" Text="Close"
                                OnClick="rbClose_Click">
                            </telerik:RadButton>
                        </div>
                        <div class="divlblAttendenceDetails">
                            <asp:Label ID="lblAttendenceDetails" runat="server" Text="My Attendence Details"></asp:Label>
                        </div>
                        <div class="divEmplyeeDetail">
                            <asp:Label ID="lblEmployeeName" runat="server" Text="Employee Name"></asp:Label>
                            <telerik:RadTextBox ID="rtxtEmployeeName" runat="server" CssClass="rtxtEmployeeNameStyle"
                                Width="160px">
                            </telerik:RadTextBox>
                            <asp:Label ID="lblDate" runat="server" Text="Date" CssClass="lblDateStyle"></asp:Label>
                            <telerik:RadTextBox ID="rtxtDate" runat="server" CssClass="rtbxDateStyle" Width="160px">
                            </telerik:RadTextBox>
                        </div>
                        <div class="divGrid">
                            <telerik:RadGrid ID="rgMyAttendenceDetails" runat="server" GridLines="None" AutoGenerateColumns="false"
                                ShowHeader="true" ShowFooter="true" EnableEmbeddedSkins="false" OnNeedDataSource="rgMyAttendenceDetails_NeedDataSource"
                                Skin="Internal" CssClass="RadGridStyle">
                                <HeaderStyle VerticalAlign="Middle" HorizontalAlign="Center" CssClass="RadGridStyle" />
                                <MasterTableView AutoGenerateColumns="false" EnableNoRecordsTemplate="true" ShowHeadersWhenNoRecords="true"
                                    ShowHeader="true" ShowFooter="true" CssClass="RadGridStyle">
                                    <NoRecordsTemplate>
                                        <div>
                                            <asp:Literal ID="ltlNoRecords" runat="server" Text="No Records"></asp:Literal>
                                        </div>
                                    </NoRecordsTemplate>
                                    <Columns>
                                        <telerik:GridBoundColumn HeaderText="PunchIn" DataField ="PunchIn">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="PunchOut" DataField="PunchOut">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="PunchIn2" DataField="PunchIn2">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="PunchOut2" DataField="PunchOut2">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="PunchIn3" DataField="PunchIn3">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="PunchOut3" DataField="PunchOut3">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="PunchIn4" DataField="PunchIn4">
                                        </telerik:GridBoundColumn>
                                        <telerik:GridBoundColumn HeaderText="PunchOut4" DataField="PunchOut4">
                                        </telerik:GridBoundColumn>
                                    </Columns>
                                </MasterTableView>
                            </telerik:RadGrid>
                            <asp:Label ID="lblDetails" runat="server" Visible="True"></asp:Label>
                        </div>
                        <div class="divComments">
                            <asp:Label ID="lblComments" runat="server" Text="Comments" Visible="true"></asp:Label>
                            <telerik:RadTextBox ID="rtbxComments" runat="server" Width="350px" Height="50px"
                                TextMode="MultiLine" MaxLength="300" CssClass="rtbxCommentsStyle" Visible="true">
                            </telerik:RadTextBox>
                        </div>
                        <div class="divType">
                            <asp:Label ID="lblType" runat="server" Text="Type" Visible="true"></asp:Label>
                            <telerik:RadComboBox ID="rcbxType" runat="server" CssClass="rcbxTypeStyle" Visible="true"
                                AutoPostBack="false" Width="125px">
                            </telerik:RadComboBox>
                        </div>
                        <div class="divbtn">
                            <telerik:RadButton ID="rbOk" runat="server" Text="Ok" ButtonType="StandardButton"
                                Width="75px" Visible="true" OnClick="rbOk_Click">
                            </telerik:RadButton>
                            <telerik:RadButton ID="rbSendMail" runat="server" Text="SendMail" ButtonType="StandardButton"
                                Width="75px" Visible="true" OnClick="rbSendMail_Click">
                            </telerik:RadButton>
                            <telerik:RadButton ID="rbApprove" runat="server" Text="Approve" ButtonType="StandardButton"
                                Width="75px" Visible="false">
                            </telerik:RadButton>
                            <telerik:RadButton ID="rbReject" runat="server" Text="Reject" ButtonType="StandardButton"
                                Width="75px" Visible="false">
                            </telerik:RadButton>
                        </div>
                    </asp:Panel>
                </ContentTemplate>
            </telerik:RadWindow>
        </Windows>
    </telerik:RadWindowManager>
</div>


1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 06 Nov 2012, 08:30 AM
Hi Naveen,

To remove the sorting functionality of GridTemplateColumn you could try setting the GridTemplateColumn.SortExpression property to empty string.
...
GridTemplateColumn tempcolPresentType = new GridTemplateColumn();
tempcolPresentType. SortExpression = String.Empty;
...

Please give it try and let me know if it helps you.

Greetings,
Radoslav
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Naveen kumar
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or