using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class UserControl_AddDept : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
   
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (this.DropDownList1.SelectedIndex != 0)
        {
            MODEL.Dept dept = BLL.BLLdept.getDeptModel(Convert.ToInt32(this.DropDownList1.SelectedValue));
            this.TextBox1.Text = dept.DeptName;
            this.FCKeditor1.Value = dept.DeptIntroduce;
        }
        else
        {
            this.TextBox1.Text = "";
            this.FCKeditor1.Value = "";
        }
    }
    protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        bool bl = BLL.BLLdept.checkDept(args.Value);
        if (bl == false)
        {
            args.IsValid = false;
        }
        else {
            args.IsValid = true;
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (this.DropDownList1.SelectedIndex == 0)
        {
            if (this.CustomValidator1.IsValid == false)
            {
                msgBox.putMsg("部门名称有重复");
                return;
            }
            MODEL.Dept dept = new MODEL.Dept();
            dept.DeptName = this.TextBox1.Text;
            dept.DeptIntroduce = this.FCKeditor1.Value;
            BLL.BLLdept.Insert(dept);
            msgBox.putMsg(" 部门插入成功", "AddDept.aspx");
        }
        else
        {
            MODEL.Dept dt = BLL.BLLdept.getDeptModel(Convert.ToInt32(this.DropDownList1.SelectedValue));
            dt.DeptID = Convert.ToInt32(this.DropDownList1.SelectedValue);
            dt.DeptName = this.TextBox1.Text;
            dt.DeptIntroduce = this.FCKeditor1.Value;
            BLL.BLLdept.Update(dt);
            msgBox.putMsg("部门更新成功", "AddDept.aspx");
        }
    }
    protected void DropDownList1_DataBound(object sender, EventArgs e)
    {
        this.DropDownList1.Items.Insert(0, "新建部门");
    }
   
}

////在跟新，插入，删除返回bool类型比较好，这里没有处理插入和更新失败的情况。。。。。。。。。