private void LoadData()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int companyLevelId = Int32.Parse(ddlWorkingLocation.SelectedValue);

            dashboardExpiredServiceRequestsTDS = (DashboardTDS)HttpContext.Current.Session["dashboardExpiredServiceRequestsTDS"];
            DashboardExpiredServiceRequests model = new DashboardExpiredServiceRequests(dashboardExpiredServiceRequestsTDS);

            // ... Load for admin
            if (Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_ADMIN"]))
            {
                if (companyLevelId == 0)
                {
                    if (ddlType.SelectedValue != "(All)")
                    {
                        model.LoadAllExpiredItemsByUnitType(companyId, ddlType.SelectedValue);
                    }
                    else
                    {
                        model.LoadAllExpiredItems(companyId);
                    }
                }
                else
                {
                    if (ddlType.SelectedValue != "(All)")
                    {
                        model.LoadAllExpiredItemsByCompanyLevelIdUnitType(companyId, companyLevelId, ddlType.SelectedValue);
                    }
                    else
                    {
                        model.LoadAllExpiredItemsByCompanyLevelId(companyId, companyLevelId);
                    }
                }
            }
            else
            {
                // ... Load for assigned employee
                int loginId = Convert.ToInt32(Session["loginID"]);
                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

                if (companyLevelId == 0)
                {
                    if (ddlType.SelectedValue != "(All)")
                    {
                        model.LoadAllExpiredItemsByAssignTeamMemberIDUnitType(employeeId, companyId, ddlType.SelectedValue);
                    }
                    else
                    {
                        model.LoadAllExpiredItemsByAssignTeamMemberID(employeeId, companyId);
                    }
                }
                else
                {
                    if (ddlType.SelectedValue != "(All)")
                    {
                        model.LoadAllExpiredItemsByAssignTeamMemberIDCompanyLevelIdUnitType(employeeId, companyId, companyLevelId, ddlType.SelectedValue);
                    }
                    else
                    {
                        model.LoadAllExpiredItemsByAssignTeamMemberIDCompanyLevelId(employeeId, companyId, companyLevelId);
                    }
                }
            }

            model.UpdateForDashboard(companyId);

            HttpContext.Current.Session.Add("dashboardExpiredServiceRequestsTDS", dashboardExpiredServiceRequestsTDS);
            Page.DataBind();
        }
        private void PostPageChanges()
        {
            DashboardExpiredServiceRequests dashboardExpiredServiceRequests = new DashboardExpiredServiceRequests(dashboardExpiredServiceRequestsTDS);

            // Update grdExpiredServiceRequests rows
            foreach (GridViewRow row in grdExpiredServiceRequests.Rows)
            {
                string serviceIdLabel = ((Label)row.FindControl("lblServiceID")).Text.Trim();
                int serviceId = Int32.Parse(serviceIdLabel.ToString().Trim());
                bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;
                int companyId = Int32.Parse(hdfCompanyId.Value);

                dashboardExpiredServiceRequests.Update(serviceId, companyId, selected);
            }

            dashboardExpiredServiceRequests.Data.AcceptChanges();

            // Store datasets
            Session["dashboardExpiredServiceRequestsTDS"] = dashboardExpiredServiceRequestsTDS;
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_VIEW"]) && Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_EDIT"])))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Validate query string
                if ((string)Request.QueryString["source_page"] == null)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in wucExpiredItems.ascx");
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();

                // Prepare initial data
                HttpContext.Current.Session.Remove("dashboardExpiredServiceRequestsDummy");
                ArrayList arrayListWidgetData = (ArrayList)HttpContext.Current.Session["expiredItemsWidget"];

                // If coming from
                // ... Out
                if (Request.QueryString["source_page"] == "out")
                {
                    CompanyLevelsManagersGateway companyLevelsManagersGateway = new CompanyLevelsManagersGateway();

                    int loginId = Convert.ToInt32(Session["loginID"]);
                    EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                    int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

                    // ... For Grid
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    int companyLevelId = companyLevelsManagersGateway.GetCompanyLevelId(employeeId, companyId);

                    // ... For ddl working location
                    companyLevelsForExpiredItemsTDS = new CompanyLevelsTDS();

                    CompanyLevel companyLevel = new CompanyLevel(companyLevelsForExpiredItemsTDS);
                    companyLevel.LoadNodes(companyId);

                    GetNodeForCompanyLevel(1);

                    ddlWorkingLocation.Items.Insert(0, new ListItem("(All)", "0"));

                    if (HttpContext.Current.Session["expiredItemsWidget"] != null)
                    {
                        ddlWorkingLocation.SelectedIndex = Convert.ToInt32(arrayListWidgetData[0].ToString());
                        ddlType.SelectedIndex = Convert.ToInt32(arrayListWidgetData[1].ToString());

                        companyLevelId = Convert.ToInt32(ddlWorkingLocation.SelectedValue);
                    }
                    else
                    {
                        ddlWorkingLocation.SelectedValue = companyLevelId.ToString();
                    }

                    dashboardExpiredServiceRequestsTDS = new DashboardTDS();
                    DashboardExpiredServiceRequests model = new DashboardExpiredServiceRequests(dashboardExpiredServiceRequestsTDS);

                    // ... Load for admin
                    if (Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_ADMIN"]))
                    {
                        if (companyLevelId == 0)
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllExpiredItemsByUnitType(companyId, ddlType.SelectedValue);
                            }
                            else
                            {
                                model.LoadAllExpiredItems(companyId);
                            }
                        }
                        else
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllExpiredItemsByCompanyLevelIdUnitType(companyId, companyLevelId, ddlType.SelectedValue);
                            }
                            else
                            {
                                model.LoadAllExpiredItemsByCompanyLevelId(companyId, companyLevelId);
                            }
                        }
                    }
                    else
                    {
                        if (companyLevelId == 0)
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllExpiredItemsByAssignTeamMemberIDUnitType(employeeId, companyId, ddlType.SelectedValue);
                            }
                            else
                            {
                                // ... Load for assigned employee
                                model.LoadAllExpiredItemsByAssignTeamMemberID(employeeId, companyId);
                            }
                        }
                        else
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllExpiredItemsByAssignTeamMemberIDCompanyLevelIdUnitType(employeeId, companyId, companyLevelId, ddlType.SelectedValue);
                            }
                            else
                            {
                                model.LoadAllExpiredItemsByAssignTeamMemberIDCompanyLevelId(employeeId, companyId, companyLevelId);
                            }
                        }
                    }

                    model.UpdateForDashboard(companyId);

                    // ... Store datasets
                    HttpContext.Current.Session.Add("dashboardExpiredServiceRequestsTDS", dashboardExpiredServiceRequestsTDS);
                    HttpContext.Current.Session.Add("companyLevelsForExpiredItemsTDS", companyLevelsForExpiredItemsTDS);
                }
            }
            else
            {
                // Prepare initial data
                HttpContext.Current.Session.Remove("dashboardExpiredServiceRequestsDummy");

                dashboardExpiredServiceRequestsTDS = (DashboardTDS)HttpContext.Current.Session["dashboardExpiredServiceRequestsTDS"];
                companyLevelsForExpiredItemsTDS = (CompanyLevelsTDS)HttpContext.Current.Session["companyLevelsForExpiredItemsTDS"];
            }
        }