Click here to Skip to main content
16,020,103 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
this is my ASPX code

<%@ Page Title="Add Adhoc" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="AddAdhocRoster.aspx.cs" Inherits="AddAdhocRoster" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="Act" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server">
<script type="text/javascript">

function CheckBoxListValidator(source, arguments) {
var Control;
Control = document.getElementById(source).getElementsByTagName("input");
var check = false;
if (eval(Control)) {
for (var i = 0; i < Control.length; i++) {
if (Control[i].tagName == 'INPUT') {

if (Control[i].checked) {
check = true;
}
}
}
if (!check)
arguments.IsValid = false;
else
arguments.IsValid = true;
}
}


function DownloadTemplate() {
var win = window.open('../Roster/Download/UploadRoster.xlsx', '', '');
return false;
}

var updateProgress = null;

function postbackButtonClick() {
updateProgress = $find("<%= UpdateProgress2.ClientID %>");
window.setTimeout("updateProgress.set_visible(true)", updateProgress.get_displayAfter());
return true;
}

</script>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="Server">
<asp:Panel ID="pnlMessage" runat="server" Visible="false">

You are not eligible for adding adhoc request.

You have opt-out for transport facility


<asp:Panel ID="pnlPage" runat="server">
<asp:UpdateProgress ID="UpdateProgsress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<progresstemplate>
<%--<img src="~/Images/Loading.gif" alt="" />--%>
<asp:Image ImageUrl="~/Images/Loading.gif" runat="server" ID="Lodingimg" Style="position: absolute; top: 140px; left: 30px;" />


<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<contenttemplate>

Add Adhoc Request


<asp:RadioButton ID="rbtSingle" runat="server" Visible="false" CssClass="bulkcss"
Checked="true" Text="Single" OnCheckedChanged="rbtSingle_CheckedChanged" AutoPostBack="true" />
<asp:RadioButton ID="rbtBulk" runat="server" Visible="false" CssClass="bulkcss"
Text="Bulk Adhoc Upload" OnCheckedChanged="rbtBulk_CheckedChanged" AutoPostBack="true" />



<asp:Panel ID="pnlsingle" runat="server">

<table id="tblEmpProc" runat="server" cellpadding="2" cellspacing="1" style="border-collapse: collapse;" class="page-tbl">
Select Site
<asp:DropDownList ID="ddlSite" AutoPostBack="true" runat="server" OnSelectedIndexChanged="ddlSite_SelectedIndexChanged"
ValidationGroup="Add-DisplayAdhoc">

<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="Please select Site"
ValidationGroup="Add-DisplayAdhoc" SetFocusOnError="true" InitialValue="" ControlToValidate="ddlSite"
ForeColor="#CC3300">
Select Process
<asp:DropDownList ID="ddlProcess" Enabled="false" AutoPostBack="true" runat="server"
OnSelectedIndexChanged="ddlProcess_SelectedIndexChanged" ValidationGroup="Add-DisplayAdhoc">

<asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ErrorMessage="Please select Process"
ValidationGroup="Add-DisplayAdhoc" SetFocusOnError="true" InitialValue="" ControlToValidate="ddlProcess"
ForeColor="#CC3300">




<table id="tblTMSelf" runat="server" cellpadding="2" cellspacing="1" width="100%" style="border-collapse: collapse;" visible="true" class="page-tbl">
Adhoc For
<asp:DropDownList ID="ddlTMSelf" runat="server" ValidationGroup="Add-DisplayAdhoc"
AutoPostBack="True"
OnSelectedIndexChanged="ddlTMSelf_SelectedIndexChanged">
<asp:ListItem Value="select">-Select-
<asp:ListItem Value="Self">Self
<asp:ListItem Value="Team-Member">Team Member

 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Please select Adhoc For"
ValidationGroup="Add-DisplayAdhoc" SetFocusOnError="true" InitialValue="select" ControlToValidate="ddlTMSelf"
ForeColor="#CC3300">


<table id="tblapprover" runat="server" cellpadding="2" cellspacing="1" width="100%" style="border-collapse: collapse;" visible="true" class="page-tbl">
Select Approver
<asp:DropDownList ID="ddlApprover" runat="server" ValidationGroup="Add-DisplayAdhoc"
AutoPostBack="True">

<%--<asp:RequiredFieldValidator ID="RequiredFieldValidatorApprover" runat="server" ErrorMessage="Please select approver"
ValidationGroup="Add-DisplayAdhoc" SetFocusOnError="true" InitialValue="" ControlToValidate="ddlApprover"
ForeColor="#CC3300" Visible="false">--%>
<asp:CustomValidator ID="CustomApprovervalidator" runat="server" ControlToValidate="ddlApprover"
ErrorMessage="Please select approver" ForeColor="#CC3300" OnServerValidate="CustomApprovervalidator_ServerValidate"
ValidationGroup="Add-DisplayAdhoc" EnableClientScript="False" ValidateEmptyText="True">

<table id="tblCUser" runat="server" cellpadding="2" cellspacing="1" width="100%" style="border-collapse: collapse;" visible="true" class="page-tbl">
isNew Employee
<asp:DropDownList ID="rdNewEmployee" runat="server" OnSelectedIndexChanged="rdNewEmployee_SelectedIndexChanged"
AutoPostBack="true">
<asp:ListItem Value="0">No
<asp:ListItem Value="1">Yes


<table id="tblOEmp" runat="server" cellpadding="2" cellspacing="1" width="100%" style="border-collapse: collapse;" visible="true" class="page-tbl">
Select Employee's
<asp:CheckBoxList ID="cbEmployees" AutoPostBack="true" runat="server" Enabled="false"
ValidationGroup="Add-DisplayAdhoc" RepeatColumns="6" CellSpacing="2" RepeatDirection="Vertical"
Width="100%" BorderWidth="0" TextAlign="Right" OnSelectedIndexChanged="cbEmployees_SelectedIndexChanged">

 <asp:Label ID="lblSelEmployee" runat="server" ForeColor="#CC3300">
<%--<asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate=""
ErrorMessage="Please select approver" ForeColor="#CC3300" ValidationGroup="Add-DisplayAdhoc" EnableClientScript="True" ClientValidationFunction="CheckBoxListValidator(this, arguments);" ValidateEmptyText="True">--%>


<table id="tblEmployeeList" runat="server" cellpadding="2" cellspacing="1" width="100%" style="border-collapse: collapse;" visible="false" class="page-tbl">
Employee Name
<asp:TextBox ID="txtEmpName" runat="server" ValidationGroup="Add-DisplayRoster">
Employee Address
<asp:TextBox ID="txtAddress" runat="server" MaxLength="200" Rows="3" TextMode="MultiLine"
ValidationGroup="Add-DisplayAdhoc" Width="500px">


<tr runat="server" id="trtRemarks" visible="false">

Adhoc Type
<asp:DropDownList ID="ddlAdhocType" runat="server" ValidationGroup="Add-DisplayAdhoc">
<asp:ListItem Text="- Select -" Value="">

<asp:ListItem Text="Pickup" Value="1">

<asp:ListItem Text="Drop" Value="2">


<asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ErrorMessage="Please select Adhoc Type"
ValidationGroup="Add-DisplayAdhoc" SetFocusOnError="true" InitialValue="" ControlToValidate="ddlAdhocType"
ForeColor="#CC3300">
Adhoc Roster Date
<asp:TextBox ID="txtRStartDate" runat="server" ValidationGroup="Add-DisplayRoster">
<Act:MaskedEditExtender ID="txtRStartDate_MaskedEditExtender" runat="server" TargetControlID="txtRStartDate"
Mask="99/99/9999" InputDirection="LeftToRight" MessageValidatorTip="False" AutoComplete="False"
>

<Act:CalendarExtender ID="calRStartDate" runat="server" TargetControlID="txtRStartDate"
CssClass="ajax__calendar" Format="MM/dd/yyyy" ClearTime="false" PopupButtonID="imgDatepicker">

<img id="imgDatepicker" src="Images/DatePicker1.gif" />
<Act:MaskedEditValidator ID="MaskedEditValidator12" runat="server" ControlToValidate="txtRStartDate"
IsValidEmpty="false" ControlExtender="txtRStartDate_MaskedEditExtender" Display="Dynamic"
EmptyValueMessage="Please select Adhoc Date" ValidationGroup="Add-DisplayAdhoc"
InvalidValueMessage="Invalid Date" ForeColor="#CC3300">
Adhoc Roster Time
<asp:TextBox ID="txtAdhocRosterTime" runat="server" ValidationGroup="Add-DisplayRoster">
<Act:MaskedEditExtender ID="txtAdhocRosterTime_MaskedEditExtender" runat="server"
TargetControlID="txtAdhocRosterTime" Mask="99:99" MaskType="Time" ClearTextOnInvalid="True"
UserTimeFormat="TwentyFourHour">

<Act:MaskedEditValidator ID="MaskedEditValidator11" ControlExtender="txtAdhocRosterTime_MaskedEditExtender"
runat="server" ControlToValidate="txtAdhocRosterTime" IsValidEmpty="false" InvalidValueMessage="Please enter time in 24 hrs format"
Display="Dynamic" ForeColor="#CC3300" ValidationGroup="Add-DisplayAdhoc">
Remarks
<asp:TextBox ID="txtReason" MaxLength="300" runat="server" ValidationGroup="Add-DisplayAdhoc"
Width="400px" Rows="3" TextMode="MultiLine">
Transport Remarks
<asp:TextBox ID="txtTransportRemarks" MaxLength="300" runat="server" ValidationGroup="Add-DisplayAdhoc"
Width="400px" Rows="3" Visible="false" TextMode="MultiLine">
<asp:Button ID="btnAddRoster" runat="server" Text="Add Adhoc Roster" ValidationGroup="Add-DisplayAdhoc"
OnClick="btnAddRoster_Click" />












<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<contenttemplate>
<asp:Panel ID="pnlbulk" runat="server" Visible="false">



<asp:Label ID="Label2" Text="Note" runat="server" Font-Bold="True" ForeColor="Red">
<asp:Label ID="lblnote" Text="This page is only for Home pickup and Home Drop." runat="server" ForeColor="#FF3300">
<asp:Label ID="Label1" Text="If you have any query please contact transport Admin." runat="server" ForeColor="#FF3300">














<asp:Label ID="lblMessage" runat="server" Text="" Width="100%">
<asp:ValidationSummary ID="ValidationSummary1" ShowValidationErrors="true" runat="server" ForeColor="Red" ValidationGroup="upload" />

<asp:UpdateProgress ID="UpdateProgress2" runat="server" AssociatedUpdatePanelID="UpdatePanel2">
<progresstemplate>
<%--<img src="~/Images/Loading.gif" alt="" />--%>
<asp:Image ImageUrl="~/Images/Loading.gif" runat="server" ID="Lodingimg2" />





Select File:
<asp:FileUpload ID="FileUploadRosterAdhoc" runat="server" />




<asp:Button ID="btnUpload" runat="server" Text="Upload" ValidationGroup="upload"
OnClick="btnUpload_Click" />
   
<asp:Button ID="btnDownloadTemplate" runat="server" Text="Download Template" OnClientClick="DownloadTemplate();" />


<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
ControlToValidate="FileUploadRosterAdhoc"
ValidationExpression=".+(.xls|.XLS|.xlsx|.XLSX )$" Display="None" ErrorMessage="Please select valid file format."
ValidationGroup="upload">

<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
ErrorMessage="Please select file to upload." ControlToValidate="FileUploadRosterAdhoc" ValidationGroup="upload" Display="None">






<asp:Button ID="btnExporttoExcel" runat="server" Text="Export(Excel)" UseSubmitBehavior="true" Visible="false"
OnClick="btnExporttoExcel_Click" />



<asp:GridView ID="grdViewEmployee" Width="100%" runat="server" AllowPaging="false" AutoGenerateColumns="false"
GridLines="None" ShowHeaderWhenEmpty="True" CssClass="GridView" CellSpacing="0" OnRowDataBound="grdViewEmployee_RowDataBound"
CellPadding="2" ShowFooter="true" DataKeyNames="EmployeeCode,AdhocDate">
<footerstyle cssclass="dataGridHeader">
<rowstyle cssclass="dataGridItem">
<SelectedRowStyle CssClass="dataGridSelectedItemStyle" />
<pagerstyle cssclass="dataGridPagerStyle">
<HeaderStyle CssClass="dataGridHeader" />
<alternatingrowstyle cssclass="dataGridAltItem">
<emptydatarowstyle cssclass="dataGridEmptyItemStyle">
<columns> <asp:TemplateField>
<itemtemplate>
<asp:CheckBox ID="chk" runat="server" Checked='<%# Eval("chk") %>' />


<asp:BoundField DataField="EmployeeCode" HeaderText="Employee Code" />
<asp:BoundField DataField="EmployeeName" HeaderText="Employee Name" />
<asp:BoundField DataField="AdhocDate" HeaderText="Date" DataFormatString="{0:dd-M-yyyy}" />
<asp:BoundField DataField="AdhocTime" HeaderText="Time" DataFormatString="{0:t}" />
<asp:BoundField DataField="Error" HeaderText="Error" />








<asp:Button ID="btnSaveData" runat="server" Text="Submit" Visible="false"
OnClick="btnSaveData_Click" />




<asp:Label ID="lblMsg" runat="server">



<triggers> <asp:PostBackTrigger ControlID="btnUpload" />
<%--<asp:AsyncPostBackTrigger ControlID="btnUpload" />--%>






C#----

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Web.UI.HtmlControls;
using Microsoft.ApplicationBlocks.Data;
using BLL;
using DAL;
using System.Collections;
using System.IO;
using System.Data.OleDb;
using System.Threading;

public partial class AddAdhocRoster : System.Web.UI.Page
{
    EmployeeBO objEmployeeBO = new EmployeeBO();
    RosterAdhoc objAdhoc = new RosterAdhoc();
    public DateTime RosterStartdate = DateTime.Today;
    public DateTime RosterEnddate = DateTime.Today;

    protected void Page_Load(object sender, EventArgs e)
    {
        ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
        scriptManager.RegisterPostBackControl(this.btnExporttoExcel);

        Page.Form.Attributes.Add("enctype", "multipart/form-data");
        try
        {
            if (Session["LoginEmployee"] != null)
            {
                btnAddRoster.Enabled = true;
                if (!IsPostBack)
                {
                    SetRoleBasedView();
                }
                if (IsPostBack)
                {
                    if (txtRStartDate.Text.Length > 0)
                        calRStartDate.SelectedDate = DateTime.ParseExact(txtRStartDate.Text, calRStartDate.Format, null);
                }
            }
            else
            {
                Response.Redirect("SessionExpired.aspx", false);
            }


        }
        catch (Exception ex)
        {

            lblMsg.CssClass = "error";
            lblMsg.Text = ex.Message.ToString();
        }

        Page.Title = "Add Adhoc";
    }

