Exemple #1
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        #region get rule data

        string sRuleName = this.txtRuleName.Text.Trim();
        bool   bEnabled  = this.chkEnabled.Checked;
        string sDesc     = this.txtDesc.Text.Trim();
        if (string.IsNullOrEmpty(sDesc))
        {
            sDesc             = txtRuleName.Text.Trim();
            this.txtDesc.Text = sDesc;
        }

        string sRecomEmailTemplateID  = this.ddlRecomActionTemplate.SelectedValue;
        int    isRecomEmailTemplateID = Convert.ToInt32(sRecomEmailTemplateID);

        string sAlertEmailTemplateID = this.ddlAlertEmailTemplate.SelectedValue;
        int    iAlertEmailTemplateID = Convert.ToInt32(sAlertEmailTemplateID);

        bool   bReqAck     = this.chkReqAck.Checked;
        string sAdvFormula = this.txtFormula.Text.Trim();

        string sScope = this.ddlScope.SelectedValue;
        Int16  iScope = Convert.ToInt16(sScope);

        #region get loan target

        //string sTarget = this.ddlTarget.SelectedValue;
        //Int16 iTarget = Convert.ToInt16(sTarget);

        LPWeb.Model.Template_Rules_LoanTarget modelLoanTarget = new LPWeb.Model.Template_Rules_LoanTarget();

        modelLoanTarget.ActiveLoans   = this.chkTargetActiveLoans.Checked;
        modelLoanTarget.ActiveLeads   = this.chkTargetActiveLeads.Checked;
        modelLoanTarget.ArchivedLoans = this.chkTargetArchivedLoans.Checked;
        modelLoanTarget.ArchivedLeads = this.chkTargetArchivedLeads.Checked;

        Int16 iTarget = modelLoanTarget.LoanTargetValue;

        if (iTarget == 0)
        {
            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_NoLoanTarget", "$('#divContainer').hide();alert('No target for rule selected. Please select a rule target.');$('#divContainer').show();", true);
            return;
        }

        #endregion

        #endregion

        Template_Rules RuleManager = new Template_Rules();

        #region 检查Rule Name是否重复

        bool bIsExist = RuleManager.IsExist_Edit(this.iRuleID, sRuleName);
        if (bIsExist == true)
        {
            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Duplicate", "$('#divContainer').hide();alert('The rule name has been taken. Please use a different name.');$('#divContainer').show();", true);
            return;
        }

        #endregion

        #region get condition data

        string sSequences      = this.hdnSequences.Text;
        string sPointFieldIDs  = this.hdnPointFieldIDs.Text;
        string sConditions     = this.hdnConditions.Text;
        string sTolerances     = this.hdnTolerances.Text;     // [$xxx$],[$yyy$],[$zzz$]
        string sToleranceTypes = this.hdnToleranceTypes.Text; // $,%,#null#

        #endregion

        #region build conditiion list


        DataTable ConditionList = RuleManager.GetConditionList(" and 1=0");

        string[] SequenceArray      = sSequences.Split(',');
        string[] PointFieldIDArray  = sPointFieldIDs.Split(',');
        string[] ConditionArray     = sConditions.Split(',');
        string[] ToleranceArray     = sTolerances.Split(',');
        string[] ToleranceTypeArray = sToleranceTypes.Split(',');

        for (int i = 0; i < PointFieldIDArray.Length; i++)
        {
            string sSequence       = SequenceArray[i];
            string sPointFieldID   = PointFieldIDArray[i];
            string sConditionID    = ConditionArray[i];
            string sToleranceBlock = ToleranceArray[i];
            string sToleranceType  = ToleranceTypeArray[i];

            #region format Tolerance

            string sTelerance = sToleranceBlock.Replace("[$", string.Empty);
            sTelerance = sTelerance.Replace("$]", string.Empty);

            #endregion

            #region add rows

            DataRow ConditionRow = ConditionList.NewRow();
            ConditionRow["RuleCondId"]   = 0;
            ConditionRow["RuleId"]       = this.iRuleID;
            ConditionRow["PointFieldId"] = Convert.ToInt32(sPointFieldID);
            ConditionRow["Condition"]    = Convert.ToInt32(sConditionID);
            ConditionRow["Tolerance"]    = sTelerance;
            if (sToleranceType == "#null#")
            {
                ConditionRow["ToleranceType"] = DBNull.Value;
            }
            else if (sToleranceType == "#empty#")
            {
                ConditionRow["ToleranceType"] = string.Empty;
            }
            else
            {
                ConditionRow["ToleranceType"] = sToleranceType;
            }
            ConditionRow["Sequence"] = Convert.ToInt32(sSequence);
            ConditionList.Rows.Add(ConditionRow);

            #endregion
        }

        #endregion

        // insert
        if (sAdvFormula.Trim() == string.Empty)
        {
            sAdvFormula = sSequences.Replace(",", " AND ");
        }
        RuleManager.UpdateRule(this.iRuleID, sRuleName, sDesc, bEnabled, iAlertEmailTemplateID, bReqAck, isRecomEmailTemplateID, sAdvFormula, iScope, iTarget, ConditionList);

        DataTable dtNewRuleWithEmailTpltInfo = RuleManager.GetRuleWithAlertEmailTpltInfo(this.iRuleID);
        string    strReturn = "<table></table>";
        if (dtNewRuleWithEmailTpltInfo.Rows.Count > 0)
        {
            strReturn = "<table><Rule RuleId=\"{0}\" Name=\"{1}\" AlertEmailTemplId=\"{2}\" AlertEmailTpltName=\"{3}\"></Rule></table>";
            strReturn = string.Format(strReturn, dtNewRuleWithEmailTpltInfo.Rows[0]["RuleId"],
                                      string.Format("{0}", dtNewRuleWithEmailTpltInfo.Rows[0]["Name"]).Replace("<", "&amp;lt;"), dtNewRuleWithEmailTpltInfo.Rows[0]["AlertEmailTemplId"],
                                      string.Format("{0}", dtNewRuleWithEmailTpltInfo.Rows[0]["AlertEmailTpltName"]).Replace("<", "&amp;lt;"));
        }
        strReturn = strReturn.Replace('<', '\u0001').Replace("'", "&#39;");
        // success
        this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Success", string.Format("updateSuccessfully('{0}');", strReturn), true);
    }