private void btnOpenStudent_Click(object sender, RoutedEventArgs e)
        {
            StudentView studentView = new StudentView();

            //this.Close();
            studentView.ShowDialog();
        }
示例#2
0
        private void btnUpdate_Click(object sender, RoutedEventArgs e)
        {
            student = (Student)dataGridStudent.SelectedItem;

            try
            {
                sqlConn.Open();

                string     query = string.Format("update tblStudent set StudentName='{0}', SurName='{1}' where StudentID='{2}';", txtName.Text, txtSurname.Text, student.StudentID);
                SqlCommand comm  = new SqlCommand(query, sqlConn);
                if (student.StudentID != 0)
                {
                    comm.ExecuteNonQuery();
                    MessageBox.Show("Student succesfully updated!");
                }
                else
                {
                    MessageBox.Show("Please select Student for updating!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            finally
            {
                sqlConn.Close();

                StudentView studentView = new StudentView();
                this.Close();
                studentView.ShowDialog();
            }
        }
示例#3
0
        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (txtName.Text != "" && txtSurname.Text != "")
            {
                string query1 = string.Format("select * from tblStudent where StudentName='{0}' and SurName='{1}';", txtName.Text, txtSurname.Text);

                sqlConn.Open();

                SqlCommand    comm1     = new SqlCommand(query1, sqlConn);
                SqlDataReader sqlReader = comm1.ExecuteReader();

                if (!sqlReader.HasRows)
                {
                    string query = string.Format("insert into tblStudent values ('{0}','{1}')", txtName.Text, txtSurname.Text);
                    try
                    {
                        sqlReader.Close();
                        SqlCommand comm = new SqlCommand(query, sqlConn);
                        comm.ExecuteNonQuery();
                        MessageBox.Show("Student succesfully added!");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message.ToString());
                    }
                    finally
                    {
                        sqlConn.Close();

                        StudentView studentView = new StudentView();
                        this.Close();
                        studentView.ShowDialog();
                    }
                }
                else
                {
                    MessageBox.Show("Particular Student already exist!");
                    sqlReader.Close();
                    sqlConn.Close();
                    txtName.Text    = "";
                    txtSurname.Text = "";
                }
            }
            else
            {
                MessageBox.Show("Please write name and surname of Student before add to database!");
            }
        }
示例#4
0
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            student = (Student)dataGridStudent.SelectedItem;

            try
            {
                if (student != null)
                {
                    sqlConn.Open();

                    string     query = string.Format("delete from tblStudent where StudentID='{0}';", student.StudentID);
                    SqlCommand comm  = new SqlCommand(query, sqlConn);
                    if (student.StudentID != 0)
                    {
                        comm.ExecuteNonQuery();
                        MessageBox.Show("Student deleted succesfully!");
                    }
                    else
                    {
                        MessageBox.Show("Please select Student for deleting!");
                    }
                }
                else
                {
                    MessageBox.Show("Please select Student for delete!");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToString());
            }
            finally
            {
                sqlConn.Close();

                StudentView studentView = new StudentView();
                this.Close();
                studentView.ShowDialog();
            }
        }