    /// <summary>
    /// MANAGED FOR USER,TEAM MANAGER AND ADMINISTRATOR ROLES
    /// NISHA NARANG-04/11/2011
    /// </summary>
    protected void SetRoleBasedView()
    {

        if (Session["LoginEmployee"] != null)
        {
            DataTable processAdmin = objEmployeeBO.GetProcessAdminById(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString());

            string ProcessAdminEID = string.Empty;
            Session["Adminprocess"] = null;
            if (processAdmin != null && processAdmin.Rows.Count > 0)
            {
                ProcessAdminEID = processAdmin.Rows[0]["EmployeeCode"].ToString();
                Session["Adminprocess"] = processAdmin.Rows[0]["ProcessName"].ToString();
            }
            else
            {
                ProcessAdminEID = string.Empty;
                Session["Adminprocess"] = null;
            }
            // if the user id Process admin then view the bulk upload button
            if (!string.IsNullOrEmpty(ProcessAdminEID))
            {
                rbtBulk.Visible = true;
                rbtSingle.Visible = true;
            }

            pnlMessage.Visible = false;
            pnlPage.Visible = true;
            Hashtable htRoles = new Hashtable();
            if (!object.Equals(Session["EmployeeRole"], null))
            {
                htRoles = (Hashtable)Session["EmployeeRole"];


                if (htRoles.Contains("team-manager")) // FOR TEAM-MANAGER
                {
                    // show bulk upload adhoc tab
                    rbtBulk.Visible = rbtSingle.Visible = true;

                    BindLocation(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
                    foreach (ListItem li in ddlSite.Items)
                    {
                        if (li.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString())
                        {
                            li.Selected = true;
                            ddlSite.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString();
                            ddlSite.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteName;
                            BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
                            foreach (ListItem li1 in ddlProcess.Items)
                            {
                                if (li1.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString())
                                {
                                    li1.Selected = true;
                                    ddlProcess.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString();
                                    ddlProcess.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).OrganisationalUnitName;
                                    break;
                                }
                            }
                            break;
                        }
                    }
                    //selecting the first site for the team-manager in case manager sits at other site and team sits at another site
                    if (ddlSite.SelectedValue == "")
                    {
                        if (ddlSite.Items.Count > 2 || ddlSite.Items.Count == 2) // multiple/single sites 
                        {
                            foreach (ListItem li in ddlSite.Items)
                            {
                                li.Selected = false;
                            }
                            ddlSite.Items[1].Selected = true;
                            ddlSite.SelectedItem.Value = ddlSite.Items[1].Value.ToString();
                            ddlSite.Text = ddlSite.Items[1].Text.ToString();
                            BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
                            foreach (ListItem li1 in ddlProcess.Items)
                            {
                                li1.Selected = false;
                            }
                            ddlProcess.Items[1].Selected = true;
                            ddlProcess.SelectedItem.Value = ddlProcess.Items[1].Value.ToString();
                            ddlProcess.Text = ddlProcess.Items[1].Text.ToString();
                        }

                    }
                    BindApproverList(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString());
                    if (ddlSite.SelectedValue != "")
                    {
                        BindProcessEmployees(null);
                    }

                    if (ddlSite.Items.Count > 2) // multiple sites
                    {
                        ddlSite.Enabled = true;
                        if (ddlProcess.Items.Count > 2) //multiple sites
                            ddlProcess.Enabled = true;
                    }
                    else if (ddlSite.Items.Count == 2 && (ddlProcess.Items.Count > 2)) //single site multiple teams
                    {
                        ddlSite.Enabled = false;
                        ddlProcess.Enabled = true;
                    }
                    else
                    {
                        ddlSite.Enabled = false;
                        ddlProcess.Enabled = false;
                    }


                    tblCUser.Visible = false;
                    tblOEmp.Visible = false;
                    //page will only be visible to team managers who are using the transport
                    if (((View_EmployeeMaster)Session["LoginEmployee"]).IsActive == true && ((View_EmployeeMaster)Session["LoginEmployee"]).AvailingTransport == false)
                    {
                        ddlTMSelf.Items.Remove("Self");
                        tblapprover.Visible = false;
                    }
                    else
                    {
                        tblapprover.Visible = true;
                    }
                }
                else if (htRoles.Contains("administrator"))
                {
                    BindApproverList(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString());
                    if (Convert.ToInt32(((View_EmployeeMaster)Session["LoginEmployee"]).RoleID.ToString()) == 2) // transport administrator but team manager
                    {
                        BindLocation(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
                        foreach (ListItem li in ddlSite.Items)
                        {
                            if (li.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString())
                            {
                                li.Selected = true;
                                ddlSite.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString();
                                ddlSite.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteName;
                                BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
                                foreach (ListItem li1 in ddlProcess.Items)
                                {
                                    if (li1.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString())
                                    {
                                        li1.Selected = true;
                                        ddlProcess.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString();
                                        ddlProcess.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).OrganisationalUnitName;
                                        break;
                                    }
                                }
                                break;
                            }
                        }


                        //selecting the first site for the team-manager in case manager sits at other site and team sits at another site
                        if (ddlSite.SelectedValue == "")
                        {
                            if (ddlSite.Items.Count > 2 || ddlSite.Items.Count == 2) // multiple/single sites 
                            {
                                foreach (ListItem li in ddlSite.Items)
                                {
                                    li.Selected = false;
                                }
                                ddlSite.Items[1].Selected = true;
                                ddlSite.SelectedItem.Value = ddlSite.Items[1].Value.ToString();
                                ddlSite.Text = ddlSite.Items[1].Text.ToString();
                                BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
                                foreach (ListItem li1 in ddlProcess.Items)
                                {
                                    li1.Selected = false;
                                }
                                ddlProcess.Items[1].Selected = true;
                                ddlProcess.SelectedItem.Value = ddlProcess.Items[1].Value.ToString();
                                ddlProcess.Text = ddlProcess.Items[1].Text.ToString();
                            }

                        }
                        if (ddlSite.SelectedValue != "")
                        {
                            BindProcessEmployees(null);
                        }

                        if (ddlSite.Items.Count > 2) // multiple sites
                        {
                            ddlSite.Enabled = true;
                            if (ddlProcess.Items.Count > 2) //multiple sites
                                ddlProcess.Enabled = true;
                        }
                        else if (ddlSite.Items.Count == 2 && (ddlProcess.Items.Count > 2)) //single site multiple teams
                        {
                            ddlSite.Enabled = false;
                            ddlProcess.Enabled = true;
                        }
                        else
                        {
                            ddlSite.Enabled = false;
                            ddlProcess.Enabled = false;
                        }

                        tblCUser.Visible = false;
                        tblOEmp.Visible = false;
                        //page will only be visible to team managers who are using the transport
                        if (((View_EmployeeMaster)Session["LoginEmployee"]).IsActive == true && ((View_EmployeeMaster)Session["LoginEmployee"]).AvailingTransport == false)
                        {
                            ddlTMSelf.Items.Remove("Self");
                            tblapprover.Visible = false;
                        }
                        else
                        {
                            tblapprover.Visible = true;
                        }
                    }
                    else if (Convert.ToInt32(((View_EmployeeMaster)Session["LoginEmployee"]).RoleID.ToString()) == 3) //transport administrator but user
                    {
                        BindLocation(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 2);
                        foreach (ListItem li in ddlSite.Items)
                        {
                            if (li.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString())
                            {
                                li.Selected = true;
                                ddlSite.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString();
                                ddlSite.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteName;
                                BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 2);
                                foreach (ListItem li1 in ddlProcess.Items)
                                {
                                    if (li1.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString())
                                    {
                                        li1.Selected = true;
                                        ddlProcess.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString();
                                        ddlProcess.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).OrganisationalUnitName;
                                        break;
                                    }
                                }
                                break;
                            }
                        }
                        ddlProcess.Enabled = false;
                        ddlSite.Enabled = false;
                        tblapprover.Visible = true;
                        tblCUser.Visible = false;
                        tblOEmp.Visible = false;
                        tblTMSelf.Visible = false;
                    }
                }
                else  // FOR USER
                {

                    BindLocation(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 2);
                    foreach (ListItem li in ddlSite.Items)
                    {
                        if (li.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString())
                        {
                            li.Selected = true;
                            ddlSite.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString();
                            ddlSite.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteName;
                            BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 2);
                            foreach (ListItem li1 in ddlProcess.Items)
                            {
                                if (li1.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString())
                                {
                                    li1.Selected = true;
                                    ddlProcess.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString();
                                    ddlProcess.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).OrganisationalUnitName;
                                    break;
                                }
                            }
                            break;
                        }
                    }

