Пример #1
0
        private async void btnTimeFilter_Click(object sender, RoutedEventArgs e)
        {
            if (!allowUserInteraction) return;
            allowUserInteraction = false;

            btnTimeFilter.IsEnabled = false;
            List<TimeFilteringModel> tfms = new List<TimeFilteringModel>();
            bool succ = false;
            try
            {
                bool[] days = new bool[7];

                ReductionStep2ColorStatus color = rdbRedColor.IsChecked == true ? ReductionStep2ColorStatus.RED : ReductionStep2ColorStatus.WHITE;

                #region r1

                if (Day0.IsChecked == true)
                    days[0] = true;
                if (Day1.IsChecked == true)
                    days[1] = true;
                if (Day2.IsChecked == true)
                    days[2] = true;
                if (Day3.IsChecked == true)
                    days[3] = true;
                if (Day4.IsChecked == true)
                    days[4] = true;
                if (Day5.IsChecked == true)
                    days[5] = true;
                if (Day6.IsChecked == true)
                    days[6] = true;

                string[] tFrom = txtStartTime.Text.Split(':');
                string[] tTo = txtFinishTime.Text.Split(':');

                int hStart;
                int mStart;

                int hFinish;
                int mFinish;

                if (!int.TryParse(tFrom[0], out hStart))
                {
                    throw new Exception();
                }
                if (!int.TryParse(tFrom[1], out mStart))
                {
                    throw new Exception();
                }


                if (!int.TryParse(tTo[0], out hFinish))
                {
                    throw new Exception();
                }
                if (!int.TryParse(tTo[1], out mFinish))
                {
                    throw new Exception();
                }

                #endregion


                List<TimeAndSite> ts = new List<TimeAndSite>();

                await Task.Run(() =>
                {

                    for (int i = 0; i < days.Length; i++)
                    {
                        if (days[i] == true)
                        {
                            TimeAndSite time = new TimeAndSite
                            {
                                StartTime = new LocalTime() { Hour = hStart, Minute = mStart, },
                                FinishTime = new LocalTime() { Hour = hFinish, Minute = mFinish, },
                                Day = (Harif.Infrastructures.GeneralEnums.Day)i
                            };
                            ts.Add(time);
                        }
                    }




                    foreach (var ofRow in offeredCourseRows)
                    {
                        if (ofRow.Color != color && OfferedCoursesServiceProvider.DoTheyCollide(ofRow.GoalVersionOfferedCourseRow.TimeAndSitesAndExam.TimeAndSites, ts))
                        {
                            TimeFilteringModel model = new TimeFilteringModel
                            {
                                Row = ofRow
                            };
                            model.TempOriginColor = model.Row.Color;
                            ofRow.Color = color;
                            tfms.Add(model);
                        }
                    }

                    if (greenCourses.Count > 0)
                    {
                        List<Box> boxes = new List<Box>();

                        foreach (var item in greenCourses)
                        {
                            boxes.Add(ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(item));
                        }

                        List<Box> res = null;
                        var task = Task.Run(() => ReductionStep2ServiceProvider.Validate(boxes, exampCollideChecking));
                        if (task.Wait(TimeSpan.FromMilliseconds(timeoutMs)))
                            res = task.Result;
                        else
                        {
                            res = null;
                        }

                        if (res == null)
                        {
                            throw new Exception();
                        }
                        else
                        {
                            //is ok
                        }
                    }
                    else
                    {
                        //is ok
                    }

                    succ = true;

                });
            }
            catch
            {

                foreach (var tfm in tfms)
                {
                    tfm.Row.Color = tfm.TempOriginColor;
                }
                lblMsgActionPerform.Foreground = Brushes.Red;
                lblMsgActionPerform.Content = "خطایی رخ داده است";
            }
            finally
            {
                btnTimeFilter.IsEnabled = true;
                allowUserInteraction = true;

                if (succ)
                {
                    lblMsgActionPerform.Foreground = Brushes.DarkGreen;
                    lblMsgActionPerform.Content = "فیلتر با موفقیت اعمال شد";

                    btnCourseNavigation_Click(selectedButton, null);
                }
            }



        }
