protected void addSchedBtn_Click(object sender, EventArgs e)
        {
            ScheduleManager sM = new ScheduleManager();
            PreferenceManager pM = new PreferenceManager();
            String availability = "";

            try
            {
                if (availabilityCheckBox.Items.Cast<ListItem>().Any(item => item.Selected))
                {
                    foreach (ListItem listDay in availabilityCheckBox.Items)
                        if (listDay.Selected)
                            availability += listDay.Value + "-";

                    availability = availability.Remove(availability.Length - 1);

                    if (pM.addPreference(Session["account"].ToString(), categoryDropDownList.SelectedItem.Value.ToString(), subjectTxtBox.Text, descTxtBox.Text, targetTxtBox.Text, priceTxtBox.Text))
                        if (sM.addSchedule(availability, startingTimeTxtBox1.Text + ":" + startingTimeTxtBox2.Text + "-" + EndTimeTxtBox1.Text + ":" + EndTimeTxtBox2.Text))
                           Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Schedule added!');</script>");
                }
                else
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Please select an available day');</script>");
            }
            catch
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert('Error adding schedule');</script>");
            }
        }
Пример #2
0
        public bool addSchedule(String day, String time)
        {
            try
            {
                PreferenceManager pm = new PreferenceManager();
                string insertQuery;
                int id = pm.getTopPrefID();

                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
                conn.Open();

                insertQuery = "insert into [T.P.SCHEDULE] (pref_id, day, time) values (@PrefID, @Day, @Time);";
                SqlCommand com = new SqlCommand(insertQuery, conn);
                com.Parameters.AddWithValue("@PrefID", id);
                com.Parameters.AddWithValue("@Day", day);
                com.Parameters.AddWithValue("@Time", time);
                com.ExecuteNonQuery();

                conn.Close();

                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Schedule");
                return false;
            }
        }
        protected void addSchedBtn_Click(object sender, EventArgs e)
        {
            ScheduleManager sM = new ScheduleManager();
            PreferenceManager pM = new PreferenceManager();

            try
            {
                if (pM.addPreference(Session["account"].ToString(), categoryTxtBox.Text, subjectTxtBox.Text, descTxtBox.Text, targetTxtBox.Text, priceTxtBox.Text) && sM.addSchedule(dayTxtBox.Text, timeTxtBox.Text))
                    MessageBox.Show("Schedule Added!");
            }
            catch
            {
                MessageBox.Show("Error Adding Schedule!");
            }
                
        }