public Student GetStudent(string regNo)
        {
            try
            {
                SqlConnectionObj.Open();
                string query = string.Format("select * from tbl_Student where RegNo={0}", regNo);
                SqlCommandObj.CommandText = query;
                SqlDataReader reader = SqlCommandObj.ExecuteReader();
                Student aStudent=new Student();
                while (reader.Read())
                {
                    aStudent.Name = reader[1].ToString();
                    aStudent.RegNo = reader[3].ToString();
                    aStudent.Email = reader[2].ToString();
                    aStudent.ContactNo = Convert.ToInt32(reader[4]);
                }
                return aStudent;
            }
            catch (Exception exception)
            {

                throw new Exception("Error occurred during student management system.", exception);
            }
            finally
            {
                SqlConnectionObj.Close();
            }
        }
        public string GetBook(List<Book> books, DateTime toShortDateString, Student aStudent)
        {
            SqlConnectionObj.Open();
            foreach (Book book in books)
            {
                string query = string.Format("Insert into tbl_Issueed(Book_id,Lend_copy,Issue_date,student_Reg) values({0},{1},'{2}', '{3}')", book.Id, book.OutsideCopy, toShortDateString, aStudent.RegNo);
                SqlCommandObj.CommandText = query;
                SqlCommandObj.ExecuteNonQuery();
            }

            return "Book Lend Successfully";
        }
 public string Save(Student aStudent)
 {
     if (studentGateway.HasEmail(aStudent.Email))
     {
         throw new Exception("Email address already used.");
     }
     else if (studentGateway.HasRegNo(aStudent.RegNo))
     {
         throw new Exception("Reg no already used.");
     }
     else
     {
         return studentGateway.Save(aStudent);
     }
 }
 private void saveButton_Click(object sender, EventArgs e)
 {
     Student aStudent=new Student();
     aStudent.Id = id;
     aStudent.Name = nameTextBox.Text;
     aStudent.Email = emailTextBox.Text;
     aStudent.RegNo = regNoTextBox.Text;
     aStudent.ContactNo = Convert.ToInt32(contactNoTextBox.Text);
     if (nameTextBox.Text==string.Empty)
     {
         MessageBox.Show("Please entre name.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     else if (emailTextBox.Text==string.Empty)
     {
         MessageBox.Show("Please entre email address.", "Information", MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
     }
     else if (regNoTextBox.Text==string.Empty)
     {
         MessageBox.Show("Please entre registration No.", "Information", MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
     }
     else if(contactNoTextBox.Text==string.Empty)
     {
         MessageBox.Show("Please entre contact No.", "Information", MessageBoxButtons.OK,
                         MessageBoxIcon.Information);
     }
     else
     {
         string message = null;
         try
         {
             message = studentManager.Save(aStudent);
             MessageBox.Show(message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         catch (Exception exception)
         {
             MessageBox.Show(exception.Message,"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
     ClearAll();
 }
 public string GetBook(List<Book> books, DateTime toShortDateString, Student aStudent)
 {
     return issueGateway.GetBook(books,toShortDateString,aStudent);
 }
 public string Save(Student aStudent)
 {
     try
     {
         SqlConnectionObj.Open();
         string query = string.Format("insert into tbl_Student values('{0}','{1}','{2}','{3}')",
                                      aStudent.Name, aStudent.Email, aStudent.RegNo,
                                      aStudent.ContactNo);
         SqlCommandObj.CommandText = query;
         SqlCommandObj.ExecuteNonQuery();
     }
     catch (Exception exception)
     {
         throw new Exception("Student does not load this student.",exception);
     }
     finally
     {
         SqlConnectionObj.Close();
     }
     return aStudent.Name+" hase been saved.";
 }
 public Student SearchStudent(string studentId)
 {
     Student aStudent=new Student();
     try
     {
         SqlConnectionObj.Open();
         string query = string.Format("select * from tbl_Student where regNo='{0}'", studentId);
         SqlCommandObj.CommandText = query;
         SqlDataReader reader = SqlCommandObj.ExecuteReader();
         while (reader.Read())
         {
             aStudent.Id = Convert.ToInt32(reader["Id"]);
             aStudent.Name = reader["Name"].ToString();
             aStudent.Email = reader["Email"].ToString();
             aStudent.RegNo = reader["RegNo"].ToString();
             aStudent.ContactNo = Convert.ToInt32(reader["ContactNo"]);
         }
     }
     catch (Exception exception)
     {
         throw new Exception("System doesnot load this student reg no.",exception);
     }
     finally
     {
         SqlConnectionObj.Close();
     }
     return aStudent;
 }
 private void studentSearchButton_Click(object sender, EventArgs e)
 {
     studentId = (regNoTextBox.Text);
     if (regNoTextBox.Text!="")
     {
         try
         {
             Student aStudent=new Student();
             aStudent=studentManager.SearchStudent(studentId);
             nameTextBox.Text = aStudent.Name;
             emailTextBox.Text = aStudent.Email;
             contactNoTextBox.Text = aStudent.ContactNo.ToString();
             if (nameTextBox.Text!="")
             {
                 saveButton.Enabled = true;
             }
         }
         catch (Exception exception)
         {
             MessageBox.Show(exception.Message, @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
        private void saveButton_Click(object sender, EventArgs e)
        {
            Student aStudent=new Student();
            string regNo = regNoTextBox.Text;
            aStudent = studentManager.SearchStudent(regNo);
            string message = "";
            if (aStudent!=null)
            {
                foreach (Book aBook in books)
                {
                    bookManager.UpdateBook(aBook.Id,aBook.OutsideCopy,1);
                }
                string dateTime = dtpIssueDate.Text;
                message = issueManager.GetBook(books, DateTime.ParseExact(dateTime, "dd-MM-yyyy hh:mm:ss",CultureInfo.InvariantCulture), aStudent);
                ClearAll();

                MessageBox.Show(message);
            }
        }