Beispiel #1
0
 public OfferedCourseRow(GoalVersionOfferedCoursesRow goalVersion, ReductionStep2ColorStatus color, int rowId, OfferedCourse parentCourse)
 {
     GoalVersionOfferedCourseRow = goalVersion;
     Color         = color;
     RowId         = rowId;
     OfferedCourse = parentCourse;
 }
        private void SetButtonBackgroundColor(Button btn, ReductionStep2ColorStatus rowColor)
        {
            if (rowColor == ReductionStep2ColorStatus.Grey)
            {
                BrushConverter bc = new BrushConverter();
                Brush brush = (Brush)bc.ConvertFrom("#d0cdcd");
                brush.Freeze();

                btn.Background = brush;
                btn.Foreground = Brushes.Black;

            }
            else if (rowColor == ReductionStep2ColorStatus.RED)
            {
                BrushConverter bc = new BrushConverter();
                Brush brush = (Brush)bc.ConvertFrom("#f0513c");
                brush.Freeze();
                btn.Background = brush;
                btn.Foreground = Brushes.White;
            }
            else if (rowColor == ReductionStep2ColorStatus.WHITE)//default color
            {
                BrushConverter bc = new BrushConverter();
                Brush brush = (Brush)bc.ConvertFrom("#ffffff");
                brush.Freeze();
                btn.Background = brush;
                btn.Foreground = Brushes.Black;
                btn.Content = null;
            }
            else if (rowColor == ReductionStep2ColorStatus.Green)
            {
                BrushConverter bc = new BrushConverter();
                Brush brush = (Brush)bc.ConvertFrom("#8ee269");
                brush.Freeze();
                btn.Background = brush;
                btn.Foreground = Brushes.Black;
                btn.Content = new PackIcon { Kind = PackIconKind.Check };
            }
        }
        private void SetCardBackgroundColor(Card card, ReductionStep2ColorStatus rowColor)
        {

            if (rowColor == ReductionStep2ColorStatus.Grey)
            {
                BrushConverter bc = new BrushConverter();
                Brush brush = (Brush)bc.ConvertFrom("#d0cdcd");
                brush.Freeze();

                card.Background = brush;
                card.Foreground = Brushes.Black;

            }
            else if (rowColor == ReductionStep2ColorStatus.RED)
            {
                BrushConverter bc = new BrushConverter();
                Brush brush = (Brush)bc.ConvertFrom("#f0513c");
                brush.Freeze();
                card.Background = brush;
                card.Foreground = Brushes.White;
            }
            else if (rowColor == ReductionStep2ColorStatus.WHITE)//default color
            {
                BrushConverter bc = new BrushConverter();
                Brush brush = (Brush)bc.ConvertFrom("#ffffff");
                brush.Freeze();
                card.Background = brush;
                card.Foreground = Brushes.Black;
            }
            else if (rowColor == ReductionStep2ColorStatus.Green)
            {
                BrushConverter bc = new BrushConverter();
                Brush brush = (Brush)bc.ConvertFrom("#8ee269");
                brush.Freeze();
                card.Background = brush;
                card.Foreground = Brushes.Black;
            }
        }
Beispiel #4
0
 public OfferedCourse(Course course, int courseId, ReductionStep2ColorStatus color)
 {
     this.CourseId = courseId;
     Course        = course;
     this.Color    = color;
 }
        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);
                }
            }



        }
        private Card AddNewRowToStackPanel(StackPanel originStackPanel, string rowId, string professorName, string remainedCapacity, string timeAndSiteAndExamRawString, string Description, string parentCourseId, ReductionStep2ColorStatus rowColor)
        {
            Card card = new Card
            {
                Cursor = Cursors.Hand
            };

            SetCardBackgroundColor(card, rowColor);
            //v.i
            card.Name = "card" + parentCourseId + "_" + rowId;

            card.MouseDoubleClick += Card_MouseDoubleClick;
            card.Margin = new Thickness(5);
            originStackPanel.Children.Add(card);

            Grid gridRow = new Grid();
            card.Content = gridRow;

            gridRow.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });//id
            gridRow.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(200) });//professorName
            gridRow.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(30) });//remain capacity
            gridRow.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(225) });//time and ...
            gridRow.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(370) });//description

            AddNewTextBlockToGrid(gridRow, rowId, 0, 0);
            AddNewTextBlockToGrid(gridRow, professorName, 0, 1);
            AddNewTextBlockToGrid(gridRow, remainedCapacity, 0, 2);
            AddNewTextBlockToGrid(gridRow, timeAndSiteAndExamRawString, 0, 3);
            AddNewTextBlockToGrid(gridRow, Description, 0, 4);

            return card;
        }