                    BindApproverList(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString());
                    ddlProcess.Enabled = false;
                    ddlSite.Enabled = false;
                    tblapprover.Visible = true;
                    tblCUser.Visible = false;
                    tblOEmp.Visible = false;
                    tblTMSelf.Visible = false;
                }
            }


            //if (htRoles.Contains("administrator"))//|| htRoles.Contains("transport-desk"))// FOR TRANSPORT ADMINISTRATOR , TRANSPORT DESK
            //{
            //    txtTransportRemarks.Visible = true;
            //    tblapprover.Visible = false;
            //    tblTMSelf.Visible = false;
            //    BindLocation(string.Empty, 0);
            //    ddlProcess.Enabled = true;
            //    ddlSite.Enabled = true;
            //    trtRemarks.Visible = true;
            //    btnAddRoster.Visible = true;

            //    //tblapprover.Visible = true;
            //    //tblCUser.Visible = false;
            //    //tblOEmp.Visible = false;
            //    //tblTMSelf.Visible = false;
            //}
            //else 

            //else
            //{
            //    pnlMessage.Visible = true;
            //    pnlPage.Visible = false;
            //}
        }

    }

    protected void ResetFields()
    {
        BindLocation(string.Empty, 0);
        ddlProcess.Items.Clear();
        ddlProcess.Enabled = false;
        //ddlProcess.Items.Clear();
        //ddlProcess.Enabled = false;
        cbEmployees.Items.Clear();
        cbEmployees.Enabled = false;
    }

    protected void DisableFields()
    {
        ddlSite.Items.Clear();
        ddlSite.Enabled = false;
        ddlProcess.Items.Clear();
        ddlProcess.Enabled = false;
        //ddlProcess.Items.Clear();
        //ddlProcess.Enabled = false;
        cbEmployees.Items.Clear();
        cbEmployees.Enabled = false;
        ddlAdhocType.Enabled = false;
        txtAdhocRosterTime.Enabled = false;
        txtReason.Enabled = false;
    }

    protected void calRStartDate_DateChanged(object sender, EventArgs e)
    {
        txtRStartDate.Text = calRStartDate.SelectedDate.ToString();
    }

    protected void BindApproverList(string employeeCode)
    {
        ddlApprover.Items.Clear();

        // View_EmployeeMaster objEmp = (View_EmployeeMaster)Session["LoginEmployee"];
        //ddlApprover.DataSource = objEmployeeBO.GetApproverList(objEmp.EmployeeCode);
        ddlApprover.DataSource = objEmployeeBO.GetApproverList(employeeCode);
        ddlApprover.DataTextField = "EmployeeName";
        ddlApprover.DataValueField = "ApproverCodeEmail";
        //EmployeeEmail
        ddlApprover.DataBind();
        if (ddlApprover.Items.Count > 0)
        {
            ddlApprover.Items.Insert(0, new ListItem("- Select -", ""));
            ddlApprover.SelectedIndex = 0;
        }
    }

    /// <summary>
    /// MANAGED FOR USER,TEAM MANAGER AND TRANSPORT ADMINISTRATOR ROLE
    /// Nisha Narang-04/11/2011
    /// </summary>
    /// <param name="EmployeeID"></param>
    /// <param name="type"></param>
    protected void BindLocation(string EmployeeID, int type)
    {
        ddlSite.Items.Clear();

        if (type == 0) // FOR TRANSPORT ADMINISTRATOR 
        {
            ddlSite.DataSource = objEmployeeBO.GetSites();
            ddlSite.DataTextField = "SiteName";
            ddlSite.DataValueField = "ID";
            ddlSite.DataBind();
            ddlSite.Items.Insert(0, new ListItem("- Select -", ""));
            ddlSite.Enabled = false;
        }
        else if (type == 1) // FOR TEAM MANAGER
        {
            string SupervisorID = EmployeeID;
            ddlSite.DataSource = objEmployeeBO.GetSitesByRM(SupervisorID);
            ddlSite.DataTextField = "SiteName";
            ddlSite.DataValueField = "SiteID";
            ddlSite.DataBind();
            ddlSite.Items.Insert(0, new ListItem("- Select -", ""));
            ddlSite.Enabled = true;
            ddlProcess.Enabled = true;
            //cblDeptManagers.Enabled=true;
        }
        else if (type == 2)// FOR USER
        {
            ddlSite.DataSource = objEmployeeBO.GetSiteByEmployee(EmployeeID);
            ddlSite.DataTextField = "SiteName";
            ddlSite.DataValueField = "SiteID";
            ddlSite.DataBind();
            ddlSite.Items.Insert(0, new ListItem("- Select -", ""));
            ddlSite.Enabled = false;
            ddlProcess.Enabled = false;
        }
    }



    /// <summary>
    /// MANAGED FOR USER,TEAM-MANAGER AND TRANSPORT
    /// Nisha Narang-04/11/2011
    /// </summary>
    /// <param name="EmployeeID"></param>
    /// <param name="RoleType"></param>

    protected void BindProcess(string EmployeeID, int RoleType)
    {
        ddlProcess.Items.Clear();
        if (RoleType == 0 && ddlSite.SelectedItem.Value != "") // For Transport Administrator
        {
            ddlProcess.DataSource = objEmployeeBO.GetProcess(Convert.ToInt64(ddlSite.SelectedItem.Value));
            ddlProcess.DataTextField = "OrganisationalUnitName";
            ddlProcess.DataValueField = "ID";
            ddlProcess.DataBind();
            ddlProcess.Items.Insert(0, new ListItem("- Select -", ""));
        }
        else if (RoleType == 1 && ddlSite.SelectedItem.Value != "") // For Team Manager
        {
            string SupervisorID = EmployeeID;
            ddlProcess.DataSource = objEmployeeBO.GetProcessByRM(SupervisorID, Convert.ToInt32(ddlSite.SelectedItem.Value));
            ddlProcess.DataTextField = "OrganisationalUnitName";
            ddlProcess.DataValueField = "OrgUnitID";
            ddlProcess.DataBind();
            ddlProcess.Items.Insert(0, new ListItem("- Select -", ""));
        }
        else if (RoleType == 2 && ddlSite.SelectedItem.Value != "") // For user
        {

            ddlProcess.DataSource = objEmployeeBO.GetProcessByEmployee(EmployeeID);
            ddlProcess.DataTextField = "OrganisationalUnitName";
            ddlProcess.DataValueField = "OrgUnitID";
            ddlProcess.DataBind();
            ddlProcess.Items.Insert(0, new ListItem("- Select -", ""));
        }
    }

    /// <summary>
    /// binding the employees according to 
    /// </summary>
    /// <param name="htRoles"></param>
    protected void BindProcessEmployees(Hashtable htRoles = null)
    {

        cbEmployees.Items.Clear();

        List<long> OrgunitID = new List<long>();
        foreach (ListItem li in ddlProcess.Items)
        {
            if (li.Selected == true && li.Value != "")
            {
                OrgunitID.Add(Convert.ToInt64(li.Value));
                break;
            }
        }
        //long subProcessId = 0;
        //if (ddlSubProcess.SelectedIndex > 0)
        //    subProcessId = Convert.ToInt64(ddlSubProcess.SelectedValue);
        //cbEmployees.DataSource = objEmployeeBO.GetEmployeesByProcess(ProcessID, Convert.ToInt64(ddlProcess.SelectedItem.Value), Convert.ToInt64(ddlSite.SelectedItem.Value), subProcessId);
        if (htRoles == null && ddlSite.SelectedItem.Value != "")
        {
            cbEmployees.DataSource = objEmployeeBO.GetEmployeesByOrgUnit(OrgunitID, Convert.ToInt64(ddlSite.SelectedItem.Value), ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode);
        }
        else if (htRoles.Contains("administrator") && ddlSite.SelectedItem.Value != "")// || htRoles.Contains("transport-desk"))
        {
            cbEmployees.DataSource = objEmployeeBO.GetEmployeesByOrgUnit(OrgunitID, Convert.ToInt64(ddlSite.SelectedItem.Value), string.Empty);

        }
        cbEmployees.DataTextField = "EmployeeName";
        cbEmployees.DataValueField = "EmployeeCode";
        cbEmployees.DataBind();
        if (cbEmployees.Items.Count > 0)
        {
            cbEmployees.Enabled = true;
            cbEmployees.Items.Insert(0, new ListItem("Select All", "-1"));
        }
    }

    protected void ddlSite_SelectedIndexChanged(object sender, EventArgs e)
    {


        Hashtable htRoles = new Hashtable();
        if (!object.Equals(Session["EmployeeRole"], null))
        {
            htRoles = (Hashtable)Session["EmployeeRole"];
            if (htRoles.Contains("team-manager"))
            {
                BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
            }
            else
            {
                BindProcess(string.Empty, 0);
            }
        }
        else
        {
            BindProcess(string.Empty, 0);
        }
        //if (ddlProcess.Items.Count > 2)
        //{
        //    //multiple sites multiple teams
        //    foreach (ListItem li1 in ddlProcess.Items)
        //    {
        //        li1.Selected = false;
        //    }
        //    ddlProcess.Enabled = true;
        //}
        //else if (ddlProcess.Items.Count == 2)
        //{
        //    ddlProcess.Items[0].Selected = true;
        //    ddlProcess.SelectedItem.Value = ddlProcess.Items[0].Value.ToString();
        //    ddlProcess.Text = ddlProcess.Items[0].Text.ToString();
        //    ddlProcess.Items[1].Selected = true;
        //    ddlProcess.SelectedItem.Value = ddlProcess.Items[1].Value.ToString();
        //    ddlProcess.Text = ddlProcess.Items[1].Text.ToString();
        //    ddlProcess.Enabled = false;

        //}
    }
    /// <summary>
    /// NISHA NARANG --12/10/2011
    /// MANAGED FOR BINDING THE APPROVER HIERARCHY OF AN EMPLOYEE
    /// 
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void ddlProcess_SelectedIndexChanged(object sender, EventArgs e)
    {
        //ddlProcess.Enabled = true;
        //BindProcess();
        Hashtable htRoles = new Hashtable();
        if (!object.Equals(Session["EmployeeRole"], null))
        {
            htRoles = (Hashtable)Session["EmployeeRole"];

            if (htRoles.Contains(("User".ToLower())))
            {
                View_EmployeeMaster objEmp = (View_EmployeeMaster)Session["LoginEmployee"];
                // binding the manager hierarchy for User Role
                BindApproverList(objEmp.EmployeeCode);
            }
            else
            {
                //binding the employees for Team Manager and Transport Administrator as Team Manager
                BindProcessEmployees(htRoles);
                // For Team-Manager Role -Team Manager himself is first level approver
                // as if list of employees gets populated then approver tab is not required
                if (cbEmployees.Items.Count > 0)
                {
                    tblapprover.Visible = false;
                    //BindApproverList(cbEmployees.Items[0].Value.ToString());
                }
            }
        }
        else
        {
            // binding the employees for Transport Administrator 
            BindProcessEmployees(null);

            if (cbEmployees.Items.Count > 0)
            {
                tblapprover.Visible = false;
                BindApproverList(cbEmployees.Items[0].Value.ToString());
            }

        }
    }


    /// <summary>
    /// MANAGING FOR SELECT ALL FUNCTIONALITY
    /// Nisha Narang - 13/10/2011
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void cbEmployees_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblSelEmployee.Text = "";
        foreach (ListItem li in cbEmployees.Items)
        {

            if (li.Selected == true)
            {
                if (Convert.ToInt32(li.Value) == -1)
                {
                    foreach (ListItem li1 in cbEmployees.Items)
                    {
                        li1.Selected = true;
                        //ProcessID.Add(Convert.ToInt64(li.Value));
                    }
                    ViewState["boolAllChecked"] = 1;
                    break;
                }
                else
                {
                    //ProcessID.Add(Convert.ToInt64(li.Value));
                    break;
                }

            }
            else if (li.Selected == false)
            {
                if (Convert.ToInt32(li.Value) == -1 && Convert.ToInt32(ViewState["boolAllChecked"]) == 1)
                {
                    foreach (ListItem li1 in cbEmployees.Items)
                    {
                        li1.Selected = false;
                    }
                    ViewState["boolAllChecked"] = 0; break;
                }

            }
        }
    }



    protected void btnAddRoster_Click(object sender, EventArgs e)
    {
        lblMsg.Text = "";
        Hashtable htRoles = new Hashtable();
        //Page.Validate();
        try
        {
            if (Page.IsValid)
            {
                bool chkEmpSelected = false;
                //check for employee selected or not
                if (ddlTMSelf.SelectedValue.ToLower().Equals("team-member"))
                {
                    foreach (ListItem li in cbEmployees.Items)
                    {
                        if (li.Selected == true)
                        {
                            chkEmpSelected = true;
                            break;
                        }

                    }
                    if (!chkEmpSelected)
                    {
                        lblSelEmployee.CssClass = "error";
                        lblSelEmployee.Text = "Please Select Employee.";
                        cbEmployees.Focus();
                        return;
                    }
                }



                //checking for adhoc date should be today's date and later
                DateTime Startdate = DateTime.Now.Date; DateTime Enddate = calRStartDate.SelectedDate.Value;
                TimeSpan span = Enddate.Subtract(Startdate);
                if (span.Days >= 0)
                {
                    btnAddRoster.Enabled = false;
                    // getting Transport Email address according to the selected site

                    string siteTransportEmailAddress = string.Empty;
                    string selectedSite = ddlSite.SelectedItem.Text;
                    if (selectedSite.ToLower().Equals("pune"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["PuneDeskMail"].ToString();
                    }
                    else if (selectedSite.ToLower().Equals("andheri"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["AndheriDeskMail"].ToString();
                    }
                    else if (selectedSite.ToLower().Equals("vikhroli"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["VikhroliDeskMail"].ToString();
                    }
                    else if (selectedSite.ToLower().Equals("thane"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["ThaneDeskMail"].ToString();
                    }
                    else if (selectedSite.ToLower().Equals("bangalore"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["BangaloreDeskMail"].ToString();
                    }
                    else if (selectedSite.ToLower().Equals("pune kn"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["KNDeskMail"].ToString();
                    }
                    //
                    if (!object.Equals(Session["EmployeeRole"], null))
                    {
                        htRoles = (Hashtable)Session["EmployeeRole"];
                        string websiteURL = ConfigurationManager.AppSettings["WebSiteURL"].ToString();
                        //string emailFilePath = Page.ResolveClientUrl("~/ViewAdhocRoster.aspx") + "?Action=EMail&ReferenceID=";
                        string emailFilePath = websiteURL + "/ViewAdhocRoster.aspx?Action=EMail&ReferenceID=";
                        if (htRoles.Contains("administrator"))// || htRoles.Contains("transport-desk"))
                        {
                            if (Convert.ToInt32(((View_EmployeeMaster)Session["LoginEmployee"]).RoleID.ToString()) == 2) //transport administrator but actually Team Manager
                            {
                                SaveAdhocTeamManager(emailFilePath, siteTransportEmailAddress);
                            }
                            else if (Convert.ToInt32(((View_EmployeeMaster)Session["LoginEmployee"]).RoleID.ToString()) == 3) //transport administrator but actually User
                            {
                                SaveAdhocUser(emailFilePath, siteTransportEmailAddress);
                            }
                            //SaveAdhocAdmin(emailFilePath, siteTransportEmailAddress);
                        }
                        else if (htRoles.Contains("team-manager")) // team manager
                        {
                            SaveAdhocTeamManager(emailFilePath, siteTransportEmailAddress);
                        }
                        else // Save for USER Role -logged in user is adding the adhoc request by himself.
                        {
                            SaveAdhocUser(emailFilePath, siteTransportEmailAddress);
                        }
                    }
                }
                else
                {
                    lblMsg.CssClass = "error";
                    lblMsg.Text = "Warning : Adhoc Date should be equal to Today Date or greater than Today Date!";
                }
            }
        }
        catch (Exception ex)
        {
            lblMsg.CssClass = "error";
            lblMsg.Text = ex.Message.ToString();
        }

    }

    protected void rdNewEmployee_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (rdNewEmployee.SelectedItem.Value == "1")
        {
            tblEmployeeList.Visible = true;
            tblOEmp.Visible = false;
            tblapprover.Visible = false;
            //RequiredFieldValidatorApprover.Visible = true;
        }
        else
        {
            /// Nisha Narang - 18/10/2011
            tblOEmp.Visible = true;
            Hashtable htRoles = new Hashtable();
            if (!object.Equals(Session["EmployeeRole"], null))
            {
                htRoles = (Hashtable)Session["EmployeeRole"];

                if (htRoles.Contains("team-manager") && ddlTMSelf.SelectedItem.Value.ToLower().Equals("self"))
                {
                    tblapprover.Visible = true;
                }
                else
                {
                    tblapprover.Visible = false;
                }
            }
            else
            {
                tblapprover.Visible = false;
            }
            tblEmployeeList.Visible = false;
            //RequiredFieldValidatorApprover.Visible = false;
        }
    }
    /// <summary>
    /// Nisha Narang - 17/10/2011
    /// custom validator to validate selection of approver according to user role
    /// </summary>
    /// <param name="source"></param>
    /// <param name="args"></param>
    protected void CustomApprovervalidator_ServerValidate(object source, ServerValidateEventArgs args)
    {

        //this validator only works for team-manager & user roles 
        //if login user is administrator /transport-desk then Adhoc is self approved no need for the selection
        if (rdNewEmployee.SelectedValue.ToString().Equals("2"))
        {
            Hashtable htRoles = new Hashtable();
            if (!object.Equals(Session["EmployeeRole"], null))
            {
                htRoles = (Hashtable)Session["EmployeeRole"];

                if (htRoles.Contains("team-manager") || htRoles.Contains("administrator"))
                {
                    args.IsValid = true;
                }
            }
        }
        else
        {
            Hashtable htRoles = new Hashtable();
            if (!object.Equals(Session["EmployeeRole"], null))
            {
                htRoles = (Hashtable)Session["EmployeeRole"];

                if (htRoles.Contains("user") || htRoles.Contains("team-manager") || htRoles.Contains("administrator"))
                {
                    if (ddlApprover.SelectedIndex > 0)
                    {
                        args.IsValid = true;
                    }
                    else
                    {
                        args.IsValid = false;
                    }
                }
                else
                {
                    args.IsValid = false;
                }
            }
            //args.IsValid = false;
            //lblMsg.Text = "Select Approver";
        }
    }
    protected void ddlSubProcess_SelectedIndexChanged(object sender, EventArgs e)
    {

        Hashtable htRoles = new Hashtable();
        if (!object.Equals(Session["EmployeeRole"], null))
        {
            htRoles = (Hashtable)Session["EmployeeRole"];
            if (htRoles.Contains(("user")))
            {
                View_EmployeeMaster objEmp = (View_EmployeeMaster)Session["LoginEmployee"];
                BindApproverList(objEmp.EmployeeCode);
                // BindProcessEmployees();
            }
            else
            {
                BindProcessEmployees(null);
                BindApproverList(cbEmployees.Items[0].Value.ToString());
            }
        }
        else
        {
            BindProcessEmployees(null);
            BindApproverList(cbEmployees.Items[0].Value.ToString());
        }

    }
    protected void CustomValidatorsubprocess_ServerValidate(object source, ServerValidateEventArgs args)
    {
        //if (ddlSubProcess.Enabled == true)
        //{
        //    if (ddlSubProcess.Items.Count > 0)
        //    {
        //        if (ddlSubProcess.SelectedIndex > 0)
        //        {
        //            args.IsValid = true;
        //        }
        //        else
        //        {
        //            args.IsValid = false;
        //        }
        //    }
        //    else
        //    {
        //        args.IsValid = false;
        //    }
        //}
    }
    protected void ddlTMSelf_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlTMSelf.SelectedItem.Value.ToLower().Equals("team-member"))
        {
            tblapprover.Visible = false;
            BindProcessEmployees(null);
            tblCUser.Visible = true;
            tblOEmp.Visible = true;
            tblEmployeeList.Visible = false;
        }
        else if (ddlTMSelf.SelectedItem.Value.ToLower().Equals("self"))
        {

            tblapprover.Visible = true;
            tblCUser.Visible = false;
            tblOEmp.Visible = false;
            tblEmployeeList.Visible = false;
        }
        else if (ddlTMSelf.SelectedItem.Value.ToLower().Equals("select"))
        {

            tblOEmp.Visible = false;
            tblCUser.Visible = false;
        }

    }

    protected void SaveAdhocAdmin(string emailFilePath, string siteTransportEmailAddress)
    {

        //*********************************************************************************************************************************
        // CASE WHEN TRANSPORT ADMINISTRATOR OR TRANSPORT DESK IS RAISING ADHOC REQUEST
        //*********************************************************************************************************************************
        if (tblCUser.Visible == false)
        {
            objAdhoc = new RosterAdhoc();
            TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
            objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
            objAdhoc.AdhocTime = tsAdhoc;
            objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
            objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
            objAdhoc.EmployeeCode = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;

            objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
            objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
            //objAdhoc.ProcessID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
            objAdhoc.Remarks = txtReason.Text;
            objAdhoc.ApprovalStatusID = -1;// In-progress status
            //adding approver employee code
            string approverEmpCode = string.Empty;
            if (tblapprover.Visible == true)
            {
                if (ddlApprover.SelectedItem.Value.Contains('-'))
                {
                    approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
                }
                else
                {
                    approverEmpCode = ddlApprover.SelectedItem.Value;
                }
                objAdhoc.FirstLevelApprover = approverEmpCode;
            }
            else
            {
                objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
            }

            objAdhoc.FirstLevelApprovedDate = DateTime.Now;
            objAdhoc.isActive = true;

            OperationStatus os = objEmployeeBO.InsertNewEmpAdhocRequest(objAdhoc);
            lblMsg.Text = "Adhoc Successfully Added!";
            if (os.InsertedRowID > 0)
            {
                //string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();

                string MailBody = "";
                MailBody = "Hi," +
                    "<p>New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " + calRStartDate.SelectedDate.Value.Date.ToShortDateString() + ", Time: " + tsAdhoc + " by " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for self.<br /> (Employee Code: " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode + ") Process : " + ddlProcess.SelectedItem.Text + "<br />" +
                    "Requesting you to Approve/Reject  for further process.<br />" +
                    "<br /><br />" +
                    "You can access the request by clicking on " +
                    "<a href='" + emailFilePath + Convert.ToString(os.InsertedRowID) + "'>WBR</a>" +
                    "<br /><br />" +
                    "<b>Regards," +
                    "<br />" +
                    "Transport Team</b>" +
                    "<br /><br /><br /><br /><center><i>This is a system generated e-mail. Please do not reply to this e-mail.</i><br />" +
                    "<font size=2>Capita India- Application Services Team</font></center>";
                //emailFilePath + Convert.ToString(os.InsertedRowID) + "</p><br />" + //Adhoc reference ID: " + os.InsertedRowID + "</p>" +
                //"<p><b>Regards,<br />Transport Team</b></p>";
                WBREmail mail = new WBREmail();
                string HeadName, HeadEmail = string.Empty;
                HeadName = ddlApprover.SelectedItem.Text.ToString();


                if (ddlApprover.SelectedItem.Value.Contains('-'))
                {
                    HeadEmail = ddlApprover.SelectedItem.Value.Split('-')[1];
                }
                else
                {
                    HeadEmail = ddlApprover.SelectedItem.Value;
                }
                mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), HeadName, HeadEmail,
                            "", "", "New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
                lblMsg.CssClass = "success";
                lblMsg.Text = "Adhoc added successfully.";
            }
        }
        // Nisha Narang - 21/10/2011
        //*********************************************************************************************************************************
        // CASE WHEN TEAM MANAGER RAISING THE ADHOC REQUEST FOR HIS TEAM MEMBER 
        // REQUEST REQUIRES FURTHER APPROVAL OF TRANSPORT AND MAIL GOES TO TRANSPORT
        //*********************************************************************************************************************************
        else if (rdNewEmployee.SelectedItem.Value == "0")
        {
            foreach (ListItem li in cbEmployees.Items)
            {
                if (Convert.ToInt32(li.Value) != -1)
                {
                    if (li.Selected == true)
                    {
                        DataTable dtEmpDatilsforEmail = new DataTable();
                        List<string> EmpID = new List<string>();

                        objAdhoc = new RosterAdhoc();
                        TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
                        objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
                        objAdhoc.AdhocTime = tsAdhoc;
                        objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
                        objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;// Team-Manager Id
                        objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
                        objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
                        objAdhoc.EmployeeCode = li.Value;
                        objAdhoc.Remarks = txtReason.Text;
                        objAdhoc.ApprovalStatusID = -1; // in progress status
                        //adding approver employee code
                        string approverEmpCode = string.Empty;
                        if (tblapprover.Visible == true)
                        {
                            if (ddlApprover.SelectedItem.Value.Contains('-'))
                            {
                                approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
                            }
                            else
                            {
                                approverEmpCode = ddlApprover.SelectedItem.Value;
                            }

                            objAdhoc.FirstLevelApprover = approverEmpCode;
                        }
                        else
                        {
                            objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
                        }
                        objAdhoc.FirstLevelApprovedDate = DateTime.Now;
                        objAdhoc.isActive = true;

                        OperationStatus os = objEmployeeBO.InsertAdhocRequest(objAdhoc);
                        //lblMsg.Text = "Adhoc Successfully Added!";

                        EmpID.Add(li.Value);

                        if (os.InsertedRowID > 0)
                        {
                            //string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
                            string MailBody = "";
                            MailBody = "Hi," +
                               "<p>New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " + calRStartDate.SelectedDate.Value.Date.ToShortDateString() + ", Time: " + tsAdhoc + " by " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for Employee Name: " + li.Text.ToString() + "(Employee Code: " + li.Value + ") Process : " + ddlProcess.SelectedItem.Text + "<br />" +
                                "Requesting you to Approve/Reject  for further process.<br />" +
                                "<br /><br />" +
                                "You can access the request by clicking on " +
                                "<a href='" + emailFilePath + Convert.ToString(os.InsertedRowID) + "'>WBR</a>" +
                                "<br /><br />" +
                                "<b>Regards," +
                                "<br />" +
                                "Transport Team</b>" +
                                "<br /><br /><br /><br /><center><i>This is a system generated e-mail. Please do not reply to this e-mail.</i><br />" +
                                "<font size=2>Capita India- Application Services Team</font></center>";
                            WBREmail mail = new WBREmail();
                            //********************************************************
                            // Direct Email to transport
                            //********************************************************
                            mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), "Transport-Desk", siteTransportEmailAddress,
                                       "", "", "New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
                            lblMsg.CssClass = "success";
                            lblMsg.Text = "Adhoc added successfully.";
                            //break;

                        }
                    }
                }
            }
        }
        else
        {
            // Nisha Narang - 20/10/2011
            //*********************************************************************************************************************************
            // CASE WHEN TRANSPORT ADMINISTRATOR RAISING THE ADHOC REQUEST FOR A NEW JOINEE OF ANY PROCESS 
            // REQUEST IS ALREADY BEING APPROVED BY THE FIRST APPROVER FROM TRANSPORT ADMINISTRATOR
            //*********************************************************************************************************************************

            DataTable dtEmpDatilsforEmail = new DataTable();
            List<string> EmpID = new List<string>();

            objAdhoc = new RosterAdhoc();
            TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
            objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
            objAdhoc.AdhocTime = tsAdhoc;
            objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
            objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;// Team-Manager Id
            objAdhoc.EmployeeCode = "NJ";
            objAdhoc.EmployeeName = txtEmpName.Text;
            objAdhoc.EmpAddress = txtAddress.Text;
            objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
            objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
            //objAdhoc.ProcessID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
            objAdhoc.Remarks = txtReason.Text;
            objAdhoc.ApprovalStatusID = -1;//In-Progress Status
            //adding approver employee code
            string approverEmpCode = string.Empty;
            if (tblapprover.Visible == true)
            {
                if (ddlApprover.SelectedItem.Value.Contains('-'))
                {
                    approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
                }
                else
                {
                    approverEmpCode = ddlApprover.SelectedItem.Value;
                }
                objAdhoc.FirstLevelApprover = approverEmpCode;
            }
            else
            {
                objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
            }
            objAdhoc.FirstLevelApprovedDate = DateTime.Now;

            objAdhoc.isActive = true;

            OperationStatus os = objEmployeeBO.InsertNewEmpAdhocRequest(objAdhoc);
            lblMsg.Text = "Adhoc Successfully Added!";
            lblMsg.CssClass = "success";
            if (os.InsertedRowID > 0)
            {
                if (tblOEmp.Visible == false)
                {
                    //string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
                    string MailBody = "";
                    MailBody = "Hi," +
                       "<p>New Adhoc  " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " + calRStartDate.SelectedDate.Value.Date.ToShortDateString() + ", Time: " + tsAdhoc + " by " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for Employee Name: " + txtEmpName.Text + "(Employee Code: NJ ) Process : " + ddlProcess.SelectedItem.Text + "<br />" +
                       "Requesting you to Approve/Reject  for further process.<br />" +
                        "<br /><br />" +
                        "You can access the request by clicking on " +
                        "<a href='" + emailFilePath + Convert.ToString(os.InsertedRowID) + "'>WBR</a>" +
                        "<br /><br />" +
                        "<b>Regards," +
                        "<br />" +
                        "Transport Team</b>" +
                        "<br /><br /><br /><br /><center><i>This is a system generated e-mail. Please do not reply to this e-mail.</i><br />" +
                        "<font size=2>Capita India- Application Services Team</font></center>";
                    WBREmail mail = new WBREmail();
                    mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), "Transport-Desk", siteTransportEmailAddress,
                               "", "", "New Adhoc   " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
                }

            }

        }

    }

    protected void SaveAdhocTeamManager(string emailFilePath, string siteTransportEmailAddress)
    {
        // Nisha Narang - 21/10/2011
        //*********************************************************************************************************************************
        // CASE WHEN TEAM MANAGER RAISING THE ADHOC REQUEST FOR HIS TEAM MEMBER 
        // REQUEST REQUIRES FURTHER APPROVAL OF TRANSPORT AND MAIL GOES TO TRANSPORT
        //*********************************************************************************************************************************
        if (tblCUser.Visible == false)
        {
            SaveAdhocUser(emailFilePath, siteTransportEmailAddress);
        }
        else if (rdNewEmployee.SelectedItem.Value == "0")
        {
            foreach (ListItem li in cbEmployees.Items)
            {
                if (Convert.ToInt32(li.Value) != -1)
                {
                    if (li.Selected == true)
                    {
                        DataTable dtEmpDatilsforEmail = new DataTable();
                        List<string> EmpID = new List<string>();

                        objAdhoc = new RosterAdhoc();
                        TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
                        objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
                        objAdhoc.AdhocTime = tsAdhoc;
                        objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
                        objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;// Team-Manager Id
                        objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
                        objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
                        objAdhoc.EmployeeCode = li.Value;
                        objAdhoc.Remarks = txtReason.Text;
                        objAdhoc.ApprovalStatusID = -1; // in progress status
                        //adding approver employee code
                        string approverEmpCode = string.Empty;
                        if (tblapprover.Visible == true)
                        {
                            if (ddlApprover.SelectedItem.Value.Contains('-'))
                            {
                                approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
                            }
                            else
                            {
                                approverEmpCode = ddlApprover.SelectedItem.Value;
                            }

                            objAdhoc.FirstLevelApprover = approverEmpCode;
                        }
                        else
                        {
                            objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
                        }
                        objAdhoc.FirstLevelApprovedDate = DateTime.Now;
                        objAdhoc.isActive = true;

                        OperationStatus os = objEmployeeBO.InsertAdhocRequest(objAdhoc);
                        lblMsg.Text = "Adhoc Successfully Added!";

                        EmpID.Add(li.Value);

                        if (os.InsertedRowID > 0)
                        {
                            //string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
                            string MailBody = "";
                            MailBody = "Hi," +
                               "<p>New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " +
                               calRStartDate.SelectedDate.Value.Date.ToShortDateString() + ", Time: " + tsAdhoc + " by "
                               + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for Employee Name: " + li.Text.ToString()
                               + "(Employee Code: " + li.Value + ") Process : " + ddlProcess.SelectedItem.Text + "<br />" +
                                "Requesting you to Approve/Reject  for further process.<br />" +
                                "<br /><br />" +
                                "You can access the request by clicking on " +
                                "<a href='" + emailFilePath + Convert.ToString(os.InsertedRowID) + "'>WBR</a>" +
                                "<br /><br />" +
                                "<b>Regards," +
                                "<br />" +
                                "Transport Team</b>" +
                                "<br /><br /><br /><br /><center><i>This is a system generated e-mail. Please do not reply to this e-mail.</i><br />" +
                                "<font size=2>Capita India- Application Services Team</font></center>";
                            WBREmail mail = new WBREmail();
                            //********************************************************
                            // Direct Email to transport
                            //********************************************************
                            mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), "Transport-Desk", siteTransportEmailAddress,
                                       "", "", "New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
                            lblMsg.CssClass = "success";
                            lblMsg.Text = "Adhoc added successfully.";
                            //break;

                        }
                    }
                }
            }
        }
        else
        {
            // Nisha Narang - 20/10/2011
            //*********************************************************************************************************************************
            // CASE WHEN TEAM MANAGER RAISING THE ADHOC REQUEST FOR A NEW JOINEE IN HIS TEAM
            // REQUEST FURTHER APPROVAL OF TRANSPORT AND MAIL GOES TO TRANSPORT
            //*********************************************************************************************************************************

            DataTable dtEmpDatilsforEmail = new DataTable();
            List<string> EmpID = new List<string>();

            objAdhoc = new RosterAdhoc();
            TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
            objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
            objAdhoc.AdhocTime = tsAdhoc;
            objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
            objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;// Team-Manager Id
            objAdhoc.EmployeeCode = "NJ";
            objAdhoc.EmployeeName = txtEmpName.Text;
            objAdhoc.EmpAddress = txtAddress.Text;
            objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
            objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
            //objAdhoc.ProcessID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
            objAdhoc.Remarks = txtReason.Text;
            objAdhoc.ApprovalStatusID = -1;//In-Progress Status
            //adding approver employee code
            string approverEmpCode = string.Empty;
            if (tblapprover.Visible == true)
            {
                if (ddlApprover.SelectedItem.Value.Contains('-'))
                {
                    approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
                }
                else
                {
                    approverEmpCode = ddlApprover.SelectedItem.Value;
                }
                objAdhoc.FirstLevelApprover = approverEmpCode;
            }
            else
            {
                objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
            }
            objAdhoc.FirstLevelApprovedDate = DateTime.Now;

            objAdhoc.isActive = true;

            OperationStatus os = objEmployeeBO.InsertNewEmpAdhocRequest(objAdhoc);
            lblMsg.Text = "Adhoc Successfully Added!";
            lblMsg.CssClass = "success";
            if (os.InsertedRowID > 0)
            {
                if (tblOEmp.Visible == false)
                {
                    //string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
                    string MailBody = "";
                    MailBody = "Hi," +
                       "<p>New Adhoc  " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " + calRStartDate.SelectedDate.Value.Date.ToShortDateString()
                       + ", Time: " + tsAdhoc + " by " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName
                       + " for Employee Name: " + txtEmpName.Text + "(Employee Code: NJ ) Process : " +
                       ddlProcess.SelectedItem.Text + "<br />" +
                       "Requesting you to Approve/Reject  for further process.<br />" +
                        "<br /><br />" +
                        "You can access the request by clicking on " +
                        "<a href='" + emailFilePath + Convert.ToString(os.InsertedRowID) + "'>WBR</a>" +
                        "<br /><br />" +
                        "<b>Regards," +
                        "<br />" +
                        "Transport Team</b>" +
                        "<br /><br /><br /><br /><center><i>This is a system generated e-mail. Please do not reply to this e-mail.</i><br />" +
                        "<font size=2>Capita India- Application Services Team</font></center>";
                    WBREmail mail = new WBREmail();

                    mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), "Transport-Desk", siteTransportEmailAddress,
                               "", "", "New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
                }

            }

        }

    }

    protected void SaveAdhocUser(string emailFilePath, string siteTransportEmailAddress)
    {
        // Nisha Narang - 19/10/2011
        //*********************************************************************************************************************************
        // CASE WHEN USER IS RAISING THE REQUEST FOR HIMSELF
        // AND MAIL GOES TO HIS MANAGER FOR APPROVAL //AND CC TO TRANSPORT
        //*********************************************************************************************************************************

        objAdhoc = new RosterAdhoc();
        TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
        objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
        objAdhoc.AdhocTime = tsAdhoc;
        objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
        objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
        objAdhoc.EmployeeCode = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;

        objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
        objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
        //objAdhoc.ProcessID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
        objAdhoc.Remarks = txtReason.Text;
        objAdhoc.ApprovalStatusID = 0;// New Adhoc Request
        //adding approver employee code
        string approverEmpCode = string.Empty;
        if (tblapprover.Visible == true)
        {
            if (ddlApprover.SelectedItem.Value.Contains('-'))
            {
                approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
            }
            else
            {
                approverEmpCode = ddlApprover.SelectedItem.Value;
            }
            objAdhoc.FirstLevelApprover = approverEmpCode;
        }
        else
        {
            objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
        }

        objAdhoc.FirstLevelApprovedDate = DateTime.Now;
        objAdhoc.isActive = true;

        OperationStatus os = objEmployeeBO.InsertNewEmpAdhocRequest(objAdhoc);

        if (os.InsertedRowID > 0)
        {
            //string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
            string MailBody = "";
            MailBody = "Hi," +
               "<p>New Adhoc  " + ddlAdhocType.SelectedItem.Text + "  Request is raised for Date: " + calRStartDate.SelectedDate.Value.Date.ToShortDateString() + ", Time: " + tsAdhoc + " by " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for self (Employee Code: " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode + ") Process : " + ddlProcess.SelectedItem.Text + "<br />" +
               "Requesting you to Approve/Reject  for further process.<br />" +
                    "<br /><br />" +
                    "You can access the request by clicking on " +
                    "<a href='" + emailFilePath + Convert.ToString(os.InsertedRowID) + "'>WBR</a>" +
                    "<br /><br />" +
                    "<b>Regards," +
                    "<br />" +
                    "Transport Team</b>" +
                    "<br /><br /><br /><br /><center><i>This is a system generated e-mail. Please do not reply to this e-mail.</i><br />" +
                    "<font size=2>Capita India- Application Services Team</font></center>";

            string HeadName, HeadEmail = string.Empty;
            HeadName = ddlApprover.SelectedItem.Text.ToString();


            if (ddlApprover.SelectedItem.Value.Contains('-'))
            {
                HeadEmail = ddlApprover.SelectedItem.Value.Split('-')[1];
            }
            else
            {
                HeadEmail = ddlApprover.SelectedItem.Value;
            }
            WBREmail mail = new WBREmail();
            mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), HeadName, HeadEmail,
                     "", "", "New Adhoc   " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
        }


        lblMsg.CssClass = "success";
        lblMsg.Text = "Adhoc added successfully.";

    }

    protected void rbtSingle_CheckedChanged(object sender, EventArgs e)
    {
        rbtBulk.Checked = false;
        pnlbulk.Visible = false;
        pnlsingle.Visible = true;
        lblMessage.Text = lblMsg.Text = string.Empty;
    }
    protected void rbtBulk_CheckedChanged(object sender, EventArgs e)
    {
        rbtSingle.Checked = false;
        pnlsingle.Visible = false;
        pnlbulk.Visible = true;
        lblMessage.Text = lblMsg.Text = string.Empty;
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {

        #region upload file code
        Hashtable htRoles = new Hashtable();
        try
        {
            if (!object.Equals(Session["EmployeeRole"], null))
            {
                htRoles = (Hashtable)Session["EmployeeRole"];

                if (htRoles.Contains("team-manager") || Session["Adminprocess"] != null)
                {

                    bool success = false;

                    //1. upload the file
                    //2 . get the data into a datatable from excel sheet 
                    //2.1 read the data table row by row
                    //2.2 update the roster table by key employee code and roster date (pick up time , route no, zone no)
                    //3  delete the file

                    DataTable dtExcel = new DataTable();
                    string strConnection = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
                    SqlConnection myConn = new SqlConnection(strConnection);
                    string filePath = string.Empty;

                    if (FileUploadRosterAdhoc.HasFile)
                    {
                        if (System.IO.Path.GetExtension(FileUploadRosterAdhoc.FileName) == ".xls" || System.IO.Path.GetExtension(FileUploadRosterAdhoc.FileName) == ".xlsx")
                        {
                            //Saving file on Server
                            filePath = Server.MapPath("~/Roster/Upload/Schedule_RosterAdhoc.xlsx");
                            if (File.Exists(filePath))
                                File.Delete(filePath);

                            FileUploadRosterAdhoc.SaveAs(filePath);
                            // Reading the file for data upload
                            string sExcelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'";

                            using (OleDbConnection con = new OleDbConnection(sExcelConnectionString))
                            {
                                con.Open();
                                string worksheetName = "Roster";
                                string strCommand = "SELECT * FROM [" + worksheetName + "$]";
                                OleDbCommand excelCommand = new OleDbCommand(strCommand, con);
                                OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();
                                excelDataAdapter.SelectCommand = excelCommand;
                                excelDataAdapter.Fill(dtExcel);

                                DataTable dtRoster = FillDatatableInfo(dtExcel);

                                try
                                {
                                    if (ValidateExcelDates(dtRoster))
                                    {

                                        if (Session["Adminprocess"] != null)
                                        {
                                            success = ValidateExcel(dtRoster, "ProcessAdmin");
                                        }
                                        else
                                        {
                                            success = ValidateExcel(dtRoster, "TM");
                                        }
                                        if (success)
                                        {
                                            // SaveBulkAdhoc(dtRoster);
                                        }
                                        else
                                        {
                                            lblMessage.CssClass = "error";
                                            lblMessage.Text = "Warning : Check below information and Click on Submit button for save only valid data!";
                                        }
                                    }
                                    else
                                    {
                                        lblMessage.CssClass = "error";
                                        lblMessage.Text = "Warning :Some of Employees Adhoc Date is less than Today Date!";
                                    }

                                }
                                catch (Exception ex)
                                {

                                    lblMessage.CssClass = "error";
                                    lblMessage.Text = ex.Message.ToString();

                                }
                            }
                        }
                    }
                    if (success)
                    {

                        lblMessage.CssClass = "success";
                        lblMessage.Text = "Data Upload Successful.";
                    }
                }
                else
                {
                    lblMessage.CssClass = "error";
                    lblMessage.Text = "You don't have permission to upload file.";
                }
            }
        }
        catch (Exception ex)
        {
            lblMessage.CssClass = "error";
            lblMessage.Text = ex.Message.ToString();
        }

        #endregion

    }
    // method is used for save data from excel to Database for bulk adhoc 
    private void SaveBulkAdhoc(DataTable dtRoster)
    {
        btnUpload.Enabled = false;
        Roster empRoster;
        RosterAdhoc empAdhoc;
        EmployeeBO objEmployee;
        bool flag = false;
        string websiteURL = ConfigurationManager.AppSettings["WebSiteURL"].ToString();
        string emailFilePath = websiteURL + "/ViewAdhocRoster.aspx?Action=EMail&ReferenceID=";

        foreach (DataRow dr in dtRoster.Rows)
        {

            bool chk = Convert.ToBoolean(dr["chk"]);

            if (chk)
            {
                string empCode = Convert.ToString(dr["EmployeeCode"]);
                string EmpName = Convert.ToString(dr["EmployeeName"]);
                {
                    //code for get site email id
                    #region code for get site email id

                    string siteTransportEmailAddress = string.Empty;
                    string selectedSite = Convert.ToString(objEmployeeBO.GetSiteByEmployee(empCode).Rows[0]["SiteName"]);
                    string process = Convert.ToString(objEmployeeBO.GetProcessByEmployee(empCode).Rows[0]["OrganisationalUnitName"]);

                    if (selectedSite.ToLower().Equals("pune"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["PuneDeskMail"].ToString();
                    }
                    else if (selectedSite.ToLower().Equals("andheri"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["AndheriDeskMail"].ToString();
                    }
                    else if (selectedSite.ToLower().Equals("vikhroli"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["VikhroliDeskMail"].ToString();
                    }
                    else if (selectedSite.ToLower().Equals("thane"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["ThaneDeskMail"].ToString();
                    }
                    else if (selectedSite.ToLower().Equals("bangalore"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["BangaloreDeskMail"].ToString();
                    }
                    else if (selectedSite.ToLower().Equals("pune kn"))
                    {
                        siteTransportEmailAddress = ConfigurationManager.AppSettings["KNDeskMail"].ToString();
                    }

                    #endregion

                    objEmployee = new EmployeeBO();
                    empRoster = new Roster();
                    empAdhoc = new RosterAdhoc();

                    //EmployeeCode RosterDate
                    DateTime Startdate = DateTime.Now.Date;
                    TimeSpan span = Convert.ToDateTime(dr["AdhocDate"]).Subtract(Startdate);
                    if (span.Days >= 0)
                    {

                        if (!Convert.ToString(dr["EmployeeCode"]).Equals(string.Empty))
                        {

                            int AdhocType;
                            if (Convert.ToString(dr["AdhocTypeID"]) == "Pickup")
                            {
                                AdhocType = 1;
                            }
                            else
                            {
                                AdhocType = 2;
                            }

                            objAdhoc = new RosterAdhoc();
                            TimeSpan tsAdhoc = Convert.ToDateTime(dr["AdhocTime"]).TimeOfDay;
                            objAdhoc.AdhocDate = Convert.ToDateTime(dr["AdhocDate"]);
                            objAdhoc.AdhocTime = tsAdhoc;
                            objAdhoc.AdhocTypeID = AdhocType;
                            objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
                            objAdhoc.EmployeeCode = empCode;

                            objAdhoc.SiteID = Convert.ToInt64(dr["SiteID"]);
                            objAdhoc.OrgUnitID = Convert.ToInt64(dr["OrgUnitID"]);
                            objAdhoc.Remarks = Convert.ToString(dr["Remark"]);
                            objAdhoc.ApprovalStatusID = -1;// New Adhoc Request
                            //adding approver employee code
                            string approverEmpCode = string.Empty;

                            objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;

                            objAdhoc.FirstLevelApprovedDate = DateTime.Now;
                            objAdhoc.isActive = true;

                            OperationStatus os = objEmployeeBO.InsertNewEmpAdhocRequest(objAdhoc);
                            flag = true;
                            #region Email Code
                            // code for send email
                            if (os.InsertedRowID > 0)
                            {
                                //string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
                                string MailBody = "";
                                MailBody = "Hi," +
                                   "<p>New Adhoc " + Convert.ToString(dr["AdhocTypeID"]) + " Request is raised for Date: " +
                                   Convert.ToDateTime(dr["AdhocDate"]).ToShortDateString() + ", Time: " + tsAdhoc + " by "
                                   + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for Employee Name: " + EmpName
                                   + "(Employee Code: " + empCode + ") Process : " + process + "<br />" +
                                    "Requesting you to Approve/Reject  for further process.<br />" +
                                    "<br /><br />" +
                                    "You can access the request by clicking on " +
                                    "<a href='" + emailFilePath + Convert.ToString(os.InsertedRowID) + "'>WBR</a>" +
                                    "<br /><br />" +
                                    "<b>Regards," +
                                    "<br />" +
                                    "Transport Team</b>" +
                                    "<br /><br /><br /><br /><center><i>This is a system generated e-mail. Please do not reply to this e-mail.</i><br />" +
                                    "<font size=2>Capita India- Application Services Team</font></center>";
                                WBREmail mail = new WBREmail();

                                //********************************************************
                                // Direct Email to transport
                                //********************************************************
                                mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(),
                                    ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), "Transport-Desk",
                                    siteTransportEmailAddress,
                                           "", "", "New Adhoc " + Convert.ToString(dr["AdhocTypeID"]) + " Request", MailBody);
                                lblMsg.CssClass = "success";
                                lblMsg.Text = "Adhoc added successfully.";
                                //break;
                                lblMessage.CssClass = "success";
                                lblMessage.Text = "Data Upload Successful.";
                            }

                            #endregion
                        }
                    }

                    objEmployee = null;
                }
            }
            btnUpload.Enabled = true;
        }

        if (flag)
        {
            lblMsg.CssClass = "success";
            lblMsg.Text = "Adhoc added successfully.";
            //break;
            lblMessage.CssClass = "success";
            lblMessage.Text = "Data Upload Successful.";
            btnExporttoExcel.Visible = false;
            grdViewEmployee.DataSource = null;
            grdViewEmployee.DataBind();
            btnSaveData.Visible = false;
            btnUpload.Enabled = true;
        }
        else
        {
            lblMsg.CssClass = "error";
            lblMsg.Text = "No data for Save.";
            //break;
            lblMessage.CssClass = "error";
            lblMessage.Text = "No data for Save.";
        }

    }

    private DataTable FillDatatableInfo(DataTable dtExcel)
    {
        //DataTable dtResult = dtExcel;
        dtExcel.Columns.Add("EmployeeName", typeof(string));
        dtExcel.Columns.Add("SiteID", typeof(long));
        dtExcel.Columns.Add("OrgUnitID", typeof(long));
        dtExcel.Columns.Add("RMID", typeof(string));
        dtExcel.Columns.Add("AvailingTransport", typeof(bool));
        dtExcel.Columns.Add("IsActive", typeof(bool));

        EmployeeMaster emp;
        foreach (DataRow dr in dtExcel.Rows)
        {
            emp = new EmployeeMaster();
            emp = objEmployeeBO.GetEmployeeByEmpID(Convert.ToString(dr["EmployeeCode"])).FirstOrDefault();
            if (emp != null)
            {
                dr["EmployeeName"] = emp.EmployeeName;
                dr["SiteID"] = emp.SiteID;
                dr["OrgUnitID"] = emp.OrgUnitID;
                dr["RMID"] = emp.RMID;
                dr["AvailingTransport"] = emp.AvailingTransport;
                dr["IsActive"] = emp.IsActive;
            }
        }
        dtExcel.AcceptChanges();
        return dtExcel;
    }

    private bool ValidateExcelDates(DataTable dtExcel)
    {
        bool flag = true;
        DateTime Startdate = DateTime.Now.Date;
        foreach (DataRow dr in dtExcel.Rows)
        {
            if (!string.IsNullOrEmpty(Convert.ToString(dr["AdhocDate"])))
            {
                TimeSpan span = Convert.ToDateTime(dr["AdhocDate"]).Subtract(Startdate);
                if (span.Days >= 0)
                {
                    flag = true;
                }
                else
                {
                    return false;
                }
            }
        }
        return flag;
    }

    private bool ValidateExcel(DataTable dtRoster, string User)
    {
        ViewState["dtOtherEmployee"] = null;
        bool flag = false;
        dtRoster.Columns.Add("Chk", typeof(bool));
        dtRoster.Columns.Add("Error", typeof(string));

        foreach (DataRow dr in dtRoster.Rows)
        {
            if (User == "ProcessAdmin")
            {
                try
                {
                    List<Int32> OrgunitIdlist = objEmployeeBO.GetOrgIDbyName(Convert.ToString(Session["Adminprocess"]));
                    // check other process employee or wrong employee ID
                    if (!OrgunitIdlist.Contains(Convert.ToInt32(dr["OrgUnitID"])))
                    {
                        dr["chk"] = false;
                        dr["Error"] = "Ouside Process";
                    }
                }
                catch (Exception)
                {
                    dr["chk"] = false;
                    dr["Error"] = "Envalid Employee ID";
                }
            }
            if (User == "TM")
            {
                if (((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode != Convert.ToString(dr["RMID"]))
                {
                    dr["chk"] = false;
                    dr["Error"] = "Employee has different Reporting Manager";
                }
            }
            try
            {
                if (Convert.ToBoolean(dr["AvailingTransport"]) == false || Convert.ToBoolean(dr["IsActive"]) == false)
                {
                    dr["chk"] = false;
                    dr["Error"] = "Not Availing Transport";
                }
            }
            catch (Exception)
            {
                dr["chk"] = false;
                dr["Error"] = "Envalid Employee ID";
            }
            if (string.IsNullOrEmpty(Convert.ToString(dr["Error"])))
            {

                dr["chk"] = true;
                dr["Error"] = "Valid";
            }

        }
        DataRow ndr = dtRoster.NewRow();
        ndr["EmployeeCode"] = "1234";
        ndr["EmployeeName"] = "test";
        ndr["AdhocDate"] = DateTime.Today;
        ndr["chk"] = false;
        dtRoster.Rows.Add(ndr);
        dtRoster.AcceptChanges();

        if (dtRoster != null && dtRoster.Rows.Count > 0 && !string.IsNullOrEmpty(Convert.ToString(dtRoster.Rows[0]["EmployeeCode"])))
        {
            flag = false;
            btnExporttoExcel.Visible = true;
            btnSaveData.Visible = true;
            ViewState["dtOtherEmployee"] = dtRoster;
            grdViewEmployee.DataSource = dtRoster;
            grdViewEmployee.DataBind();
        }
        else
        {
            flag = true;
            btnExporttoExcel.Visible = btnSaveData.Visible = false;
            grdViewEmployee.DataSource = null;
            grdViewEmployee.DataBind();
        }
        return flag;
    }

    protected void btnExporttoExcel_Click(object sender, EventArgs e)
    {
        try
        {
            DataTable dt = new DataTable();
            if (ViewState["dtOtherEmployee"] != null)
            {
                dt = (DataTable)ViewState["dtOtherEmployee"];

                // This actually makes your HTML output to be downloaded as .xls file
                Response.Clear();
                Response.ClearContent();
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", "attachment; filename=OtherEmployee.xls");

                // Create a dynamic control, populate and render it
                GridView excel = new GridView();
                excel.DataSource = dt;
                excel.DataBind();
                excel.RenderControl(new HtmlTextWriter(Response.Output));

                Response.Flush();
                Response.End();

            }
        }
        catch (ThreadAbortException ex)
        {
            lblMsg.CssClass = "error";
            lblMsg.Text = ex.Message.ToString();
        }

    }
    protected void grdViewEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        CheckBox chk = (CheckBox)e.Row.FindControl("chk");
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (!chk.Checked)
            {
                chk.Enabled = false;
            }
        }
    }
    protected void btnSaveData_Click(object sender, EventArgs e)
    {
        DataTable dtRoster = (DataTable)ViewState["dtOtherEmployee"];


        foreach (GridViewRow dgr in grdViewEmployee.Rows)
        {
            string empid = Convert.ToString(grdViewEmployee.DataKeys[dgr.RowIndex].Values[0]);
            DateTime date = Convert.ToDateTime(grdViewEmployee.DataKeys[dgr.RowIndex].Values[1]);

            CheckBox chk = (CheckBox)dgr.FindControl("chk");
            if (!chk.Checked)
            {
                DataRow[] newdr = dtRoster.Select("EmployeeCode = " + empid + " AND AdhocDate ='" + date + "'");
                newdr[0]["chk"] = false;
            }
            else
            {
                DataRow[] newdr = dtRoster.Select("EmployeeCode = " + empid + " AND AdhocDate ='" + date + "'");
                newdr[0]["chk"] = true;
            }
        }
        dtRoster.AcceptChanges();

        if (dtRoster != null)
        {
            SaveBulkAdhoc(dtRoster);
        }
    }
}


What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Web.UI.HtmlControls;
using Microsoft.ApplicationBlocks.Data;
using BLL;
using DAL;
using System.Collections;
using System.IO;
using System.Data.OleDb;
using System.Threading;

public partial class AddAdhocRoster : System.Web.UI.Page
{
EmployeeBO objEmployeeBO = new EmployeeBO();
RosterAdhoc objAdhoc = new RosterAdhoc();
public DateTime RosterStartdate = DateTime.Today;
public DateTime RosterEnddate = DateTime.Today;

protected void Page_Load(object sender, EventArgs e)
{
ScriptManager scriptManager = ScriptManager.GetCurrent(this.Page);
scriptManager.RegisterPostBackControl(this.btnExporttoExcel);

Page.Form.Attributes.Add("enctype", "multipart/form-data");
try
{
if (Session["LoginEmployee"] != null)
{
btnAddRoster.Enabled = true;
if (!IsPostBack)
{
SetRoleBasedView();
}
if (IsPostBack)
{
if (txtRStartDate.Text.Length > 0)
calRStartDate.SelectedDate = DateTime.ParseExact(txtRStartDate.Text, calRStartDate.Format, null);
}
}
else
{
Response.Redirect("SessionExpired.aspx", false);
}


}
catch (Exception ex)
{

lblMsg.CssClass = "error";
lblMsg.Text = ex.Message.ToString();
}

Page.Title = "Add Adhoc";
}

///
/// MANAGED FOR USER,TEAM MANAGER AND ADMINISTRATOR ROLES
/// NISHA NARANG-04/11/2011
///

protected void SetRoleBasedView()
{

if (Session["LoginEmployee"] != null)
{
DataTable processAdmin = objEmployeeBO.GetProcessAdminById(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString());

string ProcessAdminEID = string.Empty;
Session["Adminprocess"] = null;
if (processAdmin != null && processAdmin.Rows.Count > 0)
{
ProcessAdminEID = processAdmin.Rows[0]["EmployeeCode"].ToString();
Session["Adminprocess"] = processAdmin.Rows[0]["ProcessName"].ToString();
}
else
{
ProcessAdminEID = string.Empty;
Session["Adminprocess"] = null;
}
// if the user id Process admin then view the bulk upload button
if (!string.IsNullOrEmpty(ProcessAdminEID))
{
rbtBulk.Visible = true;
rbtSingle.Visible = true;
}

pnlMessage.Visible = false;
pnlPage.Visible = true;
Hashtable htRoles = new Hashtable();
if (!object.Equals(Session["EmployeeRole"], null))
{
htRoles = (Hashtable)Session["EmployeeRole"];


if (htRoles.Contains("team-manager")) // FOR TEAM-MANAGER
{
// show bulk upload adhoc tab
rbtBulk.Visible = rbtSingle.Visible = true;

BindLocation(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
foreach (ListItem li in ddlSite.Items)
{
if (li.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString())
{
li.Selected = true;
ddlSite.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString();
ddlSite.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteName;
BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
foreach (ListItem li1 in ddlProcess.Items)
{
if (li1.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString())
{
li1.Selected = true;
ddlProcess.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString();
ddlProcess.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).OrganisationalUnitName;
break;
}
}
break;
}
}
//selecting the first site for the team-manager in case manager sits at other site and team sits at another site
if (ddlSite.SelectedValue == "")
{
if (ddlSite.Items.Count > 2 || ddlSite.Items.Count == 2) // multiple/single sites
{
foreach (ListItem li in ddlSite.Items)
{
li.Selected = false;
}
ddlSite.Items[1].Selected = true;
ddlSite.SelectedItem.Value = ddlSite.Items[1].Value.ToString();
ddlSite.Text = ddlSite.Items[1].Text.ToString();
BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
foreach (ListItem li1 in ddlProcess.Items)
{
li1.Selected = false;
}
ddlProcess.Items[1].Selected = true;
ddlProcess.SelectedItem.Value = ddlProcess.Items[1].Value.ToString();
ddlProcess.Text = ddlProcess.Items[1].Text.ToString();
}

}
BindApproverList(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString());
if (ddlSite.SelectedValue != "")
{
BindProcessEmployees(null);
}

if (ddlSite.Items.Count > 2) // multiple sites
{
ddlSite.Enabled = true;
if (ddlProcess.Items.Count > 2) //multiple sites
ddlProcess.Enabled = true;
}
else if (ddlSite.Items.Count == 2 && (ddlProcess.Items.Count > 2)) //single site multiple teams
{
ddlSite.Enabled = false;
ddlProcess.Enabled = true;
}
else
{
ddlSite.Enabled = false;
ddlProcess.Enabled = false;
}


tblCUser.Visible = false;
tblOEmp.Visible = false;
//page will only be visible to team managers who are using the transport
if (((View_EmployeeMaster)Session["LoginEmployee"]).IsActive == true && ((View_EmployeeMaster)Session["LoginEmployee"]).AvailingTransport == false)
{
ddlTMSelf.Items.Remove("Self");
tblapprover.Visible = false;
}
else
{
tblapprover.Visible = true;
}
}
else if (htRoles.Contains("administrator"))
{
BindApproverList(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString());
if (Convert.ToInt32(((View_EmployeeMaster)Session["LoginEmployee"]).RoleID.ToString()) == 2) // transport administrator but team manager
{
BindLocation(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
foreach (ListItem li in ddlSite.Items)
{
if (li.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString())
{
li.Selected = true;
ddlSite.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString();
ddlSite.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteName;
BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
foreach (ListItem li1 in ddlProcess.Items)
{
if (li1.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString())
{
li1.Selected = true;
ddlProcess.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString();
ddlProcess.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).OrganisationalUnitName;
break;
}
}
break;
}
}


//selecting the first site for the team-manager in case manager sits at other site and team sits at another site
if (ddlSite.SelectedValue == "")
{
if (ddlSite.Items.Count > 2 || ddlSite.Items.Count == 2) // multiple/single sites
{
foreach (ListItem li in ddlSite.Items)
{
li.Selected = false;
}
ddlSite.Items[1].Selected = true;
ddlSite.SelectedItem.Value = ddlSite.Items[1].Value.ToString();
ddlSite.Text = ddlSite.Items[1].Text.ToString();
BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
foreach (ListItem li1 in ddlProcess.Items)
{
li1.Selected = false;
}
ddlProcess.Items[1].Selected = true;
ddlProcess.SelectedItem.Value = ddlProcess.Items[1].Value.ToString();
ddlProcess.Text = ddlProcess.Items[1].Text.ToString();
}

}
if (ddlSite.SelectedValue != "")
{
BindProcessEmployees(null);
}

if (ddlSite.Items.Count > 2) // multiple sites
{
ddlSite.Enabled = true;
if (ddlProcess.Items.Count > 2) //multiple sites
ddlProcess.Enabled = true;
}
else if (ddlSite.Items.Count == 2 && (ddlProcess.Items.Count > 2)) //single site multiple teams
{
ddlSite.Enabled = false;
ddlProcess.Enabled = true;
}
else
{
ddlSite.Enabled = false;
ddlProcess.Enabled = false;
}

tblCUser.Visible = false;
tblOEmp.Visible = false;
//page will only be visible to team managers who are using the transport
if (((View_EmployeeMaster)Session["LoginEmployee"]).IsActive == true && ((View_EmployeeMaster)Session["LoginEmployee"]).AvailingTransport == false)
{
ddlTMSelf.Items.Remove("Self");
tblapprover.Visible = false;
}
else
{
tblapprover.Visible = true;
}
}
else if (Convert.ToInt32(((View_EmployeeMaster)Session["LoginEmployee"]).RoleID.ToString()) == 3) //transport administrator but user
{
BindLocation(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 2);
foreach (ListItem li in ddlSite.Items)
{
if (li.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString())
{
li.Selected = true;
ddlSite.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString();
ddlSite.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteName;
BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 2);
foreach (ListItem li1 in ddlProcess.Items)
{
if (li1.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString())
{
li1.Selected = true;
ddlProcess.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString();
ddlProcess.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).OrganisationalUnitName;
break;
}
}
break;
}
}
ddlProcess.Enabled = false;
ddlSite.Enabled = false;
tblapprover.Visible = true;
tblCUser.Visible = false;
tblOEmp.Visible = false;
tblTMSelf.Visible = false;
}
}
else // FOR USER
{

BindLocation(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 2);
foreach (ListItem li in ddlSite.Items)
{
if (li.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString())
{
li.Selected = true;
ddlSite.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteID.ToString();
ddlSite.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).SiteName;
BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 2);
foreach (ListItem li1 in ddlProcess.Items)
{
if (li1.Value == ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString())
{
li1.Selected = true;
ddlProcess.SelectedItem.Value = ((View_EmployeeMaster)Session["LoginEmployee"]).OrgUnitID.ToString();
ddlProcess.Text = ((View_EmployeeMaster)Session["LoginEmployee"]).OrganisationalUnitName;
break;
}
}
break;
}
}

BindApproverList(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString());
ddlProcess.Enabled = false;
ddlSite.Enabled = false;
tblapprover.Visible = true;
tblCUser.Visible = false;
tblOEmp.Visible = false;
tblTMSelf.Visible = false;
}
}


//if (htRoles.Contains("administrator"))//|| htRoles.Contains("transport-desk"))// FOR TRANSPORT ADMINISTRATOR , TRANSPORT DESK
//{
// txtTransportRemarks.Visible = true;
// tblapprover.Visible = false;
// tblTMSelf.Visible = false;
// BindLocation(string.Empty, 0);
// ddlProcess.Enabled = true;
// ddlSite.Enabled = true;
// trtRemarks.Visible = true;
// btnAddRoster.Visible = true;

// //tblapprover.Visible = true;
// //tblCUser.Visible = false;
// //tblOEmp.Visible = false;
// //tblTMSelf.Visible = false;
//}
//else

//else
//{
// pnlMessage.Visible = true;
// pnlPage.Visible = false;
//}
}

}

