예제 #1
0
        public MainWindowTasksGridViewModel(IEventAggregator eventAggregator, IUnityContainer unityContainer, IPreferencesService preferencesService, ITaskService taskService, IUserService userService)
            : base(eventAggregator, unityContainer, userService)
        {
            this.preferencesService = preferencesService;
            this.taskService        = taskService;
            this.taskSearchCriteria = new TaskSearchCriteria();

            Pagination  = new PaginationViewModel(eventAggregator, preferencesService);
            ProgressBar = new ProgressBarViewModel(eventAggregator, preferencesService);
        }
예제 #2
0
        public TaskSearchReturnValue MemberTaskSearch(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest,
                                                      TaskSearchCriteria criteria)
        {
            TaskSearchReturnValue returnValue = null;

            if (Functions.ValidateIWSToken(oHostSecurityToken))
            {
                oDiaryService = new DiaryService();
                returnValue   = oDiaryService.MemberTaskSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
            }
            else
            {
                returnValue         = new TaskSearchReturnValue();
                returnValue.Success = false;
                returnValue.Message = "Invalid Token";
            }
            return(returnValue);
        }
예제 #3
0
        private void searchExecute()
        {
            TaskSearchCriteria criteria = new TaskSearchCriteria();

            if (!String.IsNullOrEmpty(filtrName.Text))
            {
                criteria.TaskName = filtrName.Text;
            }
            if (!String.IsNullOrEmpty(filtrCategory.Text))
            {
                criteria.TaskCategory = filtrCategory.Text;
            }

            criteria.TaskDateFrom = filterDateFrom.Value;
            criteria.TaskDateTo   = filterDateTo.Value;

            tasksList = taskService.SearchTasks(criteria, loggedUser.Id);
            dataGridView1.DataSource = tasksList;
            loadDataGridAndCombos(false, false);
            loadCurrentTaskToControls();
        }
 public TaskSearchReturnValue MemberTaskSearch(HostSecurityToken oHostSecurityToken, CollectionRequest collectionRequest,
                         TaskSearchCriteria criteria)
 {
     TaskSearchReturnValue returnValue = null;
     if (Functions.ValidateIWSToken(oHostSecurityToken))
     {
         oDiaryService = new DiaryService();
         returnValue = oDiaryService.MemberTaskSearch(Functions.GetLogonIdFromToken(oHostSecurityToken), collectionRequest, criteria);
     }
     else
     {
         returnValue = new TaskSearchReturnValue();
         returnValue.Success = false;
         returnValue.Message = "Invalid Token";
     }
     return returnValue;
 }
