/* Decline button for the completed hours gridview */ protected void DeclineButton(object sender, System.EventArgs e) { /* * //Get the button that raised the event * LinkButton btn = (LinkButton)sender; * * //Get the row that contains this button * GridViewRow gvr = (GridViewRow)btn.NamingContainer;*/ //Grid row number int num = gvr.RowIndex; int WeekOfMonth = GetWeekOfMonth.GetWeekNumberOfMonth(Convert.ToDateTime(gvr.Cells[2].Text)); string[] name; string firstName; string lastName; DateTime dt = Convert.ToDateTime(gvr.Cells[1].Text); DateTime dt1 = Convert.ToDateTime(gvr.Cells[2].Text); name = gvr.Cells[0].Text.Split(' '); firstName = name[0]; lastName = name[1]; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); con.Open(); string CompletedHours = ("DELETE FROM Calendar WHERE Id = @CurrentUser " + "and FacilitatorFirstName = @FirstName and FacilitatorLastName = @LastName " + "and StartTime = @StartTime and EndTime = @EndTime and RoomId = @Room"); SqlCommand GetCompletedHours = new SqlCommand(CompletedHours, con); GetCompletedHours.Parameters.AddWithValue("@CurrentUser", User.Identity.GetUserId()); GetCompletedHours.Parameters.AddWithValue("@FirstName", firstName); GetCompletedHours.Parameters.AddWithValue("@LastName", lastName); GetCompletedHours.Parameters.AddWithValue("@StartTime", dt); GetCompletedHours.Parameters.AddWithValue("@EndTime", dt1); GetCompletedHours.Parameters.AddWithValue("@Room", GetRoomId(gvr.Cells[3].Text)); SqlDataReader addHoursReader = GetCompletedHours.ExecuteReader(); Response.Redirect("index.aspx"); }
/*Submits the hours to stats with the donated hours going to the updated email * **Code mostly repeated from Confirm button to be refactored** */ protected void onConfirm(object sender, EventArgs e) { //GridViewRow gvr = GridView4.SelectedRow; /* * //Get the button that raised the event * LinkButton btn = (LinkButton)sender; * * //Get the row that contains this button * GridViewRow gvr = (GridViewRow)btn.NamingContainer; */ //Grid row number int num = gvr.RowIndex; int WeekOfMonth = GetWeekOfMonth.GetWeekNumberOfMonth(Convert.ToDateTime(gvr.Cells[2].Text)); var manager = Context.GetOwinContext().GetUserManager <ApplicationUserManager>(); string[] name; string firstName; string lastName; string newFirstName; string newLastName; string startTime; string endTime; string[] startDate; string[] endDate; string[] array; string month; string year; DateTime dt = Convert.ToDateTime(gvr.Cells[1].Text); DateTime dt1 = Convert.ToDateTime(gvr.Cells[2].Text); float totalHours = (float)(dt1 - dt).TotalHours; //Gets the selected facilitator name from the dropdown name = FacilitatorDropDown.Text.Split(' '); newFirstName = name[0]; newLastName = name[1]; //Gets the original facilitator so that the proper row in Calendar dataTable gets deleted name = gvr.Cells[0].Text.Split(' '); firstName = name[0]; lastName = name[1]; startDate = gvr.Cells[1].Text.Split(' '); startTime = startDate[1]; endDate = gvr.Cells[2].Text.Split(' '); endTime = endDate[1]; //fixes the case where time is split on "-" or "/" if (endDate[0].Contains('-')) { array = endDate[0].Split('-'); month = array[1]; year = array[0]; } else { array = endDate[0].Split('/'); month = array[0]; if (array[2].Length == 2) { year = "20" + array[2]; } else { year = array[2]; } } //Checks if the timeslot is the lunch hour and gives double time if it is if ((TimeSpan.Compare(dt.TimeOfDay, new TimeSpan(12, 0, 0)) == 0 || TimeSpan.Compare(dt.TimeOfDay, new TimeSpan(12, 0, 0)) == -1) && (TimeSpan.Compare(dt1.TimeOfDay, new TimeSpan(13, 0, 0)) == 0 || TimeSpan.Compare(dt1.TimeOfDay, new TimeSpan(13, 0, 0)) == 1)) { //Look for Field Trips (Only double time for lunch on regular days) SqlConnection fieldTripCheck = new SqlConnection { ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString() }; SqlDataAdapter adapter = new SqlDataAdapter(); fieldTripCheck.Open(); SqlDataAdapter getFieldTrips = new SqlDataAdapter("Select Location From FieldTrips where CONVERT(DATE, StartTime) = @CurrentDate", ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); getFieldTrips.SelectCommand.Parameters.AddWithValue("@CurrentDate", dt.Date); DataTable table = new DataTable(); getFieldTrips.Fill(table); //If not a fieldtrip give double time for lunch hour if (table.Rows.Count == 0) { totalHours += 1; } fieldTripCheck.Close(); } SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); con.Open(); string CompletedHours = ("INSERT INTO Stats (Id, FacilitatorFirstName, FacilitatorLastName, RoomId, " + "WeekOfMonth, WeekOfYear, Month, Year, WeeklyHours, Donate) VALUES (@NewUser, @NewFirstName, " + "@NewLastName, @Room, @WeekOfMonth, @WeekOfYear, @Month, @Year, @WeeklyHours, @CurrentUser); " + "DELETE FROM Calendar WHERE Id = @CurrentUser and FacilitatorFirstName = @FirstName and FacilitatorLastName = @LastName " + "and StartTime = @StartTime and EndTime = @EndTime and RoomId = @Room"); SqlCommand GetCompletedHours = new SqlCommand(CompletedHours, con); //The userID is gotte GetCompletedHours.Parameters.AddWithValue("@NewUser", EmailTextbox.Text); GetCompletedHours.Parameters.AddWithValue("@NewFirstName", newFirstName); GetCompletedHours.Parameters.AddWithValue("@NewLastName", newLastName); GetCompletedHours.Parameters.AddWithValue("@WeekOfMonth", WeekOfMonth); GetCompletedHours.Parameters.AddWithValue("@WeekOfYear", GetWeekOfMonth.GetWeekOfYear(DateTime.Parse(gvr.Cells[2].Text))); GetCompletedHours.Parameters.AddWithValue("@Month", month); GetCompletedHours.Parameters.AddWithValue("@Year", year); GetCompletedHours.Parameters.AddWithValue("@WeeklyHours", totalHours); GetCompletedHours.Parameters.AddWithValue("@StartTime", dt); GetCompletedHours.Parameters.AddWithValue("@EndTime", dt1); GetCompletedHours.Parameters.AddWithValue("@Room", GetRoomId(gvr.Cells[3].Text)); GetCompletedHours.Parameters.AddWithValue("@CurrentUser", User.Identity.GetUserId()); GetCompletedHours.Parameters.AddWithValue("@FirstName", firstName); GetCompletedHours.Parameters.AddWithValue("@LastName", lastName); SqlDataReader addHoursReader = GetCompletedHours.ExecuteReader(); manager.SendEmail(EmailTextbox.Text, "Facilitation Hours Recieved", newFirstName + " " + newLastName + " has recieved " + totalHours + " hours from " + User.Identity.GetUserId() + " (" + firstName + " " + lastName + ")" + " for the month of " + CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(Int32.Parse(month)) + "!"); Response.Redirect(Request.RawUrl); }
//Confirm button on completed hours grid protected void ConfirmButton(object sender, System.EventArgs e) { //Grid row number int num = gvr.RowIndex; int WeekOfMonth = GetWeekOfMonth.GetWeekNumberOfMonth(Convert.ToDateTime(gvr.Cells[2].Text)); string[] name; string firstName; string lastName; string startTime; string endTime; string[] startDate; string[] endDate; string[] array; string month; string year; string day; int hour; int min; DateTime calendarStart = Convert.ToDateTime(gvr.Cells[1].Text); DateTime calendarEnd = Convert.ToDateTime(gvr.Cells[2].Text); name = gvr.Cells[0].Text.Split(' '); firstName = name[0]; lastName = name[1]; startDate = gvr.Cells[1].Text.Split(' '); startTime = startTimeTextBox.Text; endDate = gvr.Cells[2].Text.Split(' '); endTime = endTimeTextBox.Text; //fixes the case where time is split on "-" or "/" if (endDate[0].Contains('-')) { array = endDate[0].Split('-'); month = array[1]; year = array[0]; day = array[2]; } else { array = endDate[0].Split('/'); month = array[0]; day = array[1]; if (array[2].Length == 2) { year = "20" + array[2]; } else { year = array[2]; } } array = startTimeTextBox.Text.Split(':'); hour = Convert.ToInt32(array[0]); min = Convert.ToInt32(array[1]); DateTime dt = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day), hour, min, 0); System.Diagnostics.Debug.WriteLine(dt.ToString()); array = endTimeTextBox.Text.Split(':'); hour = Convert.ToInt32(array[0]); min = Convert.ToInt32(array[1]); DateTime dt1 = new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day), hour, min, 0); System.Diagnostics.Debug.WriteLine(dt1.ToString()); float totalHours = (float)(dt1 - dt).TotalHours; //Checks if the timeslot is the lunch hour and gives double time if it is if ((TimeSpan.Compare(dt.TimeOfDay, new TimeSpan(12, 0, 0)) == 0 || TimeSpan.Compare(dt.TimeOfDay, new TimeSpan(12, 0, 0)) == -1) && (TimeSpan.Compare(dt1.TimeOfDay, new TimeSpan(13, 0, 0)) == 0 || TimeSpan.Compare(dt1.TimeOfDay, new TimeSpan(13, 0, 0)) == 1)) { //Look for Field Trips (Only double time for lunch on regular days) SqlConnection fieldTripCheck = new SqlConnection { ConnectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString() }; SqlDataAdapter adapter = new SqlDataAdapter(); fieldTripCheck.Open(); SqlDataAdapter getFieldTrips = new SqlDataAdapter("Select Location From FieldTrips where CONVERT(DATE, StartTime) = @CurrentDate", ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); getFieldTrips.SelectCommand.Parameters.AddWithValue("@CurrentDate", dt.Date); DataTable table = new DataTable(); getFieldTrips.Fill(table); //If not a fieldtrip give double time for lunch hour if (table.Rows.Count == 0) { totalHours += 1; } fieldTripCheck.Close(); } SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString); con.Open(); string CompletedHours = ("INSERT INTO Stats (Id, FacilitatorFirstName, FacilitatorLastName, RoomId, " + "WeekOfMonth, WeekOfYear, Month, Year, WeeklyHours, Donate) VALUES (@CurrentUser, @FirstName, " + "@LastName, @Room, @WeekOfMonth, @WeekOfYear, @Month, @Year, @WeeklyHours, @Donate); " + "DELETE FROM Calendar WHERE Id = @CurrentUser and FacilitatorFirstName = @FirstName and FacilitatorLastName = @LastName " + "and StartTime = @StartTime and EndTime = @EndTime and RoomId = @Room"); SqlCommand GetCompletedHours = new SqlCommand(CompletedHours, con); GetCompletedHours.Parameters.AddWithValue("@CurrentUser", User.Identity.GetUserId()); GetCompletedHours.Parameters.AddWithValue("@FirstName", firstName); GetCompletedHours.Parameters.AddWithValue("@LastName", lastName); GetCompletedHours.Parameters.AddWithValue("@WeekOfMonth", WeekOfMonth); GetCompletedHours.Parameters.AddWithValue("@WeekOfYear", GetWeekOfMonth.GetWeekOfYear(DateTime.Parse(gvr.Cells[2].Text))); GetCompletedHours.Parameters.AddWithValue("@Month", month); GetCompletedHours.Parameters.AddWithValue("@Year", year); GetCompletedHours.Parameters.AddWithValue("@WeeklyHours", totalHours); GetCompletedHours.Parameters.AddWithValue("@StartTime", calendarStart); GetCompletedHours.Parameters.AddWithValue("@EndTime", calendarEnd); GetCompletedHours.Parameters.AddWithValue("@Donate", ""); GetCompletedHours.Parameters.AddWithValue("@Room", GetRoomId(gvr.Cells[3].Text)); SqlDataReader addHoursReader = GetCompletedHours.ExecuteReader(); //Page_Load(null, EventArgs.Empty); Response.Redirect(Request.RawUrl); }