Ejemplo n.º 1
0
 private void button2_Click_2(object sender, EventArgs e)
 {
     CourseNameInput.Clear();
     CourseNumberInput.Clear();
     FacultyInput.Clear();
     HoursInput.Clear();
     TeacherNameInput.Clear();
     StudentNameInput.Clear();
 }
Ejemplo n.º 2
0
 private void StudentNameInput_KeyPress(object sender, KeyPressEventArgs e)
 {
     if ((((e.KeyChar < 'A') || (e.KeyChar > 'z')) && !(e.KeyChar == ' ') && !(e.KeyChar == '.') && !(Char.IsControl(e.KeyChar))) || (textBox1.Text.Length > 35))
     {
         e.Handled = true;
     }
     if (e.KeyChar == (char)Keys.Enter)
     {
         StudentNameInput.Focus();
     }
 }
Ejemplo n.º 3
0
 private void button2_Click_1(object sender, EventArgs e)
 {
     if (CheckData(CourseNameInput.Text, CourseNumberInput.Text, FacultyInput.Text, HoursInput.Text, TeacherNameInput.Text, StudentNameInput.Text) == false)
     {
         return;
     }
     try
     {
         if (String.IsNullOrWhiteSpace(TeacherNameInput.Text))
         {
             TeacherNameInput.Text = null;
         }
         SqlCommand addcom = new SqlCommand("INSERT INTO [Table] ([Навзание курса],[Шифр курса],[Факультет],[Количество часов], [ФИО преподователя], [ФИО студента])VALUES(@Course,@Number,@Faculty,@Hours,@Teacher,@Student)", SqlCon);
         addcom.Parameters.AddWithValue("Course", CourseNameInput.Text);
         addcom.Parameters.AddWithValue("Number", Convert.ToInt32(CourseNumberInput.Text));
         addcom.Parameters.AddWithValue("Faculty", FacultyInput.Text);
         addcom.Parameters.AddWithValue("Hours", HoursInput.Text);
         addcom.Parameters.AddWithValue("Teacher", TeacherNameInput.Text);
         addcom.Parameters.AddWithValue("Student", StudentNameInput.Text);
         addcom.ExecuteNonQuery();
         CourseNameInput.Clear();
         CourseNumberInput.Clear();
         FacultyInput.Clear();
         HoursInput.Clear();
         TeacherNameInput.Clear();
         StudentNameInput.Clear();
         SearchBox.Clear();
         SqlCommand command = new SqlCommand();
         command = new SqlCommand("SELECT * FROM [Table]", SqlCon);
         BuildDB(command);
         MessageBox.Show($"Успешное добавление в БД", "Успех!",
                         MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     catch (System.Data.SqlClient.SqlException)
     {
         DialogResult result = MessageBox.Show($"Предмет с таким шифром уже существует. Желаете обновить его в БД?", "Непорядок",
                                               MessageBoxButtons.YesNo, MessageBoxIcon.Information);
         if (result == DialogResult.Yes)
         {
             if (CheckData(CourseNameInput.Text, CourseNumberInput.Text, FacultyInput.Text, HoursInput.Text, TeacherNameInput.Text, StudentNameInput.Text) == false)
             {
                 return;
             }
             try
             {
                 if (String.IsNullOrWhiteSpace(TeacherNameInput.Text))
                 {
                     TeacherNameInput.Text = null;
                 }
                 SqlCommand addcom = new SqlCommand("UPDATE [Table] SET [Навзание курса] = @Course,[Шифр курса] = @Number,[Факультет] = @Faculty,[Количество часов] = @Hours, [ФИО преподователя] = @Teacher, [ФИО студента] = @Student WHERE [Шифр курса] = " + CourseNumberInput.Text, SqlCon);
                 addcom.Parameters.AddWithValue("Course", CourseNameInput.Text);
                 addcom.Parameters.AddWithValue("Number", Convert.ToInt32(CourseNumberInput.Text));
                 addcom.Parameters.AddWithValue("Faculty", FacultyInput.Text);
                 addcom.Parameters.AddWithValue("Hours", HoursInput.Text);
                 addcom.Parameters.AddWithValue("Teacher", TeacherNameInput.Text);
                 addcom.Parameters.AddWithValue("Student", StudentNameInput.Text);
                 addcom.ExecuteNonQuery();
                 CourseNameInput.Clear();
                 CourseNumberInput.Clear();
                 FacultyInput.Clear();
                 HoursInput.Clear();
                 TeacherNameInput.Clear();
                 StudentNameInput.Clear();
                 SqlCommand command = new SqlCommand();
                 command = new SqlCommand("SELECT * FROM [Table]", SqlCon);
                 BuildDB(command);
                 SearchBox.Clear();
                 MessageBox.Show($"Успешное обновление БД", "Успех!",
                                 MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message.ToString());
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message.ToString());
     }
 }