コード例 #1
0
        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