protected void gv_FeeListDetail_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        IList <CAT_FeeApplyDetail> _details = (IList <CAT_FeeApplyDetail>)ViewState["FeeListDetails"];
        int ID = 0;

        if (int.TryParse(gv_FeeListDetail.DataKeys[e.RowIndex]["ID"].ToString(), out ID) && ID > 0)
        {
            CAT_FeeApplyDetailBLL _bll = new CAT_FeeApplyDetailBLL(ID);
            _bll.Delete();
        }
        _details.RemoveAt(e.RowIndex);
        BindGrid();
    }
    protected void bt_OpenAdjust_Click(object sender, EventArgs e)
    {
        Button                bt_Adjust        = (Button)sender;
        GridViewRow           drv              = (GridViewRow)bt_Adjust.NamingContainer;
        int                   rowIndex         = drv.RowIndex;
        int                   ID               = int.Parse(gv_FeeListDetail.DataKeys[rowIndex]["ID"].ToString());
        CAT_FeeApplyDetailBLL _bll             = new CAT_FeeApplyDetailBLL(ID);
        TextBox               tbx_AdjustReason = (TextBox)drv.FindControl("tbx_AdjustReason");
        TextBox               tbx_AdjustCost   = (TextBox)drv.FindControl("tbx_AdjustCost");

        _bll.Model.AdjustCost   = decimal.Parse(tbx_AdjustCost.Text.Trim());
        _bll.Model.AdjustReason = tbx_AdjustReason.Text;
        _bll.Update();
    }
    protected void bt_AddDetail_Click(object sender, EventArgs e)
    {
        IList <CAT_FeeApplyDetail> _details = (IList <CAT_FeeApplyDetail>)ViewState["FeeListDetails"];
        CAT_FeeApplyDetail         _m       = new CAT_FeeApplyDetail();
        int client = 0;

        int.TryParse(select_Client.SelectValue, out client);
        _m.Client       = client;
        _m.AccountTitle = int.Parse(ddl_AccountTitle.SelectedValue);
        if (TreeTableBLL.GetChild("MCS_PUB.dbo.AC_AccountTitle", "ID", "SuperID", _m.AccountTitle).Rows.Count > 0)
        {
            MessageBox.Show(this, "费用科目必须选择最底级会计科目!" + ddl_AccountTitle.SelectedItem.Text);
            return;
        }
        _m.ApplyCost = decimal.Parse(tbx_ApplyCost.Text.Trim());
        _m.DICost    = decimal.Parse(tbx_DICost.Text.Trim());
        _m.Remark    = tbx_Remark.Text.Trim();
        if ((int)ViewState["ID"] != 0)
        {
            _m.BeginMonth = AC_AccountMonthBLL.GetMonthByDate(new CAT_ActivityBLL((int)ViewState["ID"]).Model.PlanBeginDate);
            _m.Activity   = (int)ViewState["ID"];
        }
        else
        {
            _m.BeginMonth = AC_AccountMonthBLL.GetCurrentMonth();
        }
        if (_details.Where(p => p.Client == client && p.AccountTitle == _m.AccountTitle).Count() == 0)
        {
            if (_m.Activity > 0)
            {
                CAT_FeeApplyDetailBLL _bll = new CAT_FeeApplyDetailBLL();
                _bll.Model = _m;
                _bll.Add();
            }
            _details.Add(_m);
            BindGrid();
        }
    }
 protected void bt_AddDetail_Click(object sender, EventArgs e)
 {
     IList<CAT_FeeApplyDetail> _details = (IList<CAT_FeeApplyDetail>)ViewState["FeeListDetails"];
     CAT_FeeApplyDetail _m = new CAT_FeeApplyDetail();
     int client = 0;
     int.TryParse(select_Client.SelectValue, out client);
     _m.Client = client;
     _m.AccountTitle = int.Parse(ddl_AccountTitle.SelectedValue);
     if (TreeTableBLL.GetChild("MCS_PUB.dbo.AC_AccountTitle", "ID", "SuperID", _m.AccountTitle).Rows.Count > 0)
     {
         MessageBox.Show(this, "费用科目必须选择最底级会计科目!" + ddl_AccountTitle.SelectedItem.Text);
         return;
     }
     _m.ApplyCost = decimal.Parse(tbx_ApplyCost.Text.Trim());
     _m.DICost = decimal.Parse(tbx_DICost.Text.Trim());
     _m.Remark = tbx_Remark.Text.Trim();
     if ((int)ViewState["ID"] != 0)
     {
         _m.BeginMonth = AC_AccountMonthBLL.GetMonthByDate(new CAT_ActivityBLL((int)ViewState["ID"]).Model.PlanBeginDate);
         _m.Activity = (int)ViewState["ID"];
     }
     else
     {
         _m.BeginMonth = AC_AccountMonthBLL.GetCurrentMonth();
     }
     if (_details.Where(p => p.Client == client && p.AccountTitle == _m.AccountTitle).Count() == 0)
     {
         if (_m.Activity > 0)
         {
             CAT_FeeApplyDetailBLL _bll = new CAT_FeeApplyDetailBLL();
             _bll.Model = _m;
             _bll.Add();
         }
         _details.Add(_m);
         BindGrid();
     }
 }
    protected void gv_FeeListDetail_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        IList<CAT_FeeApplyDetail> _details = (IList<CAT_FeeApplyDetail>)ViewState["FeeListDetails"];
        int ID = 0;

        if (int.TryParse(gv_FeeListDetail.DataKeys[e.RowIndex]["ID"].ToString(), out ID) && ID > 0)
        {
            CAT_FeeApplyDetailBLL _bll = new CAT_FeeApplyDetailBLL(ID);
            _bll.Delete();
        }
        _details.RemoveAt(e.RowIndex);
        BindGrid();
    }
 protected void bt_OpenAdjust_Click(object sender, EventArgs e)
 {
     Button bt_Adjust = (Button)sender;
     GridViewRow drv = (GridViewRow)bt_Adjust.NamingContainer;
     int rowIndex = drv.RowIndex;
     int ID = int.Parse(gv_FeeListDetail.DataKeys[rowIndex]["ID"].ToString());
     CAT_FeeApplyDetailBLL _bll = new CAT_FeeApplyDetailBLL(ID);
     TextBox tbx_AdjustReason = (TextBox)drv.FindControl("tbx_AdjustReason");
     TextBox tbx_AdjustCost = (TextBox)drv.FindControl("tbx_AdjustCost");
     _bll.Model.AdjustCost = decimal.Parse(tbx_AdjustCost.Text.Trim());
     _bll.Model.AdjustReason = tbx_AdjustReason.Text;
     _bll.Update();
 }
    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());
            }
        }
    }
    protected void Page_Load(object sender, System.EventArgs e)
    {
        #region 获取举办医院控件
        MCSSelectControl select_StageClient = (MCSSelectControl)pl_detail.FindControl("CAT_Activity_StageClient");
        if (select_StageClient != null)
        {
            select_StageClient.SelectChange += new SelectChangeEventHandler(select_StageClient_SelectChange);
        }
        DropDownList ddl_classify = pl_detail.FindControl("CAT_Activity_Classify") != null ? (DropDownList)pl_detail.FindControl("CAT_Activity_Classify") : null;
        if (ddl_classify != null)
        {
        }
        #endregion

        // 在此处放置用户代码以初始化页面
        if (!Page.IsPostBack)
        {
            #region 获取页面参数
            ViewState["ID"] = Request.QueryString["ID"] != null?int.Parse(Request.QueryString["ID"]) : 0;

            ViewState["Classify"] = Request.QueryString["Classify"] != null?int.Parse(Request.QueryString["Classify"]) : 0;

            #endregion

            BindDropDown();

            ViewState["FeeListDetails"]   = CAT_FeeApplyDetailBLL.GetModelList("Activity=" + ViewState["ID"].ToString());
            ViewState["GiftListDetails"]  = CAT_GiftApplyDetailBLL.GetModelList("Activity=" + ViewState["ID"].ToString());
            ViewState["SalesListDetails"] = CAT_SalesVolumeDetailBLL.GetModelList("Activity=" + ViewState["ID"].ToString());
            ViewState["EditAdjust"]       = false;
            if ((int)ViewState["ID"] != 0)
            {
                //修改
                BindData();
                BindGrid();
            }
            else
            {
                //新增
                Org_StaffBLL staff = new Org_StaffBLL((int)Session["UserID"], true);
                ((MCSTreeControl)pl_detail.FindControl("CAT_Activity_Officialcity")).SelectValue = staff.Model.OfficialCity.ToString();
                ((MCSTreeControl)pl_detail.FindControl("CAT_Activity_OrganizeCity")).SelectValue = staff.Model.OrganizeCity.ToString();

                string state = Request.QueryString["State"] != null ? Request.QueryString["State"] : "11";    //默认为排期中的活动
                ((DropDownList)pl_detail.FindControl("CAT_Activity_State")).SelectedValue = state;

                bt_Stage.Visible = false;

                bt_Submit.Visible     = false;
                bt_Approve.Visible    = false;
                bt_Complete.Visible   = false;
                bt_Cancel.Visible     = false;
                UploadFile001.Visible = false;
                gv_FeeListDetail.Columns[gv_FeeListDetail.Columns.Count - 2].Visible = false; //调整按钮
                gv_FeeListDetail.Columns[gv_FeeListDetail.Columns.Count - 3].Visible = false; //批复金额
                gv_FeeListDetail.Columns[gv_FeeListDetail.Columns.Count - 4].Visible = false; //扣减额原因
                gv_FeeListDetail.Columns[gv_FeeListDetail.Columns.Count - 5].Visible = false; //扣减额
                gv_GiftListDetail.Columns[2].Visible = false;                                 //调整数量
                gv_GiftListDetail.Columns[3].Visible = false;                                 //使用数量
                gv_GiftListDetail.Columns[4].Visible = false;                                 //剩余数量
                pl_detail.SetPanelVisible("Panel_CAT_ActivityDetail_02", false);
            }
        }

        if (ViewState["ApproveFlag"] == null || (int)ViewState["ApproveFlag"] != 1)
        {
            MCSTabControl1.Items[2].Visible = false;
        }
    }