예제 #5
0
        public int GetTasksPagesCount(int pageSize, TaskSearchCriteria criteria)
        {
            using (var session = Hibernate.SessionFactory.OpenSession())
            {
                Task         t  = null;
                TaskStatus   s  = null;
                TaskPriority p  = null;
                TaskGenre    g  = null;
                TaskComment  c  = null;
                User         uc = null;

                var query = session.QueryOver(() => t)
                            .JoinAlias(() => t.Status, () => s)
                            .JoinAlias(() => t.Priority, () => p)
                            .JoinAlias(() => t.Genre, () => g)
                            .Left.JoinAlias(() => t.Comments, () => c)
                            .Left.JoinAlias(() => c.User, () => uc);

                if (criteria.TaskAuthorUsername.IsNotNull())
                {
                    query.Where(() => t.Author == criteria.TaskAuthorUsername);
                }
                if (criteria.ShowTasksOnly)
                {
                    query.Where(() => g.Id == 4);
                }
                if (criteria.ShowInstallationsOnly)
                {
                    query.Where(() => g.Id == 2);
                }
                if (criteria.ShowTonersOnly)
                {
                    query.Where(() => g.Id == 3);
                }
                if (criteria.ShowUpdatesOnly)
                {
                    query.Where(() => g.Id == 1);
                }
                if (criteria.ShowWithoutCanceledTasks)
                {
                    query.Where(Res.Not(Res.Eq(Pro.Property("s.Id"), 1)));
                }
                if (criteria.TaskId.IsNotNull())
                {
                    query.Where(() => t.Id == criteria.TaskId.Value);
                }
                if (criteria.Topic.IsNotNull())
                {
                    query.Where(Res.InsensitiveLike(Pro.Property("t.Topic"), criteria.Topic, MatchMode.Anywhere));
                }
                if (criteria.Content.IsNotNull())
                {
                    query.Where(Res.InsensitiveLike(Pro.Property("t.Content"), criteria.Content, MatchMode.Anywhere));
                }
                if (criteria.StartDate.IsNotNull())
                {
                    query.Where(Res.Eq(Pro.Cast(SqlType.Date, Pro.Property("t.StartPeriod")), criteria.StartDate.Value));
                }
                if (criteria.StartHour.IsNotNull())
                {
                    query.Where(Res.Eq(Pro.Cast(SqlType.Time, Pro.Property("t.StartPeriod")), criteria.StartHour.Value.ToString()));
                }
                if (criteria.EndDate.IsNotNull())
                {
                    query.Where(Res.Eq(Pro.Cast(SqlType.Date, Pro.Property("t.EndPeriod")), criteria.EndDate.Value));
                }
                if (criteria.EndDate.IsNotNull())
                {
                    query.Where(Res.Eq(Pro.Cast(SqlType.Time, Pro.Property("t.EndPeriod")), criteria.EndHour.Value.ToString()));
                }
                if (criteria.TaskPriorityId.IsNotNull())
                {
                    query.Where(() => p.Id == criteria.TaskPriorityId);
                }
                if (criteria.TaskStatusId.IsNotNull())
                {
                    query.Where(() => s.Id == criteria.TaskStatusId);
                }

                if (criteria.TaskParticipantId.IsNotNull())
                {
                    Task subT = null;
                    User subU = null;

                    var subquery = QueryOver.Of(() => subT)
                                   .JoinAlias(() => subT.Users, () => subU)
                                   .Where(Res.And(
                                              Res.EqProperty(Pro.Property("t.Id"), Pro.Property("subT.Id")),
                                              Res.Eq(Pro.Property("subU.Id"), criteria.TaskParticipantId)))
                                   .SelectList(l => l
                                               .Select(() => subU.Id));

                    query.WithSubquery.WhereExists(subquery);
                }


                if (criteria.Comment.IsNotNull())
                {
                    TaskComment subC = null;
                    Task        subT = null;

                    var subquery = QueryOver.Of(() => subC)
                                   .JoinAlias(() => subC.Task, () => subT)
                                   .Where(Res.And(
                                              Res.EqProperty(Pro.Property("subT.Id"), Pro.Property("t.Id")),
                                              Res.InsensitiveLike(Pro.Property("subC.Content"), criteria.Comment, MatchMode.Anywhere)))
                                   .SelectList(l => l
                                               .Select(() => subT.Id));

                    query.WithSubquery.WhereExists(subquery);
                }

                if (criteria.CommentAuthorId.IsNotNull())
                {
                    TaskComment subC = null;
                    Task        subT = null;
                    User        subU = null;

                    var subquery = QueryOver.Of(() => subC)
                                   .JoinAlias(() => subC.Task, () => subT)
                                   .JoinAlias(() => subC.User, () => subU)
                                   .Where(Res.And(
                                              Res.EqProperty(Pro.Property("subT.Id"), Pro.Property("t.Id")),
                                              Res.Eq(Pro.Property("subU.Id"), criteria.CommentAuthorId)))
                                   .SelectList(l => l
                                               .Select(() => subT.Id));

                    query.WithSubquery.WhereExists(subquery);
                }

                var result = Math.Ceiling((1.0 * query.RowCount()) / pageSize);
                return(result == 0 ? 1 : Convert.ToInt32(result));
            }
        }
