コード例 #1
0
        public DepartmentReturnValue GetDepartment(Guid logonId, int deptId)
        {
            dsDepartments         dsDepartmentReturnValue = new dsDepartments();
            DepartmentReturnValue departmentReturnValue   = new DepartmentReturnValue();

            departmentReturnValue.Department = new Department();
            //DsBranches branchReturnValue = new DsBranches();
            //OrganisationReturnValue organisationReturnValue = new OrganisationReturnValue();
            //dsDepartments departmentReturnValue = new dsDepartments();
            //DsWorkTypes workTypeReturnValue = new DsWorkTypes();
            //EarnerReturnValue earnerReturnValue = new EarnerReturnValue();
            //DsPersons personReturnValue = new DsPersons();

            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:
                        // Can do everything
                        break;

                    case DataConstants.UserType.Client:
                    case DataConstants.UserType.ThirdParty:
                        throw new Exception("Access denied");

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

                    dsDepartmentReturnValue = SrvDepartmentLookup.GetDepartMentOnDepartmentId(deptId);

                    departmentReturnValue.Department.DeptArchived = dsDepartmentReturnValue.Tables[0].Rows[0]["DeptArchived"].ToString();
                    departmentReturnValue.Department.DeptId       = int.Parse(dsDepartmentReturnValue.Tables[0].Rows[0]["DeptId"].ToString());
                    departmentReturnValue.Department.DeptName     = dsDepartmentReturnValue.Tables[0].Rows[0]["DeptName"].ToString();
                    departmentReturnValue.Department.DeptNo       = dsDepartmentReturnValue.Tables[0].Rows[0]["DeptNo"].ToString();
                }
                finally
                {
                    // Remove the logged on user's ApplicationSettings from the
                    // list of concurrent sessions
                    Host.UnloadLoggedOnUser();
                }
            }
            catch (System.Data.SqlClient.SqlException)
            {
                departmentReturnValue.Success = false;
                departmentReturnValue.Message = Functions.SQLErrorMessage;
            }
            catch (Exception ex)
            {
                departmentReturnValue.Success = false;
                departmentReturnValue.Message = ex.Message;
            }

            return(departmentReturnValue);
        }
コード例 #2
0
        /// <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);
        }