Example #1
0
        public static List <WeekCA> GetSemesterCA()
        {
            // if the directory doesn't exist, create it


            // create the object for the input stream for a text file
            StreamReader textIn =
                new StreamReader(
                    new FileStream(path, FileMode.OpenOrCreate, FileAccess.Read));

            // create the array list for customers
            List <WeekCA>   WeekList = new List <WeekCA>();
            List <string[]> CAsList  = new List <string[]>();

            // read the data from the file and store it in the ArrayList
            while (textIn.Peek() != -1)
            {
                string   row     = textIn.ReadLine();
                string[] columns = row.Split('|');
                WeekCA   s       = new WeekCA();
                s.WeekNo = columns[0];
                s.Date   = columns[1];



                string          row2      = textIn.ReadLine();
                string[]        columns2  = row2.Split(':');
                List <string[]> m         = new List <string[]>();
                var             studentCA = new List <string>();



                foreach (var f in columns2)
                {
                    if (f != "")
                    {
                        studentCA.Add(f);
                    }
                }



                s.CA = studentCA;



                WeekList.Add(s);

                string spacing = textIn.ReadLine();
            }

            textIn.Close();

            return(WeekList);
        }
Example #2
0
        private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            listBox2.Items.Clear();//Clear both listboxes to populate with data from new selected week
            listBox1.Items.Clear();


            foreach (string b in CAList)
            {
                listBox1.Items.Add(b);     //Populate listbox1 with all CA's that we can then select to add into a week from, not really needed but very handy
            }


            string WeekNo = listBox3.SelectedItem.ToString();

            foreach (WeekCA a in WeekList)
            {
                if (a.WeekNo == WeekNo)
                {
                    txtName.Text = a.WeekNo;
                    txtDate.Text = a.Date;

                    foreach (string j in a.CA)
                    {
                        listBox2.Items.Add(j);
                        for (var i = listBox1.Items.Count - 1; i >= 0; i--)
                        {
                            var item = listBox1.Items[i];

                            if (listBox2.Items.Contains(item))
                            {
                                listBox1.Items.Remove(item);     //What we do here is basically check if an item in the object instances CA list exists in listbox1,
                                                                 //and if it does we remove it from listbox1. This makes it so we dont have multiple repeats of the same
                                                                 //CA on either listbox1 or listbox2
                            }
                        }
                    }

                    SelectedWeek = a; //and our choice becomes the new SelectedWeek

                    return;
                }
            }
        }
Example #3
0
        private void btnAddStudent_Click(object sender, EventArgs e)
        {
            //Creates new week, saves from user input and saves to file.
            WeekCA newWeek = new WeekCA();

            newWeek.WeekNo = txtName.Text;
            newWeek.Date   = txtDate.Text;
            List <string> CA = new List <string>();

            foreach (string a in listBox2.Items)
            {
                CA.Add(a);
            }

            newWeek.CA = CA;

            listBox3.Items.Add(newWeek.WeekNo);

            WeekList.Add(newWeek);

            MessageBox.Show("New Week and selected details have been added. Please click save to file to save the new entry");
        }
Example #4
0
        WeekCA SelectedWeek  = new WeekCA();                 //Tells the program which week we selected, so it can display the data in that week.

        public Form1()
        {
            SelectedWeek = WeekList[0]; //Not really needed, just default the first week as the selected when starting program
            InitializeComponent();


            listBox1.Items.Clear();                  //Clear listbox before populating, not needed but good practice
            foreach (WeekCA c in WeekList)           //Foreach week in the list
            {
                foreach (string e in c.CA)           //Foreach string in each weeks list of CA
                {
                    if (!listBox1.Items.Contains(e)) //Populating the menu
                    {
                        listBox1.Items.Add(e);
                        CAList.Add(e);
                    }
                }
            }
            foreach (var b in WeekList) //Populating the left hand side listbox
            {
                listBox3.Items.Add(b.WeekNo);
            }
        }