Esempio n. 1
0
        /// <summary>
        /// 显示学员信息
        /// </summary>
        public FrmStudentinfo(StudentExt objStudent)
        {
            InitializeComponent();
            this.lblStudentIdNo.Text = objStudent.StudentId.ToString();
            this.lblStudentName.Text = objStudent.StudentName;
            this.lblPhoneNumber.Text = objStudent.PhoneNumber;
            this.lblAddress.Text = objStudent.StudentAddress;
            this.lblBirthday.Text = objStudent.Birthday.ToShortDateString();
            this.lblCardNo.Text = objStudent.CardNo;
            this.lblClass.Text = objStudent.ClassName;
            this.lblGender.Text = objStudent.Gender;
            //图片反序列化
            this.pbStu.Image = objStudent.StuImage.Length == 0 ? Image.FromFile("default.png") : (Image) new SerializeObjectToString().DeserializeObject(objStudent.StuImage);

        }
Esempio n. 2
0
 public void ExecutePrint(StudentExt objStudent)
 {
     //1.定义一个Excel工作簿
     Microsoft.Office.Interop.Excel.Application excelApp = new Application();
     //2.获取已创建好的工作簿路径
     string excelBookPath = Environment.CurrentDirectory + "\\StudentInfo.xls";
     //3.将现有工作簿加入已定义的工作簿集合
     excelApp.Workbooks.Add(excelBookPath);
     //4.获取第一个工作表
     Worksheet objSheet = (Worksheet)excelApp.Worksheets[1];
     //5.在当前Excel中写入数据
     if (objStudent.StuImage.Length != 0)
     {
         //将图片保存在指定的位置
         Image objImage = (Image)new
             StudentManager.SerializeObjectToString().DeserializeObject(objStudent.StuImage);
         if (File.Exists(Environment.CurrentDirectory + "\\Student.jpg"))
             File.Delete(Environment.CurrentDirectory + "\\Student.jp");
         else
         {
             //保存图片到系统目录(当前会保存到debug或者release文件夹中)
             objImage.Save(Environment.CurrentDirectory + "\\Student.jpg");
             //将图片插入到Excel中
             objSheet.Shapes.AddPicture(Environment.CurrentDirectory + "\\Student.jpg", MsoTriState.msoFalse, MsoTriState.msoTrue, 10, 50, 70, 80);
             //使用完毕后删除保存的图片
             File.Delete(Environment.CurrentDirectory + "\\Student.jpg");
         }
     }
     //写入其他数据
     objSheet.Cells[4, 4] = objStudent.StudentId;
     objSheet.Cells[4, 6] = objStudent.StudentName;
     objSheet.Cells[4, 8] = objStudent.Gender;
     objSheet.Cells[6, 4] = objStudent.ClassName;
     objSheet.Cells[6, 6] = objStudent.PhoneNumber;
     objSheet.Cells[8, 4] = objStudent.StudentAddress;
     //6.打印预览
     excelApp.Visible = true;
     excelApp.Sheets.PrintPreview(true);
     //7.释放对象
     excelApp.Quit();
     System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApp);//释放
     excelApp = null;
 }
Esempio n. 3
0
        public FrmEditStudent(StudentExt objStudent)
        {
            InitializeComponent();
            //初始化班级下拉框
            this.cboClassName.DataSource = objClassService.GetAllClass();
            this.cboClassName.DisplayMember = "ClassName";
            this.cboClassName.ValueMember = "ClassId";

            this.txtStudentId.Text = objStudent.StudentId.ToString();
            this.txtStudentIdNo.Text = objStudent.StudentIdNo.ToString();
            this.txtStudentName.Text = objStudent.StudentName;
            this.txtPhoneNumber.Text = objStudent.PhoneNumber;
            this.txtAddress.Text = objStudent.StudentAddress;
            this.dtpBirthday.Text = objStudent.Birthday.ToShortDateString();
            this.txtCardNo.Text = objStudent.CardNo;
            if (objStudent.Gender == "男") this.rdoMale.Checked = true;
            else this.rdoFemale.Checked = true;
            this.cboClassName.Text = objStudent.ClassName;
            //图片反序列化
            this.pbStu.Image = objStudent.StuImage.Length == 0 ? Image.FromFile("default.png") : (Image)new SerializeObjectToString().DeserializeObject(objStudent.StuImage);
        }
Esempio n. 4
0
 private StudentExt GetStudentBySql(string whereSql)
 {
     string sql = "select StudentName,StudentId,Age,Gender,Birthday,CardNo,ClassName,StudentIdNo,PhoneNumber,StudentAddress,StuImage from Students";
     sql += " inner join StudentClass on Students.ClassId=StudentClass.ClassId ";//注意开头的空格
     sql += whereSql;
     SqlDataReader objReader = SQLHelper.GetReader(sql);
     StudentExt objStudent = null;
     if (objReader.Read())
     {
         objStudent = new StudentExt()
         {
             StudentId = Convert.ToInt32(objReader["StudentId"]),
             StudentName = objReader["StudentName"].ToString(),
             Gender = objReader["Gender"].ToString(),
             Birthday = Convert.ToDateTime(objReader["Birthday"]),
             ClassName = objReader["ClassName"].ToString(),
             CardNo = objReader["CardNo"].ToString(),
             StudentIdNo = objReader["StudentIdNo"].ToString(),
             Age = Convert.ToInt32(objReader["Age"]),
             PhoneNumber = objReader["PhoneNumber"].ToString(),
             StudentAddress = objReader["StudentAddress"].ToString(),
             StuImage = objReader["StuImage"] is DBNull ? "" : objReader["StuImage"].ToString()
         };
     }
     objReader.Close();
     return objStudent;
 }