using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp8 { public partial class Form1 : Form { public List pool; public class Slacker { private int[] array; public Slacker(params int[] _input) { array = new int[5]; for (int i = 0; i < 5; i++) array[i] = Convert.ToInt32(_input[i]); } public int this[int index] { get { if (index < 0 || index > 4) throw new IndexOutOfRangeException(); // else return array[index]; } set { } } public override string ToString() { return array[0] + " " + array[1] + " " + array[2] + " " + array[3] + " " + array[4]; } } public Form1() { InitializeComponent(); pool = new List(); Random rng = new Random(); int[] slackerArray = new int[5]; for (int i = 0; i < 1000; i++) { for (int j = 0; j < 5; j++) { slackerArray[j] = rng.Next(100); } pool.Add(new Slacker(slackerArray)); } /* string inputSlacker; using (StreamReader inFile = new StreamReader("..//..//input.txt")) { MessageBox.Show("Can I read this file?"); for (int i = 0; i < 1000; i++) { inputSlacker = inFile.ReadLine(); if (inputSlacker == null) break; // else pool.Add(new Slacker(inputSlacker.Split())); } } */ /* Random rng = new Random(); using (StreamWriter outFile = new StreamWriter("..//..//input.txt")) { for (int i = 0; i < 1000; i++) { for (int j = 0; j < 5; j++) { outFile.Write(rng.Next(100) + " "); } outFile.WriteLine(); } } */ } private void Query1_Button_Click(object sender, EventArgs e) { if (!Query1_LessThan.Checked && !Query1_GreaterThan.Checked) { OutputText.Text = "Please select one of the relational Radio Buttons for this query."; return; } // else, let's get started OutputText.Text = ""; if (!Query1_Sorted.Checked) { var CombinedQuery = from N in pool where (N[0] < Query1_UpDown.Value && Query1_LessThan.Checked) || (N[0] > Query1_UpDown.Value && Query1_GreaterThan.Checked) select N; /* * Example of a "chained" query var ChainedQuery = from N in CombinedQuery where N[1] == 50 select N; */ foreach (Slacker i in CombinedQuery) { OutputText.AppendText(i + "\n"); } } else { var CombinedQuery = from N in pool where (N[0] < Query1_UpDown.Value && Query1_LessThan.Checked) || (N[0] > Query1_UpDown.Value && Query1_GreaterThan.Checked) orderby N[1] ascending select N; foreach (Slacker i in CombinedQuery) { OutputText.AppendText(i + "\n"); } } /* if (Query1_LessThan.Checked) { var LessThanQuery = from N in pool where N[0] < Query1_UpDown.Value select N; foreach (Slacker i in LessThanQuery) { OutputText.AppendText(i + "\n"); } } else { var GreaterThanQuery = from N in pool where N[0] > Query1_UpDown.Value select N; foreach (Slacker i in GreaterThanQuery) { OutputText.AppendText(i + "\n"); } } */ } private void Query2_Button_Click(object sender, EventArgs e) { // normally, I would check for any input values that need to be specified // There aren't any for this one, so we just query! OutputText.Text = ""; // clear out old results var WeirdQuery = from N in pool group N by N[3] / 10; foreach (var Groups in WeirdQuery) { /* List test = Groups as List; if (test == null) { MessageBox.Show("Try again, Daniel."); return; } OutputText.AppendText("Here is the " + test[0][3] / 10 + " group.\n"); */ OutputText.AppendText("---------------------------\n"); foreach (Slacker i in Groups) OutputText.AppendText(i.ToString() + "\n"); OutputText.AppendText("\n\n"); } } } }