protected void ResetFields()
{
BindLocation(string.Empty, 0);
ddlProcess.Items.Clear();
ddlProcess.Enabled = false;
//ddlProcess.Items.Clear();
//ddlProcess.Enabled = false;
cbEmployees.Items.Clear();
cbEmployees.Enabled = false;
}

protected void DisableFields()
{
ddlSite.Items.Clear();
ddlSite.Enabled = false;
ddlProcess.Items.Clear();
ddlProcess.Enabled = false;
//ddlProcess.Items.Clear();
//ddlProcess.Enabled = false;
cbEmployees.Items.Clear();
cbEmployees.Enabled = false;
ddlAdhocType.Enabled = false;
txtAdhocRosterTime.Enabled = false;
txtReason.Enabled = false;
}

protected void calRStartDate_DateChanged(object sender, EventArgs e)
{
txtRStartDate.Text = calRStartDate.SelectedDate.ToString();
}

protected void BindApproverList(string employeeCode)
{
ddlApprover.Items.Clear();

// View_EmployeeMaster objEmp = (View_EmployeeMaster)Session["LoginEmployee"];
//ddlApprover.DataSource = objEmployeeBO.GetApproverList(objEmp.EmployeeCode);
ddlApprover.DataSource = objEmployeeBO.GetApproverList(employeeCode);
ddlApprover.DataTextField = "EmployeeName";
ddlApprover.DataValueField = "ApproverCodeEmail";
//EmployeeEmail
ddlApprover.DataBind();
if (ddlApprover.Items.Count > 0)
{
ddlApprover.Items.Insert(0, new ListItem("- Select -", ""));
ddlApprover.SelectedIndex = 0;
}
}

