Exemplo n.º 1
0
        private void btnYes_Click(object sender, EventArgs e)
        {
            using (SqlConnection conn = new SqlConnection(@"Data Source=DESKTOP-I1C7SOR;Initial Catalog=mathClassroomDB;Integrated Security=True"))
            {
                int    subjectPosition = 0;
                string query           = @"INSERT INTO Homework (Student, Subject, NoOfQuestions, Score, Completed, DueDate, DateSubmitted) VALUES (@Student, @Subject, @NoOfQuestions, @Score, @Completed, @DueDate, @DateSubmitted)";

                foreach (var sub in _subjects)
                {
                    conn.Open();

                    SqlCommand command = new SqlCommand(query, conn);

                    command.Parameters.AddWithValue("@Student", _studentName);
                    command.Parameters.AddWithValue("@Subject", sub);
                    command.Parameters.AddWithValue("@NoOfQuestions", _noOfQuestions[subjectPosition]);
                    command.Parameters.AddWithValue("@Score", 0);
                    command.Parameters.AddWithValue("@Completed", false);
                    command.Parameters.AddWithValue("@DueDate", _dueDate);
                    command.Parameters.AddWithValue("@DateSubmitted", "");

                    command.ExecuteNonQuery();

                    subjectPosition++;

                    conn.Close();
                }

                MessageBox.Show("Homework for " + _studentName + " have been saved.", "Homework Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);

                Hide();
                addStudentHomepage addStudent = new addStudentHomepage();
                addStudent.Show();
            }
        }
        private void addStudentBtn_Click(object sender, EventArgs e)
        {
            this.Hide();
            addStudentHomepage ash = new addStudentHomepage();

            ash.ShowDialog();
        }
Exemplo n.º 3
0
        private void loginBtn_Click(object sender, EventArgs e)
        {
            SqlConnection  conn = new SqlConnection(@"Data Source=DESKTOP-I1C7SOR;Initial Catalog=mathClassroomDB;Integrated Security=True");
            SqlDataAdapter sda  = new SqlDataAdapter("select count(*) from TeacherLogins where Username = '******' and Password = '******'", conn);
            DataTable      dt   = new DataTable();

            sda.Fill(dt);
            if (dt.Rows[0][0].ToString() == "1")
            {
                Hide();
                addStudentHomepage addStudent = new addStudentHomepage();
                addStudent.Show();
            }
            else
            {
                MessageBox.Show("please enter correct username and password");
            }
        }