Example #1
0
        public List<Student> GetAllStudents()
        {
            string query = "SELECT * FROM t_student";
            aSqlConnection.Open();
            aSqlCommand = new SqlCommand(query, aSqlConnection);
            List<Student> studentList = new List<Student>();
            SqlDataReader aSqlDataReader = aSqlCommand.ExecuteReader();

            if (aSqlDataReader != null)
            {
                while (aSqlDataReader.Read())
                {
                    Student student = new Student();
                    student.Name = aSqlDataReader["name"].ToString();
                    student.Email = aSqlDataReader["email"].ToString();
                    student.ContactNo = aSqlDataReader["contact_no"].ToString();
                    student.Date = (DateTime) aSqlDataReader["date"];
                    student.Address = aSqlDataReader["address"].ToString();
                    student.DeptId =(int) aSqlDataReader["dept_id"];
                    student.RegNo = aSqlDataReader["reg_no"].ToString();
                    studentList.Add(student);
                }
                aSqlDataReader.Close();
                aSqlConnection.Close();
            }
            return studentList;
        }
Example #2
0
 public bool Save(Student student)
 {
     if (IsEmailAlreadyExist(student.Email))
     {
         throw new Exception("Email Already Exist");
     }
     return studentGateway.Save(student) > 0;
 }
Example #3
0
 public int Save(Student student)
 {
     string query = "INSERT INTO t_student VALUES('" + student.Name + "', '" + student.Email + "', '" + student.ContactNo + "', '" + student.Date + "', '" + student.Address + "', '"  + student.DeptId + "','"+ student.RegNo +"')";
     aSqlConnection.Open();
     aSqlCommand = new SqlCommand(query, aSqlConnection);
     int rowAffected = aSqlCommand.ExecuteNonQuery();
     aSqlConnection.Close();
     return rowAffected;
 }
        private void saveButton_Click(object sender, EventArgs e)
        {
            string name = nameTextBox.Text;
            string email = emailTextBox.Text;
            string contactNo = contactNoTextBox.Text;
            DateTime date = dateTimePicker.Value;
            string address = addressTextBox.Text;
            int deptId = (int) deptComboBox.SelectedValue;
            string regNo = deptComboBox.Text + "-" + date.Year + "-" +
            studentManager.CounterStudentByYearAndDept(date.Year, deptId);

            Student student = new Student(name, email, contactNo, date, address, deptId,regNo);
            try
            {
                string pattern = null;
                pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$";

                if (Regex.IsMatch(email, pattern))
                {
                    if (studentManager.Save(student))
                    {

                        MessageBox.Show("Successfully Registered");
                    }
                    else
                    {
                        MessageBox.Show("Registation Failed");
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Email Format");
                }
            }
            catch (Exception exception)
            {

                MessageBox.Show(exception.Message);
            }
        }