///
/// MANAGED FOR USER,TEAM MANAGER AND TRANSPORT ADMINISTRATOR ROLE
/// Nisha Narang-04/11/2011
///

/// <param name="EmployeeID" />
/// <param name="type" />
protected void BindLocation(string EmployeeID, int type)
{
ddlSite.Items.Clear();

if (type == 0) // FOR TRANSPORT ADMINISTRATOR
{
ddlSite.DataSource = objEmployeeBO.GetSites();
ddlSite.DataTextField = "SiteName";
ddlSite.DataValueField = "ID";
ddlSite.DataBind();
ddlSite.Items.Insert(0, new ListItem("- Select -", ""));
ddlSite.Enabled = false;
}
else if (type == 1) // FOR TEAM MANAGER
{
string SupervisorID = EmployeeID;
ddlSite.DataSource = objEmployeeBO.GetSitesByRM(SupervisorID);
ddlSite.DataTextField = "SiteName";
ddlSite.DataValueField = "SiteID";
ddlSite.DataBind();
ddlSite.Items.Insert(0, new ListItem("- Select -", ""));
ddlSite.Enabled = true;
ddlProcess.Enabled = true;
//cblDeptManagers.Enabled=true;
}
else if (type == 2)// FOR USER
{
ddlSite.DataSource = objEmployeeBO.GetSiteByEmployee(EmployeeID);
ddlSite.DataTextField = "SiteName";
ddlSite.DataValueField = "SiteID";
ddlSite.DataBind();
ddlSite.Items.Insert(0, new ListItem("- Select -", ""));
ddlSite.Enabled = false;
ddlProcess.Enabled = false;
}
}



