コード例 #1
0
ファイル: Authorization.cs プロジェクト: NastSub/CourseWork-
 private void loginButton_Click(object sender, EventArgs e)
 {
     if (loginTextBox.Text.Length != 0 && passwordTextBox.Text.Length != 0 && loginTextBox.Text.Equals("admin") && passwordTextBox.Text.Equals("admin"))
     {
         Home_page form2 = new Home_page();
         form2.Show();
     }
 }
コード例 #2
0
        private void submitDeleteButton_Click(object sender, EventArgs e)
        {
            bool isGoodIDBook = int.TryParse(Delete.Text.Trim(), out IDBookToDelete);
            var  list         = GetStudents().Cast <Student>().ToList();
            bool isInList     = false;

            foreach (Student s in list.ToArray())
            {
                if (s.GradeBookID.Equals(IDBookToDelete))
                {
                    list.Remove(s);
                    isInList = true;
                }
            }

            if (!isGoodIDBook)
            {
                MessageBox.Show("Пожалуйста, введите Id!");
            }
            else
            {
                if (isInList == false)
                {
                    MessageBox.Show("Пожалуйста, введите Id из списка!");
                }
            }

            File.Delete(@"res\students.xml");

            using (FileStream fstr = new FileStream(@"res\students.xml", FileMode.OpenOrCreate))
            {
                formatter.Serialize(fstr, list.ToArray());
            }

            Home_page main = this.Owner as Home_page;

            main.studentsTable.DataSource = list;
            foreach (var ctrl in this.Controls)
            {
                if (ctrl is TextBox)
                {
                    (ctrl as TextBox).Clear();
                }
            }
            //if (isInList)
            //{
            //    Close();
            //}
        }
コード例 #3
0
ファイル: Search.cs プロジェクト: NastSub/CourseWork-
        private void searchButton_Click(object sender, EventArgs e)
        {
            //----
            //search = Convert.ToInt32(Search_TextBox.Text.Trim());
            bool           isGoodSearch   = int.TryParse(Search_TextBox.Text.Trim(), out search);
            var            studentList    = form.GetStudents();
            bool           isInList       = false;
            List <Student> newStudentList = new List <Student>();


            if (!isGoodSearch)
            {
                MessageBox.Show("Введите данные для поиска студента");
            }
            else
            {
                foreach (Student p in studentList.ToArray())
                {
                    if (search.Equals(p.GradeBookID))
                    {
                        newStudentList.Add(p);
                        isInList = true;
                    }
                }

                if (!isInList)
                {
                    MessageBox.Show("Такого студента нет в списке");
                }
                else
                {
                    Home_page main = this.Owner as Home_page;
                    main.studentsTable.DataSource = newStudentList;
                    foreach (var ctrl in this.Controls)
                    {
                        if (ctrl is TextBox)
                        {
                            (ctrl as TextBox).Clear();
                        }
                    }
                }
            }
        }
コード例 #4
0
        private void submitAddButton_Click(object sender, EventArgs e)
        {
            surnameToAdd = surnameToAddTextBox.Text.Trim();
            nameToAdd    = nameToAddTextBox.Text.Trim();
            groupToAdd   = groupToAddTextBox.Text.Trim();
            bool isGoodCourse = int.TryParse(courseToAddTextBox.Text.Trim(), out courseToAdd);
            bool isGoodBookId = int.TryParse(gradeBookIDToAddTextBox.Text.Trim(), out gradeBookIDToAdd);
            bool isGoodRating = int.TryParse(ratingToAddTextBox.Text.Trim(), out ratingToAdd);

            notesToAdd = notesToAddTextBox.Text;

            var  list        = GetStudents().Cast <Student>().ToList();
            bool canContinue = false;

            foreach (Student s in list.ToArray())
            {
                if (gradeBookIDToAdd.Equals(s.GradeBookID))
                {
                    MessageBox.Show("Пожалуйста, введите другой номер зачетки!");
                }
            }
            if (surnameToAddTextBox.Text.Length == 0)
            {
                MessageBox.Show("Фамилия не может быть пустой");
            }
            else if (nameToAddTextBox.Text.Length == 0)
            {
                MessageBox.Show("Имя не может быть пустым");
            }
            else if (groupToAddTextBox.Text.Length == 0)
            {
                MessageBox.Show("Группа не может быть пустой");
            }
            if (courseToAddTextBox.Text.Length == 0 || !isGoodCourse)
            {
                MessageBox.Show("Курс не может быть пустым");
            }
            else if (gradeBookIDToAddTextBox.Text.Length == 0 || !isGoodBookId)
            {
                MessageBox.Show("Номер зачетки не может быть пустым");
            }
            else if (ratingToAddTextBox.Text.Length == 0 || !isGoodRating)
            {
                MessageBox.Show("Рейтинг не может быть пустым");
            }
            else if (courseToAdd < 1 || courseToAdd > 4)
            {
                MessageBox.Show("Пожалуйста, введите правильный курс(от 1 до 4)!");
            }
            else if (gradeBookIDToAdd < 1 || gradeBookIDToAdd > 100)
            {
                MessageBox.Show("Пожалуйста, введите правильный номер зачетки(от 1 до 100)!");
            }
            else if (ratingToAdd < 1 || ratingToAdd > 100)
            {
                MessageBox.Show("Пожалуйста, введите правильный рейтинг(от 1 до 100)!");
            }
            else
            {
                canContinue = true;
            }

            if (canContinue)
            {
                Student student = new Student();
                student.Surname     = surnameToAdd;
                student.Name        = nameToAdd;
                student.Group       = groupToAdd;
                student.Course      = courseToAdd;
                student.GradeBookID = gradeBookIDToAdd;
                student.Rating      = ratingToAdd;
                student.Notes       = notesToAdd;
                list.Add(student);
                File.Delete(@"res\students.xml");

                using (FileStream fstr = new FileStream(@"res\students.xml", FileMode.OpenOrCreate))
                {
                    formatter.Serialize(fstr, list.ToArray());
                }

                Home_page main = this.Owner as Home_page;
                main.studentsTable.DataSource = list;
            }
            else
            {
                MessageBox.Show("Произошла ошибка!");
            }
            foreach (var ctrl in this.Controls)
            {
                if (ctrl is TextBox)
                {
                    (ctrl as TextBox).Clear();
                }
            }
        }