示例#1
0
        //get a single workshop
        public static Workshop getWorkshop(int id)
        {
            connectTo();
            Workshop c = null;

            try
            {
                command.CommandText = "SELECT * FROM Workshop WHERE ID=" + id;
                command.CommandType = CommandType.Text;
                connection.Open();
                OleDbDataReader read = command.ExecuteReader();

                while (read.Read())
                {
                    c = new Workshop(
                        DateTime.Parse(read["StartDate"].ToString()),
                        TimeSpan.Parse(read["StartTime"].ToString()),
                        read["Style"].ToString(),
                        read["SessionLevel"].ToString(),
                        (int)read["fkInstructorID"],
                        (int)read["Duration"],
                        (int)read["Capacity"],
                        read["Title"].ToString(),
                        read["Description"].ToString(),
                        read["Room"].ToString(),
                        (int)read["Reservations"]

                        );
                    c.Id = (int)read["ID"];
                }
            }
            catch (Exception)
            {
                throw;
            }

            finally
            {
                connection.Close();
            }

            return(c);
        }
示例#2
0
        public static List <Workshop> getWorkshops(bool condition, DateTime date)
        {
            connectTo();
            //CONDITION PARAMETER:
            //if TRUE -  store all future sessions in sessions List
            //if FALSE - store only sessions that occur on same date as provided in DateTime date

            List <Workshop> sessions = new List <Workshop>();


            try
            {
                command.CommandText = "SELECT * FROM Workshop ORDER BY StartDate ASC";
                command.CommandType = CommandType.Text;
                connection.Open();
                OleDbDataReader read = command.ExecuteReader();

                while (read.Read())
                {
                    Workshop s = new Workshop(
                        DateTime.Parse(read["StartDate"].ToString()),
                        TimeSpan.Parse(read["StartTime"].ToString()),
                        read["Style"].ToString(),
                        read["SessionLevel"].ToString(),
                        (int)read["fkInstructorID"],
                        (int)read["Duration"],
                        (int)read["Capacity"],
                        read["Title"].ToString(),
                        read["Description"].ToString(),
                        read["Room"].ToString(),
                        (int)read["Reservations"]

                        );
                    s.Id     = (int)read["ID"];
                    s.Status = read["Status"].ToString();

                    //get sessions date and store it in DateTime variable
                    DateTime scheduleTime = new DateTime(s.StartDate.Year, s.StartDate.Month, s.StartDate.Day);

                    //compare choosen date with session's date
                    //RETURN VALUES MEANING
                    // less than 0 = t1 is earlier than t2
                    //zero = t1 is same as t2
                    // more than zero = t1 is later than t2
                    //source: https://msdn.microsoft.com/en-us/library/system.datetime.compare(v=vs.110).aspx
                    int results = DateTime.Compare(scheduleTime.Date, date.Date);

                    //display all sessions from today onwards
                    if (condition)
                    {
                        if (results > 0 || results == 0)
                        {
                            sessions.Add(s);
                        }
                    }
                    //display sessions on a choosen date
                    else if (!condition)
                    {
                        int oldCheck = DateTime.Compare(scheduleTime.Date, DateTime.Now.Date);
                        if (results == 0 && oldCheck >= 0)
                        {
                            sessions.Add(s);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                connection.Close();
            }


            return(sessions);
        }
        protected void addSession(object sender, EventArgs e)
        {
            string   type        = ddl_type.SelectedValue;
            string   title       = txt_title.Text;
            string   description = txt_description.Text;
            string   style       = ddl_style.SelectedValue;
            string   level       = rdb_level.SelectedValue;
            int      capacity    = Int32.Parse(ddl_capacity.SelectedValue);
            string   room        = txt_room.Text;
            DateTime date        = myCalendar.SelectedDate;

            int      repeatWks = Int32.Parse(ddl_repeatWks.SelectedValue);
            TimeSpan time      = new TimeSpan(Int32.Parse(ddl_timeH.SelectedValue), Int32.Parse(ddl_timeM.SelectedValue), 00);

            int duration     = Int32.Parse(ddl_duration.SelectedValue);
            int count        = 0;
            int instructorID = 0;

            //Check if the choosen date is in the future
            int oldDateCheck = DateTime.Compare(date.Date.Add(time), DateTime.Now);

            if (oldDateCheck <= 0)
            {
                Response.Write("<script>alert('Choose a date in the future.')</script>");
            }
            else
            {
                try
                {
                    //find the instructor's ID number by looping through instructors name's.
                    //
                    while (!ddl_instructor.SelectedValue.Equals(instructors[count].Name))
                    {
                        count++;
                    }

                    instructorID = instructors[count].Id;
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    lb_exceptionCatch.Text = "You need to choose default value for all drop down lists.";
                }


                if (ddl_type.SelectedValue.Equals("Class"))
                {
                    Class session = new Class(date, time, style, level, instructorID, duration, capacity, title, description, room, 0, repeatWks);
                    session.schedulesClass();

                    DBconnection.addClass(session);
                }
                else
                {
                    Workshop session = new Workshop(date, time, style, level, instructorID, duration, capacity, title, description, room, 0);

                    DBconnection.addWorkshop(session);
                }

                clearControls();
                Response.Write("<script>alert('Your session has been added to the database.')</script>");
            }
        }//end of add session