///
/// MANAGED FOR USER,TEAM-MANAGER AND TRANSPORT
/// Nisha Narang-04/11/2011
///

/// <param name="EmployeeID" />
/// <param name="RoleType" />

protected void BindProcess(string EmployeeID, int RoleType)
{
ddlProcess.Items.Clear();
if (RoleType == 0 && ddlSite.SelectedItem.Value != "") // For Transport Administrator
{
ddlProcess.DataSource = objEmployeeBO.GetProcess(Convert.ToInt64(ddlSite.SelectedItem.Value));
ddlProcess.DataTextField = "OrganisationalUnitName";
ddlProcess.DataValueField = "ID";
ddlProcess.DataBind();
ddlProcess.Items.Insert(0, new ListItem("- Select -", ""));
}
else if (RoleType == 1 && ddlSite.SelectedItem.Value != "") // For Team Manager
{
string SupervisorID = EmployeeID;
ddlProcess.DataSource = objEmployeeBO.GetProcessByRM(SupervisorID, Convert.ToInt32(ddlSite.SelectedItem.Value));
ddlProcess.DataTextField = "OrganisationalUnitName";
ddlProcess.DataValueField = "OrgUnitID";
ddlProcess.DataBind();
ddlProcess.Items.Insert(0, new ListItem("- Select -", ""));
}
else if (RoleType == 2 && ddlSite.SelectedItem.Value != "") // For user
{

ddlProcess.DataSource = objEmployeeBO.GetProcessByEmployee(EmployeeID);
ddlProcess.DataTextField = "OrganisationalUnitName";
ddlProcess.DataValueField = "OrgUnitID";
ddlProcess.DataBind();
ddlProcess.Items.Insert(0, new ListItem("- Select -", ""));
}
}

///
/// binding the employees according to
///

/// <param name="htRoles" />
protected void BindProcessEmployees(Hashtable htRoles = null)
{

cbEmployees.Items.Clear();

List<long> OrgunitID = new List<long>();
foreach (ListItem li in ddlProcess.Items)
{
if (li.Selected == true && li.Value != "")
{
OrgunitID.Add(Convert.ToInt64(li.Value));
break;
}
}
//long subProcessId = 0;
//if (ddlSubProcess.SelectedIndex > 0)
// subProcessId = Convert.ToInt64(ddlSubProcess.SelectedValue);
//cbEmployees.DataSource = objEmployeeBO.GetEmployeesByProcess(ProcessID, Convert.ToInt64(ddlProcess.SelectedItem.Value), Convert.ToInt64(ddlSite.SelectedItem.Value), subProcessId);
if (htRoles == null && ddlSite.SelectedItem.Value != "")
{
cbEmployees.DataSource = objEmployeeBO.GetEmployeesByOrgUnit(OrgunitID, Convert.ToInt64(ddlSite.SelectedItem.Value), ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode);
}
else if (htRoles.Contains("administrator") && ddlSite.SelectedItem.Value != "")// || htRoles.Contains("transport-desk"))
{
cbEmployees.DataSource = objEmployeeBO.GetEmployeesByOrgUnit(OrgunitID, Convert.ToInt64(ddlSite.SelectedItem.Value), string.Empty);

}
cbEmployees.DataTextField = "EmployeeName";
cbEmployees.DataValueField = "EmployeeCode";
cbEmployees.DataBind();
if (cbEmployees.Items.Count > 0)
{
cbEmployees.Enabled = true;
cbEmployees.Items.Insert(0, new ListItem("Select All", "-1"));
}
}