예제 #6
0
        public IList <TaskPrimaryDataDTO> GetTasks(int pageNo, int pageSize, TaskSearchCriteria criteria)
        {
            using (var session = Hibernate.SessionFactory.OpenSession())
            {
                Task         t     = null;
                TaskStatus   s     = null;
                TaskPriority p     = null;
                TaskGenre    g     = null;
                TaskComment  c     = null;
                TaskComment  c_sub = null;
                User         uc    = null;

                var query = session.QueryOver(() => t)
                            .JoinAlias(() => t.Status, () => s)
                            .JoinAlias(() => t.Priority, () => p)
                            .JoinAlias(() => t.Genre, () => g)
                            .Left.JoinAlias(() => t.Comments, () => c)
                            .Left.JoinAlias(() => c.User, () => uc)
                            .Where(
                    Res.EqProperty(
                        Pro.Conditional(Res.IsNull("c.Id"), Pro.Constant(0), Pro.Property("c.Id")),
                        Pro.SubQuery(QueryOver.Of(() => c_sub)
                                     .Where(() => c_sub.Task.Id == c.Task.Id)
                                     .Select(Pro.Conditional(Res.IsNull("c_sub.Id"), Pro.Constant(0), Pro.Max("c_sub.Id"))))
                        ));

                if (criteria.TaskAuthorUsername.IsNotNull())
                {
                    query.Where(() => t.Author == criteria.TaskAuthorUsername);
                }
                if (criteria.ShowTasksOnly)
                {
                    query.Where(() => g.Id == 4);
                }
                if (criteria.ShowInstallationsOnly)
                {
                    query.Where(() => g.Id == 2);
                }
                if (criteria.ShowTonersOnly)
                {
                    query.Where(() => g.Id == 3);
                }
                if (criteria.ShowUpdatesOnly)
                {
                    query.Where(() => g.Id == 1);
                }
                if (criteria.ShowWithoutCanceledTasks)
                {
                    query.Where(Res.Not(Res.Eq(Pro.Property("s.Id"), 1)));
                }
                if (criteria.TaskId.IsNotNull())
                {
                    query.Where(() => t.Id == criteria.TaskId.Value);
                }
                if (criteria.Topic.IsNotNull())
                {
                    query.Where(Res.InsensitiveLike(Pro.Property("t.Topic"), criteria.Topic, MatchMode.Anywhere));
                }
                if (criteria.Content.IsNotNull())
                {
                    query.Where(Res.InsensitiveLike(Pro.Property("t.Content"), criteria.Content, MatchMode.Anywhere));
                }
                if (criteria.StartDate.IsNotNull())
                {
                    query.Where(Res.Eq(Pro.Cast(SqlType.Date, Pro.Property("t.StartPeriod")), criteria.StartDate.Value));
                }
                if (criteria.StartHour.IsNotNull())
                {
                    query.Where(Res.Eq(Pro.Cast(SqlType.Time, Pro.Property("t.StartPeriod")), criteria.StartHour.Value.ToString()));
                }
                if (criteria.EndDate.IsNotNull())
                {
                    query.Where(Res.Eq(Pro.Cast(SqlType.Date, Pro.Property("t.EndPeriod")), criteria.EndDate.Value));
                }
                if (criteria.EndDate.IsNotNull())
                {
                    query.Where(Res.Eq(Pro.Cast(SqlType.Time, Pro.Property("t.EndPeriod")), criteria.EndHour.Value.ToString()));
                }
                if (criteria.TaskPriorityId.IsNotNull())
                {
                    query.Where(() => p.Id == criteria.TaskPriorityId);
                }
                if (criteria.TaskStatusId.IsNotNull())
                {
                    query.Where(() => s.Id == criteria.TaskStatusId);
                }

                if (criteria.TaskParticipantId.IsNotNull())
                {
                    Task subT = null;
                    User subU = null;

                    var subquery = QueryOver.Of(() => subT)
                                   .JoinAlias(() => subT.Users, () => subU)
                                   .Where(Res.And(
                                              Res.EqProperty(Pro.Property("t.Id"), Pro.Property("subT.Id")),
                                              Res.Eq(Pro.Property("subU.Id"), criteria.TaskParticipantId)))
                                   .SelectList(l => l
                                               .Select(() => subU.Id));

                    query.WithSubquery.WhereExists(subquery);
                }

                if (criteria.Comment.IsNotNull())
                {
                    TaskComment subC = null;
                    Task        subT = null;

                    var subquery = QueryOver.Of(() => subC)
                                   .JoinAlias(() => subC.Task, () => subT)
                                   .Where(Res.And(
                                              Res.EqProperty(Pro.Property("subT.Id"), Pro.Property("t.Id")),
                                              Res.InsensitiveLike(Pro.Property("subC.Content"), criteria.Comment, MatchMode.Anywhere)))
                                   .SelectList(l => l
                                               .Select(() => subT.Id));

                    query.WithSubquery.WhereExists(subquery);
                }

                if (criteria.CommentAuthorId.IsNotNull())
                {
                    TaskComment subC = null;
                    Task        subT = null;
                    User        subU = null;

                    var subquery = QueryOver.Of(() => subC)
                                   .JoinAlias(() => subC.Task, () => subT)
                                   .JoinAlias(() => subC.User, () => subU)
                                   .Where(Res.And(
                                              Res.EqProperty(Pro.Property("subT.Id"), Pro.Property("t.Id")),
                                              Res.Eq(Pro.Property("subU.Id"), criteria.CommentAuthorId)))
                                   .SelectList(l => l
                                               .Select(() => subT.Id));

                    query.WithSubquery.WhereExists(subquery);
                }

                query.SelectList(l => l
                                 .Select(() => t.Id)
                                 .Select(() => t.Topic)
                                 .Select(() => t.Content)
                                 .Select(() => t.StartPeriod)
                                 .Select(() => t.EndPeriod)
                                 .Select(() => c.Id)
                                 .Select(() => c.Content)
                                 .Select(() => c.Date)
                                 .Select(() => uc.Username)
                                 .Select(() => s.Name)
                                 .Select(() => p.Name)
                                 .Select(() => g.Name)
                                 .Select(() => t.Author))
                .OrderBy(() => t.Id).Desc
                .TransformUsing(Transformers.AliasToBeanConstructor(typeof(TaskPrimaryDataDTO).GetConstructors()[1]))
                .Skip(pageSize * (pageNo - 1)).Take(pageSize);

                return(query.List <TaskPrimaryDataDTO>());

                #region Above generates sql like...

                /*
                 *  SELECT this_.Id AS y0_,
                 *         this_.Topic AS y1_,
                 *         this_.StartPeriod AS y2_,
                 *         this_.EndPeriod AS y3_,
                 *         c4_.Id AS y4_,
                 *         c4_.Content AS y5_,
                 *         c4_.Date AS y6_,
                 *         u5_.Username AS y7_,
                 *         s1_.Name AS y8_,
                 *         p2_.Name AS y9_,
                 *         g3_.Name AS y10_
                 *  FROM `Task` this_
                 *      LEFT OUTER JOIN `TaskComment` c4_ ON this_.Id=c4_.Task_id
                 *      LEFT OUTER JOIN `User` u5_ ON c4_.User_id=u5_.Id
                 *      INNER JOIN `TaskGenre` g3_ ON this_.Genre_id=g3_.Id
                 *      INNER JOIN `TaskStatus` s1_ ON this_.Status_id=s1_.Id
                 *      INNER JOIN `TaskPriority` p2_ ON this_.Priority_id=p2_.Id
                 *  WHERE (CASE WHEN c4_.Id IS NULL THEN ?p0 ELSE c4_.Id END) =
                 *        (SELECT (CASE WHEN this_0_.Id IS NULL THEN ?p1 ELSE max(this_0_.Id) END) AS y0_ FROM `TaskComment` this_0_)
                 *  ORDER BY this_.Id DESC
                 *  LIMIT ?p2;
                 *
                 *  ?p0 = 0 [Type: Int32 (0)],
                 *  ?p1 = 0 [Type: Int32 (0)],
                 *  ?p2 = 50 [Type: Int32 (0)]
                 */
                #endregion
            }
        }
        /// <summary>
        /// Searches for task that match the search criteria.
        /// </summary>
        public IRIS.Law.WebServiceInterfaces.Diary.Task[] SearchTask(int startRow, int pageSize, string sortBy, string taskStatus, string user, string fromDate, string toDate, bool forceRefresh)
        {
            DiaryServiceClient diaryService = null;
            IRIS.Law.WebServiceInterfaces.Diary.Task[] tasks = null;
            try
            {
                if (HttpContext.Current.Session[SessionName.LogonSettings] != null)
                {
                    Guid _logonId = ((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId;
                    CollectionRequest collectionRequest = new CollectionRequest();
                    collectionRequest.ForceRefresh = forceRefresh;
                    collectionRequest.StartRow = startRow;
                    collectionRequest.RowCount = pageSize;

                    TaskSearchCriteria criteria = new TaskSearchCriteria();
                    criteria.MemberID = user;
                    criteria.OrderBy = sortBy;
                    if (!string.IsNullOrEmpty(fromDate))
                    {
                        criteria.StartDate = Convert.ToDateTime(fromDate);
                    }
                    else
                    {
                        criteria.StartDate = DataConstants.BlankDate;
                    }

                    if (!string.IsNullOrEmpty(toDate))
                    {
                        criteria.ToDate = Convert.ToDateTime(toDate);
                    }
                    else
                    {
                        criteria.ToDate = DataConstants.BlankDate;
                    }

                    if (!string.IsNullOrEmpty(taskStatus))
                    {
                        criteria.Status = taskStatus;
                    }

                    diaryService = new DiaryServiceClient();
                    TaskSearchReturnValue returnValue = diaryService.MemberTaskSearch(_logonId,
                                                collectionRequest, criteria);

                    if (returnValue.Success)
                    {
                        _taskRowCount = returnValue.Tasks.TotalRowCount;
                        tasks = returnValue.Tasks.Rows;
                    }
                    else
                    {
                        if (returnValue.Message == "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.")
                            throw new Exception("Date is invalid");
                        else
                            throw new Exception(returnValue.Message);
                    }
                }
                return tasks;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (diaryService != null)
                {
                    if (diaryService.State != System.ServiceModel.CommunicationState.Faulted)
                        diaryService.Close();
                }
            }
        }
        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;
        }
        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;
        }
        /// <summary>
        /// Searches for task that match the search criteria.
        /// </summary>
        public IRIS.Law.WebServiceInterfaces.Diary.Task[] SearchTask(int startRow, int pageSize, string sortBy, string taskStatus, string user, string fromDate, string toDate, bool forceRefresh)
        {
            DiaryServiceClient diaryService = null;

            IRIS.Law.WebServiceInterfaces.Diary.Task[] tasks = null;
            try
            {
                if (HttpContext.Current.Session[SessionName.LogonSettings] != null)
                {
                    Guid _logonId = ((LogonReturnValue)HttpContext.Current.Session[SessionName.LogonSettings]).LogonId;
                    CollectionRequest collectionRequest = new CollectionRequest();
                    collectionRequest.ForceRefresh = forceRefresh;
                    collectionRequest.StartRow     = startRow;
                    collectionRequest.RowCount     = pageSize;

                    TaskSearchCriteria criteria = new TaskSearchCriteria();
                    criteria.MemberID = user;
                    criteria.OrderBy  = sortBy;
                    if (!string.IsNullOrEmpty(fromDate))
                    {
                        criteria.StartDate = Convert.ToDateTime(fromDate);
                    }
                    else
                    {
                        criteria.StartDate = DataConstants.BlankDate;
                    }

                    if (!string.IsNullOrEmpty(toDate))
                    {
                        criteria.ToDate = Convert.ToDateTime(toDate);
                    }
                    else
                    {
                        criteria.ToDate = DataConstants.BlankDate;
                    }

                    if (!string.IsNullOrEmpty(taskStatus))
                    {
                        criteria.Status = taskStatus;
                    }

                    diaryService = new DiaryServiceClient();
                    TaskSearchReturnValue returnValue = diaryService.MemberTaskSearch(_logonId,
                                                                                      collectionRequest, criteria);

                    if (returnValue.Success)
                    {
                        _taskRowCount = returnValue.Tasks.TotalRowCount;
                        tasks         = returnValue.Tasks.Rows;
                    }
                    else
                    {
                        if (returnValue.Message == "SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.")
                        {
                            throw new Exception("Date is invalid");
                        }
                        else
                        {
                            throw new Exception(returnValue.Message);
                        }
                    }
                }
                return(tasks);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (diaryService != null)
                {
                    if (diaryService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        diaryService.Close();
                    }
                }
            }
        }
