コード例 #1
0
        public TaskSearchReturnValue MemberTaskSearch(Guid logonId, CollectionRequest collectionRequest,
                                TaskSearchCriteria criteria)
        {
            TaskSearchReturnValue returnValue = new TaskSearchReturnValue();

            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");
                    }

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

                    // Declare an inline event (annonymous delegate) to read the
                    // dataset if it is required
                    dataListCreator.ReadDataSet += delegate(object Sender, ReadDataSetEventArgs e)
                    {
                        DiaryMemberSearchItem diaryMembers = this.GetDiaryMemberDetails(criteria.MemberID);
                        string UsersChosenMemberID = criteria.MemberID;
                        DateTime usersDiaryDate = DateTime.Today;
                        bool ShowCancelled = false;
                        string memberIds;
                        string[] usersChosenMemberIDs = new string[] { };
                        DateTime taskFromDate = usersDiaryDate;
                        DateTime taskToDate = usersDiaryDate;

                        TimeSpan timeSpan = taskToDate - taskFromDate;
                        int taskNoOfDays = (timeSpan.Days + 1);

                        int taskBookingID = 0;
                        int statusID = 0;
                        string occurrencePriority = string.Empty;
                        int dateFilter = 0;
                        int incItems = 1;
                        int progress = 0;

                        DiaryViewDts dvDiary = new DiaryViewDts();

                        if (criteria.StartDate != DataConstants.BlankDate)
                        {
                            taskFromDate = Convert.ToDateTime(criteria.StartDate);
                        }

                        if (!diaryMembers.IsGroup)
                        {
                            UsersChosenMemberID = diaryMembers.MemberID;
                            dvDiary = SrvBookingEntryLookup.GetAllTasksForMember(UsersChosenMemberID, taskFromDate,
                                ShowCancelled, taskNoOfDays, taskBookingID, statusID, occurrencePriority, dateFilter, incItems, progress);
                        }
                        else
                        {
                            usersChosenMemberIDs = this.ResolveGroupMembers(int.Parse(diaryMembers.MemberID));
                            memberIds = string.Join(",", usersChosenMemberIDs);

                            dvDiary = SrvBookingEntryLookup.GetAllTasksForMember(memberIds, taskFromDate,
                                ShowCancelled, taskNoOfDays, taskBookingID, statusID, occurrencePriority, dateFilter, incItems, progress);
                        }

                        // Add New Column Editable
                        dvDiary.DiaryEntries.Columns.Add("isEdit");
                        // Add New Column Matters
                        dvDiary.DiaryEntries.Columns.Add("OccurrenceMatter");
                        // Add New Column IsLimitation
                        dvDiary.DiaryEntries.Columns.Add("IsLimitationTask", typeof(Boolean));
                        // Add New Column NewRecordedDueDate for filtering
                        dvDiary.DiaryEntries.Columns.Add("NewRecordedDueDate", typeof(DateTime));

                        System.Collections.ArrayList listIds = new System.Collections.ArrayList();
                        foreach (DiaryViewDts.DiaryEntriesRow row in dvDiary.DiaryEntries.Rows)
                        {
                            row["isEdit"] = this.IsOccurrenceViewableBy(row.OccurrenceID);
                            row["IsLimitationTask"] = this.IsALimitationTask(Convert.ToInt32(row.BookingTypeID));

                            if (!listIds.Contains(row.BookingID))
                            {
                                listIds.Add(row.BookingID);
                            }

                            if (row["RecordedDueDate"].ToString() != "")
                            {
                                row["NewRecordedDueDate"] = Convert.ToDateTime(row["RecordedDueDate"]);
                            }
                        }

                        StringBuilder ids = new StringBuilder();
                        foreach (int bookingId in listIds)
                        {
                            ids.Append(bookingId.ToString());
                            ids.Append(",");
                        }

                        DiaryViewMattersDts matterDts = new DiaryViewMattersDts();
                        if (ids.Length > 0)
                        {
                            ids.Length--;

                            matterDts = SrvBookingEntryLookup.GetMattersForBookings(ids.ToString());
                        }

                        foreach (DiaryViewDts.DiaryEntriesRow row in dvDiary.DiaryEntries.Rows)
                        {
                            DiaryViewMattersDts.BookingMatterRow[] matterRows;
                            matterRows = (DiaryViewMattersDts.BookingMatterRow[])matterDts.BookingMatter.Select(string.Format("BookingID = {0}", row.BookingID));
                            StringBuilder sb = new StringBuilder();
                            foreach (DiaryViewMattersDts.BookingMatterRow matterRow in matterRows)
                            {
                                sb.AppendFormat("{0}$({1}-{2})  {3}~", matterRow.ProjectID, matterRow.MatterRef.Substring(0, 6), matterRow.MatterRef.Substring(6, 4), matterRow.matDescription);
                            }
                            if (sb.Length > 0)
                            {
                                string matters = sb.ToString().Substring(0, sb.Length - 1);
                                row["OccurrenceMatter"] = matters;
                            }
                        }

                        DataView dvDiaryView = new DataView(dvDiary.Tables[0]);
                        string filter = string.Empty;

                        switch (criteria.Status)
                        {
                            case "Outstanding":
                                filter += " (OccStatusDesc <> 'Completed') and ";
                                break;
                            case "Completed":
                                filter += " (OccStatusDesc = 'Completed') and ";
                                break;
                        }

                        bool isStartDate = false;

                        if (criteria.StartDate != DataConstants.BlankDate)
                        {
                            filter += " ((NewRecordedDueDate >= #" + Convert.ToDateTime(criteria.StartDate).ToString("yyyy-MM-dd") + "#) ";
                            isStartDate = true;
                        }
                        if (criteria.ToDate != DataConstants.BlankDate)
                        {
                            if (isStartDate)
                            {
                                filter += " and ";
                            }

                            filter += "(NewRecordedDueDate <= #" + Convert.ToDateTime(criteria.ToDate).ToString("yyyy-MM-dd") + "#)";

                            if (isStartDate)
                            {
                                filter += ") ";
                            }

                            filter += " and ";

                        }
                        else
                        {
                            filter += ") and ";
                        }

                        if (!string.IsNullOrEmpty(filter))
                        {
                            filter = filter.Trim().Substring(0, filter.Trim().Length - 3);
                        }

                        dvDiaryView.RowFilter = filter;

                        DataSet dsFiltered = new DataSet();
                        dsFiltered.Tables.Add(dvDiaryView.ToTable());

                        e.DataSet = dsFiltered;

                        if (criteria.OrderBy != string.Empty)
                        {
                            DataTable dt = Functions.SortDataTable(e.DataSet.Tables[0], criteria.OrderBy);
                            e.DataSet.Tables.Remove("DiaryEntries");
                            e.DataSet.Tables.Add(dt);
                        }
                    };

                    returnValue.Tasks = dataListCreator.Create(logonId,
                                                "TaskSearch",
                        // 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", "OccurrenceID"),
                                                new ImportMapping("RecordedDueDate", "RecordedDueDate"),
                                                new ImportMapping("Subject", "OccSpecificText"),
                                                new ImportMapping("StatusDesc", "OccStatusDesc"),
                                                new ImportMapping("Progress", "OccProgress"),
                                                new ImportMapping("Notes", "OccurrenceNoteText"),
                                                new ImportMapping("Matters", "OccurrenceMatter"),
                                                new ImportMapping("IsEditable", "isEdit"),
                                                new ImportMapping("IsLimitationTask", "IsLimitationTask")
                                                // More fields are required here but the service layer query may not be
                                                // providing them.  This is enough for a test.
                                                }
                                            );
                }
                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;
        }
