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 FrmEditTeacher_QQ287307421 : Form
    {
        public FrmEditTeacher_QQ287307421(String teacherNumber,FrmQueryTeacher_QQ287307421 frmQueryTeacher_QQ287307421)
        {
            InitializeComponent();
            this.teacherNumber = teacherNumber;
            this.frmQueryTeacher_QQ287307421 = frmQueryTeacher_QQ287307421;
        }
        private Teacher_QQ287307421 teacher_QQ287307421;
        private String teacherNumber;
        private FrmQueryTeacher_QQ287307421 frmQueryTeacher_QQ287307421;
        private void Btn_Update_Click(object sender, EventArgs e)
        { 
            if (this.txt_teacherName.Text == "")
            {
                MessageBox.Show("教师姓名输入不能为空!");
                this.txt_teacherName.Focus();
                return;
            }
            teacher_QQ287307421.teacherName = this.txt_teacherName.Text; //教师姓名
            teacher_QQ287307421.teacherPassword = this.txt_teacherPassword.Text;  //登录密码
            if (this.txt_teacherSex.Text == "")
            {
                MessageBox.Show("性别输入不能为空!");
                this.txt_teacherSex.Focus();
                return;
            }
            teacher_QQ287307421.teacherSex = this.txt_teacherSex.Text; //性别
            teacher_QQ287307421.teacherBirthday = this.dtp_teacherBirthday.Value;
            teacher_QQ287307421.teacherArriveDate = this.dtp_teacherArriveDate.Value;
            teacher_QQ287307421.teacherCardNumber = this.txt_teacherCardNumber.Text;  //身份证号
            teacher_QQ287307421.teacherPhone = this.txt_teacherPhone.Text;  //联系电话
            teacher_QQ287307421.teacherAddress = this.txt_teacherAddress.Text;  //家庭地址
            teacher_QQ287307421.teacherMemo = this.txt_teacherMemo.Text;  //附加信息
            if (BLL.bllTeacher_QQ287307421.EditTeacher_QQ287307421(teacher_QQ287307421))
                MessageBox.Show("教师信息更新成功!");
            else
                MessageBox.Show("教师信息更新失败!");
            frmQueryTeacher_QQ287307421.BindData("refresh");
            this.Close(); 
        }

        private void btn_teacherPhoto_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_teacherPhoto.Text = openFileDialog1.FileName;
                    pictureBox_teacherPhoto.Image = Image.FromFile(txt_teacherPhoto.Text);
                    pictureBox_teacherPhoto.SizeMode = PictureBoxSizeMode.StretchImage;
                    FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                    BinaryReader bw = new BinaryReader(fs);
                    teacher_QQ287307421.teacherPhoto = bw.ReadBytes((int)fs.Length);
                }
            }
            catch
            {
                MessageBox.Show("请选择正确的图片格式", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }

        private void FrmEditTeacher_QQ287307421_Load(object sender, EventArgs e)
        {
            teacher_QQ287307421 = BLL.bllTeacher_QQ287307421.getSomeTeacher_QQ287307421(teacherNumber);
            this.txt_teacherNumber.ReadOnly = true;
            this.txt_teacherNumber.Text = teacher_QQ287307421.teacherNumber;
            this.txt_teacherName.Text = teacher_QQ287307421.teacherName;
            this.txt_teacherPassword.Text = teacher_QQ287307421.teacherPassword;
            this.txt_teacherSex.Text = teacher_QQ287307421.teacherSex;
            this.dtp_teacherBirthday.Value = teacher_QQ287307421.teacherBirthday;
            this.dtp_teacherArriveDate.Value = teacher_QQ287307421.teacherArriveDate;
            this.txt_teacherCardNumber.Text = teacher_QQ287307421.teacherCardNumber;
            this.txt_teacherPhone.Text = teacher_QQ287307421.teacherPhone;
            byte[] teacherPhoto = (byte[])(teacher_QQ287307421.teacherPhoto);
            MemoryStream ms_teacherPhoto = new MemoryStream(teacherPhoto);
            pictureBox_teacherPhoto.Image = Image.FromStream(ms_teacherPhoto);
            this.txt_teacherAddress.Text = teacher_QQ287307421.teacherAddress;
            this.txt_teacherMemo.Text = teacher_QQ287307421.teacherMemo;
        }
    }
}
