示例#1
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        //Prevent corruption. Double check availability. Delete cookies
        if (Session["date"] != null && Session["AdvisorID"] != null)
        {

            int advisorId = Convert.ToInt32(Session["AdvisorID"].ToString());
            string date = Session["date"].ToString();
            int studentId = Convert.ToInt32(Session["StudentID"].ToString());
            Session["date"] = null;
            Session["AdvisorID"] = null;
            ronUtil2 get = new ronUtil2(advisorId);
            DateTime datev2 = DateTime.ParseExact(date, "MM/dd/yyyy", null);
            DateTime[] advisorAllSlots = get.getSlots(advisorId, date);
            DateTime[] taken = get.getTaken(advisorId, date);
            DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);

            bool proceed = false;
            for (int i = 0; i < availibility.Length; i++)
            {
                if (DropDownList1.SelectedValue.ToString() == availibility[i].ToShortTimeString())
                {
                    proceed = true;
                }
            }

            if (proceed)
            {
                DateTime picked = new DateTime();
                picked = DateTime.ParseExact(DropDownList1.SelectedValue.ToString(), "h:mm tt", CultureInfo.InvariantCulture);

                int Student_Id = studentId;
                int Advisor_Id = advisorId;
                string Time = picked.ToString("HH:mm:ss");
                string Date = datev2.ToString("yyyy-MM-dd");
                Label1.Text = Time;
                string Comments = TextArea1.Value.ToString();
                int Availability_ID= get.getAvailableID(Advisor_Id, date);

                string sqlQuery = "INSERT INTO Appointment (Availability_ID, Student_Id,Time,Date,Comment)";
                sqlQuery += " VALUES (@Availability_ID,@Student_Id,@Time,@Date,@Comment)";
                string connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();
                using (SqlConnection dataConnection = new SqlConnection(connectionString))
                {
                    using (SqlCommand dataCommand = new SqlCommand(sqlQuery, dataConnection))
                    {
                        dataCommand.Parameters.AddWithValue("Availability_ID", Availability_ID);
                        dataCommand.Parameters.AddWithValue("Student_Id", studentId);
                        dataCommand.Parameters.AddWithValue("Time", Time);
                        dataCommand.Parameters.AddWithValue("Date", Date);
                        dataCommand.Parameters.AddWithValue("Comment", Comments);
                        dataConnection.Open();
                        dataCommand.ExecuteNonQuery();
                        dataConnection.Close();
                    }
                }

                Response.Write("<script type='text/javascript'>alert('You are booked');</script>");
                Server.Transfer("Advisor.aspx");
            }
            else
            {
                Response.Write("<script type='text/javascript'>alert('Something went wrong. Try again later');</script>");
                Server.Transfer("Advisor.aspx");
            }

        }
    }
示例#2
0
    protected void Page_Load(object sender, EventArgs e)
    {
        //Prevent exceptions,corruptions.

        if (Session["date"] == null || Session["AdvisorID"] == null)
            {
                Server.Transfer("Advisor.aspx");
            }

        int studentId = Convert.ToInt32(Session["StudentID"].ToString());
        int advisorId = Convert.ToInt32(Session["AdvisorID"].ToString());
        string date = Session["date"].ToString();
        ronUtil2 get = new ronUtil2(advisorId);

        Submit.Visible = true;
        //if (get.getCheck(studentId) == true)
        //{ Submit.Visible = true; }
        //else
        //{ Cancel.Visible = true; }

        DateTime datev2 = DateTime.ParseExact(Session["date"].ToString(), "MM/dd/yyyy", null);
        DateTime[] advisorAllSlots = get.getSlots(advisorId, date);
        DateTime[] taken = get.getTaken(advisorId, date);
        DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);

        string[] shorttime = new string[availibility.Length];
        for (int i = 0; i < availibility.Length; i++)
        { shorttime[i] = availibility[i].ToShortTimeString(); }

        txtAdvisorName.Text = get.FullName;

        //Label1.Text = "Date : " + datev2.ToLongDateString();
        txtDate.Text = datev2.ToShortDateString();

            DropDownList1.DataSource = shorttime;
         //   DropDownList1.DataBind();
          if (!IsPostBack)
           {
                DropDownList1.DataBind();
           }

            if (availibility.Length==0)
            {Response.Write("<script type='text/javascript'>alert('It is fully booked.');</script>");
                Server.Transfer("Schedule.aspx");}
    }
