private void btnOpenMark_Click(object sender, RoutedEventArgs e)
        {
            MarkView markView = new MarkView();

            //this.Close();
            markView.ShowDialog();
        }
Ejemplo n.º 2
0
        private void btnAddMark_Click(object sender, RoutedEventArgs e)
        {
            //mark = (Mark)dataGridMark.SelectedItem;
            Mark objMark = new Mark();

            if (txtStudentName.Text != "" && txtStudentSurname.Text != "" && txtMarkEvaluation.Text != "" && txtSubjectName.Text != "")
            {
                // find StudentID from StudentName and StudentSurname
                string query1 = string.Format("select StudentID from tblStudent where StudentName='{0}' and SurName='{1}';", txtStudentName.Text, txtStudentSurname.Text);

                try
                {
                    sqlConn.Open();
                    SqlCommand    sqlComm = new SqlCommand(query1, sqlConn);
                    SqlDataReader sqlDR   = sqlComm.ExecuteReader();
                    if (sqlDR.Read())
                    {
                        objMark.StudentID = Convert.ToInt32(sqlDR["StudentID"]);
                    }
                    else
                    {
                        MessageBox.Show("This Student not exist! Please repeat operation!");
                    }
                    sqlDR.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    sqlConn.Close();
                }

                // Find SubjectID from Subject Name
                string query2 = string.Format("select SubjectID from tblSubject where SubjectName='{0}';", txtSubjectName.Text);

                try
                {
                    sqlConn.Open();
                    SqlCommand    sqlComm = new SqlCommand(query2, sqlConn);
                    SqlDataReader sqlDR   = sqlComm.ExecuteReader();
                    if (sqlDR.Read())
                    {
                        objMark.SubjectID = Convert.ToInt32(sqlDR["SubjectID"]);
                    }
                    else
                    {
                        MessageBox.Show("This Subject not exist! Please repeat operation!");
                    }
                    sqlDR.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
                finally
                {
                    sqlConn.Close();
                }

                // insert into tblMark values Mark, StudentID and SubjectID
                string query3 = string.Format("insert into tblMark values ({0},{1},{2})", txtMarkEvaluation.Text, objMark.StudentID, objMark.SubjectID);
                try
                {
                    sqlConn.Open();
                    SqlCommand comm = new SqlCommand(query3, sqlConn);
                    comm.ExecuteNonQuery();
                    MessageBox.Show("Mark evaluation for Student succesfully added!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());
                }
                finally
                {
                    sqlConn.Close();

                    MarkView markView = new MarkView();
                    this.Close();
                    markView.ShowDialog();
                }
            }
            else
            {
                MessageBox.Show("Please enter Mark evaluation, StudentName, StudentSurname and SubjectName before add data to database!");
            }
        }