// ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS
 //
 /// <summary>
 /// InsertDirect
 /// </summary>
 /// <param name="companyLevelId">companyLevelId</param>
 /// <param name="employeeId">employeeId</param>
 /// <param name="deleted">deleted</param>
 /// <param name="companyId">companyId</param>
 public void InsertDirect(int companyLevelId, int employeeId, bool deleted, int companyId)
 {
     CompanyLevelsManagersGateway companyLevelsManagersGateway = new CompanyLevelsManagersGateway(null);
     companyLevelsManagersGateway.Insert(companyLevelId, employeeId, deleted, companyId);
 }
        // ////////////////////////////////////////////////////////////////////////
        // 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 wucSRUnassigned.ascx");
                }

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

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

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

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

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

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

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

                    GetNodeForCompanyLevel(1);

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

                    if (HttpContext.Current.Session["unassignedSRWidget"] != 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();
                    }

                    dashboardUnassignedServiceRequestsTDS = new DashboardTDS();
                    DashboardUnassignedServiceRequests model = new DashboardUnassignedServiceRequests(dashboardUnassignedServiceRequestsTDS);

                    // ... Load for admin
                    if (Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_ADMIN"]))
                    {
                        if (companyLevelId == 0)
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllUnassignedServicesByUnitType(companyId, ddlType.SelectedValue);
                            }
                            else
                            {
                                model.LoadAllUnassignedServices(companyId);
                            }
                        }
                        else
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllUnassignedServicesByCompanyLevelIdUnitType(companyId, companyLevelId, ddlType.SelectedValue);
                            }
                            else
                            {
                                model.LoadAllUnassignedServicesByCompanyLevelId(companyId, companyLevelId);
                            }
                        }
                    }
                    else
                    {
                        if (companyLevelId == 0)
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllUnassignedServicesByAssignTeamMemberIDUnitType(employeeId, companyId, ddlType.SelectedValue);
                            }
                            else
                            {
                                // ... Load for assigned employee
                                model.LoadAllUnassignedServicesByAssignTeamMemberID(employeeId, companyId);
                            }
                        }
                        else
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllUnassignedServicesByAssignTeamMemberIDCompanyLevelIdUnitType(employeeId, companyId, companyLevelId, ddlType.SelectedValue);
                            }
                            else
                            {
                                model.LoadAllUnassignedServicesByAssignTeamMemberIDCompanyLevelId(employeeId, companyId, companyLevelId);
                            }
                        }
                    }

                    model.UpdateForDashboard(companyId);

                    // ... Store datasets
                    HttpContext.Current.Session.Add("dashboardUnassignedServiceRequestsTDS", dashboardUnassignedServiceRequestsTDS);
                    HttpContext.Current.Session.Add("companyLevelsForSRUnassignedTDS", companyLevelsForSRUnassignedTDS);
                }
            }
            else
            {
                // Prepare initial data
                HttpContext.Current.Session.Remove("dashboardUnassignedServiceRequestsDummy");

                // Restore datasets
                dashboardUnassignedServiceRequestsTDS = (DashboardTDS)HttpContext.Current.Session["dashboardUnassignedServiceRequestsTDS"];
                companyLevelsForSRUnassignedTDS = (CompanyLevelsTDS)HttpContext.Current.Session["companyLevelsForSRUnassignedTDS"];
            }
        }
 /// <summary>
 /// DeletedDirect
 /// </summary>
 /// <param name="companyLevelId">companyLevelId</param>
 /// <param name="employeeId">employeeId</param>
 /// <param name="companyId">companyId</param>
 public void DeletedDirect(int companyLevelId, int employeeId, int companyId)
 {
     CompanyLevelsManagersGateway companyLevelsManagersGateway = new CompanyLevelsManagersGateway(null);
     companyLevelsManagersGateway.Delete(companyLevelId, employeeId, companyId);
 }