示例#1
0
        private void UserAuthenticationCheck()
        {
            StudentDBEntities1 db = new StudentDBEntities1();

            try
            {
                var userName = txtBoxUsername.Text;
                var password = txtBoxPassword.Text;
                var users    = db.StudentEnrolmentUsers;
                var userRole = "";
                foreach (var item in users)
                {
                    if (item.Username == userName)
                    {
                        userRole = item.UserRole;
                    }
                }

                var user = db.StudentEnrolmentUsers.Any(u => u.Username == userName && u.Password == password);
                if (user)
                {
                    HomeForm homeForm = new HomeForm(userRole);
                    homeForm.Show();
                }
                else
                {
                    MessageBox.Show("Please enter correct credentials");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void btnAddUser_Click(object sender, EventArgs e)
        {
            StudentDBEntities1 db = new StudentDBEntities1();

            StudentEnrolmentUser user = new StudentEnrolmentUser();

            try
            {
                user.Name     = txtBoxNameOfUser.Text;
                user.Username = txtBoxUsernameUserRegistration.Text;
                if (txtBoxPasswordUserRegistration.Text == txtBoxConfirmPassword.Text)
                {
                    user.Password = txtBoxPasswordUserRegistration.Text;
                }
                else
                {
                    throw new InvalidOperationException();
                }
                user.UserRole = comboBoxUserRole.SelectedItem.ToString();

                db.StudentEnrolmentUsers.Add(user);
                db.SaveChanges();
                MessageBox.Show("User Added successfully");
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show("Confirm Password dose not match");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#3
0
        private void btnAddStudent_Click(object sender, EventArgs e)
        {
            StudentDBEntities1 db      = new StudentDBEntities1();
            Student            student = new Student();

            try
            {
                student.Student_Name = txtBoxFirstName.Text + " " + txtBoxMiddleName.Text + " " + txtBoxLastName.Text;
                var isMaleChecked   = radioButtonMale.Checked;
                var isFemaleChecked = radioButtonFemale.Checked;
                if (isMaleChecked)
                {
                    student.Student_Gender = radioButtonMale.Text;
                }
                if (isFemaleChecked)
                {
                    student.Student_Gender = radioButtonFemale.Text;
                }
                if (!isMaleChecked && !isFemaleChecked)
                {
                    throw new InvalidOperationException();
                }

                student.Student_DOB = dateTimePickerDOB.Value;
                if (!string.IsNullOrEmpty(txtBoxAge.Text))
                {
                    student.Student_Age = Convert.ToInt32(txtBoxAge.Text);
                }
                student.Student_Course  = comboBoxCourses.SelectedValue.ToString();
                student.Student_EmailID = txtBoxEmailID.Text;

                db.Students.Add(student);
                db.SaveChanges();
                MessageBox.Show("Student Added successfully");
            }
            catch (InvalidOperationException ex)
            {
                MessageBox.Show("Please select Gender");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#4
0
 private void saveCourseDataGrid_Click(object sender, EventArgs e)
 {
     try
     {
         StudentDBEntities1 db = new StudentDBEntities1();
         int id           = Convert.ToInt32(dataGridViewCourseRecord.CurrentRow.Cells[0].Value);
         var courseRecord = db.Courses.First(x => x.Course_ID == id);
         courseRecord.Course_Name     = dataGridViewCourseRecord.CurrentRow.Cells[1].Value.ToString();
         courseRecord.Course_Duration = dataGridViewCourseRecord.CurrentRow.Cells[2].Value.ToString();
         courseRecord.Course_Fees     = Convert.ToDecimal(dataGridViewCourseRecord.CurrentRow.Cells[3].Value.ToString());
         db.SaveChanges();
         MessageBox.Show("Course Updated Successfully");
         saveCourseDataGrid.Enabled = false;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void saveUserDataGrid_Click(object sender, EventArgs e)
 {
     try
     {
         StudentDBEntities1 db = new StudentDBEntities1();
         int id         = Convert.ToInt32(dataGridViewUserRecord.CurrentRow.Cells[0].Value);
         var userRecord = db.StudentEnrolmentUsers.First(x => x.userId == id);
         userRecord.Name     = dataGridViewUserRecord.CurrentRow.Cells[1].Value.ToString();
         userRecord.Username = dataGridViewUserRecord.CurrentRow.Cells[2].Value.ToString();
         userRecord.Password = dataGridViewUserRecord.CurrentRow.Cells[3].Value.ToString();
         userRecord.UserRole = dataGridViewUserRecord.CurrentRow.Cells[4].Value.ToString();
         db.SaveChanges();
         MessageBox.Show("User Updated Successfully");
         saveUserDataGrid.Enabled = false;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void deleteUserDataGrid_Click(object sender, EventArgs e)
 {
     try
     {
         var confirmDelete = MessageBox.Show("Do you want to delete this User", "Confirm Dialog", MessageBoxButtons.YesNo);
         if (confirmDelete.ToString() == "Yes")
         {
             StudentDBEntities1 db = new StudentDBEntities1();
             int id         = Convert.ToInt32(dataGridViewUserRecord.CurrentRow.Cells[0].Value);
             var userRecord = db.StudentEnrolmentUsers.First(x => x.userId == id);
             db.StudentEnrolmentUsers.Remove(userRecord);
             db.SaveChanges();
             dataGridViewUserRecord.Rows.Remove(dataGridViewUserRecord.CurrentRow);
             MessageBox.Show("User Deleted Successfully");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#7
0
        private void btnAddCourse_Click(object sender, EventArgs e)
        {
            StudentDBEntities1 db = new StudentDBEntities1();

            Course course = new Course();

            try
            {
                course.Course_Name     = txtBoxCourseName.Text;
                course.Course_Duration = txtBoxCourseDuration.Text;
                course.Course_Fees     = Convert.ToInt32(txtBoxCourseFees.Text);

                db.Courses.Add(course);
                db.SaveChanges();
                MessageBox.Show("Course Added successfully");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void deleteBtnStudentDataGrid_Click(object sender, EventArgs e)
        {
            try
            {
                StudentDBEntities1 db = new StudentDBEntities1();
                int id            = Convert.ToInt32(dataGridViewStudentRecord.CurrentRow.Cells[0].Value.ToString());
                var studentRecord = db.Students.First(x => x.Student_Id == id);

                var okCancelBtn     = MessageBoxButtons.OKCancel;
                var ConfirmDeletion = MessageBox.Show("Do you want delete this student", "Confirmation Dialog", okCancelBtn);
                if (ConfirmDeletion.ToString() == "OK")
                {
                    db.Students.Remove(studentRecord);
                    db.SaveChanges();
                    dataGridViewStudentRecord.Rows.Remove(dataGridViewStudentRecord.CurrentRow);
                    MessageBox.Show("Student Deleted Successfully");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void saveBtnStudentDataGrid_Click(object sender, EventArgs e)
        {
            try
            {
                StudentDBEntities1 db = new StudentDBEntities1();
                int id            = Convert.ToInt32(dataGridViewStudentRecord.CurrentRow.Cells[0].Value.ToString());
                var studentRecord = db.Students.First(x => x.Student_Id == id);

                studentRecord.Student_Name    = dataGridViewStudentRecord.CurrentRow.Cells[1].Value.ToString();
                studentRecord.Student_Gender  = dataGridViewStudentRecord.CurrentRow.Cells[2].Value.ToString();
                studentRecord.Student_Age     = Convert.ToInt32(dataGridViewStudentRecord.CurrentRow.Cells[3].Value.ToString());
                studentRecord.Student_DOB     = Convert.ToDateTime(dataGridViewStudentRecord.CurrentRow.Cells[4].Value.ToString());
                studentRecord.Student_Course  = dataGridViewStudentRecord.CurrentRow.Cells[5].Value.ToString();
                studentRecord.Student_EmailID = dataGridViewStudentRecord.CurrentRow.Cells[6].Value.ToString();
                db.SaveChanges();
                MessageBox.Show("Student Updated Successfully");
                saveBtnStudentDataGrid.Enabled = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }