protected void Page_Load(object sender, EventArgs e) { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated && !SessionManager.CheckNull()) { DataHandler db = new DataHandler(); using (db.Connect()) { String FirstName; String LastName; db.Command("SELECT f_name, l_name FROM Student WHERE student_id = @student_id", false); db.Add("@student_id", Request["Id"]); db.Start(); SqlDataReader reader = db.Exec(); reader.Read(); FirstName = reader.GetString(0); LastName = reader.GetString(1); lblName.Text = FirstName + " " + LastName; db.Stop(); } } }
protected void CreateNewUser(object sender, EventArgs e) { DataHandler db = new DataHandler(); using (db.Connect()) { db.Command("UserExists", true); db.Add("@username", UserName.Text); db.AddIntReturn(); db.Start(); db.ExecNonQuery(); db.Stop(); int result; result = db.ReturnValue(); if (result == 0) { db.Start(); db.Command("INSERT INTO Instructor (f_name, l_name, login, password) VALUES (@fname, @lname, @login, @pass)", false); db.Add("@fname", FirstName.Text); db.Add("@lname", LastName.Text); db.Add("@login", UserName.Text); db.Add("@pass", Password.Text); db.ExecNonQuery(); db.Stop(); lblComplete.Text = "Registration is complete."; lblComplete.Visible = true; } else { lblComplete.Text = "This user already exists."; lblComplete.Visible = true; } } }
protected void AddAssignment(object sender, EventArgs e) { DataHandler db = new DataHandler(); using (db.Connect()) { int result; int finalized; db.Command("CheckTagSystem", true); db.Add("@course_id", SessionManager.Course.ID); db.AddIntReturn(); db.Start(); db.ExecNonQuery(); result = db.ReturnValue(); db.Command("CheckFinalized", true); db.Add("@course_id", SessionManager.Course.ID); db.AddIntReturn(); db.ExecNonQuery(); finalized = db.ReturnValue(); if (result != 1) { lblError.Text = "Grading System unbalanced. Could cause inaccurate reporting. Ensure total weights add up to 100%"; lblError.Visible = true; } else if(finalized != 1) { lblError.Text = "Roster has not been finalized yet"; lblError.Visible = true; } else { lblError.Visible = false; db.Command("CreateNewAssignment", true); db.Add("@course_id", SessionManager.Course.ID); db.Add("@assignment_name", txtAssgnName.Text); db.Add("@tag_id", drpTypeList.SelectedValue); db.Add("@instructor_id", SessionManager.Instructor.ID); db.ExecNonQuery(); db.Stop(); Response.Redirect(Request.RawUrl); } } }
protected void FinalizeRoster(object sender, EventArgs e) { DataHandler db = new DataHandler(); using (db.Connect()) { db.Command("FinalizeRoster", true); db.Add("@course_id", SessionManager.Course.ID); db.Start(); db.ExecNonQuery(); db.Stop(); Response.Redirect(Request.RawUrl); } }
protected void LoginBox_Authenticate(object sender, AuthenticateEventArgs e) { DataHandler db = new DataHandler(); Instructor instructor = new Instructor(); e.Authenticated = false; using (db.Connect()) { int result; db.Command("Login", true); db.Add("@username", LoginBox.UserName); db.Add("@password", LoginBox.Password); db.AddIntReturn(); db.Start(); db.ExecNonQuery(); result = db.ReturnValue(); if (result > 0) { db.Command("CollectSessionInfoInstructor", true); db.Add("@username", LoginBox.UserName); SqlDataReader reader = db.Exec(); reader.Read(); //read the record, advance the cursor, etc. e.Authenticated = true; FormsAuthentication.RedirectFromLoginPage(LoginBox.UserName, true); instructor.UserName = LoginBox.UserName; instructor.ID = reader.GetInt32(0); //Encapsulate my Session information for later use instructor.FirstName = reader.GetString(1); instructor.LastName = reader.GetString(2); SessionManager.Instructor = instructor; } else { e.Authenticated = false; } db.Stop(); } }
protected void AddType(object sender, EventArgs e) { DataHandler db = new DataHandler(); int weight = int.Parse(txtTagWeight.Text); using (db.Connect()) { db.Command("INSERT INTO Tag (tag_type, tag_weight, course_id) VALUES (@tag_type, CONVERT(DECIMAL(16,2), @tag_weight/100.0), @course_id)", false); db.Add("@tag_type", txtTagName.Text); db.Add("@tag_weight", weight); db.Add("@course_id", SessionManager.Course.ID); db.Start(); db.ExecNonQuery(); db.Stop(); } Response.Redirect(Request.RawUrl); }
protected void AddStudent(object sender, EventArgs e) { DataHandler db = new DataHandler(); using (db.Connect()) { db.Command("AddNewStudent", true); db.Add("@f_name", txtFirstName.Text); db.Add("@l_name", txtLastName.Text); db.Add("@instructor_id", SessionManager.Instructor.ID); db.Add("@course_id", SessionManager.Course.ID); db.Start(); db.ExecNonQuery(); db.Stop(); } Response.Redirect(Request.RawUrl); }
protected void AddCourse(object sender, EventArgs e) { DataHandler db = new DataHandler(); using (db.Connect()) { db.Command("INSERT INTO Course (course_name, start_date, end_date, instructor_id) VALUES (@c_name, @start_date, @end_date, @id)", false); db.Add("@c_name", txtCourseEntry.Text); db.Add("@start_date", txtStartDate.Text); db.Add("@end_date", txtEndDate.Text); db.Add("@id", SessionManager.Instructor.ID); db.Start(); db.ExecNonQuery(); db.Stop(); } Response.Redirect(Request.RawUrl); }
protected void Page_Load(object sender, EventArgs e) { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { if (!IsPostBack) { lblCourseName.Text = SessionManager.Course.Name; DataHandler db = new DataHandler(); using (db.Connect()) { int finalized; db.Command("ListStudentsForCourse", true); db.Add("@course_id", SessionManager.Course.ID); db.Start(); rptStudents.DataSource = db.Exec(); rptStudents.DataBind(); db.Stop(); //Close the already used datareader db.Command("CheckFinalized", true); db.Add("@course_id", SessionManager.Course.ID); db.AddIntReturn(); db.Start(); db.ExecNonQuery(); finalized = db.ReturnValue(); if (finalized != 0) { lnkAdd.Visible = false; lblFinalized.Visible = true; lnkFinalize.Visible = false; } db.Stop(); } } } }
protected void Page_Load(object sender, EventArgs e) { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated && !SessionManager.CheckNull()) { if (!IsPostBack) { DataHandler db = new DataHandler(); lblInstructorName.Text = SessionManager.Instructor.FirstName + " " + SessionManager.Instructor.LastName; using (db.Connect()) { db.Command("ReturnInstructorCourses", true); db.Add("@instructor_id", SessionManager.Instructor.ID); db.Start(); rptCourses.DataSource = db.Exec(); rptCourses.DataBind(); db.Stop(); } } } }
protected void Page_Load(object sender, EventArgs e) { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { Courses course = new Courses(); DataHandler db = new DataHandler(); string Id = Request["Id"]; using (db.Connect()) { db.Command("SELECT course_name, start_date, end_date FROM Course WHERE course_id = @id", false); db.Add("@id", Id); db.Start(); SqlDataReader reader = db.Exec(); reader.Read(); //Collect this information for sessions course.ID = Convert.ToInt32(Id); course.Name = reader.GetString(0); course.StartDate = reader.GetDateTime(1); course.EndDate = reader.GetDateTime(2); SessionManager.Course = course; //Done lblCourseName.Text = reader.GetString(0); db.Stop(); //Right here I will append the ID to the ends of the navigation URLs lnkCourse.NavigateUrl += Id; lnkGrading.NavigateUrl += Id; lnkReport.NavigateUrl += Id; lnkStudents.NavigateUrl += Id; } } }
protected void ExportGradeSheet(object sender, EventArgs e) { DataHandler db = new DataHandler(); using (db.Connect()) { db.Command("ListAllCourseAndGradesForInstructor", true); db.Add("@instructor_id", SessionManager.Instructor.ID); db.Start(); SqlDataReader reader = db.Exec(); SpreadSheetExport excelExport = new SpreadSheetExport(); excelExport.CreateSpreadSheet(); //These values will keep track of the utilized Assignments and Students string prevCourse = ""; string prevAssignment = ""; string prevStudent = ""; //Will use these values to keep track of where I'm placing values string student_column = "A"; //This shouldn't change uint student_row_value = 2; string assign_column = "B"; uint assgn_row_value = 1; //This shouldn't change. //I will only increment student_row_value and assign_column when new fields are added //---------------------------------------------------------------- OrderedDictionary trackedReferences = new OrderedDictionary(); //My current strategy to solve the issue of keeping track which Student and Assignment is what and where to place //the associated grade is to keep track of said Student and Assignment in an associative array. As I come across each //Student or assignment I will store thier col and row values in the array. Once I come across said Student or Assignment //Again I will reference it and use that value to put them in their rightful place. if (reader.HasRows) { while (reader.Read()) { string currentCourse = reader["course_name"].ToString(); string currentStudent = reader["student_name"].ToString(); string currentAssignment = reader["assignment_name"].ToString(); string currentAssignmentGrade = reader["assignment_grade"].ToString(); //This section determines whether we have a new Course to add or not if (!prevCourse.Equals(currentCourse) && !prevCourse.Equals("")) //We found a new Course name and it's not the first sheet { excelExport.AddWorkSheet(currentCourse); student_row_value = 2; assign_column = "B"; //Reset these values back to thier defaults since we're going to be using a new sheet } else if (prevCourse.Equals("")) //This means our first runthrough. We're going to need the name of this course now { prevCourse = currentCourse; excelExport.AddWorkSheet(currentCourse); } //We've come across a different assignment but we've seen it before AND not a new student //if (!prevAssignment.Equals(reader["assignment_name"].ToString()) && // (trackedReferences.Contains(reader["assignment_name"].ToString()) && trackedReferences.Contains(reader["student_name"].ToString()))) if (trackedReferences.Contains(currentStudent) && trackedReferences.Contains(currentAssignment)) { excelExport.InsertTextInCell(currentAssignmentGrade, trackedReferences[currentAssignment].ToString(), (uint)trackedReferences[currentStudent], currentCourse); } //New assignment and haven't added it before and existing student else if ((!prevAssignment.Equals(currentAssignment) && !trackedReferences.Contains(currentAssignment)) && trackedReferences.Contains(currentStudent)) { excelExport.InsertTextInCell(currentAssignment, assign_column, assgn_row_value, currentCourse); trackedReferences.Add(currentAssignment, assign_column); excelExport.InsertTextInCell(currentAssignmentGrade, assign_column, (uint)trackedReferences[currentStudent], currentCourse); assign_column = excelExport.IncrementColRef(assign_column); } //New student found but not assignment else if ((!prevStudent.Equals(currentStudent) && !trackedReferences.Contains(currentStudent)) && trackedReferences.Contains(currentAssignment)) { excelExport.InsertTextInCell(currentStudent, student_column, student_row_value, currentCourse); trackedReferences.Add(currentStudent, student_row_value); excelExport.InsertTextInCell(currentAssignmentGrade, trackedReferences[currentAssignment].ToString(), student_row_value, currentCourse); student_row_value++; } else if((!trackedReferences.Contains(currentStudent) && !trackedReferences.Contains(currentAssignment)) || (prevAssignment.Equals("") && prevStudent.Equals(""))) //This appears to be a new student and assignment. Add it and place in dictionary { excelExport.InsertTextInCell(currentStudent, student_column, student_row_value, currentCourse); trackedReferences.Add(currentStudent, student_row_value); excelExport.InsertTextInCell(currentAssignment, assign_column, assgn_row_value, currentCourse); trackedReferences.Add(currentAssignment, assign_column); excelExport.InsertTextInCell(currentAssignmentGrade, assign_column, student_row_value, currentCourse); student_row_value++; assign_column = excelExport.IncrementColRef(assign_column); } //This may look weird, but I'm doing this to capture the previous value in this variable because on next iration the real current values will be captured prevCourse = currentCourse; prevAssignment = currentAssignment; prevStudent = currentStudent; } } excelExport.ExcelToResponse(); db.Stop(); } }
protected void Page_Load(object sender, EventArgs e) { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { lblError.Visible = false; if (!IsPostBack) { lblCourseName.Text = SessionManager.Course.Name; DataHandler db = new DataHandler(); using (db.Connect()) { db.Command("ListCourseAssignments", true); db.Add("@course_id", SessionManager.Course.ID); db.Start(); rptAssignments.DataSource = db.Exec(); rptAssignments.DataBind(); db.Stop(); } } } }