コード例 #2
0
        public TaskSearchReturnValue MatterTaskSearch(Guid logonId, CollectionRequest collectionRequest, TaskSearchCriteria criteria)
        {
            TaskSearchReturnValue returnValue = new TaskSearchReturnValue();

            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:
                            if (!SrvMatterCommon.WebAllowedToAccessMatter(criteria.ProjectID))
                                throw new Exception("Access denied");

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

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

                    // Declare an inline event (annonymous delegate) to read the
                    // dataset if it is required
                    dataListCreator.ReadDataSet += delegate(object Sender, ReadDataSetEventArgs e)
                    {
                        DsOccurencesForProject dvDiary = new DsOccurencesForProject();

                        dvDiary = SrvOccurenceLookup.GetOccurencesForProject(criteria.ProjectID);

                        // Add New Column Editable
                        dvDiary.uvw_OccurencesForProject.Columns.Add("isEdit");
                        dvDiary.uvw_OccurencesForProject.Columns.Add("AttendeeName");
                        dvDiary.uvw_OccurencesForProject.Columns.Add("IsLimitationTask", typeof(Boolean));
                        // Add New Column NewOccDueDate for filtering
                        dvDiary.uvw_OccurencesForProject.Columns.Add("NewOccDueDate", typeof(DateTime));

                        foreach (IRIS.Law.PmsCommonData.Diary.DsOccurencesForProject.uvw_OccurencesForProjectRow row in dvDiary.uvw_OccurencesForProject)
                        {
                            row["isEdit"] = this.IsOccurrenceViewableBy(Convert.ToInt32(row.OccurrenceID));
                            row["IsLimitationTask"] = this.IsALimitationTask(Convert.ToInt32(row.BookingTypeID));
                            row["AttendeeName"] = CommonFunctions.MakeFullName(row.PersonTitle, row.PersonName, row.PersonSurname);

                            if (row["OccDueDate"].ToString() != "")
                            {
                                row["NewOccDueDate"] = Convert.ToDateTime(row["OccDueDate"]);
                            }
                        }

                        DataView dvDiaryView = new DataView(dvDiary.Tables[0]);
                        string filter = string.Empty;

                        switch (criteria.Status)
                        {
                            case "Outstanding":
                                filter += " (OccStatus <> 'Completed') and ";
                                break;
                            case "Completed":
                                filter += " (OccStatus = 'Completed') and ";
                                break;
                        }

                        // Filter only BookingType which is of Task
                        // BookingTypeID: 4 - Key Date, 5 - Limitation Date, 12 - Standard Task
                        CollectionRequest collection = new CollectionRequest();
                        DiaryParameterReturnValue taskTypes = this.GetTaskTypes(logonId, collection);
                        string bookingTypeId = string.Empty;
                        for (int i = 0; i < taskTypes.DiaryParamters.Rows.Count; i++)
                        {
                            bookingTypeId += taskTypes.DiaryParamters.Rows[i].Id.ToString() + ",";
                        }
                        if (bookingTypeId.Length > 0)
                        {
                            bookingTypeId = bookingTypeId.Trim().Substring(0, bookingTypeId.Trim().Length - 1);
                        }
                        if (!string.IsNullOrEmpty(bookingTypeId))
                        {
                            filter += " (BookingTypeID in (" + bookingTypeId + ")) and ";
                        }
                        //filter += " (BookingTypeID in (4, 5, 12)) and ";

                        //if (criteria.StartDate != DataConstants.BlankDate)
                        //{
                        //    filter += " (OccDueDate = '" + criteria.StartDate.ToString() + "') and ";
                        //}

                        bool isStartDate = false;

                        if (criteria.StartDate != DataConstants.BlankDate)
                        {
                            filter += " ((NewOccDueDate >= #" + Convert.ToDateTime(criteria.StartDate).ToString("yyyy-MM-dd") + "#) ";
                            isStartDate = true;
                        }
                        if (criteria.ToDate != DataConstants.BlankDate)
                        {
                            if (isStartDate)
                            {
                                filter += " and ";
                            }

                            filter += "(NewOccDueDate <= #" + Convert.ToDateTime(criteria.ToDate).ToString("yyyy-MM-dd") + "#)";

                            if (isStartDate)
                            {
                                filter += ") ";
                            }

                            filter += " and ";

                        }
                        else
                        {
                            filter += ") and ";
                        }

                        if (!string.IsNullOrEmpty(criteria.MemberID))
                        {
                            DiaryMemberSearchItem diaryMembers = this.GetDiaryMemberDetails(criteria.MemberID);
                            string memberIds = string.Empty;
                            if (!diaryMembers.IsGroup)
                            {
                                memberIds += "Convert('" + criteria.MemberID + "', 'System.Guid'), ";
                            }
                            else
                            {
                                string[] usersChosenMemberIDs = this.ResolveGroupMembers(int.Parse(diaryMembers.MemberID));
                                if (usersChosenMemberIDs.Length > 0)
                                {
                                    for (int i = 0; i < usersChosenMemberIDs.Length; i++)
                                    {
                                        memberIds += "Convert('" + usersChosenMemberIDs[i] + "', 'System.Guid'),";
                                    }
                                }
                            }

                            if (!string.IsNullOrEmpty(memberIds))
                            {
                                memberIds = memberIds.Trim().Substring(0, memberIds.Trim().Length - 1);
                                filter += " (MemberID in (" + memberIds + ")) and ";
                            }
                        }
                        //If user is client or third party then can only return public tasks.
                        switch (UserInformation.Instance.UserType)
                        {
                            case DataConstants.UserType.Staff:
                                // Can do everything
                                break;
                            case DataConstants.UserType.Client:
                            case DataConstants.UserType.ThirdParty:
                                // Return only Public tasks
                                if (!string.IsNullOrEmpty(filter))
                                {
                                    filter += " (OccIsPublic = 1) and ";
                                }
                                break;
                            default:
                                throw new Exception("Unknown UserType");
                        }

                        if (!string.IsNullOrEmpty(filter))
                        {
                            filter = filter.Trim().Substring(0, filter.Trim().Length - 3);
                        }

                        dvDiaryView.RowFilter = filter;
                        dvDiaryView.Sort = "OccDueDate desc";

                        DataSet dsFiltered = new DataSet();
                        dsFiltered.Tables.Add(dvDiaryView.ToTable());

                        e.DataSet = dsFiltered;

                        if (criteria.OrderBy != string.Empty)
                        {
                            DataTable dt = Functions.SortDataTable(e.DataSet.Tables[0], criteria.OrderBy);
                            e.DataSet.Tables.Remove("uvw_OccurencesForProject");
                            e.DataSet.Tables.Add(dt);
                        }
                    };

                    returnValue.Tasks = dataListCreator.Create(logonId,
                                            "TaskMatterSearch",
                        // 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", "OccurrenceID"),
                                                new ImportMapping("DueDate", "OccDueDate"),
                                                new ImportMapping("Subject", "OccSpecificText"),
                                                new ImportMapping("StatusDesc", "OccStatus"),
                                                //new ImportMapping("Progress", "OccProgress"),
                                                new ImportMapping("AttendeesName", "AttendeeName"),
                                                //new ImportMapping("Matters", "OccurrenceMatter"),
                                                new ImportMapping("IsEditable", "isEdit"),
                                                new ImportMapping("IsLimitationTask", "IsLimitationTask")
                                                // More fields are required here but the service layer query may not be
                                                // providing them.  This is enough for a test.
                                                }
                                            );
                }
                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;
        }