private void BindClassDropDown(DropDownList ddl) { ddl.DataSource = CCMSBusinessLayer.GetClass(); ddl.DataValueField = "classid"; ddl.DataTextField = "Class"; ddl.DataBind(); ddl.Items.Insert(0, new ListItem("Select Class", "-1")); }
protected void btnUpgrade_Click(object sender, EventArgs e) { rvfClassFrom.Enabled = true; Page.Validate(); if (Page.IsValid) { int affectedRows = 0; affectedRows = CCMSBusinessLayer.UpgradeStudentClass(Convert.ToInt32(ddlFrom.SelectedValue), Convert.ToInt32(ddlTo.SelectedValue)); lblsuccssMsg.Text = affectedRows + " Student records were upgraded Sussfully"; lblsuccssMsg.Visible = true; } }
protected void RoutineAddBtn_Click(object sender, EventArgs e) { RFV_ClassList.Enabled = true; RFV_FacultyList.Enabled = true; //RFV_section_drp.Enabled = true; RFV_Semester_drp.Enabled = true; RFV_subjectlist_drp.Enabled = true; RFV_YearList.Enabled = true; Page.Validate(); if (Page.IsValid) { if (ClassList.SelectedIndex != 0 && FacultyList.SelectedIndex != 0 && Semester_drp.SelectedIndex != 0 && subjectlist_drp.SelectedIndex != 0 && YearList.SelectedIndex != 0) { Routine routine = new Routine { Fid = Convert.ToInt16(FacultyList.SelectedValue), ClassId = Convert.ToInt16(ClassList.SelectedValue), EnrollYear = YearList.SelectedItem.Text, Semester = Semester_drp.SelectedItem.Text, SubjectID = subjectlist_drp.SelectedItem.Value, SectionName = section_drp.SelectedItem.Text }; int added = CCMSBusinessLayer.AddRoutine(routine); if (added > 0) { ScriptManager.RegisterStartupScript(this, GetType(), "Success !! ", "alert('Routine details has been added.');", true); } connectionString = ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString; string sqlQuery = "Select routine.routineId, Users.FirstName + ' ' +Users.LastName as FacultyName, class.ClassName, routine.SectionName, Syllabus.Subject_Name from routine " + "inner join Users on routine.Fid = Users.UserID " + "join class on routine.ClassId = class.ClassId " + "join Syllabus on routine.SubjectId=Syllabus.Subject_Code order by Subject_Name;"; using (SqlConnection con = new SqlConnection(connectionString)) { SqlCommand cmd = new SqlCommand(sqlQuery, con); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); RoutineGridView.DataSource = rdr; RoutineGridView.DataBind(); } } clear(); } }
protected void addBtn_Click(object sender, EventArgs e) { AFD_firstname.Enabled = true; AFD_lastname.Enabled = true; AFD_email.Enabled = true; NumberValidation.Enabled = true; Page.Validate(); if (Page.IsValid) { if (firstName.Text != "" && lastName.Text != "" && EmailList.SelectedIndex != 0) { Faculty faculty = new Faculty { Active = activeCB.Checked, Contact = contact.Text, //Email = txtEmail.Text, Email = EmailList.SelectedItem.Text, LastName = lastName.Text, FirstName = firstName.Text, UserId = findUserID(EmailList.SelectedValue) }; int added = CCMSBusinessLayer.AddFaculty(faculty); if (added > 0) { ScriptManager.RegisterStartupScript(this, GetType(), "Success", "alert('Faculty detail is successfully recorded.');", true); //string connectionString = ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString; //string sqlQuery = "select * from faculty"; //using (SqlConnection con = new SqlConnection(connectionString)) //{ // SqlCommand cmd = new SqlCommand(sqlQuery, con); // con.Open(); // SqlDataReader rdr = cmd.ExecuteReader(); // FacultyGridView.DataSource = rdr; // FacultyGridView.DataBind(); //} //ContentPlaceHolder mcon = new ContentPlaceHolder(); //mcon = (ContentPlaceHolder)Master.FindControl("pageContent2"); //mcon.Visible = true; Reset(); } } } }
private static string hashPassword(string pass) { var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random(); var result = new string(Enumerable.Repeat(chars, 32).Select(s => s[random.Next(s.Length)]).ToArray()); CCMSBusinessLayer md = new CCMSBusinessLayer(); string hash = ""; string source = pass + result; using (MD5 md5Hash = MD5.Create()) { hash = md.getMd5Hash(md5Hash, source); } string combinedPassword = hash + ":" + result; return(combinedPassword); }
private void loadGrid() { CCMSBusinessLayer cb = new CCMSBusinessLayer(); if (Convert.ToInt32(facultyV.Text) == 0 && Convert.ToInt32(studentV.Text) != 0) { DataTable allTeacherSingleStudent = new DataTable(); allTeacherSingleStudent = cb.displayAllStudentsRecord(Convert.ToInt32(facultyV.Text), Convert.ToInt32(studentV.Text), startDate.Text, endDate.Text); reportGrid.Visible = true; reportGrid.DataSource = allTeacherSingleStudent; reportGrid.DataBind(); checkDateFilledOrNot(Convert.ToInt32(facultyV.Text), Convert.ToInt32(studentV.Text)); } else if (Convert.ToInt32(facultyV.Text) != 0 && Convert.ToInt32(studentV.Text) != 0) { DataTable studentClassMiss = new DataTable(); studentClassMiss = cb.GetStudentClassMiss(Convert.ToInt32(facultyV.Text), Convert.ToInt32(studentV.Text), startDate.Text, endDate.Text); reportGrid.Visible = true; reportGrid.DataSource = studentClassMiss; reportGrid.DataBind(); checkDateFilledOrNot(Convert.ToInt32(facultyV.Text), Convert.ToInt32(studentV.Text)); } else if (Convert.ToInt32(facultyV.Text) != 0 && Convert.ToInt32(studentV.Text) == 0) { DataTable singleTeacherAllStudent = new DataTable(); singleTeacherAllStudent = cb.displayOneTeacherAllStudentsRecord(Convert.ToInt32(facultyV.Text), Convert.ToInt32(studentV.Text), startDate.Text, endDate.Text); reportGrid.Visible = true; reportGrid.DataSource = singleTeacherAllStudent; reportGrid.DataBind(); checkDateFilledOrNot(Convert.ToInt32(facultyV.Text), Convert.ToInt32(studentV.Text)); } else if (Convert.ToInt32(facultyV.Text) == 0 && Convert.ToInt32(studentV.Text) == 0) { DataTable allTeacherAllStudent = new DataTable(); allTeacherAllStudent = cb.displayallTeacherAllStudentsRecord(Convert.ToInt32(facultyV.Text), Convert.ToInt32(studentV.Text), startDate.Text, endDate.Text); reportGrid.Visible = true; reportGrid.DataSource = allTeacherAllStudent; reportGrid.DataBind(); checkDateFilledOrNot(Convert.ToInt32(facultyV.Text), Convert.ToInt32(studentV.Text)); } }
public int findUserID(string email) { return(CCMSBusinessLayer.FindUserIdfromEmail(email)); }
protected void UserLogin(object sender, EventArgs e) { String cmdStr = null; string concatenateDomain = "@deerwalk.edu.np"; SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString); //check whether the username contains @deerwalk.edu.np if (txtUserName.Text.Contains('@')) { cmdStr = "select UserId from Users where userEmail = '" + txtUserName.Text + "'"; } else { cmdStr = "select UserId from Users where userEmail = '" + txtUserName.Text + concatenateDomain + "'"; } SqlCommand CheckUser = new SqlCommand(cmdStr, con); con.Open(); object UserID = CheckUser.ExecuteScalar(); if (UserID != null) { if (Convert.ToInt32(UserID.ToString()) >= 1) { String cmdStr2 = "select password,Role,isPasswordUpdated from Users where UserId = " + UserID; SqlCommand pass = new SqlCommand(cmdStr2, con); SqlDataAdapter sqlAdapter = new SqlDataAdapter(); DataTable userDetail = new DataTable(); sqlAdapter.SelectCommand = pass; sqlAdapter.Fill(userDetail); CCMSBusinessLayer md = new CCMSBusinessLayer(); if (userDetail.Rows.Count > 0) { string inputPass = txtPassword.Text; string hash; string password = userDetail.Rows[0][0].ToString(); string isPasswordUpdated = userDetail.Rows[0][2].ToString(); if (password.Contains(':')) { string[] passSplit = password.Split(':'); string hashValue = passSplit[0]; string saltValue = passSplit[1]; string pass_salt = txtPassword.Text + saltValue; using (MD5 md5Hash = MD5.Create()) { hash = md.getMd5Hash(md5Hash, pass_salt); } if (hashValue == hash) { Session["UserId"] = UserID; Session["Role"] = userDetail.Rows[0][1].ToString(); Session["isPasswordUpdated"] = userDetail.Rows[0][2].ToString(); Session["password"] = txtPassword.Text; if (isPasswordUpdated.Equals("")) { Panel p = (Panel)Master.FindControl("menubar"); p.Visible = false; ContentPlaceHolder cp = (ContentPlaceHolder)Master.FindControl("menu"); cp.Visible = false; ContentPlaceHolder cpuser = (ContentPlaceHolder)Master.FindControl("menuuser"); cpuser.Visible = false; Response.Redirect("FirstLoginPasswordChange.aspx"); } else { Response.Redirect("TimeEntry.aspx"); } } else { lblMessage.Visible = true; lblMessage.ForeColor = Color.Red; lblMessage.Text = "Invalid password .........!!"; } } else { if (password == txtPassword.Text) { Session["UserId"] = UserID; Session["Role"] = userDetail.Rows[0][1].ToString(); Session["isPasswordUpdated"] = userDetail.Rows[0][2].ToString(); Session["password"] = txtPassword.Text; if (isPasswordUpdated.Equals("False")) { Response.Redirect("FirstLoginPasswordChange.aspx"); } else { Response.Redirect("TimeEntry.aspx"); } } else { lblMessage.Visible = true; lblMessage.ForeColor = Color.Red; lblMessage.Text = "Invalid password .........!!"; } } con.Close(); } else { lblMessage.Visible = true; lblMessage.ForeColor = Color.Red; lblMessage.Text = "Invalid userName.....!!"; } } } }
public void updatePassword(Object sender, EventArgs e) { if (!string.IsNullOrEmpty(originalPassword.Text) && !string.IsNullOrEmpty(newPassword.Text) && !string.IsNullOrEmpty(confirmedPassword.Text)) { if (originalPassword.Text != Session["password"].ToString()) { lblMessage.Visible = true; lblMessage.Text = "Original Password entry incorrect."; } else if (!Regex.Equals(confirmedPassword.Text, newPassword.Text)) { lblMessage.Visible = true; lblMessage.Text = "Password doesnot match."; } else { var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; var random = new Random(); var result = new string(Enumerable.Repeat(chars, 32).Select(s => s[random.Next(s.Length)]).ToArray()); CCMSBusinessLayer md = new CCMSBusinessLayer(); string hash = ""; string source = confirmedPassword.Text + result; using (MD5 md5Hash = MD5.Create()) { hash = md.getMd5Hash(md5Hash, source); } string combinedPassword = hash + ":" + result; CreateConnection(); cmd = new SqlCommand(); cmd.Connection = conDatabase; cmd.CommandText = "Update users set password = @password,isPasswordUpdated = 'true' where UserID = @User "; cmd.Parameters.AddWithValue("@password", combinedPassword); cmd.Parameters.AddWithValue("@User", Convert.ToInt32(Session["UserId"].ToString())); try { OpenConnection(); int affectedRows = cmd.ExecuteNonQuery(); if (affectedRows > 0) { ContinueAfterPasswordChange(); Session["password"] = confirmedPassword.Text; Session["isPasswordUpdated"] = "true"; } } catch (SqlException ex) { throw ex; } finally { if (conDatabase != null) { conDatabase.Close(); } } } } }
protected void saveAttendance(Object sender, EventArgs e) { //firstly changing the date format to yyyy-MM-dd recordDateV.Text = calendar.SelectedDate.ToShortDateString(); string todayD = DateTime.Now.ToShortDateString(); string convertedDate = null; String format = "yyyy-MM-dd"; if (todayD == userChoosedDate && recordDateV.Text == "1/1/0001") { DateTime dt = Convert.ToDateTime(userChoosedDate); convertedDate = dt.ToString(format); //date converted to format yyyy-MM-dd recordDateV.Text = todayD; } else { DateTime dt = Convert.ToDateTime(recordDateV.Text); convertedDate = dt.ToString(format); //date converted to format yyyy-MM-dd } CreateConnection(); cmd = new SqlCommand(); cmd.CommandText = "select count(AttendanceDate) as counts from studentAttendance where convert(varchar(10) , AttendanceDate, 120) = @changeDate and FacultyClassId =@fid and routineId = @routineId"; cmd.Parameters.AddWithValue("@changeDate", convertedDate); cmd.Parameters.AddWithValue("@fid", facultyClassId); cmd.Parameters.AddWithValue("@routineId", routineId); cmd.Connection = conDatabase; try { OpenConnection(); SqlDataReader sdr = cmd.ExecuteReader(); if (sdr.Read()) { string count = sdr["counts"].ToString();//it will assign O if no values previously in database otherwise assign the exact count int checkCount = Convert.ToInt32(count); if (checkCount > 0) //if count greater than 0 then update otherwise insert to table of database { DateTime scheduledTime = DateTime.Now; DataTable editable = new DataTable(); editable.Columns.Add("RollNo", typeof(int)); editable.Columns.Add("FacultyClassId", typeof(int)); editable.Columns.Add("Attendance", typeof(Boolean)); editable.Columns.Add("AttendanceDate", typeof(DateTime)); editable.Columns.Add("routineid", typeof(int)); DataRow dr = null; foreach (GridViewRow gr in GridView2.Rows) { dr = editable.NewRow(); dr["RollNo"] = gr.Cells[0].Text; dr["FacultyClassId"] = facultyClassId; CheckBox cb = (CheckBox)(gr.Cells[2].FindControl("chkbox")); if (cb.Checked) { dr["Attendance"] = true; } else { dr["Attendance"] = false; } dr["AttendanceDate"] = scheduledTime; dr["routineid"] = routineId; editable.Rows.Add(dr); } DataTable AttendanceTable = editable.GetChanges(DataRowState.Added); string connectionString = ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString; SqlConnection connection = new SqlConnection(connectionString); SqlCommand insertCommand = new SqlCommand("Attendance", connection); insertCommand.Parameters.AddWithValue("@type", "update"); insertCommand.CommandType = CommandType.StoredProcedure; insertCommand.Parameters.AddWithValue("@changeDate", convertedDate); SqlParameter tvpParam = insertCommand.Parameters.AddWithValue("@AttendanceEntries", AttendanceTable); tvpParam.SqlDbType = SqlDbType.Structured; tvpParam.TypeName = "dbo.AttendanceEntryTableType"; try { connection.Open(); int affectedRows = insertCommand.ExecuteNonQuery(); if (affectedRows > 0) { System.Windows.Forms.MessageBox.Show(affectedRows + " entries updated"); } } catch (SqlException ex) { throw ex; } finally { if (connection != null) { connection.Close(); } } } else { DateTime scheduledTime = DateTime.Now; CCMSBusinessLayer objBL = new CCMSBusinessLayer(); DataTable editable = new DataTable(); editable.Columns.Add("RollNo", typeof(int)); editable.Columns.Add("FacultyClassId", typeof(int)); editable.Columns.Add("Attendance", typeof(Boolean)); editable.Columns.Add("AttendanceDate", typeof(DateTime)); editable.Columns.Add("routineid", typeof(int)); DataRow dr = null; foreach (GridViewRow gr in GridView1.Rows) { dr = editable.NewRow(); dr["RollNo"] = gr.Cells[0].Text; dr["FacultyClassId"] = facultyClassId; CheckBox cb = (CheckBox)(gr.Cells[2].FindControl("CheckBoxAttendance")); if (cb.Checked) { dr["Attendance"] = true; } else { dr["Attendance"] = false; } dr["AttendanceDate"] = scheduledTime; dr["routineid"] = routineId; editable.Rows.Add(dr); } DataTable AttendanceTable = editable.GetChanges(DataRowState.Added); string connectionString = ConfigurationManager.ConnectionStrings["dbConnection"].ConnectionString; SqlConnection connection = new SqlConnection(connectionString); SqlCommand insertCommand = new SqlCommand("Attendance", connection); insertCommand.Parameters.AddWithValue("@type", "insert"); insertCommand.CommandType = CommandType.StoredProcedure; SqlParameter tvpParam = insertCommand.Parameters.AddWithValue("@AttendanceEntries", AttendanceTable); tvpParam.SqlDbType = SqlDbType.Structured; tvpParam.TypeName = "dbo.AttendanceEntryTableType"; try { connection.Open(); int affectedRows = insertCommand.ExecuteNonQuery(); if (affectedRows > 0) { System.Windows.Forms.MessageBox.Show(affectedRows + " entries stored"); } } catch (SqlException ex) { throw ex; } finally { if (connection != null) { connection.Close(); } } } } } catch { throw new Exception(); } }