public FrmStudentInfo(StudentExt studentExt) : this() { this.lblStudentName.Text = studentExt.StudentName; this.lblGender.Text = studentExt.Gender; this.lblBirthday.Text = studentExt.Birthday.ToString("yyyyMMdd"); this.lblClass.Text = studentExt.ClassName; this.lblStudentIdNo.Text = studentExt.StudentIdNo; this.lblCardNo.Text = studentExt.CardNo; this.lblPhoneNumber.Text = studentExt.PhoneNumber; this.lblAddress.Text = studentExt.StudentAddress; this.pbStu.Image = studentExt.StuImage.Length == 0 ? Image.FromFile("default.png"): (Image)SerializeObjectToString.DeserializeObject(studentExt.StuImage); }
public static void ExecPrint(StudentExt student) { //【1】定义一个Excel工作簿对象 Application excelApp = new Application(); //【2】获取已创建工作簿的路径 string excelBookPath = Environment.CurrentDirectory + "\\StudentInfo.xlsx"; //【3】将现有的工作簿加入以及定义的工作簿集合 excelApp.Workbooks.Add(excelBookPath); //【4】获取第一个工作表 Worksheet sheet = excelApp.Worksheets[1]; //【5】将数据写入Excel //1.添加图片到指定位置 if (student.StuImage.Length != 0) { Image image = (Image)SerializeObjectToString.DeserializeObject(student.StuImage); string imagePath = Environment.CurrentDirectory + "\\StudentInfo.jpg"; if (File.Exists(imagePath)) { File.Delete(imagePath); } else { //保存图片到系统目录 image.Save(imagePath); //将图片插入到excel中 sheet.Shapes.AddPicture(imagePath, MsoTriState.msoFalse, MsoTriState.msoCTrue, 10, 50, 90, 100); File.Delete(imagePath); } } //2.写入其他数据 sheet.Cells[4, 4] = student.StudentId; sheet.Cells[4, 6] = student.StudentName; sheet.Cells[4, 8] = student.Gender; sheet.Cells[6, 4] = student.ClassName; sheet.Cells[6, 6] = student.PhoneNumber; sheet.Cells[8, 4] = student.StudentAddress; //【6】打印预览 excelApp.Visible = true; excelApp.Sheets.PrintPreview(true); //【7】释放对象 excelApp.Quit(); //退出;代表不用该程序 System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp); //释放资源;从内存中清理 excelApp = null; }
public FrmEditStudent(StudentExt studentExt) : this() { this.txtStudentId.Text = studentExt.StudentId.ToString(); this.txtStudentName.Text = studentExt.StudentName; this.rdoMale.Checked = studentExt.Gender == "男"; this.cboClassName.Text = studentExt.ClassName; this.dtpBirthday.Text = studentExt.Birthday.ToShortDateString(); this.txtStudentIdNo.Text = studentExt.StudentIdNo; this.txtCardNo.Text = studentExt.CardNo; this.txtPhoneNumber.Text = studentExt.PhoneNumber; this.txtAddress.Text = studentExt.StudentAddress; this.pbStu.Image = studentExt.StuImage.Length == 0 ? Image.FromFile("default.png") : (Image)SerializeObjectToString.DeserializeObject(studentExt.StuImage); if (studentExt.Gender == "男") { this.rdoMale.Checked = true; } else { this.rdoFemale.Checked = true; } }
/// <summary> /// 回车键打卡 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TxtStuCardNo_KeyDown(object sender, KeyEventArgs e) { if (e.KeyValue == 13 && this.txtStuCardNo.Text.Trim().Length != 0) { try { //展示学员信息 StudentExt studentInfo = studentService.GetStudebntByCardNo(this.txtStuCardNo.Text.Trim()); if (studentInfo == null) { this.lblStuName.Text = ""; this.lblStuId.Text = ""; this.lblStuClass.Text = ""; this.pbStu.Image = null; this.lblInfo.Text = "打卡失败!"; MessageBox.Show("考勤卡号错误!", "提示信息"); return; } else { //学员信息展示 this.lblStuName.Text = studentInfo.StudentName; this.lblStuId.Text = studentInfo.StudentId.ToString(); this.lblStuClass.Text = studentInfo.ClassName; #region 判断照片是否为null或者""字符串 if (studentInfo.StuImage == null || studentInfo.StuImage.Length == 0) { this.pbStu.Image = Image.FromFile("default.png"); } else { this.pbStu.Image = (Image)SerializeObjectToString.DeserializeObject(studentInfo.StuImage); } #endregion //添加打卡信息 string result = attendanceService.AddRecord(this.txtStuCardNo.Text.Trim()); if (result != "success") { this.lblInfo.Text = "打卡失败!"; MessageBox.Show(result, "提示信息"); } else { this.lblInfo.Text = "打卡成功!"; //更新打卡人员总数 SignStart(); //将学员信息同步展示到列表中 studentInfo.DTime = DateTime.Now; studentList.Add(studentInfo); this.dgvStudentList.DataSource = null; this.dgvStudentList.DataSource = studentList; //清空卡号,等待下一个打卡 this.txtStuCardNo.Text = ""; this.txtStuCardNo.Focus(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "提示信息"); } } }