protected void btnSave_ServerClick(object sender, EventArgs e)
    {
        if (btnAdd.Disabled == true)
        {
            if (Gzl.BusinessLogicLayer.KC.HasKC(txtKcmc.Value.Trim()))   //判断当前添加的课程名称是否已存在,存在则提示信息
            {
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('已存在相同课程名称');</script>");
                txtKcmc.Value = "";
            }
            else
            {
                //自动生成课程编号
                string    kcbh       = selSsyx.Value + selKcxz.SelectedValue + selKclx.SelectedValue; //构建课程编号类型组合,院系编号+课程性质+课程类型
                Hashtable queryItems = new Hashtable();                                               //构造KC查找哈希表
                queryItems.Add("kcbh", kcbh);
                DataTable table = Gzl.BusinessLogicLayer.KC.QueryKC(queryItems);                      //查找相同“院系编号+课程性质+课程类型”
                int       max   = 0;
                //找出相同“院系编号+课程性质+课程类型”的课程编号最大值
                foreach (DataRow dr in table.Rows)
                {
                    max = Math.Max(Convert.ToInt32(dr["kcbh"].ToString().Substring(6, 4)), max);
                }
                //构建当前要添加的课程编号
                string count = "";
                if (max < 9)
                {
                    max  += 1;
                    count = "000" + Convert.ToString(max);
                }
                else
                {
                    if (max < 99)
                    {
                        max  += 1;
                        count = "00" + Convert.ToString(max);
                    }
                    else
                    {
                        if (max < 999)
                        {
                            max  += 1;
                            count = "0" + Convert.ToString(max);
                        }
                        else
                        {
                            max  += 1;
                            count = Convert.ToString(max);
                        }
                    }
                }
                kcbh = kcbh + count;
                Hashtable hash = new Hashtable(); //构造课程信息哈希表
                //把课程编号、课程名称、课程性质、课程类型、有效标志添加到课程信息哈希表中
                hash.Add("kcbh", SqlStringConstructor.GetQuotedString(kcbh));
                hash.Add("kcmc", SqlStringConstructor.GetQuotedString(txtKcmc.Value.Trim()));
                hash.Add("kcxz", SqlStringConstructor.GetQuotedString(selKcxz.SelectedItem.Text));
                hash.Add("kclx", SqlStringConstructor.GetQuotedString(selKclx.SelectedItem.Text));
                hash.Add("yxbz", Convert.ToInt32(selKcyxbz.Value));
                if (checkFdkcsj.Checked == true)      //附带课程设计
                {
                    hash.Add("fdkcsj", 1);
                    Hashtable ht = new Hashtable();//构建课程设计信息哈希表
                    //把课程设计编号、课程设计名称、课程设计周数、有效标志添加到课程设计信息哈希表中
                    ht.Add("kcsjbh", SqlStringConstructor.GetQuotedString(kcbh + "sj"));
                    ht.Add("kcsjmc", SqlStringConstructor.GetQuotedString(txtKcmc.Value.Trim() + "(课程设计)"));
                    ht.Add("kcsjzs", Convert.ToDecimal(txtKcsjzs.Value));
                    ht.Add("yxbz", Convert.ToInt32(selKcsjyxbz.Value));
                    Gzl.BusinessLogicLayer.KCSJ.Add(ht);     //添加课程设计信息到数据库
                }
                else
                {
                    hash.Add("fdkcsj", 0);
                }
                Gzl.BusinessLogicLayer.KC.Add(hash);    //添加课程信息到数据库

                txtKcmc.Value        = "";
                txtKcsjmc.Value      = "";
                txtKcsjzs.Value      = "";
                txtKcmc.Disabled     = true;
                selSsyx.Disabled     = true;
                selKcyxbz.Disabled   = true;
                selKclx.Enabled      = false;
                selKcxz.Enabled      = false;
                checkFdkcsj.Enabled  = false;
                txtKcsjzs.Disabled   = true;
                selKcsjyxbz.Disabled = true;

                btnAdd.Disabled     = false;
                checkFdkcsj.Checked = false;
                btnCancel.Disabled  = true;
                btnSave.Disabled    = true;
                ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('添加成功');</script>");
                Query();
            }
        }

        if (btnChag.Disabled == true)
        {
            Hashtable hash = new Hashtable();

            hash.Add("kcmc", SqlStringConstructor.GetQuotedString(txtKcmc.Value.Trim()));
            hash.Add("kcxz", SqlStringConstructor.GetQuotedString(selKcxz.SelectedItem.Text));
            hash.Add("kclx", SqlStringConstructor.GetQuotedString(selKclx.SelectedItem.Text));
            hash.Add("yxbz", Convert.ToInt32(selKcyxbz.Value));
            string where = "Where kcbh = " + SqlStringConstructor.GetQuotedString(txtKcbh.Value.Trim());
            if (checkFdkcsj.Checked == true)
            {
                hash.Add("fdkcsj", 1);
                Hashtable ht = new Hashtable();

                if (KCSJ.HasKCSJ(txtKcbh.Value.Trim() + "sj"))
                {
                    ht.Add("kcsjmc", SqlStringConstructor.GetQuotedString(txtKcmc.Value.Trim() + "(课程设计)"));
                    ht.Add("kcsjzs", Convert.ToDecimal(txtKcsjzs.Value));
                    ht.Add("yxbz", Convert.ToInt32(selKcsjyxbz.Value));
                    string where1 = "Where kcsjbh = " + SqlStringConstructor.GetQuotedString(txtKcbh.Value.Trim() + "sj");
                    KCSJ.Update(ht, where1);
                }
                else
                {
                    ht.Add("kcsjbh", SqlStringConstructor.GetQuotedString(txtKcbh.Value.Trim() + "sj"));
                    ht.Add("kcsjmc", SqlStringConstructor.GetQuotedString(txtKcmc.Value.Trim() + "(课程设计)"));
                    ht.Add("kcsjzs", Convert.ToDecimal(txtKcsjzs.Value));
                    ht.Add("yxbz", Convert.ToInt32(selKcsjyxbz.Value));
                    KCSJ.Add(ht);
                }
            }
            else
            {
                hash.Add("fdkcsj", 0);
                if (KCSJ.HasKCSJ(txtKcbh.Value.Trim() + "sj"))
                {
                    KCSJ.Delete(txtKcbh.Value.Trim() + "sj");
                }
            }
            Gzl.BusinessLogicLayer.KC.Update(hash, where);
            txtKcmc.Value        = "";
            txtKcsjmc.Value      = "";
            txtKcsjzs.Value      = "";
            txtKcmc.Disabled     = true;
            selSsyx.Disabled     = true;
            selKcyxbz.Disabled   = true;
            selKclx.Enabled      = false;
            selKcxz.Enabled      = false;
            checkFdkcsj.Enabled  = false;
            txtKcsjzs.Disabled   = true;
            selKcsjyxbz.Disabled = true;
            checkFdkcsj.Checked  = false;
            btnSave.Disabled     = true;
            btnChag.Disabled     = false;
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('修改成功');</script>");
            Query();
        }
    }
    /// <summary>
    /// 修改
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnChag_ServerClick(object sender, EventArgs e)
    {
        ArrayList selectedKC = GetSelected();
        KC        kc         = new KC();

        if (selectedKC.Count != 1)
        {
            ClientScript.RegisterStartupScript(this.GetType(), "", "<script>alert('请选择一个课程!');</script>");
            return;
        }
        string kcbh = selectedKC[0].ToString();

        kc.LoadData(kcbh);
        txtKcbh.Value = kc.Kcbh;
        txtKcmc.Value = kc.Kcmc;
        foreach (ListItem item in selKcxz.Items)
        {
            if (item.Selected == true)
            {
                item.Selected = false;
            }
            if (item.Text == kc.Kcxz)
            {
                item.Selected = true;
            }
        }
        foreach (ListItem item in selKcyxbz.Items)
        {
            if (item.Selected == true)
            {
                item.Selected = false;
            }

            if (item.Value == Convert.ToString(Convert.ToInt32(kc.Yxbz)))
            {
                item.Selected = true;
            }
        }
        foreach (ListItem item in selKclx.Items)
        {
            if (item.Selected == true)
            {
                item.Selected = false;
            }

            if (item.Value == kc.Kclx)
            {
                item.Selected = true;
            }
        }
        if (kc.Fdkcsj == true)
        {
            checkFdkcsj.Checked = true;
            KCSJ   kcsj   = new KCSJ();
            string kcsjbh = kc.Kcbh + "sj";
            kcsj.LoadData(kcsjbh);
            txtKcsjmc.Value = kcsj.Kcsjmc;
            txtKcsjzs.Value = kcsj.Kcsjzs;
            foreach (ListItem item in selKcsjyxbz.Items)
            {
                if (item.Selected == true)
                {
                    item.Selected = false;
                }

                if (item.Value == Convert.ToString(Convert.ToInt32(kcsj.Yxbz)))
                {
                    item.Selected = true;
                }
            }
            selKcsjyxbz.Disabled = false;
            txtKcsjzs.Disabled   = false;
        }

        txtKcmc.Disabled    = false;
        selSsyx.Disabled    = false;
        selKcyxbz.Disabled  = false;
        selKclx.Enabled     = true;
        selKcxz.Enabled     = true;
        checkFdkcsj.Enabled = true;
        btnChag.Disabled    = true;
        btnSave.Disabled    = false;
        btnCancel.Disabled  = false;
        btnAdd.Disabled     = false;
    }