protected void bt_Cancel_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            CAT_ActivityBLL _bll = new CAT_ActivityBLL((int)ViewState["ID"]);

            _bll.Model.State = 3;
            _bll.Update();

            BindData();
        }
    }
    protected void bt_Stage_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            CAT_ActivityBLL a = new CAT_ActivityBLL((int)ViewState["ID"]);
            if (a.Model == null)
            {
                return;
            }

            if (a.Model.State != 4)
            {
                MessageBox.Show(this, "只有状态为排期中的活动,才可准备举办!");
                return;
            }

            a.Model.State = 11;
            a.Model["PlanToPrepareDate"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            a.Update();
            MessageBox.ShowAndRedirect(this, "操作成功!", "CAT_ActivityDetail.aspx?ID=" + ViewState["ID"].ToString());
        }
    }
    protected void bt_Submit_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            bt_OK_Click(null, null);

            CAT_ActivityBLL bll = new CAT_ActivityBLL((int)ViewState["ID"]);

            if (bll.Model.FeeApply > 0)
            {
                MessageBox.ShowAndRedirect(this, "该活动已关联到费用信息,请至费用信息中提交该申请!", "../FNA/FeeApply/FeeApplyDetail3.aspx?ID=" + bll.Model.FeeApply.ToString());
                return;
            }

            #region 发起工作流
            NameValueCollection dataobjects = new NameValueCollection();
            dataobjects.Add("ID", ViewState["ID"].ToString());
            dataobjects.Add("OrganizeCity", bll.Model.OrganizeCity.ToString());
            dataobjects.Add("FeeApply", bll.Model.FeeApply.ToString());
            #region 组合审批任务主题
            string title = bll.Model.Topic;
            #endregion

            int TaskID = EWF_TaskBLL.NewTask("CAT_ActivityApply", (int)Session["UserID"], title, "~/SubModule/CAT/CAT_ActivityDetail.aspx?ID=" + ViewState["ID"].ToString(), dataobjects);
            if (TaskID > 0)
            {
                bll.Model.State     = 12; //提交审批中
                bll.Model["TaskID"] = TaskID.ToString();
                bll.Update();

                new EWF_TaskBLL(TaskID).Start();        //直接启动流程
            }
            #endregion

            Response.Redirect("~/SubModule/EWF/TaskDetail.aspx?TaskID=" + TaskID.ToString());
        }
    }
    protected void bt_Submit_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            bt_OK_Click(null, null);

            CAT_ActivityBLL bll = new CAT_ActivityBLL((int)ViewState["ID"]);

            if (bll.Model.FeeApply > 0)
            {
                MessageBox.ShowAndRedirect(this, "该活动已关联到费用信息,请至费用信息中提交该申请!", "../FNA/FeeApply/FeeApplyDetail3.aspx?ID=" + bll.Model.FeeApply.ToString());
                return;
            }

            #region 发起工作流
            NameValueCollection dataobjects = new NameValueCollection();
            dataobjects.Add("ID", ViewState["ID"].ToString());
            dataobjects.Add("OrganizeCity", bll.Model.OrganizeCity.ToString());
            dataobjects.Add("FeeApply", bll.Model.FeeApply.ToString());
            #region 组合审批任务主题
            string title = bll.Model.Topic;
            #endregion

            int TaskID = EWF_TaskBLL.NewTask("CAT_ActivityApply", (int)Session["UserID"], title, "~/SubModule/CAT/CAT_ActivityDetail.aspx?ID=" + ViewState["ID"].ToString(), dataobjects);
            if (TaskID > 0)
            {
                bll.Model.State = 12;    //提交审批中
                bll.Model["TaskID"] = TaskID.ToString();
                bll.Update();

                new EWF_TaskBLL(TaskID).Start();        //直接启动流程
            }
            #endregion

            Response.Redirect("~/SubModule/EWF/TaskDetail.aspx?TaskID=" + TaskID.ToString());
        }
    }
    protected void bt_Stage_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            CAT_ActivityBLL a = new CAT_ActivityBLL((int)ViewState["ID"]);
            if (a.Model == null) return;

            if (a.Model.State != 4)
            {
                MessageBox.Show(this, "只有状态为排期中的活动,才可准备举办!");
                return;
            }

            a.Model.State = 11;
            a.Model["PlanToPrepareDate"] = DateTime.Now.ToString("yyyy-MM-dd HH:mm");
            a.Update();
            MessageBox.ShowAndRedirect(this, "操作成功!", "CAT_ActivityDetail.aspx?ID=" + ViewState["ID"].ToString());
        }
    }
    protected void bt_Complete_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            CAT_ActivityBLL _bll = new CAT_ActivityBLL((int)ViewState["ID"]);
            CaculateActJoinNumber(_bll.Model.ID);
            pl_detail.GetData(_bll.Model);

            #region 判断必填项
            IList<CAT_ClientJoinInfo> ClientJoinInfoList = CAT_ClientJoinInfoBLL.GetModelList("CAT_ClientJoinInfo.Activity=" + _bll.Model.ID);

            if (ClientJoinInfoList.Count > 0)
            {
                foreach (CAT_ClientJoinInfo info in ClientJoinInfoList)
                {
                    if (info.JoinState == 0)
                    {
                        MessageBox.ShowAndRedirect(this, "参与客户情况界面的参与状态必填!", "CAT_JoinInfoList.aspx?ID=" + ViewState["ID"].ToString());
                        return;
                    }
                }
            }

            if (_bll.Model["CompleteDate"] != null && _bll.Model["CompleteDate"] == "1900-01-01")
            {
                MessageBox.Show(this, "请录入活动的实际完成举办日期!");
                return;
            }

            if (_bll.Model.ApproveFlag != 1)
            {
                MessageBox.Show(this, "请确保活动已审核完!");
                return;
            }
            else if (_bll.Model.ApproveFlag == 1 && _bll.Model["ApproveTime"] != "" && _bll.Model["ApproveTime"] != null)
            {
                //if (DateTime.Parse(_bll.Model["CompleteDate"]) < DateTime.Parse(_bll.Model["ApproveTime"]))
                //{
                //    MessageBox.Show(this, "活动的完成举办日期要求必需在审核通过日期之后!");
                //    return;
                //}
            }

            TextBox txt_Sales = (TextBox)pl_detail.FindControl("CAT_Activity_Sales");

            if (txt_Sales != null && txt_Sales.Text.Trim() == "")
            {
                MessageBox.Show(this, "请填写销售额!");
                return;
            }

            TextBox txt_ActLecture = (TextBox)pl_detail.FindControl("CAT_Activity_ActLecturer");
            if (txt_ActLecture != null && txt_ActLecture.Text.Trim() == "")
            {
                MessageBox.Show(this, "请填写实际参与活动的讲师!");
                return;
            }

            TextBox txt_ActLecturerTelenum = (TextBox)pl_detail.FindControl("CAT_Activity_ActLecturerTelenum");
            if (txt_ActLecturerTelenum != null && txt_ActLecturerTelenum.Text.Trim() == "")
            {
                MessageBox.Show(this, "请填写实际参与活动的讲师的联系方式!");
                return;
            }
            #endregion

            _bll.Model.State = 2;
            _bll.Update();

            BindData();
        }
    }
    protected void bt_Cancel_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            CAT_ActivityBLL _bll = new CAT_ActivityBLL((int)ViewState["ID"]);

            _bll.Model.State = 3;
            _bll.Update();

            BindData();
        }
    }
    protected void bt_Complete_Click(object sender, EventArgs e)
    {
        if ((int)ViewState["ID"] != 0)
        {
            CAT_ActivityBLL _bll = new CAT_ActivityBLL((int)ViewState["ID"]);
            CaculateActJoinNumber(_bll.Model.ID);
            pl_detail.GetData(_bll.Model);

            #region 判断必填项
            IList <CAT_ClientJoinInfo> ClientJoinInfoList = CAT_ClientJoinInfoBLL.GetModelList("CAT_ClientJoinInfo.Activity=" + _bll.Model.ID);

            if (ClientJoinInfoList.Count > 0)
            {
                foreach (CAT_ClientJoinInfo info in ClientJoinInfoList)
                {
                    if (info.JoinState == 0)
                    {
                        MessageBox.ShowAndRedirect(this, "参与客户情况界面的参与状态必填!", "CAT_JoinInfoList.aspx?ID=" + ViewState["ID"].ToString());
                        return;
                    }
                }
            }

            if (_bll.Model["CompleteDate"] != null && _bll.Model["CompleteDate"] == "1900-01-01")
            {
                MessageBox.Show(this, "请录入活动的实际完成举办日期!");
                return;
            }

            if (_bll.Model.ApproveFlag != 1)
            {
                MessageBox.Show(this, "请确保活动已审核完!");
                return;
            }
            else if (_bll.Model.ApproveFlag == 1 && _bll.Model["ApproveTime"] != "" && _bll.Model["ApproveTime"] != null)
            {
                //if (DateTime.Parse(_bll.Model["CompleteDate"]) < DateTime.Parse(_bll.Model["ApproveTime"]))
                //{
                //    MessageBox.Show(this, "活动的完成举办日期要求必需在审核通过日期之后!");
                //    return;
                //}
            }


            TextBox txt_Sales = (TextBox)pl_detail.FindControl("CAT_Activity_Sales");

            if (txt_Sales != null && txt_Sales.Text.Trim() == "")
            {
                MessageBox.Show(this, "请填写销售额!");
                return;
            }


            TextBox txt_ActLecture = (TextBox)pl_detail.FindControl("CAT_Activity_ActLecturer");
            if (txt_ActLecture != null && txt_ActLecture.Text.Trim() == "")
            {
                MessageBox.Show(this, "请填写实际参与活动的讲师!");
                return;
            }

            TextBox txt_ActLecturerTelenum = (TextBox)pl_detail.FindControl("CAT_Activity_ActLecturerTelenum");
            if (txt_ActLecturerTelenum != null && txt_ActLecturerTelenum.Text.Trim() == "")
            {
                MessageBox.Show(this, "请填写实际参与活动的讲师的联系方式!");
                return;
            }
            #endregion

            _bll.Model.State = 2;
            _bll.Update();

            BindData();
        }
    }