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 FrmEditStudent_QQ287307421 : Form
    {
        public FrmEditStudent_QQ287307421(String studentNumber,FrmQueryStudent_QQ287307421 frmQueryStudent_QQ287307421)
        {
            InitializeComponent();
            this.studentNumber = studentNumber;
            this.frmQueryStudent_QQ287307421 = frmQueryStudent_QQ287307421;
        }
        private Student_QQ287307421 student_QQ287307421;
        private String studentNumber;
        private FrmQueryStudent_QQ287307421 frmQueryStudent_QQ287307421;
        private void Btn_Update_Click(object sender, EventArgs e)
        { 
            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.EditStudent_QQ287307421(student_QQ287307421))
                MessageBox.Show("学生信息更新成功!");
            else
                MessageBox.Show("学生信息更新失败!");
            frmQueryStudent_QQ287307421.BindData("refresh");
            this.Close(); 
        }

        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 FrmEditStudent_QQ287307421_Load(object sender, EventArgs e)
        {
            student_QQ287307421 = BLL.bllStudent_QQ287307421.getSomeStudent_QQ287307421(studentNumber);
            //查询所有的班级信息
            DataSet classInfoDs = BLL.bllClassInfo.getAllClassInfo();
            this.cb_studentClassNumber.DataSource = classInfoDs.Tables[0];
            this.cb_studentClassNumber.DisplayMember = "className";
            this.cb_studentClassNumber.ValueMember = "classNumber";
            this.cb_studentClassNumber.SelectedValue = student_QQ287307421.studentClassNumber.ToString();
            this.txt_studentNumber.ReadOnly = true;
            this.txt_studentNumber.Text = student_QQ287307421.studentNumber;
            this.txt_studentName.Text = student_QQ287307421.studentName;
            this.txt_studentPassword.Text = student_QQ287307421.studentPassword;
            this.txt_studentSex.Text = student_QQ287307421.studentSex;
            this.dtp_studentBirthday.Value = student_QQ287307421.studentBirthday;
            this.txt_studentState.Text = student_QQ287307421.studentState;
            byte[] studentPhoto = (byte[])(student_QQ287307421.studentPhoto);
            MemoryStream ms_studentPhoto = new MemoryStream(studentPhoto);
            pictureBox_studentPhoto.Image = Image.FromStream(ms_studentPhoto);
            this.txt_studentTelephone.Text = student_QQ287307421.studentTelephone;
            this.txt_studentEmail.Text = student_QQ287307421.studentEmail;
            this.txt_studentQQ.Text = student_QQ287307421.studentQQ;
            this.txt_studentAddress.Text = student_QQ287307421.studentAddress;
            this.txt_studentMemo.Text = student_QQ287307421.studentMemo;
        }
    }
}
