コード例 #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                MonthBind();

                YearDropDown.DataBind();

                /*Checks if the current year is in the dropdown (They have volunteered this year)
                 * and if not makes the starting value the bottom value (the most recent year)
                 */
                ListItem checkYear = YearDropDown.Items.FindByText(DateTime.Now.Year.ToString());
                if (checkYear != null)
                {
                    YearDropDown.SelectedValue = DateTime.Now.Year.ToString();
                }

                else
                {
                    YearDropDown.SelectedIndex = YearDropDown.Items.Count - 1;
                }

                //Sets MonthDropDown to the current month
                MonthDropDown.SelectedValue = DateTime.Now.Month.ToString();

                string month = MonthDropDown.Text;
                string year  = YearDropDown.Text;

                BindFacilitatorHours(month, year);
            }
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Gets the Selected User
            String ID = User.Identity.GetUserId();
            string month;
            string year;

            if (!IsPostBack)
            {
                //Adds the months of the year to the MonthDropDown
                MonthBind();
                //Databinds the years to YearDropDown
                YearDropDown.DataBind();

                /*Checks if the current year is in the dropdown (They have volunteered this year)
                 * and if not makes the starting value the bottom value (the most recent year)
                 * */
                ListItem checkYear = YearDropDown.Items.FindByText(DateTime.Now.Year.ToString());
                if (checkYear != null)
                {
                    YearDropDown.SelectedValue = DateTime.Now.Year.ToString();
                }

                else
                {
                    YearDropDown.SelectedIndex = YearDropDown.Items.Count - 1;
                }

                //Sets MonthDropDown to the current month
                MonthDropDown.SelectedValue = DateTime.Now.Month.ToString();

                month = MonthDropDown.Text;
                year  = YearDropDown.Text;

                //Binds the Facilitator hour table to the current date
                BindFacilitatorHours(month, year, ID);

                //Binds the Facilitator Room hour table to the current date
                BindFacilitatorRoomHours(month, year, ID);

                //Binds the Room hour table to the current date
                BindRoomHours(month, year, ID);

                //Binds the total stats table to the current date
                BindTotalStats(month, year, ID);

                monthlyHoursLabel.Text = GetMonthlyHours(month, year, ID);

                yearlyHoursLabel.Text = GetYearlyHours(month, year, ID);
                BindDonationRecieved(month, year, ID);
                BindDonationGiven(month, year, ID);
            }

            //Open Connection
            SqlConnection con = new SqlConnection
            {
                ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()
            };

            con.Open();

            //Get Facilitators
            string Facilitators = "SELECT (F.FirstName + ' '+ F.LastName) AS FacilitatorName FROM dbo.Facilitators AS F WHERE " +
                                  "F.Id = @CurrentUser";
            SqlCommand getFacilitators = new SqlCommand(Facilitators, con);

            getFacilitators.Parameters.AddWithValue("@CurrentUser", ID);

            //Execture the querey
            SqlDataReader facilitatorReader = getFacilitators.ExecuteReader();

            //Assign results
            FacView.DataSource = facilitatorReader;
            //Bind the data
            FacView.DataBind();
            facilitatorReader.Close();

            //Get Children
            string Children = "SELECT (C.FirstName + ' '+ C.LastName) AS Name, C.Grade as Grade, C.Class as Classroom FROM dbo.Children AS C WHERE " +
                              "C.Id = @CurrentUser";
            SqlCommand getChildren = new SqlCommand(Children, con);

            getChildren.Parameters.AddWithValue("@CurrentUser", ID);

            //Execute the querey
            SqlDataReader childrenReader = getChildren.ExecuteReader();

            //Assign results
            ChildView.DataSource = childrenReader;
            //Bind the data
            ChildView.DataBind();
            childrenReader.Close();
            con.Close();
        }