Example #1
0
    //-------------------------------------Get Advisors 2 Wees Schedule By ID AND NOW--------------------------------------------------------

    public string[] getAdvisor2WeekSchedule(int id)
    {
        DateTime now  = DateTime.Today;
        DateTime last = now.AddDays(8);

        DateTime[] allDays = new DateTime[8];

        for (int i = 0; i < allDays.Length; i++)
        {
            allDays[i] = now.AddDays(i);
        }


        ronUtil get = new ronUtil(id);

        string date = null;

        for (int i = 0; i < allDays.Length; i++)
        {
            for (int ii = 0; ii < get.DaysAvailable.Length; ii++)
            {
                if (allDays[i].DayOfWeek.ToString() == get.DaysAvailable[ii])
                {
                    date = allDays[i].ToShortDateString() + "," + date;
                }
            }
        }

        Char[]   splitChars = new Char[] { ',' };
        string[] splitdate  = date.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
        return(splitdate);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        ronUtil get= new ronUtil();
        GridView1.DataSource = get.loadAdvisorsToGrid();
        GridView1.DataBind();

        //if (Session["Student"] == null)
        //{ Server.Transfer("Advisor.aspx"); }
    }
Example #3
0
    //-------------------------------------Get Advisors 2 Wees Schedule By ID AND NOW--------------------------------------------------------
    public string[] getAdvisor2WeekSchedule(int id)
    {
        DateTime now = DateTime.Today;
        DateTime last = now.AddDays(8);
        DateTime[] allDays = new DateTime[8];

        for (int i = 0; i < allDays.Length; i++)
        {
            allDays[i] = now.AddDays(i);
        }

        ronUtil get = new ronUtil(id);

        string date = null;
        for (int i = 0; i < allDays.Length; i++)
        {
            for (int ii = 0; ii < get.DaysAvailable.Length; ii++)
            {
                if (allDays[i].DayOfWeek.ToString() == get.DaysAvailable[ii])
                {

                    date = allDays[i].ToShortDateString() + "," + date;
                }
            }
        }

        Char[] splitChars = new Char[] { ',' };
        string[] splitdate = date.Split(splitChars, StringSplitOptions.RemoveEmptyEntries);
        return splitdate;
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        //Prwvent excepts,corruptions.

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

        int advisorId = Convert.ToInt16(Session["ID"].ToString());
        string date = Session["date"].ToString();
        ronUtil get = new ronUtil(advisorId);
        DateTime datev2 = DateTime.ParseExact(Session["date"].ToString(), "MM/dd/yyyy", null);
        DateTime[] advisorAllSlots = get.getSlots(advisorId, datev2.ToString("yyyyMMdd"));
        DateTime[] taken = get.getTaken(advisorId, datev2.ToString("yyyy-MM-dd"));
        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(); }
        Label3.Text = "For Advisor: " + get.FullName;
        Label2.Text = "Your StudentID: " + Session["Student"].ToString(); ;
        Label1.Text = "Date:" + Session["date"].ToString();

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

            if (availibility.Length==0)
            {Response.Write("<script type='text/javascript'>alert('It is fully booked.');</script>");
                Server.Transfer("Calendar.aspx");}
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //Prevent corruption. Double check availability. Delete cookies
        if (Session["date"] != null && Session["ID"] != null)
        {
            int advisorId = Convert.ToInt16(Session["ID"].ToString());
            string date = Session["date"].ToString();
            Session["date"] = null;
            Session["ID"] = null;
            ronUtil get = new ronUtil(advisorId);
            DateTime datev2 = DateTime.ParseExact(date, "MM/dd/yyyy", null);
            DateTime[] advisorAllSlots = get.getSlots(advisorId, datev2.ToString("yyyyMMdd"));
            DateTime[] taken = get.getTaken(advisorId, datev2.ToString("yyyy-MM-dd"));
            DateTime[] availibility = get.getAvailability(advisorAllSlots, taken);

            Session["date"] = null;

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

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

                int Student_Id = 822459073;
                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 Completed = 0;

                string sqlQuery = "INSERT INTO Scheduling (Student_Id,Advisor_Id,Time,Date,Comments,Completed)";
                sqlQuery += " VALUES (@Student_Id,@Advisor_Id,@Time,@Date,@Comments,@Completed)";
                string connectionString = ConfigurationManager.ConnectionStrings["ApplicationServices"].ToString();
                using (SqlConnection dataConnection = new SqlConnection(connectionString))
                {
                    using (SqlCommand dataCommand = new SqlCommand(sqlQuery, dataConnection))
                    {

                        dataCommand.Parameters.AddWithValue("Student_Id", Student_Id);
                        dataCommand.Parameters.AddWithValue("Advisor_Id", Advisor_Id);
                        dataCommand.Parameters.AddWithValue("Time", Time);
                        dataCommand.Parameters.AddWithValue("Date", Date);
                        dataCommand.Parameters.AddWithValue("Comments", Comments);
                        dataCommand.Parameters.AddWithValue("Completed", Completed);

                        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");
            }

        }
    }
    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        int id = Convert.ToInt16(Request.QueryString["ID"]);
           ronUtil get = new ronUtil(id);

        int length = get.DaysAvailable.Length;
        DayOfWeek[] days = new DayOfWeek[length];

        for (int i = 0; i < length; i++)
        {
            days[i] = (DayOfWeek)Enum.Parse(typeof(DayOfWeek), get.DaysAvailable[i]);
        }

        e.Day.IsSelectable = false;
        e.Cell.ForeColor = System.Drawing.Color.Gray;
           // e.Cell.Font.Strikeout = true;
        e.Cell.Font.Size = 10;
            //    e.Cell.ForeColor = System.Drawing.Color.Gray;
        DateTime stratDate = DateTime.Today;
        DateTime endDate = stratDate.AddDays(8);
        //DateTime[] allDays = new DateTime[15];

        if (e.Day.Date > stratDate && e.Day.Date < endDate)
        {

            if (e.Day.IsWeekend)
            {
                e.Day.IsSelectable = false;

            }
            else
            {
                e.Day.IsSelectable = true;
              //  e.Cell.BackColor = System.Drawing.Color.AntiqueWhite;
             //   e.Cell.Font.Name = "Courier New Baltic";
               e.Cell.ForeColor = System.Drawing.Color.Black;

               e.Cell.Font.Strikeout = false;
               e.Cell.ForeColor = System.Drawing.Color.Red;
               e.Cell.Font.Size=12;
                //DAY RENDERING -ARRAY VARIABLE-.  This is the only way I can do this
                if (length == 1)
                {
                    if (e.Day.Date.DayOfWeek != days[0])
                    {
                        e.Day.IsSelectable = false;
                        //e.Cell.Font.Strikeout = true;
                        e.Cell.ForeColor = System.Drawing.Color.Gray;
                        e.Cell.Font.Size = 10;
                    }
                }

                if (length == 2)
                {
                    if (e.Day.Date.DayOfWeek != days[0] && e.Day.Date.DayOfWeek != days[1])
                    {
                        e.Day.IsSelectable = false;
                        //e.Cell.Font.Strikeout = true;
                        e.Cell.ForeColor = System.Drawing.Color.Gray;
                        e.Cell.Font.Size = 10;
                    }
                }

                if (length == 3)
                {
                    if (e.Day.Date.DayOfWeek != days[0] && e.Day.Date.DayOfWeek != days[1] && e.Day.Date.DayOfWeek != days[2])
                    {
                        e.Day.IsSelectable = false;
                        //e.Cell.Font.Strikeout = true;
                        e.Cell.ForeColor = System.Drawing.Color.Gray;
                        e.Cell.Font.Size = 10;
                    }
                }

                if (length == 4)
                {
                    if (e.Day.Date.DayOfWeek != days[0] && e.Day.Date.DayOfWeek != days[1] && e.Day.Date.DayOfWeek != days[2] && e.Day.Date.DayOfWeek != days[3])
                    {
                        e.Day.IsSelectable = false;
                        //e.Cell.Font.Strikeout = true;
                        e.Cell.ForeColor = System.Drawing.Color.Gray;
                        e.Cell.Font.Size = 10;
                    }
                }

                if (length == 5)
                {
                    if (e.Day.Date.DayOfWeek != days[0] && e.Day.Date.DayOfWeek != days[1] && e.Day.Date.DayOfWeek != days[2] && e.Day.Date.DayOfWeek != days[3] && e.Day.Date.DayOfWeek != days[4])
                    {
                        e.Day.IsSelectable = false;
                       //e.Cell.Font.Strikeout = true;
                        e.Cell.ForeColor = System.Drawing.Color.Gray;
                        e.Cell.Font.Size = 10;
                    }
                }

            }
        }
    }