private void button1_Click(object sender, EventArgs e) { Student student = new Student(); student.StudNo = textBox1.Text; student.StudName = textBox2.Text; student.StudSex = radioButton1.Checked ? '男' : '女'; student.StudBirthDate = dateTimePicker1.Value; student.StudMajor = comboBox1.Text; student.StudIsMember = checkBox1.Checked; if (pictureBox1.Image != null) { MemoryStream ms = new MemoryStream(); pictureBox1.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); student.StudPic = ms.GetBuffer(); ms.Close(); } if (studentDAL.EditStudent(student) >= 0) { MessageBox.Show("修改成功!"); Dispose(); } else { MessageBox.Show("修改失败!"); } }
public void EditStudent(int id, Student newStudent) { try { var s = _context.Student .Where(item => item.StudentCode == newStudent.StudentCode && item.Id != newStudent.Id).SingleOrDefault(); if (s == null) { Student oldStudent = _context.Student.Where(us => us.Id == id).SingleOrDefault(); if (newStudent.Password == null || newStudent.Password.Trim() == "") { newStudent.Password = oldStudent.Password; } else { newStudent.Password = BCrypt.Net.BCrypt.HashPassword(newStudent.Password); } _studentDAL.EditStudent(oldStudent, newStudent); } else { throw new Exception("Mã sinh viên đã tồn tại"); } } catch (Exception ex) { if (ex.Message.Contains("Mã sinh viên đã tồn tại")) { throw new Exception(ex.Message.ToString()); } else { throw new Exception("Error from StudentBLL: " + ex.Message.ToString()); } } }
/// <summary> /// 学生修改个人信息 /// </summary> /// <param name="student"></param> /// <returns></returns> public bool EditStudent(Student student) { return(dal.EditStudent(student) > 0); }