示例#3
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Unload += PageUnload;

        ronUtil2 get = new ronUtil2();

        //Dropdown list
        DropDownList1.DataSource = get.getStudentIds();
        if(!IsPostBack)
        DropDownList1.DataBind();

        //Tables
        //string[] days= get.DaysAvailable;
          string[] dates= get.getAdvisor2WeekSchedule();
          DateTime[] datesv2 = new DateTime[dates.Length];

          for (int i = 0; i < dates.Length; i++)
          { datesv2[i] = DateTime.Parse(dates[i]); }

        Label1.Text = datesv2[0].DayOfWeek.ToString();
        Label2.Text = datesv2[1].DayOfWeek.ToString();
        Label3.Text = datesv2[2].DayOfWeek.ToString();
        Label4.Text = datesv2[3].DayOfWeek.ToString();
        Label5.Text = datesv2[4].DayOfWeek.ToString();

        Label6.Text = datesv2[0].ToString("dd MMM yyyy");
        Label7.Text = datesv2[1].ToString("dd MMM yyyy");

        Label8.Text = datesv2[2].ToString("dd MMM yyyy");
        Label9.Text = datesv2[3].ToString("dd MMM yyyy");
        Label10.Text = datesv2[4].ToString("dd MMM yyyy");

        //Label1.Text = "1";
        //Label2.Text = "2";
        //Label3.Text = "3";
        //Label4.Text = "4";
        //Label5.Text = "5";
        //Label2.Text = get.bookingDays[1];
        //Label3.Text = get.bookingDays[2];
        //Label4.Text = get.bookingDays[3];
        //Label5.Text = get.bookingDays[4];

        int[] ID = get.getAdvisorIDs();

        //DateTime[] advisorAllSlots = get.getSlots(101, date[0]);
        //DateTime[] taken = get.getTaken(101, date[0]);
        //DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);
        //HyperLink[] link2 = new HyperLink[availibility.Length];
          //  for (int i = 0; i < link2.Length; i++) { link2[i] = new HyperLink(); }

        for (int ii = 0; ii < ID.Length; ii++)
        {
            TableCell[] td = new TableCell[8];
            HyperLink link = new HyperLink();
            link.NavigateUrl = "~/Schedule.aspx?AdvisorID=" + ID[ii];
            for (int i = 0; i < 8; i++) { td[i] = new TableCell(); }

            link.Text = get.getName(ID[ii]) + "<br /> <img src='" + get.getAdvisorImage(ID[ii])+"' width='80' height='80' />";
            link.ForeColor=System.Drawing.Color.Black;
            link.Font.Underline = false;
            td[0].Controls.Add(link);
            td[1].Text = get.getDepartment(ID[ii]).Replace("School of","");
            td[1].ForeColor = System.Drawing.Color.Black;

            for (int EachRow = 0; EachRow < 5; EachRow++)
            {
                for (int iii = 0; iii < 6; iii++)
                {
                    DateTime[] advisorAllSlots = get.getSlots(ID[ii], dates[EachRow]);
                    DateTime[] taken = get.getTaken(ID[ii], dates[EachRow]);
                    DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);
                    HyperLink[] link2 = new HyperLink[availibility.Length];
                    if (availibility.Length == 0 || iii == availibility.Length)
                    { break; }

                    if (iii == 5)
                    {
                        link2[0] = new HyperLink();
                       // link2[0].NavigateUrl = "~/View2.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[EachRow];
                        link2[0].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + datesv2[EachRow].ToString("MM/dd/yyyy") + "&bookingTime=" + availibility[0].ToShortTimeString();
                        link2[0].Text = "more";
                        link2[0].ForeColor = System.Drawing.Color.Black;
                        td[EachRow+2].Controls.Add(link2[0]);
                    }
                    else
                    {
                        for (int i = 0; i < link2.Length; i++) { link2[i] = new HyperLink(); }
                       // link2[iii].NavigateUrl = "~/View2.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[EachRow];
        //                        link2[iii].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[EachRow] + "&bookingTime=" + availibility[0].ToShortTimeString();
                        link2[iii].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + datesv2[EachRow].ToString("MM/dd/yyyy") + "&bookingTime=" + availibility[iii].ToShortTimeString();

                        link2[iii].Text = availibility[iii].ToShortTimeString() + "<br />";
                        link2[iii].ForeColor = System.Drawing.Color.Black;
                        td[EachRow+2].Controls.Add(link2[iii]);
                    }
                }
            }

            //for (int iii = 0; iii < 6; iii++)
            //{
            //    DateTime[] advisorAllSlots = get.getSlots(ID[ii], dates[1]);
            //    DateTime[] taken = get.getTaken(ID[ii], dates[1]);
            //    DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);
            //    HyperLink[] link2 = new HyperLink[availibility.Length];
            //    if (availibility.Length == 0 || iii==availibility.Length)
            //    { break; }

            //    if (iii == 5)
            //    {
            //        link2[0] = new HyperLink();
            //        link2[0].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[1] + "&bookingTime=" + availibility[0].ToShortTimeString();
            //        link2[0].Text = "more";
            //        td[3].Controls.Add(link2[0]);
            //    }
            //    else
            //    {
            //        for (int i = 0; i < link2.Length; i++) { link2[i] = new HyperLink(); }
            //        link2[iii].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[1] + "&bookingTime=" + availibility[iii].ToShortTimeString();
            //        link2[iii].Text = availibility[iii].ToShortTimeString() + "<br />";
            //        td[3].Controls.Add(link2[iii]);
            //    }
            //}

            //for (int iii = 0; iii < 6; iii++)
            //{
            //    DateTime[] advisorAllSlots = get.getSlots(ID[ii], dates[2]);
            //    DateTime[] taken = get.getTaken(ID[ii], dates[2]);
            //    DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);
            //    HyperLink[] link2 = new HyperLink[availibility.Length];
            //    if (availibility.Length == 0 || iii == availibility.Length)
            //    { break; }

            //    if (iii == 5)
            //    {
            //        link2[0] = new HyperLink();
            //        link2[0].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[2] + "&bookingTime=" + availibility[0].ToShortTimeString();
            //        link2[0].Text = "more";
            //        td[4].Controls.Add(link2[0]);
            //    }
            //    else
            //    {
            //        for (int i = 0; i < link2.Length; i++) { link2[i] = new HyperLink(); }
            //        link2[iii].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[2] + "&bookingTime=" + availibility[iii].ToShortTimeString();
            //        link2[iii].Text = availibility[iii].ToShortTimeString() + "<br />";
            //        td[4].Controls.Add(link2[iii]);
            //    }
            //}

            //for (int iii = 0; iii < 6; iii++)
            //{
            //    DateTime[] advisorAllSlots = get.getSlots(ID[ii], dates[3]);
            //    DateTime[] taken = get.getTaken(ID[ii], dates[3]);
            //    DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);
            //    HyperLink[] link2 = new HyperLink[availibility.Length];
            //    if (availibility.Length == 0 || iii == availibility.Length)
            //    { break; }

            //    if (iii == 5)
            //    {
            //        link2[0] = new HyperLink();
            //        link2[0].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[3] + "&bookingTime=" + availibility[0].ToShortTimeString();
            //        link2[0].Text = "more";
            //        td[5].Controls.Add(link2[0]);
            //    }
            //    else
            //    {
            //        for (int i = 0; i < link2.Length; i++) { link2[i] = new HyperLink(); }
            //        link2[iii].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[3] + "&bookingTime=" + availibility[iii].ToShortTimeString();
            //        link2[iii].Text = availibility[iii].ToShortTimeString() + "<br />";
            //        td[5].Controls.Add(link2[iii]);
            //    }
            //}

            //for (int iii = 0; iii < 6; iii++)
            //{
            //    DateTime[] advisorAllSlots = get.getSlots(ID[ii], dates[4]);
            //    DateTime[] taken = get.getTaken(ID[ii], dates[4]);
            //    DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);
            //    HyperLink[] link2 = new HyperLink[availibility.Length];
            //    if (availibility.Length == 0 || iii == availibility.Length)
            //    { break; }

            //    if (iii == 5)
            //    {
            //        link2[0] = new HyperLink();
            //        link2[0].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[4] + "&bookingTime=" + availibility[0].ToShortTimeString();
            //        link2[0].Text = "more";
            //        td[6].Controls.Add(link2[0]);
            //    }
            //    else
            //    {
            //        for (int i = 0; i < link2.Length; i++) { link2[i] = new HyperLink(); }
            //        link2[iii].NavigateUrl = "~/Confirm.aspx?AdvisorID=" + ID[ii] + "&bookingDate=" + dates[4] + "&bookingTime=" + availibility[iii].ToShortTimeString();
            //        link2[iii].Text = availibility[iii].ToShortTimeString() + "<br />";
            //        td[6].Controls.Add(link2[iii]);
            //    }
            //}

           //    td[3].Text = get.getTuesday(ID[ii]);
           //     td[4].Text = get.getWednesday(ID[ii]);
          //  td[5].Text = get.getThursday(ID[ii]);
          //  td[6].Text = get.getFriday(ID[ii]);
            td[0].Width = 200;
            td[1].Width = 60;
            td[2].Width = 60;
            td[3].Width = 60;
            td[4].Width = 60;
            td[5].Width = 60;
            td[6].Width = 60;

            td[2].HorizontalAlign = HorizontalAlign.Center;
            td[3].HorizontalAlign = HorizontalAlign.Center;
            td[4].HorizontalAlign = HorizontalAlign.Center;
            td[5].HorizontalAlign = HorizontalAlign.Center;
            td[6].HorizontalAlign = HorizontalAlign.Center;

            td[0].BackColor = System.Drawing.Color.White;
            td[1].BackColor = System.Drawing.Color.WhiteSmoke;
            td[2].BackColor = System.Drawing.Color.White;
            td[3].BackColor = System.Drawing.Color.WhiteSmoke;
            td[4].BackColor = System.Drawing.Color.White;
            td[5].BackColor = System.Drawing.Color.WhiteSmoke;
            td[6].BackColor = System.Drawing.Color.White;

            td[0].Height = 150;
            TableRow tRow = new TableRow();
            tRow.VerticalAlign = VerticalAlign.Top;
            myTable.Rows.Add(tRow);
            tRow.Cells.AddRange(td);
        }
    }