예제 #11
0
        public List <Task> SearchTasks(TaskSearchCriteria searchCriteria, int userId)
        {
            var searchTasks = new List <Task>();

            using (var session = NHibernateHelper.OpenSession())
            {
                ICriterion crTaskName = null;

                ICriterion crDateBetween  = null;
                ICriterion crTaskCategory = null;
                ICriterion crAllOr        = null;

                if (!String.IsNullOrEmpty(searchCriteria.TaskName))
                {
                    crTaskName = Restrictions.Like("t.TaskName", "%" + searchCriteria.TaskName + "%");
                }

                if (searchCriteria.TaskDateFrom.HasValue && searchCriteria.TaskDateTo.HasValue)
                {
                    crDateBetween = Restrictions.Between("t.TaskDate", searchCriteria.TaskDateFrom.Value, searchCriteria.TaskDateTo.Value);
                }

                if (!String.IsNullOrEmpty(searchCriteria.TaskCategory))
                {
                    crTaskCategory = Restrictions.Eq("c.CategoryName", searchCriteria.TaskCategory);
                }


                if (crTaskName != null && crDateBetween != null && crTaskCategory != null)
                {
                    crAllOr = Restrictions.Conjunction()
                              .Add(crTaskName)
                              .Add(crTaskCategory)
                              .Add(crDateBetween);
                }
                if (crTaskName != null && crTaskCategory == null && crDateBetween == null)
                {
                    crAllOr = crTaskName;
                }
                if (crTaskName != null & crTaskCategory != null && crDateBetween == null)
                {
                    crAllOr = Restrictions.Disjunction()
                              .Add(crTaskName)
                              .Add(crTaskCategory);
                }
                if (crTaskName != null && crTaskCategory == null && crDateBetween != null)
                {
                    crAllOr = Restrictions.Conjunction()
                              .Add(crTaskName)
                              .Add(crDateBetween);
                }
                if (crTaskName == null && crTaskCategory != null && crDateBetween != null)
                {
                    crAllOr = Restrictions.Conjunction()
                              .Add(crTaskCategory)
                              .Add(crDateBetween);
                }
                if (crTaskName == null && crTaskCategory == null && crDateBetween != null)
                {
                    crAllOr = Restrictions.Conjunction()
                              .Add(crDateBetween);
                }
                if (crTaskName == null && crTaskCategory != null && crDateBetween == null)
                {
                    crAllOr = Restrictions.Conjunction()
                              .Add(crTaskCategory);
                }

                var query = session.CreateCriteria <Task>("t");

                query.CreateCriteria("t.TaskCategory", "c");
                query.CreateCriteria("t.User", "u");

                ICriterion crUserId = Restrictions.Eq("u.Id", userId);
                ICriterion crEndAll = null;
                if (crAllOr != null)
                {
                    crEndAll = Restrictions.And(crUserId, crAllOr);
                }
                else
                {
                    crEndAll = crUserId;
                }
                query.Add(crEndAll);

                searchTasks = query.List <Task>().OrderByDescending(x => x.TaskDate).ToList <Task>();
            }
            return(searchTasks);
        }