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 bool Program() { if (tokens[current] == "درس") { current++; if (tokens[current] == "(") { current++; if (tokens[current] == "ت" || tokens[current] == "ع") { current++; if (tokens[current] == ")") { current++; if (tokens[current] == ":") { current++; int minuteStartTime; int hourStartTime; int minuteFinishTime; int hourFinishTime; string site = string.Empty; Day day = Day.NAN; if (tokens[current] == "شنبه" || tokens[current] == "یک شنبه" || tokens[current] == "دو شنبه" || tokens[current] == "سه شنبه" || tokens[current] == "چهار شنبه" || tokens[current] == "پنج شنبه" || tokens[current] == "جمعه") { current++; if (tokens[current - 1] == "شنبه") { day = Day.SATURDAY; } else if (tokens[current - 1] == "یک شنبه") { day = Day.SUNDAY; } if (tokens[current - 1] == "دو شنبه") { day = Day.MONDAY; } if (tokens[current - 1] == "سه شنبه") { day = Day.TUESDAY; } if (tokens[current - 1] == "چهار شنبه") { day = Day.WEDNESDAY; } if (tokens[current - 1] == "پنج شنبه") { day = Day.THURSDAY; } if (tokens[current - 1] == "جمعه") { day = Day.FRIDAY; } if (int.TryParse(tokens[current], out hourStartTime) && tokens[current].Length == 2) { current++; if (tokens[current] == ":") { current++; if (int.TryParse(tokens[current], out minuteStartTime) && tokens[current].Length == 2) { current++; if (tokens[current] == "-") { current++; if (int.TryParse(tokens[current], out hourFinishTime) && tokens[current].Length == 2) { current++; if (tokens[current] == ":") { current++; if (int.TryParse(tokens[current], out minuteFinishTime) && tokens[current].Length == 2) { current++; if (tokens[current] == "مکان") { current++; if (tokens[current] == ":") { current++; site = tokens[current]; current++; if (tokens[current] == "#") { current++; //valid TimeAndSite timeAndSite = new TimeAndSite(); timeAndSite.Day = day; timeAndSite.Site = new LocalSite() { RawStringSiteValue = site }; timeAndSite.StartTime = new LocalTime() { Minute = minuteStartTime, Hour = hourStartTime }; timeAndSite.FinishTime = new LocalTime() { Minute = minuteFinishTime, Hour = hourFinishTime }; timeAndSiteAndExams.TimeAndSites.Add(timeAndSite); return(Program()); } } } else if (tokens[current] == "#") { current++; //valid TimeAndSite timeAndSite = new TimeAndSite(); timeAndSite.Day = day; timeAndSite.Site = new LocalSite() { RawStringSiteValue = site }; timeAndSite.StartTime = new LocalTime() { Minute = minuteStartTime, Hour = hourStartTime }; timeAndSite.FinishTime = new LocalTime() { Minute = minuteFinishTime, Hour = hourFinishTime }; timeAndSiteAndExams.TimeAndSites.Add(timeAndSite); return(Program()); } } } } } } } } } } } } } } else if (tokens[current] == "امتحان") { current++; if (tokens[current] == "(") { current++; int year; int month; int day; int hourStartTime; int minuteStartTime; int hourFinishTime; int minuteFinishTime; if (int.TryParse(tokens[current], out year) && tokens[current].Length == 4) { current++; if (tokens[current] == ".") { current++; if (int.TryParse(tokens[current], out month) && tokens[current].Length == 2) { current++; if (tokens[current] == ".") { current++; if (int.TryParse(tokens[current], out day) && tokens[current].Length == 2) { current++; if (tokens[current] == ")") { current++; if (tokens[current] == "ساعت") { current++; if (tokens[current] == ":") { current++; if (int.TryParse(tokens[current], out hourStartTime) && tokens[current].Length == 2) { current++; if (tokens[current] == ":") { current++; if (int.TryParse(tokens[current], out minuteStartTime) && tokens[current].Length == 2) { current++; if (tokens[current] == "-") { current++; if (int.TryParse(tokens[current], out hourFinishTime) && tokens[current].Length == 2) { current++; if (tokens[current] == ":") { current++; if (int.TryParse(tokens[current], out minuteFinishTime) && tokens[current].Length == 2) { current++; if (tokens[current] == "#") { current++; //valid timeAndSiteAndExams.Exam = new Exam(); timeAndSiteAndExams.Exam.StartTime = new LocalTime() { Minute = minuteStartTime, Hour = hourStartTime }; timeAndSiteAndExams.Exam.FinishTime = new LocalTime() { Minute = minuteFinishTime, Hour = hourFinishTime }; timeAndSiteAndExams.Exam.Date = new LocalDate() { Day = day, Month = month, Year = year }; return(Program()); } } } } } } } } } } } } } } } } } } else if (tokens[current] == "$")//eof { return(true); } return(false); }