private void FillGridMain()
        {
            string[]      searchTokens  = textSearch.Text.ToLower().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
            long[]        userNums      = new long[0];
            JobCategory[] jobCats       = new JobCategory[0];
            JobPhase[]    jobPhases     = new JobPhase[0];
            long[]        jobPriorities = new long[0];
            if (listBoxUsers.SelectedIndices.Count > 0 && !listBoxUsers.SelectedIndices.Contains(0))
            {
                userNums = listBoxUsers.SelectedIndices.Cast <int>().Select(x => _listUsers[x - 1].UserNum).ToArray();
            }
            if (listBoxCategory.SelectedIndices.Count > 0 && !listBoxCategory.SelectedIndices.Contains(0))
            {
                jobCats = listBoxCategory.SelectedIndices.Cast <int>().Select(x => (JobCategory)(x - 1)).ToArray();
            }
            if (listBoxPhases.SelectedIndices.Count > 0 && !listBoxPhases.SelectedIndices.Contains(0))
            {
                jobPhases = listBoxPhases.SelectedIndices.Cast <int>().Select(x => (JobPhase)(x - 1)).ToArray();
            }
            if (listBoxPriorities.SelectedIndices.Count > 0 && !listBoxPriorities.SelectedIndices.Contains(0))
            {
                jobPriorities = listBoxPriorities.GetListSelected <Def>().Select(x => x.DefNum).ToArray();
            }
            Action actionCloseProgress = ODProgress.Show(ODEventType.Job, typeof(JobEvent), "Getting job data...");

            #region Get Missing Data
            //This entire section will go out to the database and get any data that is unknown based on some of the filters.
            //The other filters will be applied later via the cached lists.
            try {
                List <Job> listJobs = Jobs.GetForSearch(dateFrom.Value, dateTo.Value, jobPhases.ToList(), jobPriorities.ToList(), _listJobsAll.Select(x => x.JobNum).ToList());
                Jobs.FillInMemoryLists(listJobs, true);
                _listJobsAll.AddRange(listJobs);
            }
            catch (OutOfMemoryException oome) {
                actionCloseProgress();
                oome.DoNothing();
                MsgBox.Show(this, "Not enough memory to complete the search.  Please refine search filters.");
                return;
            }
            //Only get the feature request entries that we care about.
            JobEvent.Fire(ODEventType.Job, "Getting feature request data...");
            List <long> listFeatureRequestNums = _listJobsAll.SelectMany(x => x.ListJobLinks)
                                                 .Where(x => x.LinkType == JobLinkType.Request)
                                                 .Select(x => x.FKey)
                                                 .Distinct()
                                                 .ToList();
            //Don't download any feature requests that we already know about.
            listFeatureRequestNums.RemoveAll(x => x.In(_listFeatureRequestsAll.Select(y => y.FeatReqNum)));
            if (!listFeatureRequestNums.IsNullOrEmpty())
            {
                _listFeatureRequestsAll.AddRange(FeatureRequests.GetAll(listFeatureRequestNums));
            }
            //Only get the bug entries that we care about.
            JobEvent.Fire(ODEventType.Job, "Getting bug data...");
            List <long> listBugIds = _listJobsAll.SelectMany(x => x.ListJobLinks)
                                     .Where(x => x.LinkType == JobLinkType.Bug)
                                     .Select(x => x.FKey)
                                     .Distinct()
                                     .ToList();
            //Don't download any bugs that we already know about.
            listBugIds.RemoveAll(x => x.In(_listBugsAll.Select(y => y.BugId)));
            if (!listBugIds.IsNullOrEmpty())
            {
                _listBugsAll.AddRange(Bugs.GetMany(listBugIds));
            }
            #endregion
            JobEvent.Fire(ODEventType.Job, "Filling grid...");
            gridMain.BeginUpdate();
            gridMain.ListGridColumns.Clear();
            gridMain.ListGridColumns.Add(new GridColumn("Job\r\nNum", 50, GridSortingStrategy.AmountParse));
            gridMain.ListGridColumns.Add(new GridColumn("Priority", 50, HorizontalAlignment.Center));
            gridMain.ListGridColumns.Add(new GridColumn("Phase", 85));
            gridMain.ListGridColumns.Add(new GridColumn("Category", 80));
            gridMain.ListGridColumns.Add(new GridColumn("Job Title", -1));
            gridMain.ListGridColumns.Add(new GridColumn("Version", 80));
            gridMain.ListGridColumns.Add(new GridColumn("Est. Version", 80));
            gridMain.ListGridColumns.Add(new GridColumn("Expert", 75));
            gridMain.ListGridColumns.Add(new GridColumn("Engineer", 75));
            gridMain.ListGridColumns.Add(new GridColumn("Est.\r\nHours", 60, GridSortingStrategy.AmountParse));
            gridMain.ListGridColumns.Add(new GridColumn("Act.\r\nHours", 60, GridSortingStrategy.AmountParse));
            gridMain.ListGridColumns.Add(new GridColumn("Job\r\nMatch", 45, HorizontalAlignment.Center));
            gridMain.ListGridColumns.Add(new GridColumn("Bug\r\nMatch", 45, HorizontalAlignment.Center));
            gridMain.ListGridColumns.Add(new GridColumn("FR\r\nMatch", 45, HorizontalAlignment.Center));
            gridMain.ListGridRows.Clear();
            _listJobsFiltered = new List <Job>();
            foreach (Job jobCur in _listJobsAll)
            {
                if (jobCats.Length > 0 && !jobCats.Contains(jobCur.Category))
                {
                    continue;
                }
                if (jobPhases.Length > 0 && !jobPhases.Contains(jobCur.PhaseCur))
                {
                    continue;
                }
                if (jobPriorities.Length > 0 && !jobPriorities.Contains(jobCur.Priority))
                {
                    continue;
                }
                if (userNums.Length > 0 && !userNums.All(x => Jobs.GetUserNums(jobCur).Contains(x)))
                {
                    continue;
                }
                if (!jobCur.DateTimeEntry.Between(dateFrom.Value, dateTo.Value))
                {
                    continue;
                }
                bool isJobMatch        = false;
                bool isBugMatch        = false;
                bool isFeatureReqMatch = false;
                if (searchTokens.Length > 0)
                {
                    bool       addRow   = false;
                    List <Bug> listBugs = jobCur.ListJobLinks.FindAll(x => x.LinkType == JobLinkType.Bug)
                                          .Select(x => _listBugsAll.FirstOrDefault(y => x.FKey == y.BugId))
                                          .Where(x => x != null)
                                          .ToList();
                    List <FeatureRequest> listFeatures = jobCur.ListJobLinks.FindAll(x => x.LinkType == JobLinkType.Request)
                                                         .Select(x => _listFeatureRequestsAll.FirstOrDefault(y => x.FKey == y.FeatReqNum))
                                                         .Where(x => x != null)
                                                         .ToList();
                    foreach (string token in searchTokens.Distinct())
                    {
                        bool isFound = false;
                        //JOB MATCHES
                        if (jobCur.Title.ToLower().Contains(token) ||
                            jobCur.Implementation.ToLower().Contains(token) ||
                            jobCur.Requirements.ToLower().Contains(token) ||
                            jobCur.Documentation.ToLower().Contains(token) ||
                            jobCur.JobNum.ToString().Contains(token))
                        {
                            isFound    = true;
                            isJobMatch = true;
                        }
                        //BUG MATCHES
                        if (!isFound || !isBugMatch)
                        {
                            if (listBugs.Any(x => x.Description.ToLower().Contains(token) || x.Discussion.ToLower().Contains(token)))
                            {
                                isFound    = true;
                                isBugMatch = true;
                            }
                        }
                        //FEATURE REQUEST MATCHES
                        if (!isFound || !isFeatureReqMatch)
                        {
                            if (listFeatures.Any(x => x.Description.Contains(token) || x.FeatReqNum.ToString().ToLower().Contains(token)))
                            {
                                isFound           = true;
                                isFeatureReqMatch = true;
                            }
                        }
                        addRow = isFound;
                        if (!isFound)
                        {
                            break;                            //stop looking for additional tokens, we didn't find this one.
                        }
                    }
                    if (!addRow)
                    {
                        continue;                        //we did not find one of the search terms.
                    }
                }
                _listJobsFiltered.Add(jobCur);
                Def     jobPriority = _listJobPriorities.FirstOrDefault(y => y.DefNum == jobCur.Priority);
                GridRow row         = new GridRow();
                row.Cells.Add(jobCur.JobNum.ToString());
                row.Cells.Add(new GridCell(jobPriority.ItemName)
                {
                    ColorBackG = jobPriority.ItemColor,
                    ColorText  = (jobCur.Priority == _listJobPriorities.FirstOrDefault(y => y.ItemValue.Contains("Urgent")).DefNum) ? Color.White : Color.Black,
                });
                row.Cells.Add(jobCur.PhaseCur.ToString());
                row.Cells.Add(jobCur.Category.ToString());
                row.Cells.Add(jobCur.Title);
                row.Cells.Add(jobCur.JobVersion.ToString());
                row.Cells.Add(jobCur.ProposedVersion.ToString());
                row.Cells.Add(Userods.GetName(jobCur.UserNumExpert));
                row.Cells.Add(Userods.GetName(jobCur.UserNumEngineer));
                row.Cells.Add(jobCur.HoursEstimate.ToString());
                row.Cells.Add(jobCur.HoursActual.ToString());
                row.Cells.Add(isJobMatch ? "X" : "");
                row.Cells.Add(isBugMatch ? "X" : "");
                row.Cells.Add(new GridCell(isFeatureReqMatch ? "X" : "")
                {
                    ColorBackG = _listFeatureRequestsAll.Count == 0 ? Control.DefaultBackColor : Color.Empty
                });
                row.Tag = jobCur;
                gridMain.ListGridRows.Add(row);
            }
            gridMain.EndUpdate();
            actionCloseProgress();
        }