protected void ddlSite_SelectedIndexChanged(object sender, EventArgs e)
{


Hashtable htRoles = new Hashtable();
if (!object.Equals(Session["EmployeeRole"], null))
{
htRoles = (Hashtable)Session["EmployeeRole"];
if (htRoles.Contains("team-manager"))
{
BindProcess(((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode.ToString(), 1);
}
else
{
BindProcess(string.Empty, 0);
}
}
else
{
BindProcess(string.Empty, 0);
}
//if (ddlProcess.Items.Count > 2)
//{
// //multiple sites multiple teams
// foreach (ListItem li1 in ddlProcess.Items)
// {
// li1.Selected = false;
// }
// ddlProcess.Enabled = true;
//}
//else if (ddlProcess.Items.Count == 2)
//{
// ddlProcess.Items[0].Selected = true;
// ddlProcess.SelectedItem.Value = ddlProcess.Items[0].Value.ToString();
// ddlProcess.Text = ddlProcess.Items[0].Text.ToString();
// ddlProcess.Items[1].Selected = true;
// ddlProcess.SelectedItem.Value = ddlProcess.Items[1].Value.ToString();
// ddlProcess.Text = ddlProcess.Items[1].Text.ToString();
// ddlProcess.Enabled = false;

//}
}
///
/// NISHA NARANG --12/10/2011
/// MANAGED FOR BINDING THE APPROVER HIERARCHY OF AN EMPLOYEE
///
///

/// <param name="sender" />
/// <param name="e" />
protected void ddlProcess_SelectedIndexChanged(object sender, EventArgs e)
{
//ddlProcess.Enabled = true;
//BindProcess();
Hashtable htRoles = new Hashtable();
if (!object.Equals(Session["EmployeeRole"], null))
{
htRoles = (Hashtable)Session["EmployeeRole"];

if (htRoles.Contains(("User".ToLower())))
{
View_EmployeeMaster objEmp = (View_EmployeeMaster)Session["LoginEmployee"];
// binding the manager hierarchy for User Role
BindApproverList(objEmp.EmployeeCode);
}
else
{
//binding the employees for Team Manager and Transport Administrator as Team Manager
BindProcessEmployees(htRoles);
// For Team-Manager Role -Team Manager himself is first level approver
// as if list of employees gets populated then approver tab is not required
if (cbEmployees.Items.Count > 0)
{
tblapprover.Visible = false;
//BindApproverList(cbEmployees.Items[0].Value.ToString());
}
}
}
else
{
// binding the employees for Transport Administrator
BindProcessEmployees(null);

if (cbEmployees.Items.Count > 0)
{
tblapprover.Visible = false;
BindApproverList(cbEmployees.Items[0].Value.ToString());
}

}
}


///
/// MANAGING FOR SELECT ALL FUNCTIONALITY
/// Nisha Narang - 13/10/2011
///

/// <param name="sender" />
/// <param name="e" />
protected void cbEmployees_SelectedIndexChanged(object sender, EventArgs e)
{
lblSelEmployee.Text = "";
foreach (ListItem li in cbEmployees.Items)
{

if (li.Selected == true)
{
if (Convert.ToInt32(li.Value) == -1)
{
foreach (ListItem li1 in cbEmployees.Items)
{
li1.Selected = true;
//ProcessID.Add(Convert.ToInt64(li.Value));
}
ViewState["boolAllChecked"] = 1;
break;
}
else
{
//ProcessID.Add(Convert.ToInt64(li.Value));
break;
}

}
else if (li.Selected == false)
{
if (Convert.ToInt32(li.Value) == -1 && Convert.ToInt32(ViewState["boolAllChecked"]) == 1)
{
foreach (ListItem li1 in cbEmployees.Items)
{
li1.Selected = false;
}
ViewState["boolAllChecked"] = 0; break;
}

}
}
}



protected void btnAddRoster_Click(object sender, EventArgs e)
{
lblMsg.Text = "";
Hashtable htRoles = new Hashtable();
//Page.Validate();
try
{
if (Page.IsValid)
{
bool chkEmpSelected = false;
//check for employee selected or not
if (ddlTMSelf.SelectedValue.ToLower().Equals("team-member"))
{
foreach (ListItem li in cbEmployees.Items)
{
if (li.Selected == true)
{
chkEmpSelected = true;
break;
}

}
if (!chkEmpSelected)
{
lblSelEmployee.CssClass = "error";
lblSelEmployee.Text = "Please Select Employee.";
cbEmployees.Focus();
return;
}
}



//checking for adhoc date should be today's date and later
DateTime Startdate = DateTime.Now.Date; DateTime Enddate = calRStartDate.SelectedDate.Value;
TimeSpan span = Enddate.Subtract(Startdate);
if (span.Days >= 0)
{
btnAddRoster.Enabled = false;
// getting Transport Email address according to the selected site

string siteTransportEmailAddress = string.Empty;
string selectedSite = ddlSite.SelectedItem.Text;
if (selectedSite.ToLower().Equals("pune"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["PuneDeskMail"].ToString();
}
else if (selectedSite.ToLower().Equals("andheri"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["AndheriDeskMail"].ToString();
}
else if (selectedSite.ToLower().Equals("vikhroli"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["VikhroliDeskMail"].ToString();
}
else if (selectedSite.ToLower().Equals("thane"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["ThaneDeskMail"].ToString();
}
else if (selectedSite.ToLower().Equals("bangalore"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["BangaloreDeskMail"].ToString();
}
else if (selectedSite.ToLower().Equals("pune kn"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["KNDeskMail"].ToString();
}
//
if (!object.Equals(Session["EmployeeRole"], null))
{
htRoles = (Hashtable)Session["EmployeeRole"];
string websiteURL = ConfigurationManager.AppSettings["WebSiteURL"].ToString();
//string emailFilePath = Page.ResolveClientUrl("~/ViewAdhocRoster.aspx") + "?Action=EMail&ReferenceID=";
string emailFilePath = websiteURL + "/ViewAdhocRoster.aspx?Action=EMail&ReferenceID=";
if (htRoles.Contains("administrator"))// || htRoles.Contains("transport-desk"))
{
if (Convert.ToInt32(((View_EmployeeMaster)Session["LoginEmployee"]).RoleID.ToString()) == 2) //transport administrator but actually Team Manager
{
SaveAdhocTeamManager(emailFilePath, siteTransportEmailAddress);
}
else if (Convert.ToInt32(((View_EmployeeMaster)Session["LoginEmployee"]).RoleID.ToString()) == 3) //transport administrator but actually User
{
SaveAdhocUser(emailFilePath, siteTransportEmailAddress);
}
//SaveAdhocAdmin(emailFilePath, siteTransportEmailAddress);
}
else if (htRoles.Contains("team-manager")) // team manager
{
SaveAdhocTeamManager(emailFilePath, siteTransportEmailAddress);
}
else // Save for USER Role -logged in user is adding the adhoc request by himself.
{
SaveAdhocUser(emailFilePath, siteTransportEmailAddress);
}
}
}
else
{
lblMsg.CssClass = "error";
lblMsg.Text = "Warning : Adhoc Date should be equal to Today Date or greater than Today Date!";
}
}
}
catch (Exception ex)
{
lblMsg.CssClass = "error";
lblMsg.Text = ex.Message.ToString();
}

}

protected void rdNewEmployee_SelectedIndexChanged(object sender, EventArgs e)
{
if (rdNewEmployee.SelectedItem.Value == "1")
{
tblEmployeeList.Visible = true;
tblOEmp.Visible = false;
tblapprover.Visible = false;
//RequiredFieldValidatorApprover.Visible = true;
}
else
{
/// Nisha Narang - 18/10/2011
tblOEmp.Visible = true;
Hashtable htRoles = new Hashtable();
if (!object.Equals(Session["EmployeeRole"], null))
{
htRoles = (Hashtable)Session["EmployeeRole"];

if (htRoles.Contains("team-manager") && ddlTMSelf.SelectedItem.Value.ToLower().Equals("self"))
{
tblapprover.Visible = true;
}
else
{
tblapprover.Visible = false;
}
}
else
{
tblapprover.Visible = false;
}
tblEmployeeList.Visible = false;
//RequiredFieldValidatorApprover.Visible = false;
}
}
///
/// Nisha Narang - 17/10/2011
/// custom validator to validate selection of approver according to user role
///

/// <param name="source" />
/// <param name="args" />
protected void CustomApprovervalidator_ServerValidate(object source, ServerValidateEventArgs args)
{

//this validator only works for team-manager & user roles
//if login user is administrator /transport-desk then Adhoc is self approved no need for the selection
if (rdNewEmployee.SelectedValue.ToString().Equals("2"))
{
Hashtable htRoles = new Hashtable();
if (!object.Equals(Session["EmployeeRole"], null))
{
htRoles = (Hashtable)Session["EmployeeRole"];

if (htRoles.Contains("team-manager") || htRoles.Contains("administrator"))
{
args.IsValid = true;
}
}
}
else
{
Hashtable htRoles = new Hashtable();
if (!object.Equals(Session["EmployeeRole"], null))
{
htRoles = (Hashtable)Session["EmployeeRole"];

if (htRoles.Contains("user") || htRoles.Contains("team-manager") || htRoles.Contains("administrator"))
{
if (ddlApprover.SelectedIndex > 0)
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
}
else
{
args.IsValid = false;
}
}
//args.IsValid = false;
//lblMsg.Text = "Select Approver";
}
}
protected void ddlSubProcess_SelectedIndexChanged(object sender, EventArgs e)
{

Hashtable htRoles = new Hashtable();
if (!object.Equals(Session["EmployeeRole"], null))
{
htRoles = (Hashtable)Session["EmployeeRole"];
if (htRoles.Contains(("user")))
{
View_EmployeeMaster objEmp = (View_EmployeeMaster)Session["LoginEmployee"];
BindApproverList(objEmp.EmployeeCode);
// BindProcessEmployees();
}
else
{
BindProcessEmployees(null);
BindApproverList(cbEmployees.Items[0].Value.ToString());
}
}
else
{
BindProcessEmployees(null);
BindApproverList(cbEmployees.Items[0].Value.ToString());
}

}
protected void CustomValidatorsubprocess_ServerValidate(object source, ServerValidateEventArgs args)
{
//if (ddlSubProcess.Enabled == true)
//{
// if (ddlSubProcess.Items.Count > 0)
// {
// if (ddlSubProcess.SelectedIndex > 0)
// {
// args.IsValid = true;
// }
// else
// {
// args.IsValid = false;
// }
// }
// else
// {
// args.IsValid = false;
// }
//}
}
protected void ddlTMSelf_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlTMSelf.SelectedItem.Value.ToLower().Equals("team-member"))
{
tblapprover.Visible = false;
BindProcessEmployees(null);
tblCUser.Visible = true;
tblOEmp.Visible = true;
tblEmployeeList.Visible = false;
}
else if (ddlTMSelf.SelectedItem.Value.ToLower().Equals("self"))
{

tblapprover.Visible = true;
tblCUser.Visible = false;
tblOEmp.Visible = false;
tblEmployeeList.Visible = false;
}
else if (ddlTMSelf.SelectedItem.Value.ToLower().Equals("select"))
{

tblOEmp.Visible = false;
tblCUser.Visible = false;
}

}

protected void SaveAdhocAdmin(string emailFilePath, string siteTransportEmailAddress)
{

//*********************************************************************************************************************************
// CASE WHEN TRANSPORT ADMINISTRATOR OR TRANSPORT DESK IS RAISING ADHOC REQUEST
//*********************************************************************************************************************************
if (tblCUser.Visible == false)
{
objAdhoc = new RosterAdhoc();
TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
objAdhoc.AdhocTime = tsAdhoc;
objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
objAdhoc.EmployeeCode = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;

objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
//objAdhoc.ProcessID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
objAdhoc.Remarks = txtReason.Text;
objAdhoc.ApprovalStatusID = -1;// In-progress status
//adding approver employee code
string approverEmpCode = string.Empty;
if (tblapprover.Visible == true)
{
if (ddlApprover.SelectedItem.Value.Contains('-'))
{
approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
}
else
{
approverEmpCode = ddlApprover.SelectedItem.Value;
}
objAdhoc.FirstLevelApprover = approverEmpCode;
}
else
{
objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
}

objAdhoc.FirstLevelApprovedDate = DateTime.Now;
objAdhoc.isActive = true;

OperationStatus os = objEmployeeBO.InsertNewEmpAdhocRequest(objAdhoc);
lblMsg.Text = "Adhoc Successfully Added!";
if (os.InsertedRowID > 0)
{
//string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();

string MailBody = "";
MailBody = "Hi," +
"

New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " + calRStartDate.SelectedDate.Value.Date.ToShortDateString() + ", Time: " + tsAdhoc + " by " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for self.
(Employee Code: " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode + ") Process : " + ddlProcess.SelectedItem.Text + "
" +
"Requesting you to Approve/Reject for further process.
" +
"

" +
"You can access the request by clicking on " +
"WBR" +
"

" +
"Regards," +
"
" +
"Transport Team
" +
"



This is a system generated e-mail. Please do not reply to this e-mail.
" +
"Capita India- Application Services Team
";
//emailFilePath + Convert.ToString(os.InsertedRowID) + "


" + //Adhoc reference ID: " + os.InsertedRowID + "" +
//"

Regards,
Transport Team

";
WBREmail mail = new WBREmail();
string HeadName, HeadEmail = string.Empty;
HeadName = ddlApprover.SelectedItem.Text.ToString();


if (ddlApprover.SelectedItem.Value.Contains('-'))
{
HeadEmail = ddlApprover.SelectedItem.Value.Split('-')[1];
}
else
{
HeadEmail = ddlApprover.SelectedItem.Value;
}
mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), HeadName, HeadEmail,
"", "", "New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
lblMsg.CssClass = "success";
lblMsg.Text = "Adhoc added successfully.";
}
}
// Nisha Narang - 21/10/2011
//*********************************************************************************************************************************
// CASE WHEN TEAM MANAGER RAISING THE ADHOC REQUEST FOR HIS TEAM MEMBER
// REQUEST REQUIRES FURTHER APPROVAL OF TRANSPORT AND MAIL GOES TO TRANSPORT
//*********************************************************************************************************************************
else if (rdNewEmployee.SelectedItem.Value == "0")
{
foreach (ListItem li in cbEmployees.Items)
{
if (Convert.ToInt32(li.Value) != -1)
{
if (li.Selected == true)
{
DataTable dtEmpDatilsforEmail = new DataTable();
List<string> EmpID = new List<string>();

objAdhoc = new RosterAdhoc();
TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
objAdhoc.AdhocTime = tsAdhoc;
objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;// Team-Manager Id
objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
objAdhoc.EmployeeCode = li.Value;
objAdhoc.Remarks = txtReason.Text;
objAdhoc.ApprovalStatusID = -1; // in progress status
//adding approver employee code
string approverEmpCode = string.Empty;
if (tblapprover.Visible == true)
{
if (ddlApprover.SelectedItem.Value.Contains('-'))
{
approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
}
else
{
approverEmpCode = ddlApprover.SelectedItem.Value;
}

objAdhoc.FirstLevelApprover = approverEmpCode;
}
else
{
objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
}
objAdhoc.FirstLevelApprovedDate = DateTime.Now;
objAdhoc.isActive = true;

OperationStatus os = objEmployeeBO.InsertAdhocRequest(objAdhoc);
//lblMsg.Text = "Adhoc Successfully Added!";

EmpID.Add(li.Value);

if (os.InsertedRowID > 0)
{
//string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
string MailBody = "";
MailBody = "Hi," +
"

New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " + calRStartDate.SelectedDate.Value.Date.ToShortDateString() + ", Time: " + tsAdhoc + " by " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for Employee Name: " + li.Text.ToString() + "(Employee Code: " + li.Value + ") Process : " + ddlProcess.SelectedItem.Text + "
" +
"Requesting you to Approve/Reject for further process.
" +
"

" +
"You can access the request by clicking on " +
"WBR" +
"

" +
"Regards," +
"
" +
"Transport Team
" +
"



This is a system generated e-mail. Please do not reply to this e-mail.
" +
"Capita India- Application Services Team
";
WBREmail mail = new WBREmail();
//********************************************************
// Direct Email to transport
//********************************************************
mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), "Transport-Desk", siteTransportEmailAddress,
"", "", "New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
lblMsg.CssClass = "success";
lblMsg.Text = "Adhoc added successfully.";
//break;

}
}
}
}
}
else
{
// Nisha Narang - 20/10/2011
//*********************************************************************************************************************************
// CASE WHEN TRANSPORT ADMINISTRATOR RAISING THE ADHOC REQUEST FOR A NEW JOINEE OF ANY PROCESS
// REQUEST IS ALREADY BEING APPROVED BY THE FIRST APPROVER FROM TRANSPORT ADMINISTRATOR
//*********************************************************************************************************************************

DataTable dtEmpDatilsforEmail = new DataTable();
List<string> EmpID = new List<string>();

objAdhoc = new RosterAdhoc();
TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
objAdhoc.AdhocTime = tsAdhoc;
objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;// Team-Manager Id
objAdhoc.EmployeeCode = "NJ";
objAdhoc.EmployeeName = txtEmpName.Text;
objAdhoc.EmpAddress = txtAddress.Text;
objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
//objAdhoc.ProcessID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
objAdhoc.Remarks = txtReason.Text;
objAdhoc.ApprovalStatusID = -1;//In-Progress Status
//adding approver employee code
string approverEmpCode = string.Empty;
if (tblapprover.Visible == true)
{
if (ddlApprover.SelectedItem.Value.Contains('-'))
{
approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
}
else
{
approverEmpCode = ddlApprover.SelectedItem.Value;
}
objAdhoc.FirstLevelApprover = approverEmpCode;
}
else
{
objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
}
objAdhoc.FirstLevelApprovedDate = DateTime.Now;

objAdhoc.isActive = true;

OperationStatus os = objEmployeeBO.InsertNewEmpAdhocRequest(objAdhoc);
lblMsg.Text = "Adhoc Successfully Added!";
lblMsg.CssClass = "success";
if (os.InsertedRowID > 0)
{
if (tblOEmp.Visible == false)
{
//string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
string MailBody = "";
MailBody = "Hi," +
"

New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " + calRStartDate.SelectedDate.Value.Date.ToShortDateString() + ", Time: " + tsAdhoc + " by " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for Employee Name: " + txtEmpName.Text + "(Employee Code: NJ ) Process : " + ddlProcess.SelectedItem.Text + "
" +
"Requesting you to Approve/Reject for further process.
" +
"

" +
"You can access the request by clicking on " +
"WBR" +
"

" +
"Regards," +
"
" +
"Transport Team
" +
"



This is a system generated e-mail. Please do not reply to this e-mail.
" +
"Capita India- Application Services Team
";
WBREmail mail = new WBREmail();
mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), "Transport-Desk", siteTransportEmailAddress,
"", "", "New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
}

}

}

}

protected void SaveAdhocTeamManager(string emailFilePath, string siteTransportEmailAddress)
{
// Nisha Narang - 21/10/2011
//*********************************************************************************************************************************
// CASE WHEN TEAM MANAGER RAISING THE ADHOC REQUEST FOR HIS TEAM MEMBER
// REQUEST REQUIRES FURTHER APPROVAL OF TRANSPORT AND MAIL GOES TO TRANSPORT
//*********************************************************************************************************************************
if (tblCUser.Visible == false)
{
SaveAdhocUser(emailFilePath, siteTransportEmailAddress);
}
else if (rdNewEmployee.SelectedItem.Value == "0")
{
foreach (ListItem li in cbEmployees.Items)
{
if (Convert.ToInt32(li.Value) != -1)
{
if (li.Selected == true)
{
DataTable dtEmpDatilsforEmail = new DataTable();
List<string> EmpID = new List<string>();

objAdhoc = new RosterAdhoc();
TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
objAdhoc.AdhocTime = tsAdhoc;
objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;// Team-Manager Id
objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
objAdhoc.EmployeeCode = li.Value;
objAdhoc.Remarks = txtReason.Text;
objAdhoc.ApprovalStatusID = -1; // in progress status
//adding approver employee code
string approverEmpCode = string.Empty;
if (tblapprover.Visible == true)
{
if (ddlApprover.SelectedItem.Value.Contains('-'))
{
approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
}
else
{
approverEmpCode = ddlApprover.SelectedItem.Value;
}

objAdhoc.FirstLevelApprover = approverEmpCode;
}
else
{
objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
}
objAdhoc.FirstLevelApprovedDate = DateTime.Now;
objAdhoc.isActive = true;

OperationStatus os = objEmployeeBO.InsertAdhocRequest(objAdhoc);
lblMsg.Text = "Adhoc Successfully Added!";

EmpID.Add(li.Value);

if (os.InsertedRowID > 0)
{
//string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
string MailBody = "";
MailBody = "Hi," +
"

New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " +
calRStartDate.SelectedDate.Value.Date.ToShortDateString() + ", Time: " + tsAdhoc + " by "
+ ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for Employee Name: " + li.Text.ToString()
+ "(Employee Code: " + li.Value + ") Process : " + ddlProcess.SelectedItem.Text + "
" +
"Requesting you to Approve/Reject for further process.
" +
"

" +
"You can access the request by clicking on " +
"WBR" +
"

" +
"Regards," +
"
" +
"Transport Team
" +
"



This is a system generated e-mail. Please do not reply to this e-mail.
" +
"Capita India- Application Services Team
";
WBREmail mail = new WBREmail();
//********************************************************
// Direct Email to transport
//********************************************************
mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), "Transport-Desk", siteTransportEmailAddress,
"", "", "New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
lblMsg.CssClass = "success";
lblMsg.Text = "Adhoc added successfully.";
//break;

}
}
}
}
}
else
{
// Nisha Narang - 20/10/2011
//*********************************************************************************************************************************
// CASE WHEN TEAM MANAGER RAISING THE ADHOC REQUEST FOR A NEW JOINEE IN HIS TEAM
// REQUEST FURTHER APPROVAL OF TRANSPORT AND MAIL GOES TO TRANSPORT
//*********************************************************************************************************************************

DataTable dtEmpDatilsforEmail = new DataTable();
List<string> EmpID = new List<string>();

objAdhoc = new RosterAdhoc();
TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
objAdhoc.AdhocTime = tsAdhoc;
objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;// Team-Manager Id
objAdhoc.EmployeeCode = "NJ";
objAdhoc.EmployeeName = txtEmpName.Text;
objAdhoc.EmpAddress = txtAddress.Text;
objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
//objAdhoc.ProcessID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
objAdhoc.Remarks = txtReason.Text;
objAdhoc.ApprovalStatusID = -1;//In-Progress Status
//adding approver employee code
string approverEmpCode = string.Empty;
if (tblapprover.Visible == true)
{
if (ddlApprover.SelectedItem.Value.Contains('-'))
{
approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
}
else
{
approverEmpCode = ddlApprover.SelectedItem.Value;
}
objAdhoc.FirstLevelApprover = approverEmpCode;
}
else
{
objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
}
objAdhoc.FirstLevelApprovedDate = DateTime.Now;

objAdhoc.isActive = true;

OperationStatus os = objEmployeeBO.InsertNewEmpAdhocRequest(objAdhoc);
lblMsg.Text = "Adhoc Successfully Added!";
lblMsg.CssClass = "success";
if (os.InsertedRowID > 0)
{
if (tblOEmp.Visible == false)
{
//string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
string MailBody = "";
MailBody = "Hi," +
"

New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " + calRStartDate.SelectedDate.Value.Date.ToShortDateString()
+ ", Time: " + tsAdhoc + " by " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName
+ " for Employee Name: " + txtEmpName.Text + "(Employee Code: NJ ) Process : " +
ddlProcess.SelectedItem.Text + "
" +
"Requesting you to Approve/Reject for further process.
" +
"

" +
"You can access the request by clicking on " +
"WBR" +
"

" +
"Regards," +
"
" +
"Transport Team
" +
"



This is a system generated e-mail. Please do not reply to this e-mail.
" +
"Capita India- Application Services Team
";
WBREmail mail = new WBREmail();

mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), "Transport-Desk", siteTransportEmailAddress,
"", "", "New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
}

}

}

}

protected void SaveAdhocUser(string emailFilePath, string siteTransportEmailAddress)
{
// Nisha Narang - 19/10/2011
//*********************************************************************************************************************************
// CASE WHEN USER IS RAISING THE REQUEST FOR HIMSELF
// AND MAIL GOES TO HIS MANAGER FOR APPROVAL //AND CC TO TRANSPORT
//*********************************************************************************************************************************

objAdhoc = new RosterAdhoc();
TimeSpan tsAdhoc = new TimeSpan(Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[0]), Convert.ToInt32(txtAdhocRosterTime.Text.ToString().Split(':')[1]), 0);
objAdhoc.AdhocDate = calRStartDate.SelectedDate.Value;
objAdhoc.AdhocTime = tsAdhoc;
objAdhoc.AdhocTypeID = Convert.ToInt32(ddlAdhocType.SelectedItem.Value);
objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
objAdhoc.EmployeeCode = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;

objAdhoc.SiteID = Convert.ToInt64(ddlSite.SelectedItem.Value);
objAdhoc.OrgUnitID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
//objAdhoc.ProcessID = Convert.ToInt64(ddlProcess.SelectedItem.Value);
objAdhoc.Remarks = txtReason.Text;
objAdhoc.ApprovalStatusID = 0;// New Adhoc Request
//adding approver employee code
string approverEmpCode = string.Empty;
if (tblapprover.Visible == true)
{
if (ddlApprover.SelectedItem.Value.Contains('-'))
{
approverEmpCode = ddlApprover.SelectedItem.Value.Split('-')[0];
}
else
{
approverEmpCode = ddlApprover.SelectedItem.Value;
}
objAdhoc.FirstLevelApprover = approverEmpCode;
}
else
{
objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
}

objAdhoc.FirstLevelApprovedDate = DateTime.Now;
objAdhoc.isActive = true;

OperationStatus os = objEmployeeBO.InsertNewEmpAdhocRequest(objAdhoc);

if (os.InsertedRowID > 0)
{
//string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
string MailBody = "";
MailBody = "Hi," +
"

New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request is raised for Date: " + calRStartDate.SelectedDate.Value.Date.ToShortDateString() + ", Time: " + tsAdhoc + " by " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for self (Employee Code: " + ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode + ") Process : " + ddlProcess.SelectedItem.Text + "
" +
"Requesting you to Approve/Reject for further process.
" +
"

" +
"You can access the request by clicking on " +
"WBR" +
"

" +
"Regards," +
"
" +
"Transport Team
" +
"



This is a system generated e-mail. Please do not reply to this e-mail.
" +
"Capita India- Application Services Team
";

string HeadName, HeadEmail = string.Empty;
HeadName = ddlApprover.SelectedItem.Text.ToString();


if (ddlApprover.SelectedItem.Value.Contains('-'))
{
HeadEmail = ddlApprover.SelectedItem.Value.Split('-')[1];
}
else
{
HeadEmail = ddlApprover.SelectedItem.Value;
}
WBREmail mail = new WBREmail();
mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(), ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), HeadName, HeadEmail,
"", "", "New Adhoc " + ddlAdhocType.SelectedItem.Text + " Request", MailBody);
}


