Exemplo n.º 1
0
        public int CreateTutoringTime(TutoringTime tt)
        {
            try
            {
                comm             = new SqlCommand();
                comm.CommandText = "INSERT INTO TutoringTime(date, teacherId, time) VALUES(@date, @teacherId, @time)";
                comm.Parameters.AddWithValue("date", tt.Date);
                comm.Parameters.AddWithValue("teacherId", tt.Teacher.Id);
                comm.Parameters.AddWithValue("time", tt.Time);

                dbCon           = new DbConnection();
                comm.Connection = dbCon.GetConnection();
                comm.Connection.Open();

                comm.CommandType = CommandType.Text;
                result           = comm.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }

            finally
            {
                comm.Connection.Close();
            }
            return(result);
        }
Exemplo n.º 2
0
        public int RegisterBooking(int childId, int tutoringTimeId)
        {
            TutoringTime tt = new TutoringTime();

            tt.Id    = tutoringTimeId;
            tt.Child = new Child(childId);

            TutoringTimeDb ttDb = new TutoringTimeDb();

            return(ttDb.RegisterBooking(tt));
        }
Exemplo n.º 3
0
        public int CreateTutoringTime(DateTime date, int teacherId, string time)
        {
            TutoringTime tt = new TutoringTime();

            tt.Date    = date;
            tt.Teacher = new Teacher(teacherId);
            tt.Time    = time;

            TutoringTimeDb ttDb = new TutoringTimeDb();

            return(ttDb.CreateTutoringTime(tt));
        }
 //This method is used to check if the list of teachers for combo box
 //allready contains the given teacher
 public bool CheckIfTeacherExistsInList(TutoringTime tt)
 {
     bool teacherExistsInList = false;
     foreach (Teacher t in allTutoringTeachers)
     {
         if (t.Id == tt.Teacher.Id)
         {
             teacherExistsInList = true;
         }
     }
     return teacherExistsInList;
 }
Exemplo n.º 5
0
        //This method is used to check if the list of teachers for combo box
        //allready contains the given teacher
        public bool CheckIfTeacherExistsInList(TutoringTime tt)
        {
            bool teacherExistsInList = false;

            foreach (Teacher t in allTutoringTeachers)
            {
                if (t.Id == tt.Teacher.Id)
                {
                    teacherExistsInList = true;
                }
            }
            return(teacherExistsInList);
        }
Exemplo n.º 6
0
        private void CreateTutoringTime()
        {
            DateTime date      = calendar.SelectionRange.Start;
            string   time      = cbScTime.Text;
            int      teacherId = teacher.Id;

            if (date < DateTime.Today)
            {
                MessageBox.Show("Not possible to set available date and time");
            }
            else
            {
                if (string.IsNullOrEmpty(time))
                {
                    MessageBox.Show("Please select the time");
                }


                else
                {
                    Service1Client winService = new Service1Client();

                    tt = winService.GetTtTimesByTime(date, time, teacherId);

                    if (tt != null)
                    {
                        if (tt.Date == date)
                        {
                            if (String.Equals(tt.Time, time))
                            {
                                MessageBox.Show("Selected time is already in use");
                            }
                            else
                            {
                                winService.CreateTutoringTime(date, teacherId, time);
                                MessageBox.Show("Tutor time succesfully inserted");
                            }
                        }
                    }

                    else
                    {
                        winService.CreateTutoringTime(date, teacherId, time);
                        MessageBox.Show("Tutor time succesfully inserted");
                    }
                }
            }
        }
Exemplo n.º 7
0
        public TutoringTime GetTtTimesByTime(DateTime date, string time, int teacherId)
        {
            TutoringTimeDb ttDb = new TutoringTimeDb();

            //Constructs and adds complete Teacher object to TutoringTime
            //Returns improved object
            PersonCtrl   pCtrl      = new PersonCtrl();
            TutoringTime tt         = ttDb.GetTtTimesByTime(date, time, teacherId);
            TutoringTime completeTt = new TutoringTime();

            completeTt = tt;
            if (tt != null)
            {
                completeTt.Teacher = (Teacher)pCtrl.GetPerson(teacherId);
            }
            return(completeTt);
        }
Exemplo n.º 8
0
        public int RegisterBooking(TutoringTime tt)
        {
            SqlTransaction sqlTrans = null;

            try
            {
                comm            = new SqlCommand();
                dbCon           = new DbConnection();
                comm.Connection = dbCon.GetConnection();
                comm.Connection.Open();

                sqlTrans = comm.Connection.BeginTransaction(IsolationLevel.Serializable);

                using (comm)
                {
                    comm.CommandText = "UPDATE TutoringTime set childId=(@childId) WHERE tid =(@tutoringTimeId)";

                    comm.Parameters.AddWithValue("childId", tt.Child.Id);
                    comm.Parameters.AddWithValue("tutoringTimeId", tt.Id);

                    comm.CommandType = CommandType.Text;

                    comm.Transaction = sqlTrans;
                    result           = comm.ExecuteNonQuery();
                    if (result == 1)
                    {
                        sqlTrans.Commit();
                    }
                }
            }
            catch (Exception)
            {
                sqlTrans.Rollback();
                throw;
            }

            finally
            {
                comm.Connection.Close();
            }

            return(result);
        }
