Beispiel #1
0
        /// <summary>
        /// This Method gets all the department disregard of the branch as this is required on the load of the
        /// search page
        /// </summary>
        private void BindDeptDropDownList()
        {
            BranchDeptServiceClient departmentSearch = null;

            try
            {
                DepartmentSearchCriteria searchCriteria = new DepartmentSearchCriteria();
                //Set this flag to true to get all the departments
                searchCriteria.AllDepartment = true;

                departmentSearch = new BranchDeptServiceClient();
                CollectionRequest collectionRequest = new CollectionRequest();
                collectionRequest.ForceRefresh = false;

                DepartmentSearchReturnValue returnValue = departmentSearch.DepartmentSearch(_logonSettings.LogonId, collectionRequest, searchCriteria);

                if (returnValue.Success)
                {
                    foreach (DepartmentSearchItem department in returnValue.Departments.Rows)
                    {
                        ListItem item = new ListItem();
                        item.Text  = department.Name;
                        item.Value = department.Id.ToString() + "$" + department.No;
                        _ddlDepartment.Items.Add(item);
                    }
                    AddDefaultToDropDownList(_ddlDepartment, "All Departments");
                }
                else
                {
                    throw new Exception(returnValue.Message);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (departmentSearch != null)
                {
                    if (departmentSearch.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        departmentSearch.Close();
                    }
                }
            }
        }
 /// <summary>
 /// Search departments based on the organisation ID
 /// </summary>
 /// <param name="oHostSecurityToken">The Host Security Token from IWS</param>
 /// <param name="collectionRequest">Collection request value</param>
 /// <param name="criteria">Department search criteria</param>
 /// <returns>Collection of department search item</returns>
 public DepartmentSearchReturnValue DepartmentSearch(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest,
     DepartmentSearchCriteria criteria)
 {
     DepartmentSearchReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oBranchDeptService = new BranchDeptService();
         returnValue = oBranchDeptService.DepartmentSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
     }
     else
     {
         returnValue = new DepartmentSearchReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
        /// <summary>
        /// Search departments based on the organisation ID
        /// </summary>
        /// <param name="oHostSecurityToken">The Host Security Token from IWS</param>
        /// <param name="collectionRequest">Collection request value</param>
        /// <param name="criteria">Department search criteria</param>
        /// <returns>Collection of department search item</returns>
        public DepartmentSearchReturnValue DepartmentSearch(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest,
                                                            DepartmentSearchCriteria criteria)
        {
            DepartmentSearchReturnValue returnValue = null;

            if (Functions.ValidateIWSToken(oHostSecurityToken))
            {
                oBranchDeptService = new BranchDeptService();
                returnValue        = oBranchDeptService.DepartmentSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
            }
            else
            {
                returnValue         = new DepartmentSearchReturnValue();
                returnValue.Success = false;
                returnValue.Message = "Invalid Token";
            }
            return(returnValue);
        }
Beispiel #4
0
        /// <summary>
        /// Gets the departments.
        /// </summary>
        private void GetDepartments()
        {
            if (_ddlBranch.SelectedValue != string.Empty)
            {
                BranchDeptServiceClient departmentSearch = null;
                try
                {
                    CollectionRequest collectionRequest = new CollectionRequest();

                    DepartmentSearchCriteria searchCriteria = new DepartmentSearchCriteria();
                    searchCriteria.OrganisationId  = new Guid(GetBranchValueOnIndex(_ddlBranch.SelectedValue, 1));
                    searchCriteria.IncludeArchived = true;

                    departmentSearch = new BranchDeptServiceClient();

                    DepartmentSearchReturnValue returnValue = departmentSearch.DepartmentSearch(_logonSettings.LogonId,
                                                                                                collectionRequest, searchCriteria);

                    //Store the previous selected value. This will prevent the dept from being reset
                    //if its valid for the current branch
                    string prevValue = _ddlDepartment.SelectedValue;

                    _ddlDepartment.Items.Clear();
                    if (returnValue.Success)
                    {
                        foreach (DepartmentSearchItem department in returnValue.Departments.Rows)
                        {
                            ListItem item = new ListItem();
                            item.Text  = department.Name;
                            item.Value = department.Id.ToString() + "$" + department.No;
                            _ddlDepartment.Items.Add(item);
                        }
                        AddDefaultToDropDownList(_ddlDepartment, "All Departments");

                        //Set the prev value if it is valid for the current branch
                        if (_ddlDepartment.Items.FindByValue(prevValue) != null)
                        {
                            _ddlDepartment.SelectedValue = prevValue;
                        }
                    }
                    else
                    {
                        throw new Exception(returnValue.Message);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    if (departmentSearch != null)
                    {
                        if (departmentSearch.State != System.ServiceModel.CommunicationState.Faulted)
                        {
                            departmentSearch.Close();
                        }
                    }
                }
            }
            else
            {
                //No branch selected. Reset Departments
                _ddlDepartment.Items.Clear();
                BindDeptDropDownList();
            }
        }
        /// <summary>
        /// Search departments based on the organisation ID
        /// </summary>
        /// <param name="logonId">The logon id</param>
        /// <param name="collectionRequest">Collection request value</param>
        /// <param name="criteria">Department search criteria</param>
        /// <returns>Collection of department search item</returns>
        public DepartmentSearchReturnValue DepartmentSearch(Guid logonId, CollectionRequest collectionRequest,
            DepartmentSearchCriteria criteria)
        {
            DepartmentSearchReturnValue returnValue = new DepartmentSearchReturnValue();

            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid);
                    switch (UserInformation.Instance.UserType)
                    {
                        case DataConstants.UserType.Staff:
                        case DataConstants.UserType.Client:
                        case DataConstants.UserType.ThirdParty:
                            // Can do everything
                            break;
                        default:
                            throw new Exception("Access denied");
                    }

                    // Create a data list creator for a list of matters
                    DataListCreator<DepartmentSearchItem> dataListCreator = new DataListCreator<DepartmentSearchItem>();

                    // Declare an inline event (annonymous delegate) to read the
                    // dataset if it is required
                    dataListCreator.ReadDataSet += delegate(object Sender, ReadDataSetEventArgs e)
                    {
                        if (criteria.AllDepartment)
                        {
                            // Create the dataset for department search to get all departments
                            e.DataSet = SrvDepartmentLookup.GetDepartments();
                        }
                        else
                        {
                            // Create the dataset
                            e.DataSet = SrvDepartmentLookup.GetDepartments(criteria.OrganisationId, criteria.IncludeArchived);
                        }

                        DataTable dt = Functions.SortDataTable(e.DataSet.Tables[0], "deptName");
                        e.DataSet.Tables.Remove(e.DataSet.Tables[0]);
                        e.DataSet.Tables.Add(dt);
                    };

                    // Create the data list
                    returnValue.Departments = dataListCreator.Create(logonId,
                        // Give the query a name so it can be cached
                        "DepartmentSearch",
                        // Tell it the query criteria used so if the cache is accessed
                        // again it knows if it is the same query
                        criteria.ToString(),
                        collectionRequest,
                        // Import mappings to map the dataset row fields to the data
                        // list entity properties
                        new ImportMapping[] {
                            new ImportMapping("Id", "deptID"),
                            new ImportMapping("No", "deptNo"),
                            new ImportMapping("Name", "deptName"),
                            new ImportMapping("IsArchived", "deptArchived")
                            }
                        );
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception Ex)
            {
                returnValue.Success = false;
                returnValue.Message = Ex.Message;
            }

            return returnValue;
        }
        /// <summary>
        /// Search departments based on the organisation ID
        /// </summary>
        /// <param name="logonId">The logon id</param>
        /// <param name="collectionRequest">Collection request value</param>
        /// <param name="criteria">Department search criteria</param>
        /// <returns>Collection of department search item</returns>
        public DepartmentSearchReturnValue DepartmentSearch(Guid logonId, CollectionRequest collectionRequest,
                                                            DepartmentSearchCriteria criteria)
        {
            DepartmentSearchReturnValue returnValue = new DepartmentSearchReturnValue();

            try
            {
                // Get the logged on user from the current logons and add their
                // ApplicationSettings the list of concurrent sessions.
                Host.LoadLoggedOnUser(logonId);

                try
                {
                    Functions.RestrictRekoopIntegrationUser(UserInformation.Instance.DbUid);
                    switch (UserInformation.Instance.UserType)
                    {
                    case DataConstants.UserType.Staff:
                    case DataConstants.UserType.Client:
                    case DataConstants.UserType.ThirdParty:
                        // Can do everything
                        break;

                    default:
                        throw new Exception("Access denied");
                    }

                    // Create a data list creator for a list of matters
                    DataListCreator <DepartmentSearchItem> dataListCreator = new DataListCreator <DepartmentSearchItem>();

                    // Declare an inline event (annonymous delegate) to read the
                    // dataset if it is required
                    dataListCreator.ReadDataSet += delegate(object Sender, ReadDataSetEventArgs e)
                    {
                        if (criteria.AllDepartment)
                        {
                            // Create the dataset for department search to get all departments
                            e.DataSet = SrvDepartmentLookup.GetDepartments();
                        }
                        else
                        {
                            // Create the dataset
                            e.DataSet = SrvDepartmentLookup.GetDepartments(criteria.OrganisationId, criteria.IncludeArchived);
                        }

                        DataTable dt = Functions.SortDataTable(e.DataSet.Tables[0], "deptName");
                        e.DataSet.Tables.Remove(e.DataSet.Tables[0]);
                        e.DataSet.Tables.Add(dt);
                    };

                    // Create the data list
                    returnValue.Departments = dataListCreator.Create(logonId,
                                                                     // Give the query a name so it can be cached
                                                                     "DepartmentSearch",
                                                                     // Tell it the query criteria used so if the cache is accessed
                                                                     // again it knows if it is the same query
                                                                     criteria.ToString(),
                                                                     collectionRequest,
                                                                     // Import mappings to map the dataset row fields to the data
                                                                     // list entity properties
                                                                     new ImportMapping[] {
                        new ImportMapping("Id", "deptID"),
                        new ImportMapping("No", "deptNo"),
                        new ImportMapping("Name", "deptName"),
                        new ImportMapping("IsArchived", "deptArchived")
                    }
                                                                     );
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                returnValue.Success = false;
                returnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception Ex)
            {
                returnValue.Success = false;
                returnValue.Message = Ex.Message;
            }

            return(returnValue);
        }