protected void Page_Load(object sender, EventArgs e) { //setting a user instance based on query string or session variable if (Request.QueryString["id"] != null) { student = Membership.GetUser(Request.QueryString["id"].ToString()); } else { student = Membership.GetUser(User.Identity.Name); } studentId = (Guid)student.ProviderUserKey; string connection = ConfigurationManager.ConnectionStrings["EIMSConnectionString"].ConnectionString; sqlcon = new SqlConnection(connection); if (!IsPostBack) { string userName; //setting the userName variable based on query string or user name value in the session if (Request.QueryString["id"] != null) { userName = Request.QueryString["id"].ToString(); } else { userName = User.Identity.Name; } //iterating through the data view and setting the fields in the form StudentUserName.Text = userName; DataView dvSql = (DataView)StudentDataSource.Select(DataSourceSelectArguments.Empty); foreach (DataRowView drvSql in dvSql) { StudentName.Text = drvSql["Name"].ToString(); StudentDepartment.Text = drvSql["DepartmentName"].ToString(); StudentBatch.Text = drvSql["BatchName"].ToString(); StudentContact.Text = drvSql["Contact"].ToString(); StudentRollNum.Text = drvSql["RollNo"].ToString(); StudentEmail.Text = drvSql["Email"].ToString(); if (drvSql["Avatar"].ToString() != "") { UserPicture.ImageUrl = drvSql["Avatar"].ToString(); } } //iterating through the parent association data view to show the parent if found DataView dvSql2 = (DataView)AssociationDataSource.Select(DataSourceSelectArguments.Empty); foreach (DataRowView drvSql in dvSql2) { //checking if a record is present in the data view, then show the associated parent if (drvSql["ParentId"].ToString() != "") { ShowAssociationPanel.Visible = true; CreateAssociationPanel.Visible = false; AssociationMessage.Text = "You have a parent account"; parent = Membership.GetUser(drvSql["ParentId"]); ParentLink.NavigateUrl = "~/Shared/ParentProfile.aspx?id=" + parent.UserName.ToString(); ParentLink.Text = parent.Email + "(" + parent.UserName + ")"; } } } }
protected void btnInsert_Click(object sender, ImageClickEventArgs e) { if (Request.QueryString["id"] != null) { TextBox TotalClasses = (TextBox)gvCrud.FooterRow.FindControl("TotalClassesInsert"); DropDownList AttendanceWeek = (DropDownList)gvCrud.FooterRow.FindControl("AttendanceWeekSelect"); TextBox ClassesAttended = (TextBox)gvCrud.FooterRow.FindControl("ClassesAttendedInsert"); TextBox ClassesMissed = (TextBox)gvCrud.FooterRow.FindControl("ClassesMissedInsert"); float attendancePercentage = (Convert.ToSingle(ClassesAttended.Text) / Convert.ToSingle(TotalClasses.Text)) * 100; sqlcon.Open(); using (sqlcom = new SqlCommand("insert into attendance values(@Week,@StudentId,@SemesterId,@TotalClasses,@ClassesAttended,@ClassesMissed,@AttendancePercentage)", sqlcon)) { sqlcom.CommandType = CommandType.Text; sqlcom.Parameters.AddWithValue("@Week", AttendanceWeek.SelectedValue); sqlcom.Parameters.AddWithValue("@StudentId", studentId); //TODO semester ID from drop down sqlcom.Parameters.AddWithValue("@SemesterId", 8); sqlcom.Parameters.AddWithValue("@TotalClasses", TotalClasses.Text); sqlcom.Parameters.AddWithValue("@ClassesAttended", ClassesAttended.Text); sqlcom.Parameters.AddWithValue("@ClassesMissed", ClassesMissed.Text); sqlcom.Parameters.AddWithValue("@AttendancePercentage", attendancePercentage); int rows = sqlcom.ExecuteNonQuery(); if (rows > 0) { DataView dvSql2 = (DataView)AssociationDataSource.Select(DataSourceSelectArguments.Empty); foreach (DataRowView drvSql in dvSql2) { //checking if a record is present in the data view, then show the associated parent if (drvSql["ParentId"].ToString() != "") { parent = Membership.GetUser(drvSql["ParentId"]); //Email EimsHelper.SendMail(parent.Email, "EIMS Notification: Child Attendance Added.", "Hi Mr./Miss " + parent.UserName + ".\nYour child has a new attendance record. Take a look at the details:\nAttendance Week: " + AttendanceWeek.Text + " \nTotal Classes: " + TotalClasses.Text + "\nClasses Attended: " + ClassesAttended.Text + "\nClasses Missed: " + ClassesMissed.Text + "\nAttendance Percentage: " + attendancePercentage + "\nFor further information and reports you can always login to the EIMS with credentials you have been provided."); EimsHelper.SendMail(student.Email, "EIMS Notification: Child Attendance Added.", "Dear " + student.UserName + ".\nA new attendance record has been added to your profile and an email notification has been sent to your parent/guardian's email account. Take a look at the details:\nAttendance Week: " + AttendanceWeek.Text + " \nTotal Classes: " + TotalClasses.Text + "\nClasses Attended: " + ClassesAttended.Text + "\nClasses Missed: " + ClassesMissed.Text + "\nAttendance Percentage: " + attendancePercentage + "\nFor further information and reports you can always login to the EIMS with credentials you have been provided."); Session["Notice"] = "Attendance record has been added and Email has been sent to parent/guardian and the student!"; Response.Redirect("~/shared/StudentProfile.aspx?id=" + Request.QueryString["id"]); } } EimsHelper.SendMail(student.Email, "EIMS Notification: Child Attendance Added.", "Dear " + student.UserName + ".\nA new attendance record has been added to your profile and an email notification has been sent to your parent/guardian's email account. Take a look at the details:\nAttendance Week: " + AttendanceWeek.Text + " \nTotal Classes: " + TotalClasses.Text + "\nClasses Attended: " + ClassesAttended.Text + "\nClasses Missed: " + ClassesMissed.Text + "\nAttendance Percentage: " + attendancePercentage + "\nFor further information and reports you can always login to the EIMS with credentials you have been provided."); Session["Notice"] = "Attendance record has been added and Email has been sent to the student only because no guardian could be found!"; Response.Redirect("~/shared/StudentProfile.aspx?id=" + Request.QueryString["id"]); BindGrid(); } } } }
protected void Page_Load(object sender, EventArgs e) { // Display Picture Code if (Page.User.Identity.IsAuthenticated && !Page.User.IsInRole("Administrator")) { Image UserPic = LoginView1.FindControl("UserPicture") as Image; string strConn = ConfigurationManager.ConnectionStrings["EIMSConnectionString"].ConnectionString; using (SqlConnection conn = new SqlConnection(strConn)) { MembershipUser user = Membership.GetUser(Page.User.Identity.Name); Guid userId = (Guid)user.ProviderUserKey; conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; string avatarQuery; if (Page.User.IsInRole("Student")) { DataView dvSql2 = (DataView)AssociationDataSource.Select(DataSourceSelectArguments.Empty); foreach (DataRowView drvSql in dvSql2) { //checking if a record is present in the data view, then show the associated parent if (drvSql["ParentId"].ToString() != "") { MembershipUser parent = Membership.GetUser(drvSql["ParentId"]); HyperLink ParentLinkMaster = LoginView3.FindControl("ParentLinkMaster") as HyperLink; ParentLinkMaster.NavigateUrl = "~/Shared/ParentProfile.aspx?id=" + parent.UserName.ToString(); //ParentLink.Text = parent.Email + "(" + parent.UserName + ")"; } else { HyperLink ParentLinkMaster = LoginView3.FindControl("ParentLinkMaster") as HyperLink; ParentLinkMaster.NavigateUrl = "~/Shared/ParentProfile.aspx?id=NPF"; } } avatarQuery = "select StudentProfiles.Avatar from StudentProfiles where StudentProfiles.StudentId=@StudentId"; cmd.CommandText = avatarQuery; cmd.Parameters.AddWithValue("@StudentId", userId); } else if (Page.User.IsInRole("Teacher")) { avatarQuery = "select TeacherProfiles.Avatar from TeacherProfiles where TeacherProfiles.TeacherId=@TeacherId"; cmd.CommandText = avatarQuery; cmd.Parameters.AddWithValue("@TeacherId", userId); } else { avatarQuery = "select ParentProfiles.Avatar from ParentProfiles where ParentProfiles.ParentId=@ParentId"; cmd.CommandText = avatarQuery; cmd.Parameters.AddWithValue("@ParentId", userId); } SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { if (dr["Avatar"].ToString() != "") { UserPic.ImageUrl = dr["Avatar"].ToString(); } } } } // Display Picture Code SuccessMessages.Visible = false; if (Session["Notice"] == null) { SuccessMessages.Visible = false; } else { SuccessMessages.Visible = true; SuccessMessage.Text = Session["Notice"].ToString(); Session.Remove("Notice"); } ErrorMessages.Visible = false; if (Session["Error"] == null) { ErrorMessages.Visible = false; } else { ErrorMessages.Visible = true; ErrorMessage.Text = Session["Error"].ToString(); Session.Remove("Error"); } }