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 FrmAddTeacher_QQ287307421 : Form
    {
        public FrmAddTeacher_QQ287307421()
        {
            InitializeComponent();
        }

        private Teacher_QQ287307421 teacher_QQ287307421 = new Teacher_QQ287307421();
        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 Btn_Add_Click(object sender, EventArgs e)
        {
            if (this.txt_teacherNumber.Text == "")
            {
                MessageBox.Show("教师编号输入不能为空!");
                this.txt_teacherNumber.Focus();
                return;
            }
            teacher_QQ287307421.teacherNumber = this.txt_teacherNumber.Text;  //教师编号
            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.AddTeacher_QQ287307421(teacher_QQ287307421))
                MessageBox.Show("教师信息添加成功!");
            else
                MessageBox.Show("教师信息添加失败!");
            this.Close(); 
        }

        private void FrmAddTeacher_QQ287307421_Load(object sender, EventArgs e)
        {
            pictureBox_teacherPhoto.Image = Image.FromFile("pic/NoImage.jpg");
            pictureBox_teacherPhoto.SizeMode = PictureBoxSizeMode.StretchImage;
            FileStream teacherPhoto_fs = new FileStream("pic/NoImage.jpg", FileMode.Open, FileAccess.Read);
            BinaryReader teacherPhoto_bw = new BinaryReader(teacherPhoto_fs);
            teacher_QQ287307421.teacherPhoto = teacherPhoto_bw.ReadBytes((int)teacherPhoto_fs.Length);
        }
    }
}
