protected void btn_AddGift_Click(object sender, EventArgs e)
 {
     IList<CAT_GiftApplyDetail> _giftListdetail = (IList<CAT_GiftApplyDetail>)ViewState["GiftListDetails"];
     CAT_GiftApplyDetail _m = new CAT_GiftApplyDetail();
     int product = 0;
     if (int.TryParse(select_GiftProduct.SelectValue, out product))
     {
         _m.Product = product;
     }
     else
     {
         MessageBox.Show(this, "产品必填!");
         return;
     }
     _m.ApplyQuantity = int.Parse(txt_ApplyCount.Text.Trim());
     _m.Remark = txt_GiftRemark.Text.Trim();
     _m.Activity = (int)ViewState["ID"];
     if (_giftListdetail.Where(p => p.Product == product).Count() == 0)
     {
         _giftListdetail.Add(_m);
         if (_m.Activity > 0)
         {
             CAT_GiftApplyDetailBLL _bll = new CAT_GiftApplyDetailBLL();
             _bll.Model = _m;
             _bll.Add();
         }
         BindGrid();
     }
 }
    protected void btn_AddGift_Click(object sender, EventArgs e)
    {
        IList <CAT_GiftApplyDetail> _giftListdetail = (IList <CAT_GiftApplyDetail>)ViewState["GiftListDetails"];
        CAT_GiftApplyDetail         _m = new CAT_GiftApplyDetail();
        int product = 0;

        if (int.TryParse(select_GiftProduct.SelectValue, out product))
        {
            _m.Product = product;
        }
        else
        {
            MessageBox.Show(this, "产品必填!");
            return;
        }
        _m.ApplyQuantity = int.Parse(txt_ApplyCount.Text.Trim());
        _m.Remark        = txt_GiftRemark.Text.Trim();
        _m.Activity      = (int)ViewState["ID"];
        if (_giftListdetail.Where(p => p.Product == product).Count() == 0)
        {
            _giftListdetail.Add(_m);
            if (_m.Activity > 0)
            {
                CAT_GiftApplyDetailBLL _bll = new CAT_GiftApplyDetailBLL();
                _bll.Model = _m;
                _bll.Add();
            }
            BindGrid();
        }
    }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        CAT_ActivityBLL _bll;
        if ((int)ViewState["ID"] != 0)
        {
            //修改
            _bll = new CAT_ActivityBLL((int)ViewState["ID"]);

        }
        else
        {
            //新增
            _bll = new CAT_ActivityBLL();
        }

        pl_detail.GetData(_bll.Model);

        #region 判断必填项
        if (_bll.Model.OrganizeCity == 0)
        {
            MessageBox.Show(this, "请选择活动举办的管理片区!");
            return;
        }

        if (_bll.Model.Officialcity == 0)
        {
            MessageBox.Show(this, "请选择活动所属城市!");
            return;
        }

        if (_bll.Model.Topic == "")
        {
            MessageBox.Show(this, "活动主题不能为空!");
            return;
        }
        if (_bll.Model.Address == "")
        {
            MessageBox.Show(this, "举办地址不能为空!");
            return;
        }

        if (_bll.Model.Classify == 0)
        {
            MessageBox.Show(this, "请选择活动的分类!");
            return;
        }
        #endregion

        if ((int)ViewState["ID"] != 0)
        {
            //修改
            _bll.Model.UpdateStaff = (int)Session["UserID"];
            if (_bll.Update() == 0 && sender != null) MessageBox.ShowAndRedirect(this, "修改成功!", "CAT_ActivityList.aspx");
        }
        else
        {
            //新增

            _bll.Model.InsertStaff = (int)Session["UserID"];
            _bll.Model.ApproveFlag = 2;
            ViewState["ID"] = _bll.Add();
            if ((int)ViewState["ID"] > 0)
            {
                IList<CAT_FeeApplyDetail> _details = (IList<CAT_FeeApplyDetail>)ViewState["FeeListDetails"];
                IList<CAT_GiftApplyDetail> _giftdetail = (IList<CAT_GiftApplyDetail>)ViewState["GiftListDetails"];
                CAT_FeeApplyDetailBLL _feebll = new CAT_FeeApplyDetailBLL();
                CAT_GiftApplyDetailBLL _giftbll = new CAT_GiftApplyDetailBLL();
                foreach (CAT_GiftApplyDetail _m in _giftdetail)
                {
                    _m.Activity = (int)ViewState["ID"];
                    _giftbll.Model = _m;
                    _giftbll.Add();
                }
                foreach (CAT_FeeApplyDetail _m in _details)
                {
                    _m.Activity = (int)ViewState["ID"];
                    _feebll.Model = _m;
                    _feebll.Add();
                }
                MessageBox.ShowAndRedirect(this, "新增成功!", "CAT_ActivityDetail.aspx?ID=" + ViewState["ID"].ToString());
            }

        }
    }
    protected void bt_OK_Click(object sender, EventArgs e)
    {
        CAT_ActivityBLL _bll;

        if ((int)ViewState["ID"] != 0)
        {
            //修改
            _bll = new CAT_ActivityBLL((int)ViewState["ID"]);
        }
        else
        {
            //新增
            _bll = new CAT_ActivityBLL();
        }


        pl_detail.GetData(_bll.Model);


        #region 判断必填项
        if (_bll.Model.OrganizeCity == 0)
        {
            MessageBox.Show(this, "请选择活动举办的管理片区!");
            return;
        }

        if (_bll.Model.Officialcity == 0)
        {
            MessageBox.Show(this, "请选择活动所属城市!");
            return;
        }

        if (_bll.Model.Topic == "")
        {
            MessageBox.Show(this, "活动主题不能为空!");
            return;
        }
        if (_bll.Model.Address == "")
        {
            MessageBox.Show(this, "举办地址不能为空!");
            return;
        }

        if (_bll.Model.Classify == 0)
        {
            MessageBox.Show(this, "请选择活动的分类!");
            return;
        }
        #endregion

        if ((int)ViewState["ID"] != 0)
        {
            //修改
            _bll.Model.UpdateStaff = (int)Session["UserID"];
            if (_bll.Update() == 0 && sender != null)
            {
                MessageBox.ShowAndRedirect(this, "修改成功!", "CAT_ActivityList.aspx");
            }
        }
        else
        {
            //新增

            _bll.Model.InsertStaff = (int)Session["UserID"];
            _bll.Model.ApproveFlag = 2;
            ViewState["ID"]        = _bll.Add();
            if ((int)ViewState["ID"] > 0)
            {
                IList <CAT_FeeApplyDetail>  _details    = (IList <CAT_FeeApplyDetail>)ViewState["FeeListDetails"];
                IList <CAT_GiftApplyDetail> _giftdetail = (IList <CAT_GiftApplyDetail>)ViewState["GiftListDetails"];
                CAT_FeeApplyDetailBLL       _feebll     = new CAT_FeeApplyDetailBLL();
                CAT_GiftApplyDetailBLL      _giftbll    = new CAT_GiftApplyDetailBLL();
                foreach (CAT_GiftApplyDetail _m in _giftdetail)
                {
                    _m.Activity    = (int)ViewState["ID"];
                    _giftbll.Model = _m;
                    _giftbll.Add();
                }
                foreach (CAT_FeeApplyDetail _m in _details)
                {
                    _m.Activity   = (int)ViewState["ID"];
                    _feebll.Model = _m;
                    _feebll.Add();
                }
                MessageBox.ShowAndRedirect(this, "新增成功!", "CAT_ActivityDetail.aspx?ID=" + ViewState["ID"].ToString());
            }
        }
    }