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_Create(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"]       = 0;
            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.InsertRule(sRuleName, sDesc, iAlertEmailTemplateID, bReqAck, isRecomEmailTemplateID, sAdvFormula, iScope, iTarget, ConditionList);

        // success
        this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Success", "$('#divContainer').hide();alert('Clone rule successfully.');window.parent.location.href=window.parent.location.href;", true);
    }
Exemple #2
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        #region get rule data

        string sRuleName = this.txtRuleName.Text.Trim();
        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_Create(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"]       = 0;
            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 ");
        }

        int iSelCampaignID = 0;
        if (hfSelCampaigns.Value != "")
        {
            iSelCampaignID = Convert.ToInt32(hfSelCampaigns.Value);
            AutoCampaigns _bAutoCampaigns = new AutoCampaigns();
            int           iCount          = _bAutoCampaigns.GetMarketingCount(" AND CampaignId=" + iSelCampaignID);
            if (iCount == 0)
            {
                LPWeb.Model.AutoCampaigns _mAutoCampaigns = new LPWeb.Model.AutoCampaigns();
                _mAutoCampaigns.CampaignId = iSelCampaignID;
                _mAutoCampaigns.PaidBy     = 0;
                _mAutoCampaigns.Enabled    = true;
                _mAutoCampaigns.SelectedBy = CurrUser.iUserID;
                _bAutoCampaigns.Add(_mAutoCampaigns);
            }
        }

        int nNewId = RuleManager.InsertRule(sRuleName, sDesc, iAlertEmailTemplateID, bReqAck, isRecomEmailTemplateID, sAdvFormula, iScope, iTarget, ConditionList, iSelCampaignID);

        DataTable dtNewRuleWithEmailTpltInfo = RuleManager.GetRuleWithAlertEmailTpltInfo(nNewId);
        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", "$('#divContainer').hide();alert('Create rule successfully.');window.parent.location.href=window.parent.location.href;", true);
        this.ClientScript.RegisterClientScriptBlock(this.GetType(), "_Success", string.Format("addSuccessfully('{0}');", strReturn), true); // changed by peter 20110116
    }