Пример #2
0
        private bool IsValid(OfferedCourse offeredCourse, ReductionStepAction action, OfferedCourseRow offeredCourseRow = null)
        {
            if (action == ReductionStepAction.WHITE_ONE_RED_ROW)
            {
                return true;
            }
            else if (action == ReductionStepAction.WHITE_ALL_COURSES_ROWS)
            {
                return true;
            }
            else if (action == ReductionStepAction.RED_ALL_COURSES_ROWS)
            {
                if (offeredCourse.Color == ReductionStep2ColorStatus.Green)
                {
                    return false;
                }
                else if (offeredCourse.Color == ReductionStep2ColorStatus.WHITE)
                {
                    return true;
                }
                else throw new Exception();
            }
            else if (action == ReductionStepAction.UNCHECK_COURSE_MUST_BE_TAKE)
            {
                List<int> lst = new List<int>();
                foreach (var o in greenCourses)
                    if (o != offeredCourse)
                        lst.Add(o.Course.Id);
                //is valid state must be checked
                return MainCurriculumSateValidator.IsValidState(mainCurriculum, lst);
            }
            else if (action == ReductionStepAction.RED_ONE_WHITE_ROW)
            {
                if (offeredCourse.Color == ReductionStep2ColorStatus.WHITE)
                {
                    return true;
                }
                else if (offeredCourse.Color == ReductionStep2ColorStatus.Green)
                {
                    //temorary change the actual current value
                    offeredCourseRow.Color = ReductionStep2ColorStatus.RED;

                    List<Box> boxes = new List<Box>
                    {
                        ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(offeredCourse)
                    };

                    //restore actual value
                    offeredCourseRow.Color = ReductionStep2ColorStatus.WHITE;

                    foreach (var item in greenCourses)
                    {
                        if (item != offeredCourse)
                            boxes.Add(ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(item));
                    }

                    List<Box> res = null;
                    var task = Task.Run(() => ReductionStep2ServiceProvider.Validate(boxes, exampCollideChecking));
                    if (task.Wait(TimeSpan.FromMilliseconds(timeoutMs)))
                        res = task.Result;
                    else
                    {
                        res = null;
                    }



                    if (res == null) return false;
                    return true;

                }
                else
                    throw new Exception();
            }
            else if (action == ReductionStepAction.CHECK_COURSE_MUST_BE_TAKE)
            {
                if (offeredCourse.Course.Units + currentMustUnits > maxUnits)
                {
                    return false;
                }

                List<int> lst = new List<int>();
                foreach (var o in greenCourses)
                    lst.Add(o.Course.Id);
                lst.Add(offeredCourse.Course.Id);
                //is valid state must be checked
                bool output = MainCurriculumSateValidator.IsValidState(mainCurriculum, lst);
                if (!output) return false;

                output = false;
                for (int a = 0; a < offeredCourse.OfferedCourseRows.Count; a++)
                {
                    if (offeredCourse.OfferedCourseRows[a].Color == ReductionStep2ColorStatus.WHITE)
                    {
                        output = true;
                        break;
                    }
                }
                if (!output) return false;

                Box b1 = ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(offeredCourse);

                List<Box> boxes = new List<Box>
                {
                    b1
                };
                foreach (var item in greenCourses)
                {
                    boxes.Add(ReductionStep2ServiceProvider.CreateBoxForOfferedCourse(item));
                }

                List<Box> res = null;
                var task = Task.Run(() => ReductionStep2ServiceProvider.Validate(boxes, exampCollideChecking));
                if (task.Wait(TimeSpan.FromMilliseconds(timeoutMs)))
                    res = task.Result;
                else
                {
                    res = null;
                }

                if (res == null) return false;

                return true;
            }

            throw new Exception();
            //return false;
        }