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 FrmEditClassInfo : Form
    {
        public FrmEditClassInfo(String classNumber,FrmQueryClassInfo frmQueryClassInfo)
        {
            InitializeComponent();
            this.classNumber = classNumber;
            this.frmQueryClassInfo = frmQueryClassInfo;
        }
        private ClassInfo classInfo;
        private String classNumber;
        private FrmQueryClassInfo frmQueryClassInfo;
        private void Btn_Update_Click(object sender, EventArgs e)
        { 
            if (this.txt_className.Text == "")
            {
                MessageBox.Show("班级名称输入不能为空!");
                this.txt_className.Focus();
                return;
            }
            classInfo.className = this.txt_className.Text; //班级名称
            classInfo.classSpecialFieldNumber = this.cb_classSpecialFieldNumber.SelectedValue.ToString(); //所属专业
            classInfo.classBirthDate = this.dtp_classBirthDate.Value;
            classInfo.classTeacherCharge = this.txt_classTeacherCharge.Text;  //班主任
            classInfo.classTelephone = this.txt_classTelephone.Text;  //联系电话
            classInfo.classMemo = this.txt_classMemo.Text;  //附加信息
            if (BLL.bllClassInfo.EditClassInfo(classInfo))
                MessageBox.Show("班级信息更新成功!");
            else
                MessageBox.Show("班级信息更新失败!");
            frmQueryClassInfo.BindData("refresh");
            this.Close(); 
        }

        private void FrmEditClassInfo_Load(object sender, EventArgs e)
        {
            classInfo = BLL.bllClassInfo.getSomeClassInfo(classNumber);
            //查询所有的专业信息
            DataSet specialFieldInfoDs = BLL.bllSpecialFieldInfo.getAllSpecialFieldInfo();
            this.cb_classSpecialFieldNumber.DataSource = specialFieldInfoDs.Tables[0];
            this.cb_classSpecialFieldNumber.DisplayMember = "specialFieldName";
            this.cb_classSpecialFieldNumber.ValueMember = "specialFieldNumber";
            this.cb_classSpecialFieldNumber.SelectedValue = classInfo.classSpecialFieldNumber.ToString();
            this.txt_classNumber.ReadOnly = true;
            this.txt_classNumber.Text = classInfo.classNumber;
            this.txt_className.Text = classInfo.className;
            this.dtp_classBirthDate.Value = classInfo.classBirthDate;
            this.txt_classTeacherCharge.Text = classInfo.classTeacherCharge;
            this.txt_classTelephone.Text = classInfo.classTelephone;
            this.txt_classMemo.Text = classInfo.classMemo;
        }
    }
}
