private void addButton_Click(object sender, EventArgs e)
        {
            try
            {
                string        group           = groupsBox.Text;
                List <string> checkedSubjects = new List <string>();

                if (group == "")
                {
                    throw new Exception("Jūs turite pasirinkti kažkurią grupę prieš priskirdami dėstomus dalykus");
                }

                if (subjectsListBox.CheckedItems.Count == 0)
                {
                    throw new Exception("Jūs nepasirinkote dėstomų dalykų");
                }

                foreach (string item in subjectsListBox.CheckedItems)
                {
                    checkedSubjects.Add(item);
                }

                foreach (String item in checkedSubjects)
                {
                    subjectsListBox.Items.Remove(item);
                    string title = item;
                    otherData.AssignSubjectsToGroup(otherData.FindGroupsId(group), otherData.FindSubjectsId(title));
                }
                MessageBox.Show("Sėkmingai priskyrėte dėstomus dalykus prie grupės");
                foreach (int checkedItemIndex in subjectsListBox.CheckedIndices)
                {
                    subjectsListBox.SetItemChecked(checkedItemIndex, false);
                }
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }
        }
Beispiel #2
0
        private void addButton_Click(object sender, EventArgs e)
        {
            try
            {
                string        group           = groupsBox.Text;
                List <string> checkedStudents = new List <string>();

                if (group == "")
                {
                    throw new Exception("Jūs turite pasirinkti kažkurią grupę prieš priskirdami studentus");
                }

                if (groupsListBox.CheckedItems.Count == 0)
                {
                    throw new Exception("Jūs nepasirinkote studentų");
                }

                foreach (string item in groupsListBox.CheckedItems)
                {
                    checkedStudents.Add(item);
                }

                foreach (String item in checkedStudents)
                {
                    groupsListBox.Items.Remove(item);
                    string name    = item.Substring(0, item.IndexOf(' '));
                    string surname = item.Substring(item.IndexOf(' ') + 1);
                    usersData.AssignStudentsToGroup(otherData.FindGroupsId(group), usersData.FindStudentsId(name, surname));
                }
                MessageBox.Show("Sėkmingai priskyrėte studentus prie grupės");
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }
        }