protected void bt_Submit_Click(object sender, EventArgs e)
    {
        CM_ContractBLL _bll   = new CM_ContractBLL((int)ViewState["ContractID"]);
        CM_Client      client = new CM_ClientBLL(_bll.Model.Client).Model;

        if (_bll.Items.Count == 0)
        {
            MessageBox.Show(this, "对不起,物业租赁合同必须要录入合同具体的付款科目才能提交申请!");
            return;
        }
        decimal applycost = _bll.Items.Sum(p => p.ApplyLimit);

        NameValueCollection dataobjects = new NameValueCollection();

        dataobjects.Add("ID", _bll.Model.ID.ToString());
        dataobjects.Add("Classify", _bll.Model.Classify.ToString());
        dataobjects.Add("ApplyCost", applycost.ToString("0.##"));

        dataobjects.Add("OrganizeCityID", client.OrganizeCity.ToString());
        dataobjects.Add("PDClassify", client["PDClassify"]);        //物业类别

        #region 组织任务标题
        string _title    = "";
        Label  lb_Client = (Label)pl_detail.FindControl("CM_Contract_Client");
        if (lb_Client != null)
        {
            _title += "物业名称:" + lb_Client.Text;
        }

        if (_bll.Model.ContractCode != "")
        {
            _title += " 合同编码:" + _bll.Model.ContractCode;
        }
        #endregion

        int TaskID = EWF_TaskBLL.NewTask("CM_Contract_Flow", (int)Session["UserID"], _title,
                                         "~/SubModule/CM/PD/PropertyDetail.aspx?ClientID=" + _bll.Model.Client.ToString(), dataobjects);
        if (TaskID > 0)
        {
            _bll.Model.State       = 2;
            _bll.Model.ApproveTask = TaskID;
            _bll.Update();
            new EWF_TaskBLL(TaskID).Start();        //直接启动流程
        }

        Response.Redirect("~/SubModule/EWF/TaskDetail.aspx?TaskID=" + TaskID.ToString());
    }
    protected void bt_SetEndDate_Click(object sender, EventArgs e)
    {
        AC_AccountMonth maxendmonth = new AC_AccountMonthBLL(AC_AccountMonthBLL.GetCurrentMonth() + 1).Model;
        CM_ContractBLL  _bll        = new CM_ContractBLL((int)ViewState["ContractID"]);

        if (_bll != null && _bll.Model.ApproveFlag == 1 && _bll.Model.State == 3)
        {
            if (Convert.ToDateTime(txt_EndDate.Text.ToString().Trim()) > _bll.Model.EndDate)
            {
                MessageBox.Show(this, "设定截止日期不能大于原有截止日期!");
                return;
            }
            if (_bll.Model.EndDate <= _bll.Model.BeginDate)
            {
                MessageBox.Show(this, "对不起,合同起始日期不能大于截止日期!");
                return;
            }
            _bll.Model.EndDate = Convert.ToDateTime(txt_EndDate.Text.ToString().Trim());

            if (_bll.Model.EndDate > maxendmonth.EndDate)
            {
                MessageBox.Show(this, "对不起,截止日期最大值为" + maxendmonth.EndDate.ToString("yyyy-MM-dd") + "。");
                return;
            }
            //导购工资
            if (_bll.Model.Classify == 3)
            {
                int lastmonth   = _bll.CheckPMFeeApplyLastMonth();
                int conendmonth = AC_AccountMonthBLL.GetMonthByDate(_bll.Model.EndDate.AddDays(1));
                if (conendmonth <= lastmonth)
                {
                    MessageBox.Show(this, "对不起,该协议已生成预付管理费申请单,请重新填写终止日期(截止日期最小值为" + new AC_AccountMonthBLL(lastmonth).Model.EndDate.ToString("yyyy-MM-dd") + ")!");
                    return;
                }
            }

            _bll.Update();
            _bll.Disable((int)Session["UserID"]);
            MessageBox.ShowAndClose(this, "协议中止成功!");
        }
    }
    protected void bt_SetEndDate_Click(object sender, EventArgs e)
    {
        AC_AccountMonth maxendmonth = new AC_AccountMonthBLL(AC_AccountMonthBLL.GetCurrentMonth() + 1).Model;
        CM_ContractBLL _bll = new CM_ContractBLL((int)ViewState["ContractID"]);
        if (_bll != null && _bll.Model.ApproveFlag == 1 && _bll.Model.State == 3)
        {
            if (Convert.ToDateTime(txt_EndDate.Text.ToString().Trim()) > _bll.Model.EndDate)
            {
                MessageBox.Show(this, "设定截止日期不能大于原有截止日期!");
                return;
            }
            if (_bll.Model.EndDate <= _bll.Model.BeginDate)
            {
                MessageBox.Show(this, "对不起,合同起始日期不能大于截止日期!");
                return;
            }
            _bll.Model.EndDate =Convert.ToDateTime(txt_EndDate.Text.ToString().Trim());

            if (_bll.Model.EndDate > maxendmonth.EndDate)
            {
                MessageBox.Show(this, "对不起,截止日期最大值为" + maxendmonth.EndDate.ToString("yyyy-MM-dd") + "。");
                return;
            }
            //导购工资
            if (_bll.Model.Classify == 3)
            {
                int lastmonth = _bll.CheckPMFeeApplyLastMonth();
                int conendmonth =AC_AccountMonthBLL.GetMonthByDate(_bll.Model.EndDate.AddDays(1));
                if (conendmonth <= lastmonth)
                {
                    MessageBox.Show(this, "对不起,该协议已生成预付管理费申请单,请重新填写终止日期(截止日期最小值为" + new AC_AccountMonthBLL(lastmonth).Model.EndDate.ToString("yyyy-MM-dd") + ")!");
                    return;
                }
            }

            _bll.Update();
            _bll.Disable((int)Session["UserID"]);
            MessageBox.ShowAndClose(this, "协议中止成功!");
        }
    }
    protected void bt_Submit_Click(object sender, EventArgs e)
    {
        bt_OK_Click(null, null);
        if (ViewState["SaveResult"] != null && (bool)ViewState["SaveResult"])
        {
            CM_ContractBLL _bll = new CM_ContractBLL((int)ViewState["ContractID"]);
            if (_bll.Model.ApproveTask > 0 && _bll.Model.State == 2)
            {
                MessageBox.Show(this, "对不起,该协议已发起过流程,请勿重发!");
                return;
            }
            CM_Client client = new CM_ClientBLL(_bll.Model.Client).Model;

            if (_bll.Model.Classify == 1 && _bll.Items.Count == 0)
            {
                MessageBox.Show(this, "对不起,陈列合同必须要录入合同具体的付款科目才能提交申请!");
                return;
            }

            _bll.Items.Sum(p => p.ApplyLimit);

            NameValueCollection dataobjects = new NameValueCollection();
            dataobjects.Add("ID", _bll.Model.ID.ToString());
            dataobjects.Add("Classify", _bll.Model.Classify.ToString());
            dataobjects.Add("PromotorAwardRate", _bll.Model["PromotorAwardRate"]);
            dataobjects.Add("OrganizeCityID", client.OrganizeCity.ToString());
            dataobjects.Add("RTChannel", client["RTChannel"]);
            dataobjects.Add("RTClassify", client["RTClassify"]);
            dataobjects.Add("ApplyCost", _bll.Items.Sum(p => p.ApplyLimit).ToString("0.##"));

            #region 最长一个周期的付款方式
            if (_bll.Items.Count > 0)
            {
                int paymode = _bll.Items.Max(p => p.PayMode);
                dataobjects.Add("PayMode", paymode.ToString());
            }
            #endregion
            decimal clientavgsales = new CM_ClientBLL(_bll.Model.Client).GetSalesVolumeAvg(AC_AccountMonthBLL.GetCurrentMonth(), 3);
            decimal FeeRate = 0;
            if (clientavgsales > 0)
            {
                FeeRate = Math.Round(_bll.Items.Sum(p => p.ApplyLimit) / clientavgsales * 100, 2);
            }
            dataobjects.Add("FeeRate", FeeRate.ToString());
            #region 判断是否首次新增该类型的合同
            if (CM_ContractBLL.GetModelList("Client=" + client.ID + " AND Classify=" + _bll.Model.Classify + " AND State IN (3,9)").Count == 0)
                dataobjects.Add("IsFirstContract", "Y");
            else
            {
                dataobjects.Add("IsFirstContract", "N");

                //返利合同,如果银行帐户信息发生变更,识为新增合同-----2013-11-16日注释去除限制
                //if (_bll.Model.Classify == 2)
                //    if (_bll.Model["BankName"] != client["BankName"] ||
                //        _bll.Model["BankAccountNo"] != client["BankAccountNo"] ||
                //        _bll.Model["AccountName"] != client["AccountName"])
                //        dataobjects["IsFirstContract"] = "Y";
            }
            #endregion

            #region 组织任务标题
            string _title = "";
            Label lb_Client = (Label)pl_detail.FindControl("CM_Contract_Client");
            if (lb_Client != null) _title += "门店名称:" + lb_Client.Text;

            DropDownList ddl_Classify = (DropDownList)pl_detail.FindControl("CM_Contract_Classify");
            if (ddl_Classify != null) _title += " 合同类别:" + ddl_Classify.SelectedItem.Text;

            if (_bll.Model.ContractCode != "") _title += " 合同编码:" + _bll.Model.ContractCode;
            #endregion

            int TaskID = EWF_TaskBLL.NewTask("CM_Contract_Flow", (int)Session["UserID"], _title,
                "~/SubModule/CM/RT/RetailerContractDetail.aspx?ContractID=" + ViewState["ContractID"].ToString(), dataobjects);

            if (TaskID > 0)
            {
                _bll.Model.State = 2;
                _bll.Model.ApproveTask = TaskID;
                _bll.Update();
                new EWF_TaskBLL(TaskID).Start();        //直接启动流程
            }

            Response.Redirect("~/SubModule/EWF/TaskDetail.aspx?TaskID=" + TaskID.ToString());
        }
    }
    protected void bt_Submit_Click(object sender, EventArgs e)
    {
        CM_ContractBLL _bll = new CM_ContractBLL((int)ViewState["ContractID"]);
        CM_Client client = new CM_ClientBLL(_bll.Model.Client).Model;

        if (_bll.Items.Count == 0)
        {
            MessageBox.Show(this, "对不起,物业租赁合同必须要录入合同具体的付款科目才能提交申请!");
            return;
        }
        decimal applycost = _bll.Items.Sum(p => p.ApplyLimit);

        NameValueCollection dataobjects = new NameValueCollection();
        dataobjects.Add("ID", _bll.Model.ID.ToString());
        dataobjects.Add("Classify", _bll.Model.Classify.ToString());
        dataobjects.Add("ApplyCost", applycost.ToString("0.##"));

        dataobjects.Add("OrganizeCityID", client.OrganizeCity.ToString());
        dataobjects.Add("PDClassify", client["PDClassify"]);        //物业类别

        #region 组织任务标题
        string _title = "";
        Label lb_Client = (Label)pl_detail.FindControl("CM_Contract_Client");
        if (lb_Client != null) _title += "物业名称:" + lb_Client.Text;

        if (_bll.Model.ContractCode != "") _title += " 合同编码:" + _bll.Model.ContractCode;
        #endregion

        int TaskID = EWF_TaskBLL.NewTask("CM_Contract_Flow", (int)Session["UserID"], _title,
            "~/SubModule/CM/PD/PropertyDetail.aspx?ClientID=" + _bll.Model.Client.ToString(), dataobjects);
        if (TaskID > 0)
        {
            _bll.Model.State = 2;
            _bll.Model.ApproveTask = TaskID;
            _bll.Update();
            new EWF_TaskBLL(TaskID).Start();        //直接启动流程
        }

        Response.Redirect("~/SubModule/EWF/TaskDetail.aspx?TaskID=" + TaskID.ToString());
    }