Exemplo n.º 9
0
        public List <TutoringTime> GetTtByDate(DateTime date)
        {
            List <TutoringTime> ttTimes = new List <TutoringTime>();
            string testDate             = date.ToString("yyyy/MM/dd");

            try
            {
                comm             = new SqlCommand();
                comm.CommandText = "SELECT * FROM TutoringTime WHERE date = '" + testDate + "'";

                dbCon           = new DbConnection();
                comm.Connection = dbCon.GetConnection();
                comm.Connection.Open();

                comm.CommandType = CommandType.Text;
                SqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {
                    TutoringTime tt = new TutoringTime();
                    tt.Id   = Convert.ToInt32(dr["tid"]);
                    tt.Time = Convert.ToString(dr["time"]);
                    tt.Date = Convert.ToDateTime(dr["date"]);
                    Teacher teacher = new Teacher();
                    teacher.Id = Convert.ToInt32(dr["teacherId"]);
                    tt.Teacher = teacher;

                    ttTimes.Add(tt);
                }
            }
            catch (Exception)
            {
                throw;
            }

            finally
            {
                comm.Connection.Close();
            }

            return(ttTimes);
        }
Exemplo n.º 10
0
        //Gets all the TutoringTime objects that has childId = null (which means that it
        //is available to book)
        public List <TutoringTime> GetAllAvailableTutoringTimes()
        {
            List <TutoringTime> ttTimes = new List <TutoringTime>();

            try
            {
                comm             = new SqlCommand();
                comm.CommandText = "SELECT * FROM TutoringTime WHERE childId is null";

                dbCon           = new DbConnection();
                comm.Connection = dbCon.GetConnection();
                comm.Connection.Open();

                comm.CommandType = CommandType.Text;
                SqlDataReader dr = comm.ExecuteReader();

                while (dr.Read())
                {
                    TutoringTime tt = new TutoringTime();
                    tt.Id   = Convert.ToInt32(dr["tid"]);
                    tt.Time = Convert.ToString(dr["time"]);
                    tt.Date = Convert.ToDateTime(dr["date"]);
                    Teacher teacher = new Teacher();
                    teacher.Id = Convert.ToInt32(dr["teacherId"]);
                    tt.Teacher = teacher;

                    ttTimes.Add(tt);
                }
            }
            catch (Exception)
            {
                throw;
            }

            finally
            {
                comm.Connection.Close();
            }

            return(ttTimes);
        }
Exemplo n.º 11
0
        public TutoringTime GetTtByTtId(int ttId)
        {
            SqlTransaction sqlTrans = null;

            try
            {
                comm            = new SqlCommand();
                dbCon           = new DbConnection();
                comm.Connection = dbCon.GetConnection();
                comm.Connection.Open();

                sqlTrans = comm.Connection.BeginTransaction(IsolationLevel.Serializable);

                using (comm)
                {
                    comm.CommandText = "SELECT * FROM TutoringTime WHERE tid  = '" + ttId + "'";
                    comm.CommandType = CommandType.Text;
                    SqlDataReader dr = comm.ExecuteReader();
                    TutoringTime  tt = new TutoringTime();

                    while (dr.Read())
                    {
                        tt.Id = Convert.ToInt32(dr["tid"]);
                    }
                    return(tt);
                }
            }
            catch (Exception)
            {
                throw;
            }

            finally
            {
                comm.Connection.Close();
            }
        }
Exemplo n.º 12
0
        private void CreateTutoringTime()
        {
            DateTime date = calendar.SelectionRange.Start;
            string time = cbScTime.Text;
            int teacherId = teacher.Id;
            if (date < DateTime.Today)
            {
                MessageBox.Show("Not possible to set available date and time");
            }
            else
            {
                if (string.IsNullOrEmpty(time))
                {
                    MessageBox.Show("Please select the time");
                }

                else
                {

                    Service1Client winService = new Service1Client();

                    tt = winService.GetTtTimesByTime(date, time, teacherId);

                    if (tt != null)
                    {

                        if (tt.Date == date)
                        {
                            if (String.Equals(tt.Time, time))
                            {

                                MessageBox.Show("Selected time is already in use");

                            }
                            else
                            {
                                winService.CreateTutoringTime(date, teacherId, time);
                                MessageBox.Show("Tutor time succesfully inserted");
                            }
                        }
                    }

                    else
                    {

                        winService.CreateTutoringTime(date, teacherId, time);
                        MessageBox.Show("Tutor time succesfully inserted");

                    }
                }
            }
        }
        //Populates the table with available times, for the selected date
        private void GenerateTableRows(TutoringTime[] tts)
        {
            foreach (TutoringTime tt in tts)
            {
                if (tt.Date == TutoringTimeCalendar.SelectedDate && tt.Child == null)
                {
                    TableRow tr = new TableRow();
                    TableCell nameCell = new TableCell();
                    nameCell.Text = tt.Teacher.Name;
                    TableCell subjectCell = new TableCell();
                    subjectCell.Text = tt.Teacher.Subject;
                    TableCell timeCell = new TableCell();
                    timeCell.Text = tt.Time;
                    TableCell bookBtnCell = new TableCell();
                    Button BookBtn = new Button();
                    BookBtn.Text = "Book Time";
                    BookBtn.ID = "BookTT" + tt.Id;
                    BookBtn.Click += (send, a) => { RegisterBooking(tt.Id); };
                    bookBtnCell.Controls.Add(BookBtn);

                    tr.Controls.Add(nameCell);
                    tr.Controls.Add(subjectCell);
                    tr.Controls.Add(timeCell);
                    tr.Controls.Add(bookBtnCell);

                    BookingTable.Controls.Add(tr);
                }
            }
        }