Example #1
0
 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);
 }
Example #2
0
        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;
        }
Example #3
0
 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;
     }
 }
Example #4
0
        //提交修改
        private void BtnModify_Click(object sender, EventArgs e)
        {
            #region 数据验证
            if (this.txtStudentName.Text.Trim().Length == 0)
            {
                MessageBox.Show("学生姓名不能为空!", "提示信息");
                return;
            }

            var age = DateTime.Now.Year - Convert.ToDateTime(this.dtpBirthday.Text).Year;

            if (age < 18 || age > 35)
            {
                MessageBox.Show("年龄必须在18到35之间!", "提示信息");
                return;
            }

            if (!DataValidate.IsIdentityCard(this.txtStudentIdNo.Text.Trim()))
            {
                MessageBox.Show("身份证号不符合要求!", "提示信息");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            //验证身份证号与出生日期是否一致
            var birthday = Convert.ToDateTime(this.dtpBirthday.Text).ToString("yyyyMMdd");
            if (!this.txtStudentIdNo.Text.Trim().Contains(birthday))
            {
                MessageBox.Show("身份证与出生日期不匹配!", "提示信息");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            var studentId = Convert.ToInt32(this.txtStudentId.Text.Trim());
            if (studentService.IsIdNoExisted(this.txtStudentIdNo.Text.Trim(), studentId))
            {
                MessageBox.Show("身份证号已经被其他学员使用!", "修改提示");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            if (studentService.IsCradNoExisted(this.txtCardNo.Text.Trim(), studentId))
            {
                MessageBox.Show("考勤卡号已经被其他学员使用!", "修改提示");
                this.txtCardNo.SelectAll();
                this.txtCardNo.Focus();
                return;
            }
            #endregion

            Students student = new Students
            {
                StudentId                                          = studentId,
                StudentName                                        = this.txtStudentName.Text.Trim(),
                Gender                                             = this.rdoMale.Checked?"男":"女",
                Birthday                                           = Convert.ToDateTime(this.dtpBirthday.Text),
                StudentIdNo                                        = this.txtStudentIdNo.Text.Trim(),
                CardNo                                             = this.txtCardNo.Text.Trim(),
                StuImage                                           = this.pbStu.Image != null?SerializeObjectToString.SerializeObject(this.pbStu.Image) : "",
                                                    Age            = age,
                                                    PhoneNumber    = this.txtPhoneNumber.Text.Trim(),
                                                    StudentAddress = this.txtAddress.Text.Trim(),
                                                    ClassId        = Convert.ToInt32(this.cboClassName.SelectedValue),
            };

            try
            {
                var result = studentService.UpdateStudentInfo(student);
                if (result == 1)
                {
                    MessageBox.Show("学员信息修改成功!", "提示信息");

                    var item = FrmStudentManage.studentList.First(o => o.StudentId == studentId);
                    item.StudentName = this.txtStudentName.Text.Trim();
                    item.Gender      = this.rdoMale.Checked ? "男" : "女";
                    item.StudentIdNo = this.txtStudentIdNo.Text;
                    item.Birthday    = this.dtpBirthday.Value;
                    item.PhoneNumber = this.txtPhoneNumber.Text;
                    item.ClassName   = this.cboClassName.Text;
                    //this.dgvStudentList.Refresh();


                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示信息");
            }
        }
Example #5
0
 /// <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, "提示信息");
         }
     }
 }
Example #6
0
        //添加学员
        private void BtnAdd_Click(object sender, EventArgs e)
        {
            #region 数据验证
            if (this.txtStudentName.Text.Trim().Length == 0)
            {
                MessageBox.Show("学生姓名不能为空!", "提示信息");
                return;
            }

            if (this.rdoFemale.Checked == false && this.rdoMale.Checked == false)
            {
                MessageBox.Show("请选择性别!", "提示信息");
                return;
            }

            if (this.cboClassName.SelectedIndex == -1)
            {
                MessageBox.Show("请选择班级!", "提示信息");
                return;
            }

            var age = DateTime.Now.Year - Convert.ToDateTime(this.dtpBirthday.Text).Year;

            if (age < 18 || age > 35)
            {
                MessageBox.Show("年龄必须在18到35之间!", "提示信息");
                return;
            }

            if (!DataValidate.IsIdentityCard(this.txtStudentIdNo.Text.Trim()))
            {
                MessageBox.Show("身份证号不符合要求!", "提示信息");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            //验证身份证号与出生日期是否一致
            var birthday = Convert.ToDateTime(this.dtpBirthday.Text).ToString("yyyyMMdd");
            if (!this.txtStudentIdNo.Text.Trim().Contains(birthday))
            {
                MessageBox.Show("身份证与出生日期不匹配!", "提示信息");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            if (studentService.IsIdNoExisted(this.txtStudentIdNo.Text.Trim()))
            {
                MessageBox.Show("身份证号已经被其他学员使用!", "提示信息");
                this.txtStudentIdNo.SelectAll();
                this.txtStudentIdNo.Focus();
                return;
            }

            if (studentService.IsCradNoExisted(this.txtCardNo.Text.Trim()))
            {
                MessageBox.Show("考勤卡号已经被其他学员使用!", "提示信息");
                this.txtCardNo.SelectAll();
                this.txtCardNo.Focus();
                return;
            }



            #endregion

            #region 对象封装
            Students student = new Students
            {
                StudentName                                        = this.txtStudentName.Text.Trim(),
                Gender                                             = this.rdoFemale.Checked ? "女" : "男",
                Birthday                                           = Convert.ToDateTime(this.dtpBirthday.Text),
                StudentIdNo                                        = this.txtStudentIdNo.Text.Trim(),
                StuImage                                           = this.pbStu.Image != null?SerializeObjectToString.SerializeObject(this.pbStu.Image) : "",
                                                    Age            = age,
                                                    CardNo         = this.txtCardNo.Text.Trim(),
                                                    PhoneNumber    = this.txtPhoneNumber.Text.Trim(),
                                                    StudentAddress = this.txtAddress.Text.Trim(),
                                                    StudentId      = Convert.ToInt32(this.cboClassName.SelectedValue),
                                                    ClassId        = Convert.ToInt32(this.cboClassName.SelectedValue)
            };
            #endregion

            #region 后台调用
            try
            {
                var studenteId = studentService.AddNewStudent(student);
                if (studenteId == 1)
                {
                    student.ClassId = studenteId;
                    studentList.Add(student);
                    this.dgvStudentList.DataSource = null;
                    this.dgvStudentList.DataSource = studentList;
                    #region endregion询问是否继续添加
                    DialogResult result = MessageBox.Show("学员添加成功,是否继续添加?", "提示信息", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result == DialogResult.Yes)
                    {
                        //清空数据
                        foreach (Control item in this.gbstuinfo.Controls)
                        {
                            if (item is TextBox)
                            {
                                item.Text = string.Empty;
                            }
                        }
                        this.cboClassName.SelectedIndex = -1;
                        this.rdoFemale.Checked          = false;
                        this.rdoMale.Checked            = false;
                        this.pbStu.Image = null;
                        this.txtStudentName.Focus();
                    }
                    else
                    {
                        this.Close();
                    }
                    # endregion
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("添加学员出现访问异常:" + ex.Message);
            }
            #endregion
        }