/// <summary> /// 通过学号查找学生 /// </summary> /// <param name="StudentId"></param> /// <returns>学生信息</returns> public StudentsExt queryStudentByStudentId(int StudentId) { string sql = "Select Students.StudentId,StudentName,Gender,Birthday,StudentIdNo,CardNo,PhoneNumber,StudentAddress,Students.ClassId,ClassName,SQLServerDB,CSharp" + " from Students join StudentClass on Students.ClassId=StudentClass.ClassId " + "join ScoreList on ScoreList.StudentId=Students.StudentId " + " where Students.StudentId=@StudentId"; SqlParameter[] param = new SqlParameter[] { new SqlParameter("@StudentId", StudentId) }; StudentsExt stu = null; SqlDataReader result = new Helper.SQLHelper().QueryAll(sql, param, false); while (result.Read()) { stu = new StudentsExt() { StudentId = Convert.ToInt32(result["StudentId"]), StudentName = result["StudentName"].ToString(), Gender = result["Gender"].ToString(), Birthday = Convert.ToDateTime(result["Birthday"]), StudentIdNo = result["StudentIdNo"].ToString(), CardNo = result["CardNo"].ToString(), PhoneNumber = result["PhoneNumber"].ToString(), StudentAddress = result["StudentAddress"].ToString(), ClassId = Convert.ToInt32(result["ClassId"]), ClassName = result["ClassName"].ToString(), SQLServerDB = Convert.ToInt32(result["SQLServerDB"]), CSharp = Convert.ToInt32(result["CSharp"]) }; } result.Close(); return(stu); }
/// <summary> /// 当鼠标双击某个学员查看这个学员的详细信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void smDgStudentLsit_MouseDoubleClick(object sender, MouseButtonEventArgs e) { //接收查看是什么双击进入 //object o = sender; //SelectedItem选中单个元素选中第一项,如果有多个也会只选第一个;SelectedItems选中多个元素 //如果StudentsExt转成这个类型,表示我们点击时的这一行数据是StudentsExt这个类型 StudentsExt ext = smDgStudentLsit.SelectedItem as StudentsExt;//只能现在只能双击不能拿到学员的信息 //判断点击这个按钮是否为空,就是没点击到这行数据,这行没数据,如为空返回 if (ext == null) { return; } #region//对以下代码解释 /*//1.如何拿到学员的ID,通过ID拿到整行数据 * //2.ext要通过这个点击查询到所有学生ID,为什么ext可以点出StudentId,原因是Binding StudentId的绑定来获取的 * //3.双击后把ext.StudentId获取到的ID带入sm中GetDoubleStudentsExt的这个方法 * //4.如何把DoubleStu传递进WindowDoubleStu这个窗口里面,通过WindowDoubleStu窗口中函数的参数 * //5.老师:(1)当这个学员的完整信息已经存在的话,证明已经打开了一个窗口;(2)除非是打开新的学员窗口,否则只能把之前的窗口呈现出来 * StudentsExt DoubleStu = sm.GetDoubleStudentsExt(ext.StudentId); * * //如何展示用户信息 * View.WindowDoubleStu WindowdoubleStu = new WindowDoubleStu(DoubleStu);//这样就把含有某一个学生ID的全部值拿到了 * //Show可以打开多个窗口;ShowDialog不能同时打开多个窗口 * WindowdoubleStu.Show();*/ #endregion //list有一个属性判断list确定某元素是否存在 //DoubleList只存放学生ID if (DoubleList.Contains(ext.StudentId))//存在 { foreach (WindowDoubleStu item in WindowDouStu) {//遍历WindowDoubleStu窗口的数据 //item表示把WindowDoubleStu这个窗口的Stuext数据拿到了,当被触发时两个数据一样,表示已经打开了窗口,然后进入if判断让其item(表示整个窗口)在激活的状态下 if (item.Stuext == ext.StudentId) { //只能激活窗口,不能创建多个窗口 item.Activate(); } } } else//不存在,下面的窗口没关,上面的作判断 { StudentsExt DoubleStu = sm.GetDoubleStudentsExt(ext.StudentId);//给DoubleStu赋值 //(1)然后把DoubleList里面的属性改成int,(2)然后在DoubleStu把学生ID添加名字为DoubleList的list DoubleList.Add(DoubleStu.StudentId); View.WindowDoubleStu WindowdoubleStu = new WindowDoubleStu(DoubleStu);//实例化窗口并传入学生数据 //问题再次双击关闭窗口学生的行就点不出来,原因是DoubleList;里面已经有一个学生id了,所以再次双击就出不来了;所以我们要关闭的时候在把他对应的数据移除掉 WindowdoubleStu.Closed += WindowdoubleStu_Closed; WindowDouStu.Add(WindowdoubleStu);//用list把窗口装起来了 WindowdoubleStu.Show(); } }
public UpdateStuInfor(StudentsExt ext) { InitializeComponent(); //从上传照片 common.BitmapImg img = new common.BitmapImg(); //把获取的元素放在一个属性里方便下面的调用 studentSJ = ext; //开始在这个页面上显示修改按钮所点击的那个学生的所有信息在这里显示,点击是显示原有的 txtAddress.Text = ext.StudentAddress; //地址 txtAge.Text = ext.Age.ToString(); //年龄 txtCardNo.Text = ext.CardNo; //考勤卡号 txtName.Text = ext.StudentName; //姓名 txtPhoneNumber.Text = ext.PhoneNumber; //电话 txtStuNoId.Text = ext.StudentIdNo; //ID if (ext.Gender == "男") //性别 { radBoy.IsChecked = true; } else { radGirl.IsChecked = true; } /*//获取或设置要选定的日期 * datePkBirthday.DisplayDate =Convert.ToDateTime(ext.Birthday); * //获取或设置当前要选定的日期 * datePkBirthday.SelectedDate = Convert.ToDateTime(ext.Birthday);*/ datePkBirthday.Text = ext.Birthday; //图片的显示,如果当前图片为空时进入获取这下面zwzp图片 if (string.IsNullOrEmpty(ext.StuImage)) { stuImg.Source = new BitmapImage(new Uri("/img1/bg/zwzp.jpg", UriKind.RelativeOrAbsolute)); } else { //如果学员的Iamge字段中能够查询到数据,那么就可以直接将这个数据反序列化成BitmapImage对象 image = BinaryStuObjcet.FBinaryForStu(ext.StuImage) as common.BitmapImg; img1.Buffer = image.Buffer; BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); bitmap.StreamSource = new MemoryStream(image.Buffer); bitmap.EndInit(); stuImg.Source = bitmap; } //获取下拉列表的内容 List <StudentClass> classes = csm.GetClasses(); cmbClassName.ItemsSource = classes; cmbClassName.DisplayMemberPath = "ClassName"; cmbClassName.SelectedValuePath = "ClassId"; cmbClassName.SelectedIndex = ext.ClassId - 1; }
public ActionResult StudentUpdate(StudentsExt stu) { int result = new StudentsManage().UpdateStudent(stu); if (result > 0) { return(Content("<script type='text/javascript'>alert('更新成功!');document.location='" + Url.Action("Index", "Students") + "'</script>")); } else if (result == 0) { return(Content("<script type='text/javascript'>alert('更新失败!');document.location='" + Url.Action("Index", "Students") + "'</script>")); } else { return(Content("<script type='text/javascript'>alert('系统异常');document.location='" + Url.Action("Index", "Students") + "'</script>")); } }
/// <summary> /// 修改学员信息:是以UpdateStuInfor窗口WPF创建 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void UpdataStuButton_Click(object sender, RoutedEventArgs e) { //表示在DataGrid里面选中的一行 StudentsExt selectStu = smDgStudentLsit.SelectedItem as StudentsExt; //没有选中提示,返回 if (selectStu == null) { MessageBox.Show("请选择要修改的学员!", "提示"); return; } //1.sm.GetDoubleStudentsExt(selectStu.StudentId)---》selectStu表示选中一行的所以数据----》只要点击后的学生ID值----》然后通过这个点击的ID值传进GetDoubleStudentsExt获取整个行,获取到行后用一个盒子接收 StudentsExt studentsExt = sm.GetDoubleStudentsExt(selectStu.StudentId); //2.创建或实例化一下修改的页面,并传递参数 UpdateStuInfor updateStuInfor = new UpdateStuInfor(studentsExt); //点击修改按钮显示这个窗口 updateStuInfor.ShowDialog(); //每次修改完后刷新DG中这个学员的信息 RefreshDG(); }
/// <summary> /// 删除学员 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Button_Click(object sender, RoutedEventArgs e) { //点击确定后获取这一行点击的数据 selectStu = smDgStudentLsit.SelectedItem as StudentsExt; //判断DoubleList范性里面是否获取到//用来记录当前的选择的学员StudentsExt if (DoubleList.Contains(selectStu.StudentId)) { MessageBox.Show("请关闭正在查看的学员信息界面", "提示"); return; } if (selectStu == null) { MessageBox.Show("请选择要删除的学员!", "提示"); return; } //实例化把这一行学生ID全部拿到,判断这行不为空 StudentsExt students = sm.GetDoubleStudentsExt(selectStu.StudentId); if (students == null) { MessageBox.Show("您选择的学员信息已经被删除!", "提示"); return; } MessageBoxResult mbr = MessageBox.Show("您确定要删除【" + students.StudentName + "】", "警告", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (mbr == MessageBoxResult.OK) { if (sm.DeleteStudentById(students.StudentId)) { MessageBox.Show("删除成功!", "提示"); } else { MessageBox.Show("删除失败请稍后再试!", "提示"); } } }
//打印学员信息( 实现打印及打印预览) private void BtnPrint_Click(object sender, RoutedEventArgs e) { //点击选中的学员,按下打印学员信息的buttom按钮,这样就获取具体学员的信息了(用一个实体类接收一下在smDgStudentLsit里面数据,当点击时把所有的值用selectStu接收一下) selectStu = smDgStudentLsit.SelectedItem as StudentsExt;//(现在selectStu里面就装了点击时所包含的值) //当StudentsExt的值等于等于空值时,表示 if (selectStu == null) { MessageBox.Show("请选择您要打印的学员", "提示"); return; } //实例化放图片的空数据 common.BitmapImg image = null; if (string.IsNullOrEmpty(selectStu.StuImage)) { //最后在StudentsExt多添加了一个属性 selectStu.ImgPath = "/img1/bg/zwzp.jpg"; } //如果有图片执行下面获取的图片 else { //(获取数据库中图片的反序列化)用空的图片类来接收数据库中的这个图片(当点击要打印学生信息就可以获取selectStu.StuImage的数据) image = BinaryStuObjcet.FBinaryForStu(selectStu.StuImage) as common.BitmapImg; //实例化BitmapImage用来封装序列化和反序列化的转换路径的*记录方式* BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit();//用信号通知BitmapImage初始化开始 //图像流: 对象的集合编码为图像流(new无法自己出来,所以自己输入) BitmapEncoder encoder = new PngBitmapEncoder(); /*1.向图像流中添加 * 2.BitmapFrame图像数据属于静态类 * 3.创建这个BitmapImage路径并添加给图像流 * 4.就相当于给这个图像流输入照片路径 * 总结:encoder.Frames.Add相当于给图像流中添加图片的路径 */ encoder.Frames.Add(BitmapFrame.Create(bitmap));//把图片从数据库拿到的图片路径拿到,并创建 //获取事件 long sc = DateTime.Now.Ticks; //using表示方式这个流被其他替代,在using里绝对不会被替代相当一个封闭环境 using (MemoryStream stream = new MemoryStream()) { //**encoder里面获取到的内容给了stream流**:将位图图像编码为指定的流;把 encoder.Save(stream); //用一个byte数组来装这个流 byte[] buffer = stream.ToArray(); /*1.file是一个静态类可以直接使用里面的方法 * 2.使用WriteAllBytes这个方法创建一个新文件在其中写入指定的字节数组,然后关闭改文件。如果目标问价以存在,则覆盖改文件 * 3.AppDomain应用程序中独立执行的环境 * 4.CurrentDomain获取当前程序域 * 5.BaseDirectory获取基目录 * 6.sc表示当前时间 * 7.printImg文件名、 * 8.buffer表示记录stream流中的所有内容 * 总结创建了一个图片文件 */ File.WriteAllBytes(AppDomain.CurrentDomain.BaseDirectory + "/printImg/" + sc + ".png", buffer); //??? stream.Close(); //关闭流 } //获取学生图片的路径 selectStu.ImgPath = AppDomain.CurrentDomain.BaseDirectory + "/printImg/" + sc + ".png"; } /*1.创建打印学生信息界面 * 2.参数1(PrintModel.xaml:框架形式是流文档所以创建流文档写打印界面):表示对打印界面的设计 * 3.参数2(selectStu):表示获取学生的所有数据 */ View.PrintWindow frmPrint = new PrintWindow("PrintModel.xaml", selectStu); //获取或设置一个值,该值指示窗口是否具有任务栏按钮 frmPrint.ShowInTaskbar = false; //打开打印学生窗口窗口 frmPrint.ShowDialog(); }
/// <summary> /// 这个也是构造函数所以里面可以传参数 /// </summary> // 下面的函数有了StudentsExt参数类型,这样我们只需要把在FrmStuManager这个窗口的数据以参数的形式传递进来;这个函数就可以访问到数据了 public WindowDoubleStu(StudentsExt ext) { InitializeComponent(); //把参数类型StudentsExt的学生ID赋给Stuext Stuext = ext.StudentId; //在主窗口放一个lable名字Id测试 //Id.Content = ext.StudentName; this.Title = ext.StudentName + "-信息"; //地址 lblAddress.Content = ext.StudentAddress; //年龄 lblAge.Content = ext.Age; //出生日期 lblBirthday.Content = ext.Birthday.ToString(); //考勤卡号 lblCardNo.Content = ext.CardNo; //课程名字 lblClassName.Content = ext.ClassName; //性别 lblGender.Content = ext.Gender; //学生名字 lblName.Content = ext.StudentName; //学生电话 lblPhoneNumber.Content = ext.PhoneNumber; //学生ID lblStuId.Content = ext.StudentId; //学生身份证号 lblStuNoId.Content = ext.StudentIdNo; //学生图片 //if这个图片为空时进入绑定这个图片 if (string.IsNullOrEmpty(ext.StuImage)) { //在创建的时候直接用image图片装 stuImg.Source = new BitmapImage(new Uri("/img1/bg/zwzp.jpg", UriKind.RelativeOrAbsolute)); } else { //1.第一步给通用层Common中添加序列化和反序列化 //2.先反序列化 //1.现在通用层里面添加一个类,用里面的属性来实现序列化的转变 //2.反序列化在数据库中获取 //(1)如果学员的Iamge字段中能够查询到数据,那么就可以直接将这个数据反序列化成BitmapImage对象 //(2)反序列化就可以从数据库中那图片了 //如果学员的Iamge字段中能够查询到数据,那么就可以直接将这个数据反序列化成BitmapImage对象 //(3)要求封装好的 /*BitmapImage image = Common.BinaryStuObjcet.FBinaryForStu(ext.StuImage) as BitmapImage;*/ //2.获取到ext.StuImage的名字 common.BitmapImg image = BinaryStuObjcet.FBinaryForStu(ext.StuImage) as common.BitmapImg; //3.实例化一下这个装图片盒子 BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); //获取反序列化的内容 bitmap.StreamSource = new MemoryStream(image.Buffer); bitmap.EndInit(); //图片名字的路径上赋一个bitmap stuImg.Source = bitmap; /* image.Buffer = image.Buffer; * BitmapImage bitmap = new BitmapImage(); * bitmap.BeginInit(); * bitmap.StreamSource = new MemoryStream(image.Buffer); * bitmap.EndInit(); * stuImg.Source = bitmap;*/ /* //如果学员的Iamge字段中能够查询到数据,那么就可以直接将这个数据反序列化成BitmapImage对象 * common.BitmapImg image = SerializeObjectTostring.DeserializeObject(stu.StuImage) as common.BitmapImg; * BitmapImage bitmap = new BitmapImage(); * bitmap.BeginInit(); * bitmap.StreamSource = new MemoryStream(image.Buffer); * bitmap.EndInit(); * stuImg.Source = bitmap;*/ } }