Exemple #2
0
 private void FillGridMain()
 {
     if (!_IsSearchReady)
     {
         return;
     }
     Cursor = Cursors.WaitCursor;
     gridMain.BeginUpdate();
     gridMain.Columns.Clear();
     //TODO: change columns
     gridMain.Columns.Add(new ODGridColumn("Job\r\nNum", 50));
     gridMain.Columns.Add(new ODGridColumn("Phase", 85));
     gridMain.Columns.Add(new ODGridColumn("Category", 80));
     gridMain.Columns.Add(new ODGridColumn("Job Title", 300));
     gridMain.Columns.Add(new ODGridColumn("Version", 80));
     gridMain.Columns.Add(new ODGridColumn("Expert", 75));
     gridMain.Columns.Add(new ODGridColumn("Engineer", 75));
     gridMain.Columns.Add(new ODGridColumn("Job\r\nMatch", 45)
     {
         TextAlign = HorizontalAlignment.Center
     });
     gridMain.Columns.Add(new ODGridColumn("Bug\r\nMatch", 45)
     {
         TextAlign = HorizontalAlignment.Center
     });
     gridMain.Columns.Add(new ODGridColumn("Feature\r\nRequest\r\nMatch", 45)
     {
         TextAlign = HorizontalAlignment.Center
     });
     gridMain.Rows.Clear();
     string[] searchTokens = textSearch.Text.ToLower().Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
     _listJobsFiltered = new List <Job>();
     long[]        userNums  = new long[0];
     JobCategory[] jobCats   = new JobCategory[0];
     JobPhase[]    jobPhases = new JobPhase[0];
     if (listBoxUsers.SelectedIndices.Count > 0 && !listBoxUsers.SelectedIndices.Contains(0))
     {
         userNums = listBoxUsers.SelectedIndices.Cast <int>().Select(x => _listUsers[x - 1].UserNum).ToArray();
     }
     if (listBoxCategory.SelectedIndices.Count > 0 && !listBoxCategory.SelectedIndices.Contains(0))
     {
         jobCats = listBoxCategory.SelectedIndices.Cast <int>().Select(x => (JobCategory)(x - 1)).ToArray();
     }
     if (listBoxStatus.SelectedIndices.Count > 0 && !listBoxStatus.SelectedIndices.Contains(0))
     {
         jobPhases = listBoxStatus.SelectedIndices.Cast <int>().Select(x => (JobPhase)(x - 1)).ToArray();
     }
     foreach (Job jobCur in _listJobsAll)
     {
         if (jobCats.Length > 0 && !jobCats.Contains(jobCur.Category))
         {
             continue;
         }
         if (jobPhases.Length > 0 && !jobPhases.Contains(jobCur.PhaseCur))
         {
             continue;
         }
         if (userNums.Length > 0 && !userNums.All(x => Jobs.GetUserNums(jobCur).Contains(x)))
         {
             continue;
         }
         bool isJobMatch        = false;
         bool isBugMatch        = false;
         bool isFeatureReqMatch = false;
         if (searchTokens.Length > 0)
         {
             bool                  addRow       = false;
             List <Bug>            listBugs     = jobCur.ListJobLinks.FindAll(x => x.LinkType == JobLinkType.Bug).Select(x => _listBugsAll.FirstOrDefault(y => x.FKey == y.BugId)).Where(x => x != null).ToList();
             List <FeatureRequest> listFeatures = jobCur.ListJobLinks.FindAll(x => x.LinkType == JobLinkType.Request).Select(x => _listFeatureRequestsAll.FirstOrDefault(y => x.FKey == y.FeatReqNum)).Where(x => x != null).ToList();
             foreach (string token in searchTokens.Distinct())
             {
                 bool isFound = false;
                 //JOB MATCHES
                 if (jobCur.Title.ToLower().Contains(token) ||
                     jobCur.Implementation.ToLower().Contains(token) ||
                     jobCur.Requirements.ToLower().Contains(token) ||
                     jobCur.Documentation.ToLower().Contains(token) ||
                     jobCur.JobNum.ToString().Contains(token))
                 {
                     isFound    = true;
                     isJobMatch = true;
                 }
                 //BUG MATCHES
                 if (!isFound || !isBugMatch)
                 {
                     if (listBugs.Any(x => x.Description.ToLower().Contains(token) || x.Discussion.ToLower().Contains(token)))
                     {
                         isFound    = true;
                         isBugMatch = true;
                     }
                 }
                 //FEATURE REQUEST MATCHES
                 if (!isFound || !isFeatureReqMatch)
                 {
                     if (listFeatures.Any(x => x.Description.Contains(token) || x.FeatReqNum.ToString().ToLower().Contains(token)))
                     {
                         isFound           = true;
                         isFeatureReqMatch = true;
                     }
                 }
                 addRow = isFound;
                 if (!isFound)
                 {
                     break;                            //stop looking for additional tokens, we didn't find this one.
                 }
             }
             if (!addRow)
             {
                 continue;                        //we did not find one of the search terms.
             }
         }
         _listJobsFiltered.Add(jobCur);
         ODGridRow row = new ODGridRow();
         row.Cells.Add(jobCur.JobNum.ToString());
         row.Cells.Add(jobCur.PhaseCur.ToString());
         row.Cells.Add(jobCur.Category.ToString());
         row.Cells.Add(jobCur.Title.Left(53, true));
         row.Cells.Add(jobCur.JobVersion.ToString());
         row.Cells.Add(Userods.GetName(jobCur.UserNumExpert));
         row.Cells.Add(Userods.GetName(jobCur.UserNumEngineer));
         row.Cells.Add(isJobMatch ? "X" : "");
         row.Cells.Add(isBugMatch ? "X" : "");
         row.Cells.Add(new ODGridCell(isFeatureReqMatch ? "X" : "")
         {
             CellColor = _listFeatureRequestsAll.Count == 0 ? Control.DefaultBackColor : Color.Empty
         });
         row.Tag = jobCur;
         gridMain.Rows.Add(row);
     }
     gridMain.EndUpdate();
     Cursor = Cursors.Default;
 }