lblMsg.CssClass = "success";
lblMsg.Text = "Adhoc added successfully.";

}

protected void rbtSingle_CheckedChanged(object sender, EventArgs e)
{
rbtBulk.Checked = false;
pnlbulk.Visible = false;
pnlsingle.Visible = true;
lblMessage.Text = lblMsg.Text = string.Empty;
}
protected void rbtBulk_CheckedChanged(object sender, EventArgs e)
{
rbtSingle.Checked = false;
pnlsingle.Visible = false;
pnlbulk.Visible = true;
lblMessage.Text = lblMsg.Text = string.Empty;
}
protected void btnUpload_Click(object sender, EventArgs e)
{

#region upload file code
Hashtable htRoles = new Hashtable();
try
{
if (!object.Equals(Session["EmployeeRole"], null))
{
htRoles = (Hashtable)Session["EmployeeRole"];

if (htRoles.Contains("team-manager") || Session["Adminprocess"] != null)
{

bool success = false;

//1. upload the file
//2 . get the data into a datatable from excel sheet
//2.1 read the data table row by row
//2.2 update the roster table by key employee code and roster date (pick up time , route no, zone no)
//3 delete the file

DataTable dtExcel = new DataTable();
string strConnection = ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString;
SqlConnection myConn = new SqlConnection(strConnection);
string filePath = string.Empty;

if (FileUploadRosterAdhoc.HasFile)
{
if (System.IO.Path.GetExtension(FileUploadRosterAdhoc.FileName) == ".xls" || System.IO.Path.GetExtension(FileUploadRosterAdhoc.FileName) == ".xlsx")
{
//Saving file on Server
filePath = Server.MapPath("~/Roster/Upload/Schedule_RosterAdhoc.xlsx");
if (File.Exists(filePath))
File.Delete(filePath);

FileUploadRosterAdhoc.SaveAs(filePath);
// Reading the file for data upload
string sExcelConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'";

using (OleDbConnection con = new OleDbConnection(sExcelConnectionString))
{
con.Open();
string worksheetName = "Roster";
string strCommand = "SELECT * FROM [" + worksheetName + "$]";
OleDbCommand excelCommand = new OleDbCommand(strCommand, con);
OleDbDataAdapter excelDataAdapter = new OleDbDataAdapter();
excelDataAdapter.SelectCommand = excelCommand;
excelDataAdapter.Fill(dtExcel);

DataTable dtRoster = FillDatatableInfo(dtExcel);

try
{
if (ValidateExcelDates(dtRoster))
{

if (Session["Adminprocess"] != null)
{
success = ValidateExcel(dtRoster, "ProcessAdmin");
}
else
{
success = ValidateExcel(dtRoster, "TM");
}
if (success)
{
// SaveBulkAdhoc(dtRoster);
}
else
{
lblMessage.CssClass = "error";
lblMessage.Text = "Warning : Check below information and Click on Submit button for save only valid data!";
}
}
else
{
lblMessage.CssClass = "error";
lblMessage.Text = "Warning :Some of Employees Adhoc Date is less than Today Date!";
}

}
catch (Exception ex)
{

lblMessage.CssClass = "error";
lblMessage.Text = ex.Message.ToString();

}
}
}
}
if (success)
{

lblMessage.CssClass = "success";
lblMessage.Text = "Data Upload Successful.";
}
}
else
{
lblMessage.CssClass = "error";
lblMessage.Text = "You don't have permission to upload file.";
}
}
}
catch (Exception ex)
{
lblMessage.CssClass = "error";
lblMessage.Text = ex.Message.ToString();
}

#endregion

}
// method is used for save data from excel to Database for bulk adhoc
private void SaveBulkAdhoc(DataTable dtRoster)
{
btnUpload.Enabled = false;
Roster empRoster;
RosterAdhoc empAdhoc;
EmployeeBO objEmployee;
bool flag = false;
string websiteURL = ConfigurationManager.AppSettings["WebSiteURL"].ToString();
string emailFilePath = websiteURL + "/ViewAdhocRoster.aspx?Action=EMail&ReferenceID=";

foreach (DataRow dr in dtRoster.Rows)
{

bool chk = Convert.ToBoolean(dr["chk"]);

if (chk)
{
string empCode = Convert.ToString(dr["EmployeeCode"]);
string EmpName = Convert.ToString(dr["EmployeeName"]);
{
//code for get site email id
#region code for get site email id

string siteTransportEmailAddress = string.Empty;
string selectedSite = Convert.ToString(objEmployeeBO.GetSiteByEmployee(empCode).Rows[0]["SiteName"]);
string process = Convert.ToString(objEmployeeBO.GetProcessByEmployee(empCode).Rows[0]["OrganisationalUnitName"]);

if (selectedSite.ToLower().Equals("pune"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["PuneDeskMail"].ToString();
}
else if (selectedSite.ToLower().Equals("andheri"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["AndheriDeskMail"].ToString();
}
else if (selectedSite.ToLower().Equals("vikhroli"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["VikhroliDeskMail"].ToString();
}
else if (selectedSite.ToLower().Equals("thane"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["ThaneDeskMail"].ToString();
}
else if (selectedSite.ToLower().Equals("bangalore"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["BangaloreDeskMail"].ToString();
}
else if (selectedSite.ToLower().Equals("pune kn"))
{
siteTransportEmailAddress = ConfigurationManager.AppSettings["KNDeskMail"].ToString();
}

#endregion

objEmployee = new EmployeeBO();
empRoster = new Roster();
empAdhoc = new RosterAdhoc();

//EmployeeCode RosterDate
DateTime Startdate = DateTime.Now.Date;
TimeSpan span = Convert.ToDateTime(dr["AdhocDate"]).Subtract(Startdate);
if (span.Days >= 0)
{

if (!Convert.ToString(dr["EmployeeCode"]).Equals(string.Empty))
{

int AdhocType;
if (Convert.ToString(dr["AdhocTypeID"]) == "Pickup")
{
AdhocType = 1;
}
else
{
AdhocType = 2;
}

objAdhoc = new RosterAdhoc();
TimeSpan tsAdhoc = Convert.ToDateTime(dr["AdhocTime"]).TimeOfDay;
objAdhoc.AdhocDate = Convert.ToDateTime(dr["AdhocDate"]);
objAdhoc.AdhocTime = tsAdhoc;
objAdhoc.AdhocTypeID = AdhocType;
objAdhoc.CreatedBy = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;
objAdhoc.EmployeeCode = empCode;

objAdhoc.SiteID = Convert.ToInt64(dr["SiteID"]);
objAdhoc.OrgUnitID = Convert.ToInt64(dr["OrgUnitID"]);
objAdhoc.Remarks = Convert.ToString(dr["Remark"]);
objAdhoc.ApprovalStatusID = -1;// New Adhoc Request
//adding approver employee code
string approverEmpCode = string.Empty;

objAdhoc.FirstLevelApprover = ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode;

objAdhoc.FirstLevelApprovedDate = DateTime.Now;
objAdhoc.isActive = true;

OperationStatus os = objEmployeeBO.InsertNewEmpAdhocRequest(objAdhoc);
flag = true;
#region Email Code
// code for send email
if (os.InsertedRowID > 0)
{
//string TDeskEmail = ConfigurationManager.AppSettings["TDeskMail"].ToString();
string MailBody = "";
MailBody = "Hi," +
"

New Adhoc " + Convert.ToString(dr["AdhocTypeID"]) + " Request is raised for Date: " +
Convert.ToDateTime(dr["AdhocDate"]).ToShortDateString() + ", Time: " + tsAdhoc + " by "
+ ((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeName + " for Employee Name: " + EmpName
+ "(Employee Code: " + empCode + ") Process : " + process + "
" +
"Requesting you to Approve/Reject for further process.
" +
"

" +
"You can access the request by clicking on " +
"WBR" +
"

" +
"Regards," +
"
" +
"Transport Team
" +
"



This is a system generated e-mail. Please do not reply to this e-mail.
" +
"Capita India- Application Services Team
";
WBREmail mail = new WBREmail();

//********************************************************
// Direct Email to transport
//********************************************************
mail.Email(ConfigurationManager.AppSettings["MailFromName"].ToString(),
ConfigurationManager.AppSettings["MailFromEmailAddress"].ToString(), "Transport-Desk",
siteTransportEmailAddress,
"", "", "New Adhoc " + Convert.ToString(dr["AdhocTypeID"]) + " Request", MailBody);
lblMsg.CssClass = "success";
lblMsg.Text = "Adhoc added successfully.";
//break;
lblMessage.CssClass = "success";
lblMessage.Text = "Data Upload Successful.";
}

#endregion
}
}

objEmployee = null;
}
}
btnUpload.Enabled = true;
}

if (flag)
{
lblMsg.CssClass = "success";
lblMsg.Text = "Adhoc added successfully.";
//break;
lblMessage.CssClass = "success";
lblMessage.Text = "Data Upload Successful.";
btnExporttoExcel.Visible = false;
grdViewEmployee.DataSource = null;
grdViewEmployee.DataBind();
btnSaveData.Visible = false;
btnUpload.Enabled = true;
}
else
{
lblMsg.CssClass = "error";
lblMsg.Text = "No data for Save.";
//break;
lblMessage.CssClass = "error";
lblMessage.Text = "No data for Save.";
}

}

private DataTable FillDatatableInfo(DataTable dtExcel)
{
//DataTable dtResult = dtExcel;
dtExcel.Columns.Add("EmployeeName", typeof(string));
dtExcel.Columns.Add("SiteID", typeof(long));
dtExcel.Columns.Add("OrgUnitID", typeof(long));
dtExcel.Columns.Add("RMID", typeof(string));
dtExcel.Columns.Add("AvailingTransport", typeof(bool));
dtExcel.Columns.Add("IsActive", typeof(bool));

EmployeeMaster emp;
foreach (DataRow dr in dtExcel.Rows)
{
emp = new EmployeeMaster();
emp = objEmployeeBO.GetEmployeeByEmpID(Convert.ToString(dr["EmployeeCode"])).FirstOrDefault();
if (emp != null)
{
dr["EmployeeName"] = emp.EmployeeName;
dr["SiteID"] = emp.SiteID;
dr["OrgUnitID"] = emp.OrgUnitID;
dr["RMID"] = emp.RMID;
dr["AvailingTransport"] = emp.AvailingTransport;
dr["IsActive"] = emp.IsActive;
}
}
dtExcel.AcceptChanges();
return dtExcel;
}

private bool ValidateExcelDates(DataTable dtExcel)
{
bool flag = true;
DateTime Startdate = DateTime.Now.Date;
foreach (DataRow dr in dtExcel.Rows)
{
if (!string.IsNullOrEmpty(Convert.ToString(dr["AdhocDate"])))
{
TimeSpan span = Convert.ToDateTime(dr["AdhocDate"]).Subtract(Startdate);
if (span.Days >= 0)
{
flag = true;
}
else
{
return false;
}
}
}
return flag;
}

private bool ValidateExcel(DataTable dtRoster, string User)
{
ViewState["dtOtherEmployee"] = null;
bool flag = false;
dtRoster.Columns.Add("Chk", typeof(bool));
dtRoster.Columns.Add("Error", typeof(string));

foreach (DataRow dr in dtRoster.Rows)
{
if (User == "ProcessAdmin")
{
try
{
List<int32> OrgunitIdlist = objEmployeeBO.GetOrgIDbyName(Convert.ToString(Session["Adminprocess"]));
// check other process employee or wrong employee ID
if (!OrgunitIdlist.Contains(Convert.ToInt32(dr["OrgUnitID"])))
{
dr["chk"] = false;
dr["Error"] = "Ouside Process";
}
}
catch (Exception)
{
dr["chk"] = false;
dr["Error"] = "Envalid Employee ID";
}
}
if (User == "TM")
{
if (((View_EmployeeMaster)Session["LoginEmployee"]).EmployeeCode != Convert.ToString(dr["RMID"]))
{
dr["chk"] = false;
dr["Error"] = "Employee has different Reporting Manager";
}
}
try
{
if (Convert.ToBoolean(dr["AvailingTransport"]) == false || Convert.ToBoolean(dr["IsActive"]) == false)
{
dr["chk"] = false;
dr["Error"] = "Not Availing Transport";
}
}
catch (Exception)
{
dr["chk"] = false;
dr["Error"] = "Envalid Employee ID";
}
if (string.IsNullOrEmpty(Convert.ToString(dr["Error"])))
{

dr["chk"] = true;
dr["Error"] = "Valid";
}

}
DataRow ndr = dtRoster.NewRow();
ndr["EmployeeCode"] = "1234";
ndr["EmployeeName"] = "test";
ndr["AdhocDate"] = DateTime.Today;
ndr["chk"] = false;
dtRoster.Rows.Add(ndr);
dtRoster.AcceptChanges();

if (dtRoster != null && dtRoster.Rows.Count > 0 && !string.IsNullOrEmpty(Convert.ToString(dtRoster.Rows[0]["EmployeeCode"])))
{
flag = false;
btnExporttoExcel.Visible = true;
btnSaveData.Visible = true;
ViewState["dtOtherEmployee"] = dtRoster;
grdViewEmployee.DataSource = dtRoster;
grdViewEmployee.DataBind();
}
else
{
flag = true;
btnExporttoExcel.Visible = btnSaveData.Visible = false;
grdViewEmployee.DataSource = null;
grdViewEmployee.DataBind();
}
return flag;
}

protected void btnExporttoExcel_Click(object sender, EventArgs e)
{
try
{
DataTable dt = new DataTable();
if (ViewState["dtOtherEmployee"] != null)
{
dt = (DataTable)ViewState["dtOtherEmployee"];

// This actually makes your HTML output to be downloaded as .xls file
Response.Clear();
Response.ClearContent();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=OtherEmployee.xls");

// Create a dynamic control, populate and render it
GridView excel = new GridView();
excel.DataSource = dt;
excel.DataBind();
excel.RenderControl(new HtmlTextWriter(Response.Output));

Response.Flush();
Response.End();

}
}
catch (ThreadAbortException ex)
{
lblMsg.CssClass = "error";
lblMsg.Text = ex.Message.ToString();
}

}
protected void grdViewEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
{
CheckBox chk = (CheckBox)e.Row.FindControl("chk");
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (!chk.Checked)
{
chk.Enabled = false;
}
}
}
protected void btnSaveData_Click(object sender, EventArgs e)
{
DataTable dtRoster = (DataTable)ViewState["dtOtherEmployee"];


foreach (GridViewRow dgr in grdViewEmployee.Rows)
{
string empid = Convert.ToString(grdViewEmployee.DataKeys[dgr.RowIndex].Values[0]);
DateTime date = Convert.ToDateTime(grdViewEmployee.DataKeys[dgr.RowIndex].Values[1]);

CheckBox chk = (CheckBox)dgr.FindControl("chk");
if (!chk.Checked)
{
DataRow[] newdr = dtRoster.Select("EmployeeCode = " + empid + " AND AdhocDate ='" + date + "'");
newdr[0]["chk"] = false;
}
else
{
DataRow[] newdr = dtRoster.Select("EmployeeCode = " + empid + " AND AdhocDate ='" + date + "'");
newdr[0]["chk"] = true;
}
}
dtRoster.AcceptChanges();

if (dtRoster != null)
{
SaveBulkAdhoc(dtRoster);
}
}
}

Posted
Updated 24-May-16 5:29am
v2
Comments
Sergey Alexandrovich Kryukov 24-May-16 10:27am    
Sorry, no information, no advice.
Use the debugger, use logging...
—SA

1 solution

This is one of the most common problems we get asked, and it's also the one we are least equipped to answer, but you are most equipped to answer yourself.

Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it contains null - which means that there is no instance of a class in the variable.
It's a bit like a pocket: you have a pocket in your shirt, which you use to hold a pen. If you reach into the pocket and find there isn't a pen there, you can't sign your name on a piece of paper - and you will get very funny looks if you try! The empty pocket is giving you a null value (no pen here!) so you can't do anything that you would normally do once you retrieved your pen. Why is it empty? That's the question - it may be that you forgot to pick up your pen when you left the house this morning, or possibly you left the pen in the pocket of yesterdays shirt when you took it off last night.

We can't tell, because we weren't there, and even more importantly, we can't even see your shirt, much less what is in the pocket!

Back to computers, and you have done the same thing, somehow - and we can't see your code, much less run it and find out what contains null when it shouldn't.
But you can - and Visual Studio will help you here. Run your program in the debugger and when it fails, VS will show you the line it found the problem on. You can then start looking at the various parts of it to see what value is null and start looking back through your code to find out why. So put a breakpoint at the beginning of the method containing the error line, and run your program from the start again. This time, VS will stop before the error, and let you examine what is going on by stepping through the code looking at your values.

But we can't do that - we don't have your code, we don't know how to use it if we did have it, we don't have your data. So try it - and see how much information you can find out!
 
Share this answer
 
Comments
Dj@y 24-May-16 11:31am    
I put my code
OriginalGriff 24-May-16 11:47am    
That doesn't help, because we can't run it under the same circumstances you do: we don't have access to your setup or data. So it really is up to you to use the debugger and work out what is going on at run time.

Give it a try: this is a skill, and the only way to develop it is to use it!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900