using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

using Model;

namespace LoginFrame
{
    public partial class FrmAddStudent_QQ287307421 : Form
    {
        public FrmAddStudent_QQ287307421()
        {
            InitializeComponent();
        }

        private Student_QQ287307421 student_QQ287307421 = new Student_QQ287307421();
        private void btn_studentPhoto_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            try
            {
                openFileDialog1.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyComputer);
                openFileDialog1.Filter = "图片（*.jpg;*.bmp;*.gif,*.png）|*.jpg;*.bmp;*.gif;*.png";
                if (openFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    this.txt_studentPhoto.Text = openFileDialog1.FileName;
                    pictureBox_studentPhoto.Image = Image.FromFile(txt_studentPhoto.Text);
                    pictureBox_studentPhoto.SizeMode = PictureBoxSizeMode.StretchImage;
                    FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                    BinaryReader bw = new BinaryReader(fs);
                    student_QQ287307421.studentPhoto = bw.ReadBytes((int)fs.Length);
                }
            }
            catch
            {
                MessageBox.Show("请选择正确的图片格式", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void Btn_Add_Click(object sender, EventArgs e)
        {
            if (this.txt_studentNumber.Text == "")
            {
                MessageBox.Show("学号输入不能为空!");
                this.txt_studentNumber.Focus();
                return;
            }
            student_QQ287307421.studentNumber = this.txt_studentNumber.Text;  //学号
            if (this.txt_studentName.Text == "")
            {
                MessageBox.Show("姓名输入不能为空!");
                this.txt_studentName.Focus();
                return;
            }
            student_QQ287307421.studentName = this.txt_studentName.Text; //姓名
            if (this.txt_studentPassword.Text == "")
            {
                MessageBox.Show("登录密码输入不能为空!");
                this.txt_studentPassword.Focus();
                return;
            }
            student_QQ287307421.studentPassword = this.txt_studentPassword.Text; //登录密码
            if (this.txt_studentSex.Text == "")
            {
                MessageBox.Show("性别输入不能为空!");
                this.txt_studentSex.Focus();
                return;
            }
            student_QQ287307421.studentSex = this.txt_studentSex.Text; //性别
            student_QQ287307421.studentClassNumber = this.cb_studentClassNumber.SelectedValue.ToString(); //所在班级
            student_QQ287307421.studentBirthday = this.dtp_studentBirthday.Value;
            student_QQ287307421.studentState = this.txt_studentState.Text;  //政治面貌
            student_QQ287307421.studentTelephone = this.txt_studentTelephone.Text;  //联系电话
            student_QQ287307421.studentEmail = this.txt_studentEmail.Text;  //学生邮箱
            student_QQ287307421.studentQQ = this.txt_studentQQ.Text;  //联系qq
            student_QQ287307421.studentAddress = this.txt_studentAddress.Text;  //家庭地址
            student_QQ287307421.studentMemo = this.txt_studentMemo.Text;  //附加信息
            if (BLL.bllStudent_QQ287307421.AddStudent_QQ287307421(student_QQ287307421))
                MessageBox.Show("学生信息添加成功!");
            else
                MessageBox.Show("学生信息添加失败!");
            this.Close(); 
        }

        private void FrmAddStudent_QQ287307421_Load(object sender, EventArgs e)
        {
            //查询所有的班级信息
            DataSet classInfoDs = BLL.bllClassInfo.getAllClassInfo();
            this.cb_studentClassNumber.DataSource = classInfoDs.Tables[0];
            this.cb_studentClassNumber.DisplayMember = "className";
            this.cb_studentClassNumber.ValueMember = "classNumber";
            pictureBox_studentPhoto.Image = Image.FromFile("pic/NoImage.jpg");
            pictureBox_studentPhoto.SizeMode = PictureBoxSizeMode.StretchImage;
            FileStream studentPhoto_fs = new FileStream("pic/NoImage.jpg", FileMode.Open, FileAccess.Read);
            BinaryReader studentPhoto_bw = new BinaryReader(studentPhoto_fs);
            student_QQ287307421.studentPhoto = studentPhoto_bw.ReadBytes((int)studentPhoto_fs.Length);
        }
    }
}
