protected void btnLogin_Click(object sender, EventArgs e) { string studentNum = txtStudentNum.Text; string password = txtPassword.Text; using (RegistrationDB entityContext = new RegistrationDB()) { //Authenicate the user's credential against data stored var validSt = (from st in entityContext.Students where (st.StudentNum == studentNum && st.Password == password) select st).FirstOrDefault <Student>(); //if student not found, return to first page with error message if (validSt == null) { Session["validSt"] = 0; } else //if student is found, save sessions and direct to second page: { Session["studentName"] = validSt.Name; Session["studentNumber"] = validSt.StudentNum; Response.Redirect("CurrentRegistrations.aspx"); } } }
protected void Button2_Click1(object sender, EventArgs e) { if (RegistrationDB.isCustomerExist(UserName.Text)) { lblFailed.Visible = true; return; } lblFailed.Visible = false; DataLayer.RegistrationDB.AddCustomer(FirstName.Text, LastName.Text, Phone.Text, City.Text, UserName.Text, Password.Text); lblSuccess.Visible = true; }
private bool IsSelectedProductRegistered() { bool blnResult; blnResult = RegistrationDB.ProductRegistered((int)(cboCustomers.SelectedValue), (string)cboProducts.SelectedValue); if (!blnResult) { Validator.ShowError("The selected product is not registered for this customer"); } return(blnResult); }
protected void registerButton_Click(object sender, EventArgs e) { if (RegistrationDB.isCustomerExist(userNameTextBox.Text)) { failedLabel.Visible = true; return; } failedLabel.Visible = false; string encryptedPwd = LoginUtility.GetEncryptedValue(passwordTextBox.Text); RegistrationDB.AddCustomer(firstNameTextBox.Text, lastNameTextBox.Text, phoneTextBox.Text, cityTextBox.Text, userNameTextBox.Text, encryptedPwd); successLabel.Visible = true; }
/// <summary> /// 核对姓名 /// </summary> /// <param name="name"></param> /// <returns></returns> public bool IsName(string name) { bool flag = false; string tmp = new RegistrationDB(_conString).GetNullName(); if (tmp == string.Empty) { flag = true; } else if (tmp == name) { flag = true; } else { flag = false; } return(flag); }
/// <summary> /// 查询是否已借出 /// </summary> /// <returns></returns> public bool IsItemReturn() { bool flag = false; string[] tmp = new RegistrationDB(_conString).GetLast(); if (tmp[0] == null) { flag = true; } else if (tmp[4] != string.Empty) { flag = true; } else { flag = false; State = "借出人:" + tmp[0] + " 借出原因:" + tmp[1] + " 实际借出时间:" + tmp[2] + " 预计归还时间:" + tmp[3]; } return(flag); }
private void btnRegister_Click(object sender, EventArgs e) { string productID = Convert.ToString(cBoxProduct.SelectedValue); int customerID = Convert.ToInt32(cBoxCustName.SelectedValue); try { RegistrationDB regDB = new RegistrationDB(); if (regDB.ProductRegistration(customerID, productID)) { MessageBox.Show("Registration Exists", "Registration", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { Registration aRegistration = new Registration(); DateTime myDateTime = DateTime.Now; string sqlFormattedDate = myDateTime.ToString("yyyy-MM-dd HH:mm:ss.fff"); aRegistration.RegistrationDate = myDateTime; regDB.AddRegistration(aRegistration); MessageBox.Show("Registrationd Added", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
protected void btnLogin_Click(object sender, EventArgs e) { string studentNum = txtStudentNum.Text; string password = txtPassword.Text; using (RegistrationDB entityContext = new RegistrationDB()) { //Authenicate the user's credential againt data stored //in the Student table in the Registration DB by searching //for the student with the user entered studentNum and password if ((from s in entityContext.Students where s.StudentNum == studentNum && s.Password == password select s).FirstOrDefault() != null) { //store result into session if student already exists Session["loggedIn"] = "yes"; (Session)["studentNumber"] = studentNum; //sends user to CurrentRegustrations.aspx page. //will give them welcome screen if they come back here Response.Redirect("CurrentRegistrations.aspx"); } else { // generate Session["loggedIn"] = "no"; //Reload page so changes are submitted Response.Redirect("Default.aspx"); } } }
protected void Page_Load(object sender, EventArgs e) { //Redirect unauthenticated user to the Default page. string authenticationStatus = Session["loggedIn"] as string; if (authenticationStatus == "no" || authenticationStatus == null) { Response.Redirect("Default.aspx"); } //Get the Home LinkButton on the Master page //make it visible and attach an event handler //so that when clicked, redirect the user to the Default page. LinkButton btnHome = (LinkButton)Master.FindControl("btnHome"); btnHome.Click += (s, a) => Response.Redirect("Default.aspx"); //I know this isn't properly connected to masterpage buttons at the moment :( BulletedList topMenu = (BulletedList)Master.FindControl("topMenu"); if (!IsPostBack) { topMenu.Items.Add(new ListItem("Home")); topMenu.Items.Add(new ListItem("Log Out")); } //topMenu.Click += topMenu_Click; //Get the Logout LinkButton on the Master page //make it visible and attach the event handler Logout to it LinkButton btnLogout = (LinkButton)Master.FindControl("btnLogout"); btnLogout.Click += (s, a) => Logout(s, a); using (RegistrationDB entityContext = new RegistrationDB()) { //Get the registered course list of the authenticated user. string studentNumber = Session["studentNumber"] as string; //trying to pair the student's number with the course code from the DB. //I think my sql server isn't correct so I have some incorrect variables here //attempted to display correct courses via the database using Entity Framework List <Course> CourseList = (from a in entityContext where a.Course.Code == Registration.Course_CourseID && a.StudentId == studentNumber select a).FirstOrDefault <Course>(); //If the user clicked the delete link of a coure, //delete the selected course from the user's registration //same problems as above in terms of accessing "Registration" string action = Request.Params["action"] as string; if (action == "delete") { string ID = Request.Params["id"]; var course = (from c in entityContext.Courses where c.CourseID == ID select c).FirstOrDefault <Course>(); if (course != null) { //I realize "Registration is the incorrect property for (int i = course.Registration.Count() - 1; i >= 0; i--) { var record = course.Registration.ElementAt <Course>(i); course.Registration.Remove(record); } } entityContext.Courses.Remove(course); entityContext.SaveChanges(); Response.Redirect("CurrentRegistrations.aspx"); } //making list to display up to date courses //Display the registered course list (use ShowCourseInfo method) ShowCourseInfo(CourseList); } }
protected void Page_Load(object sender, EventArgs e) { //Redirect unauthenticated user to the Default page. if (Session["studentName"] == null) { Response.Redirect("Default.aspx"); } else { using (RegistrationDB entityContext = new RegistrationDB()) { //showing the list of courses List <Course> courses = entityContext.Courses.ToList <Course>(); //existing list of all courses List <Course> filteredCourses = new List <Course>(); //new empty list foreach (Course course in courses) //loops through each course { foreach (Student st in course.Students) //loops through each course to see which students are related to it //refer to diagram for navigation properties, that links both tables together { if (st.Name == (string)Session["studentName"]) //select the courses where studentName == the student's name from first page { filteredCourses.Add(course); //add selected courses to the new list "filteredCourses" } } } ShowCourseInfo(filteredCourses); //calling the method to display courses //deleting course string action = Request.Params["action"]; string courseId = Request.Params["id"]; string stNumber = (string)Session["studentNumber"]; if (Request.Params["action"] == "delete") { var removeCourse = (from c in entityContext.Courses where c.CourseID == courseId select c).FirstOrDefault <Course>(); //selecting course by id if (removeCourse != null) { for (int i = courses.Count() - 1; i >= 0; i--) //removing from list { var ar = courses.ElementAt <Course>(i); courses.Remove(ar); } } entityContext.Courses.Remove(removeCourse); //removing from database entityContext.SaveChanges(); Response.Redirect("CurrentRegistrations.aspx"); } } } //Get the Home LinkButton on the Master page //make it visible and attach an event handler //so that when clicked, redirect the user to the Default page LinkButton btnHome = (LinkButton)Master.FindControl("btnHome"); //instanciating Home Button btnHome.Visible = true; //making it visible btnHome.Click += (s, a) => Response.Redirect("Default.aspx"); //adding action to Home Button //Get the Logout LinkButton on the Master page //make it visible and attach the event handler Logout to it LinkButton btnLogout = (LinkButton)Master.FindControl("btnLogout"); //instanciating Logout Button btnLogout.Visible = true; //making it visible btnLogout.Click += (s, a) => Logout(s, a); //ading an action to Logout button }