public ActionResult Edit(TbStudent student) { if (ModelState.IsValid) { var dao = new UserDao(); if (!string.IsNullOrEmpty(student.Password)) { var encryp = Encryptor.MD5Hash(student.Password); student.Password = encryp; } var result = dao.Update(student); if (result) { SetAlert("Sửa thông tin người dùng thành công", "success"); return(RedirectToAction("Index", "User")); } else { ModelState.AddModelError("", "Cập nhật không thành công"); } } return(View("Index")); }
public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { var dao = new UserDao(); if (dao.CheckUserName(model.Username)) { ModelState.AddModelError("", "Tên đăng nhập đã tồn tại."); } else { var user = new TbStudent(); user.Username = model.Username; user.Password = Encryptor.MD5Hash(model.Password); user.Ho = model.Ho; user.Ten = model.Ten; user.NgaySinh = model.NgaySinh; user.GioiTinh = model.GioiTinh; user.Active = true; var result = dao.Insert(user); if (result > 0) { ViewBag.Success = "Đăng ký thành công."; model = new RegisterModel(); } else { ModelState.AddModelError("", "Đăng ký không thành công."); } } } return(View(model)); }
protected void Page_Load(object sender, EventArgs e) { string sjName = ""; HttpCookie usercookie = Request.Cookies["nowloginuser"]; string url = PublicClass.CheckLogin(usercookie, ""); if (url != "") { Response.Redirect(url); } if (!IsPostBack) { string action = Request["action"]; if (action != null && action.ToString().Equals("Elspenvlaues")) { sjName = Request["sjName"].ToString(); } spannowtime.InnerText = "服务器时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"); string user = usercookie.Value; Tobj.YhID = TbUserManager.GetStudentID(user); TbStudent tStudent = TbStudentManager.GetStudentByID(Tobj.YhID); testPaperList = TbTestPaperManager.GetAllTestpaperByPages(len, page, sjName, 2); Hello = tStudent.XsName; Elspen.Value = sjName; } }
/// <summary> /// 根据用户ID查询对应详细信息 /// </summary> /// <param name="YhID"></param> public void GetStudent(int YhID) { TbStudent student = TbStudentManager.GetStudentByID(YhID); TbUser user = TbUserManager.GetAllUser(YhID); string message = student.YhID + "," + student.XsName + "," + student.XsSex + "," + student.BjName + "," + student.Remark + "," + user.YhName + "," + user.Xh + "," + user.YhPwd; Response.Write(message); }
/// <summary> /// 导入用户 /// </summary> protected void BeginImport_Click(object sender, EventArgs e) { string path = ""; if (FileUpload1.PostedFile != null) { path = FileUpload1.PostedFile.FileName; } if (path == "") { lblImportResult.Text = "请选择导入文件!"; return; } if (!path.Contains(':') || !path.Contains('\\')) { lblImportResult.Text = "请设置您当前浏览器:工具-internet选项-安全-自定\n义级别-将文件上传到服务器是包含本地路径!"; return; } string hzm = path.Substring(path.LastIndexOf('.') + 1); if (hzm != "xls" && hzm != "xlsx") { lblImportResult.Text = "本系统只支持excel文件格式导入,可以参考下面摸板!"; return; } TbUser user = null; TbStudent stu = null; DataSet ds = ExcelToDataSet(path); foreach (DataTable table in ds.Tables) { foreach (DataRow row in table.Rows) { user = new TbUser(); user.Xh = row[3].ToString(); user.YhName = row[4].ToString(); user.YhPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(row[5].ToString(), "MD5"); user.Zt = 3; int userIdentity = TbUserManager.AddUser(user); if (userIdentity > 0) { stu = new TbStudent(); stu.XsName = row[0].ToString(); stu.XsSex = row[1].ToString(); stu.YhID = userIdentity; stu.BjName = row[2].ToString(); stu.Remark = ""; int stuIdentity = TbStudentManager.AddStudent(stu); } } } lblImportResult.Text = "导入成功!"; }
/// <summary> /// 添加学员信息,返回当前标示符 /// </summary> /// <param name="stu">当前添加学员信息</param> /// <returns></returns> public int AddStudent(TbStudent stu) { string sql = "insert into tbStudent(XsName,XsSex,YhID,BjName,Remark)values(@XsName,@XsSex,@YhID,@BjName,@Remark)select @@IDENTITY"; SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@XsName", stu.XsName), new SqlParameter("@XsSex", stu.XsSex), new SqlParameter("@YhID", stu.YhID), new SqlParameter("@BjName", stu.BjName), new SqlParameter("@Remark", stu.Remark) }; return(DBHelper.GetScalar(sql, paras)); }
/// <summary> /// 根据用户ID修改学生信息 /// </summary> /// <param name="stu">学生对象</param> /// <returns></returns> public int SetStudent(TbStudent stu) { string Sql_update = "update tbStudent set XsName=@XsName,XsSex=@XsSex,BjName=@BjName,Remark=@Remark where YhID=@YhID"; SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@XsName", stu.XsName), new SqlParameter("@XsSex", stu.XsSex), new SqlParameter("@BjName", stu.BjName), new SqlParameter("@YhID", stu.YhID), new SqlParameter("@Remark", stu.Remark) }; return(DBHelper.ExecuteCommand(Sql_update, paras)); }
private async Task SetupStudentData() { using (var db = new ApplicationDbContext(_dbContextOptions)) { var student = new TbStudent { ClassId = 1, FirstName = "test1", Gender = "male", Grade = 1, LastName = "lastname", ParentEmail = "*****@*****.**", ParentCellNumber = "1234512345" }; var student2 = new TbStudent { ClassId = 1, FirstName = "testuser2", Gender = "male", Grade = 1, LastName = "lastname", ParentEmail = "*****@*****.**", ParentCellNumber = "1234512345" }; var student3 = new TbStudent { ClassId = 2, FirstName = "testuser3", Gender = "male", Grade = 1, LastName = "lastname", ParentEmail = "*****@*****.**", ParentCellNumber = "1234512345" }; var student4 = new TbStudent { ClassId = 3, FirstName = "testuser4", Gender = "male", Grade = 1, LastName = "lastname", ParentEmail = "*****@*****.**", ParentCellNumber = "1234512345" }; await db.TbStudent.AddRangeAsync(student, student2, student3, student4); await db.SaveChangesAsync(); } }
public ActionResult Edit(TbStudent user) { if (ModelState.IsValid) { var dao = new UserDao(); var result = dao.Update(user); if (result) { return(RedirectToAction("Info", "User")); } else { ModelState.AddModelError("", "Cập nhật không thành công"); } } return(View("Info")); }
protected void ButtonOK_Click(object sender, EventArgs e) { TbUser User = new TbUser(); TbStudent Student = new TbStudent(); User.YhName = this.TextYh.Text; User.Xh = this.textStudentID.Text; User.Zt = 3; Student.XsName = this.TextName.Text; Student.BjName = this.BjName.Text; if (this.RadButNan.Checked) { Student.XsSex = this.RadButNan.Value; } else { Student.XsSex = this.RadButNv.Value; } Student.Remark = this.textBz.Text; if (this.HiddenYhID.Value == "") { this.BjName.Text = "请选择..."; User.YhPwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.TextMm.Text, "MD5"); TbUserManager.SeeUser(User); Student.YhID = TbUserManager.AddUser(User); TbStudentManager.AddStudent(Student); Load_Student(); } else { User.YhPwd = this.TextMm.Text.Trim(); User.YhID = int.Parse(this.HiddenYhID.Value); Student.YhID = int.Parse(this.HiddenYhID.Value); TbUserManager.SetUser(User); TbStudentManager.SetStudent(Student); this.HiddenYhID.Value = ""; } this.textStudentID.Text = ""; this.TextYh.Text = ""; this.TextName.Text = ""; this.textBz.Text = ""; this.BjName.Text = "请选择..."; this.RadButNan.Checked = true; Load_Student(); }
public ActionResult Create(TbStudent student) { if (ModelState.IsValid) { var dao = new UserDao(); var encryp = Encryptor.MD5Hash(student.Password); student.Password = encryp; int id = dao.Insert(student); if (id > 0) { SetAlert("Thêm người dùng thành công", "success"); return(RedirectToAction("Index", "User")); } else { ModelState.AddModelError("", "Thêm mới không thành công"); } } return(View("Index")); }
/// <summary> /// 根据用户ID返回对应详细信息 /// </summary> /// <param name="ZyID">用户ID</param> /// <returns></returns> public TbStudent GetStudentByID(int YhID) { TbStudent student = null; string sql = "select * from tbStudent where YhID=@YhID"; SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@YhID", YhID) }; SqlDataReader reader = DBHelper.GetReader(sql, paras); if (reader.Read()) { student = new TbStudent(); student.YhID = YhID; student.XsName = reader["XsName"].ToString(); student.Remark = reader["Remark"].ToString(); student.XsSex = reader["XsSex"].ToString(); student.BjName = reader["BjName"].ToString(); reader.Close(); } return(student); }
public async Task <int> AddStudentAsync(StudentModel studentModel) { var studentClass = await _dbContext.TbClass.FindAsync(studentModel.classId); if (studentClass == null) { throw new ArgumentException("Invalid Class Id"); //Add exceptions middleware } var student = new TbStudent { ClassId = studentModel.classId, FirstName = studentModel.FirstName, Gender = studentModel.Gender, Grade = studentModel.Grade, LastName = studentModel.LastName, ParentCellNumber = studentModel.ParentPhoneNumber, ParentEmail = studentModel.ParentEmail }; await _dbContext.TbStudent.AddAsync(student); return(await _dbContext.SaveChangesAsync()); }
public bool Update(TbStudent entity) { try { var user = db.TbStudents.SingleOrDefault(x => x.ID == entity.ID); if (!string.IsNullOrEmpty(entity.Password)) { user.Password = entity.Password; } user.Ho = entity.Ho; user.Ten = entity.Ten; user.NgaySinh = entity.NgaySinh; user.GioiTinh = entity.GioiTinh; user.Active = entity.Active; user.Thi = entity.Thi; db.SaveChanges(); return(true); } catch (Exception) { return(false); } }
public int Insert(TbStudent entity) { db.TbStudents.Add(entity); db.SaveChanges(); return(entity.ID); }
} /// <summary> /// 根据用户ID修改学生信息 /// </summary> /// <param name="stu">学生对象</param> /// <returns></returns> public static int SetStudent(TbStudent stu) { return(tbstuservice.SetStudent(stu)); }
/// <summary> /// 添加学员信息,返回当前标示符 /// </summary> /// <param name="stu">当前添加学员信息</param> /// <returns></returns> public static int AddStudent(TbStudent stu) { return(tbstuservice.AddStudent(stu)); }