static void TestDAL() { using (Model1 en = new Model1()) { Console.WriteLine("默认记录数量:{0}", en.Students.Count()); Student stu = new Student { Name = "LY", Sex = "M", Age = 28, Pwd = "L38" }; StuDbAccessor.Add(stu); Console.WriteLine("添加了一条记录后记录数量:{0}", en.Students.Count()); StuDbAccessor.Delete(2); Console.WriteLine("删除了一条记录后记录数量:{0}", en.Students.Count()); Student stuUpdate = new Student { Name = "name1", Sex = "M", Age = 1, Pwd = "pwd1" }; StuDbAccessor.Update(1, stuUpdate); Console.WriteLine("更新了第一条记录,下面是更新后的属性"); Student updated1 = StuDbAccessor.SelectById(1); Console.WriteLine(string.Format("{0}\t{1}\t{2}\t{3}", updated1.Name, updated1.Pwd, updated1.Sex, updated1.Pwd)); } }
private void btnDelete_Click(object sender, EventArgs e) { Student selStudent = this.GetFirstSelectedStudent(); StuDbAccessor.Delete(selStudent.ID); this.ViewAllStudent(); }
public void TestDelete() { using (Model1 en = new Model1()) { StuDbAccessor.Delete(2); Assert.AreEqual(en.Students.Count(), 4); } }
private void btnAdd_Click(object sender, EventArgs e) { frmEdit editor = new frmEdit(); if (editor.ShowDialog() == DialogResult.OK) { StuDbAccessor.Add(editor.student); this.ViewAllStudent(); } }
public void TestAdd() { using (Model1 en = new Model1()) { Student stu = new Student { Name = "LY", Sex = "M", Age = 28, Pwd = "L38" }; StuDbAccessor.Add(stu); Assert.AreEqual(en.Students.Count(), 5); } }
private void btnUpdate_Click(object sender, EventArgs e) { Student selStudent = this.GetFirstSelectedStudent(); if (selStudent != null) { frmEdit editor = new frmEdit(selStudent); int oldId = selStudent.ID; if (editor.ShowDialog() == DialogResult.OK) { StuDbAccessor.Update(oldId, selStudent); this.ViewAllStudent(); } } }
public ActionResult Index(LoginModel objuserlogin) { IList <Student> students = StuDbAccessor.SelectAll(); bool b = students.Any(x => x.Name.TrimEnd() == objuserlogin.UserName && x.Pwd.TrimEnd() == objuserlogin.UserPassword); if (b) { ViewBag.Status = "恭喜您登录成功!"; } else { ViewBag.Status = "用户名或密码错误!"; } return(View(objuserlogin)); }
public bool CheckStudent(string name, string pwd) { IList <Student> students = StuDbAccessor.SelectAll(); return(students.Any(x => x.Name.TrimEnd() == name && x.Pwd.TrimEnd() == pwd)); }
/// <summary> /// 根据是否特价查看 /// </summary> private void ViewAllStudent() { this.lstStudent = new BindingList <Student>(StuDbAccessor.SelectAll()); this.dgvStudents.DataSource = this.lstStudent; }