public static IQueryable <TSource> AddOrderAndPageFilters <TSource>(this System.Linq.IQueryable <TSource> input, FilterModelBase filter) { if (filter != null) { if (filter.OrderBy.Length > 0) { input = input.OrderBy(filter.OrderBy); } else if (filter.OrderByDescending.Length > 0) { input = input.OrderBy(filter.OrderByDescending + " DESC"); } if (filter.Skip > 0 && filter.Take > 0) { return(input .SkipIf(true, filter.Skip) .TakeIf(true, filter.Take)); } return(input .SkipIf(filter.Page > 0, filter.Page * filter.PageLimit) .TakeIf(filter.PageLimit > 0, filter.PageLimit)); } return(input); }
protected override System.Linq.IOrderedQueryable <OrderInfo> MakeDefaultOrderBy(System.Linq.IQueryable <OrderInfo> queryable) { return(queryable.OrderBy(x => x.IsDeliverySuccessful)); }
public ViewClassTestAnalysisWindow(Test test, Class classS) { InitializeComponent(); // This code is largely identical to ViewTestAnalysisWindow.xaml.cs. Could potentially be merged if application was to be expanded. // Do a quick exit if the test has no questions, to avoid division by zero errors if (test.TestQuestions.Count() == 0) { App.Message("Validation Error", "That test has no questions, and cannot be analysed."); Close(); } // Set up window test_ = test; class_ = classS; lblTitle.Content = "Results Overview For: " + test_.TestName + ", by class " + class_.ClassName; // Set up results // We need to select all results which: // 1- Have the same ID as this test // 2- Were sat by a student in this class // 2 is easiest done through code analysis rather than a query, and we have very little data so this is appropriate and will not be slow. results_ = from testResults in App.db.TestResults where testResults.TestID == test_.TestID select testResults; // This lambda looks complicated but it is straightforward in principle. It just checks to see if they are in the class by querying for classes // identical to this in their StudentClasses link and then checking if the count is more than 0. results_ = results_.Where( x => x.Student.StudentClasses.Where(y => y.Class == class_).Count() > 0 ); // Set up the student list lstStudentData.ItemsSource = results_; calculateVariables(); lblStudentCount.Content = studentCount_; lblAveragePercentage.Content = averageMark_ + " / " + test.MaxScore; // Add percentage onto the label content with += lblAveragePercentage.Content += " (" + (100 / test.MaxScore) * averageMark_ + "%)"; lblStandardDeviation.Content = Math.Round(standardDeviation_, 2); // The textbox for the top/bottom achieving students is slightly more complicated // but still relatively straightforward int lastScore = -1; foreach (TestResult result in results_.OrderByDescending(x => x.Score.Value)) { // results.Score == lastScore ensures that if we're no longer the top in the class, we stop iterating if (lastScore == -1 || result.Score.Value == lastScore) { // lastScore != -1 signifies non-first iteration if (lastScore != -1) { // Put a new line in if it isn't the first line. // We don't want to do this in the first line to avoid // having a new line to start. txtTopInClass.Text += "\r\n"; } txtTopInClass.Text += result.Student.StudentName; // Update last score for future iterations lastScore = result.Score.Value; } else { break; } } int topScore = lastScore; // Used to break the worst in class if everyone had the same score lastScore = -1; // Set to -1 again for first-time initialisation trigger // Exactly the same but ordering ascendingly, and only occurs if the top score =/= to the bottom score. foreach (TestResult result in results_.OrderBy(x => x.Score.Value)) { // Quick check to break if the worst are also the top (i.e. everyone had the same mark) if (topScore == result.Score.Value) { break; } // results.Score == lastScore ensures that if we're no longer the top in the class, we stop iterating if (lastScore == -1 || result.Score.Value == lastScore) { if (lastScore != -1) { txtWorstInClass.Text += "\r\n"; } txtWorstInClass.Text += result.Student.StudentName; // Update last score for future iterations lastScore = result.Score.Value; } else { break; } } // Now calculate which word(s) were spelt wrong the most and least. Simple procedure, Dictionary <string, int> scores = getWordsScoreOverall(results_); if (scores != null) { // To order them, we're going to need a List of KeyValuePair instead List <KeyValuePair <string, int> > scoresList = scores.ToList(); // Sort it using a simple lamba scoresList.Sort((x, y) => x.Value.CompareTo(y.Value)); // Now grab the top and bottom scores int bottomQScore = scoresList.First().Value; int topQScore = scoresList.Last().Value; // Now we list the top words List <string> topWords = new List <string>(); List <string> bottomWords = new List <string>(); foreach (KeyValuePair <string, int> score in scoresList) { // Elseif is used intentionally to ensure that if the topQScore // is equal to the bottomQScore if (score.Value == topQScore) { topWords.Add(score.Key); } else if (score.Value == bottomQScore) { bottomWords.Add(score.Key); } } txtSpeltRightMost.Text = string.Join("\r\n", topWords); txtSpeltWrongMost.Text = string.Join("\r\n", bottomWords); } }
public ViewTestAnalysisWindow(Test test) { InitializeComponent(); // Do a quick exit if the test has no questions, to avoid division by zero errors if (test.TestQuestions.Count() == 0) { App.Message("Validation Error", "That test has no questions, and cannot be analysed."); Close(); } // Set up window test_ = test; lblTitle.Content = "Results Overview For: " + test_.TestName; // Set up results results_ = from testResults in App.db.TestResults where testResults.TestID == test_.TestID select testResults; // Set up the student list lstStudentData.ItemsSource = results_; calculateVariables(); lblStudentCount.Content = studentCount_; lblAveragePercentage.Content = averageMark_ + " / " + test.MaxScore; // Add percentage onto the label content with += lblAveragePercentage.Content += " (" + (100 / test.MaxScore) * averageMark_ + "%)"; lblStandardDeviation.Content = Math.Round(standardDeviation_, 2); // The textbox for the top/bottom achieving students is slightly more complicated // but still relatively straightforward int lastScore = -1; // Only do this code if there are results, since otherwise it's invalid. if (results_.Count() != 0) { foreach (TestResult result in results_.OrderByDescending(x => x.Score.Value)) { // results.Score == lastScore ensures that if we're no longer the top in the class, we stop iterating if (lastScore == -1 || result.Score.Value == lastScore) { // lastScore != -1 signifies non-first iteration if (lastScore != -1) { // Put a new line in if it isn't the first line. // We don't want to do this in the first line to avoid // having a new line to start. txtTopInClass.Text += "\r\n"; } txtTopInClass.Text += result.Student.StudentName; // Update last score for future iterations lastScore = result.Score.Value; } else { break; } } int topScore = lastScore; // Used to break the worst in class if everyone had the same score lastScore = -1; // Set to -1 again for first-time initialisation trigger // Exactly the same but ordering ascendingly, and only occurs if the top score =/= to the bottom score. foreach (TestResult result in results_.OrderBy(x => x.Score.Value)) { // Quick check to break if the worst are also the top (i.e. everyone had the same mark) if (topScore == result.Score.Value) { break; } // results.Score == lastScore ensures that if we're no longer the top in the class, we stop iterating if (lastScore == -1 || result.Score.Value == lastScore) { if (lastScore != -1) { txtWorstInClass.Text += "\r\n"; } txtWorstInClass.Text += result.Student.StudentName; // Update last score for future iterations lastScore = result.Score.Value; } else { break; } } // Now calculate which word(s) were spelt wrong the most and least. Simple procedure, Dictionary <string, int> scores = getWordsScoreOverall(results_); if (scores != null) { // To order them, we're going to need a List of KeyValuePair instead List <KeyValuePair <string, int> > scoresList = scores.ToList(); // Sort it using a simple lamba scoresList.Sort((x, y) => x.Value.CompareTo(y.Value)); // Now grab the top and bottom scores int bottomQScore = scoresList.First().Value; int topQScore = scoresList.Last().Value; // Now we list the top words List <string> topWords = new List <string>(); List <string> bottomWords = new List <string>(); foreach (KeyValuePair <string, int> score in scoresList) { // Elseif is used intentionally to ensure that if the topQScore // is equal to the bottomQScore if (score.Value == topQScore) { topWords.Add(score.Key); } else if (score.Value == bottomQScore) { bottomWords.Add(score.Key); } } txtSpeltRightMost.Text = string.Join("\r\n", topWords); txtSpeltWrongMost.Text = string.Join("\r\n", bottomWords); } } // Finally, if it's a class test (And therefore only has one class), // we hide the button to show class statistics if (test_.WholeYearTest == false) { btnClassPerformance.Visibility = System.Windows.Visibility.Hidden; } }
public ActionResult SortFilterColumn(string f_country, string f_city, string f_street, string f_house, int?f_number_min, int?f_number_max, int?f_index, string f_date, DateTime?f_StartDate, DateTime?f_EndDate, string sortType, bool?sortReverse, int?page) //сортируем таблицу по столбцу { int curPage = 0; // текущая страница; System.Linq.IQueryable <Addres> f_data = db.Addres; //Отфильтруем по Стране, Городу и улице if (f_country != null) { f_data = f_data.Where(p => p.Country.Contains(f_country)); } if (f_city != null) { f_data = f_data.Where(p => p.City.Contains(f_city)); } if (f_street != null) { f_data = f_data.Where(p => p.Street.Contains(f_street)); } //Фильтруем по номеру дома if (f_house != "") { if (f_number_min != null) { f_data = f_data.Where(p => (p.Number >= f_number_min)); } if (f_number_max != null) { f_data = f_data.Where(p => (p.Number <= f_number_max)); } } //Фильтруем по индексу if (f_index != null) { f_data = f_data.Where(p => p.Index == f_index); } //Фильтруем по дате if (f_date != "") { if (f_StartDate != null) { f_data = f_data.Where(p => (p.Date >= f_StartDate)); } if (f_EndDate != null) { f_data = f_data.Where(p => (p.Date <= f_EndDate)); } } switch (sortType) { case "Id": f_data = (sortReverse == false) ? f_data.OrderByDescending(p => p.Id) : f_data.OrderBy(p => p.Id); break; case "Country": f_data = (sortReverse == false) ? f_data.OrderByDescending(p => p.Country) : f_data.OrderBy(p => p.Country); break; case "City": f_data = (sortReverse == false) ? f_data.OrderByDescending(p => p.City) : f_data.OrderBy(p => p.City); break; case "Street": f_data = (sortReverse == false) ? f_data.OrderByDescending(p => p.Street) : f_data.OrderBy(p => p.Street); break; case "Num": f_data = (sortReverse == false) ? f_data.OrderByDescending(p => p.Number) : f_data.OrderBy(p => p.Number); break; case "Index": f_data = (sortReverse == false) ? f_data.OrderByDescending(p => p.Index) : f_data.OrderBy(p => p.Index); break; case "Date": f_data = (sortReverse == false) ? f_data.OrderByDescending(p => p.Date) : f_data.OrderBy(p => p.Date); break; default: f_data = (sortReverse == false) ? f_data.OrderByDescending(p => p.Id) : f_data.OrderBy(p => p.Id); break; } int count = f_data.Count(); if (page != null) { curPage = (int)page; } //возьмем 100 записей начиная с (100 * curPage) f_data = f_data.Skip(100 * curPage).Take(100); var prm = new { data = f_data, count = count }; return(Json(prm, JsonRequestBehavior.AllowGet)); // и наш объект address сериализован }