コード例 #1
0
ファイル: RuleGroupSetup.aspx.cs プロジェクト: PulseCRM/Pulse
        /// <summary>
        /// Save user info
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Model.Template_RuleGroups ruleGroup = null;
            if ("0" == Mode)
            {
                ruleGroup = new Model.Template_RuleGroups();
                GetValue(ref ruleGroup);

                // check duplicate
                if (ruleGroupManager.IsRuleGroupNameExists(-1, ruleGroup.Name))
                {
                    PageCommon.AlertMsg(this, "Duplicate rule group name!");
                    return;
                }

                try
                {
                    // save the new added rule group info, nSourceUID is null or not indicated to clone or not
                    RuleGroupID = ruleGroupManager.AddRuleGroupInfo(ruleGroup, this.hiAllIds.Value, null);
                    Mode        = "1";

                    ClientFun(this.updatePanel, "saveSuccessfully", "saveSuccess();");
                }
                catch (Exception ex)
                {
                    ClientFun(this.updatePanel, "failedToSave", "alert('Failed to save rule group info, please try it again.');");
                    LPLog.LogMessage(LogType.Logerror, "Error occured when save rule group info: " + ex.Message);
                    return;
                }
            }
            else if ("1" == Mode)
            {
                ruleGroup = ruleGroupManager.GetModel(RuleGroupID.Value);
                GetValue(ref ruleGroup);

                // check name duplicate
                if (ruleGroupManager.IsRuleGroupNameExists(RuleGroupID.Value, ruleGroup.Name))
                {
                    ClientFun(this.updatePanel, "duplicateName", "alert('Duplicate rule group name!');");
                    return;
                }

                try
                {
                    // update current user info, without personalization info
                    ruleGroupManager.UpdateRuleGroupInfo(ruleGroup, this.hiAllIds.Value);
                    ClientFun(this.updatePanel, "saveSuccessfully", "saveSuccess();");
                }
                catch (Exception ex)
                {
                    ClientFun(this.updatePanel, "failedToSave", "alert('Failed to save rule group info, please try it again.');");
                    LPLog.LogMessage(LogType.Logerror, "Failed to save rule group info: " + ex.Message);
                    return;
                }
            }
        }
コード例 #2
0
ファイル: RuleGroupSetup.aspx.cs プロジェクト: PulseCRM/Pulse
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DoInitData();
                BindGrid();

                if ("0" == Mode)
                {
                }
                if ("1" == Mode)
                {
                    if (!RuleGroupID.HasValue)
                    {
                        // if no UserId,thorw exception
                        LPLog.LogMessage(LogType.Logerror, "Invalid RuleGroupID");
                        throw new Exception("Invalid RuleGroupID");
                    }
                    else
                    {
                        Model.Template_RuleGroups rg = ruleGroupManager.GetModel(RuleGroupID.Value);
                        bool bIsReferenced           = ruleGroupManager.IsReferencedByLoan(RuleGroupID.Value);
                        if (null == rg)
                        {
                            LPLog.LogMessage(LogType.Logerror, string.Format("Can not find rule group with ID:{0}", RuleGroupID.Value));
                        }
                        else
                        {
                            this.tbGroupName.Text        = rg.Name;
                            this.tbDescription.Text      = rg.Desc;
                            this.ddlScope.SelectedValue  = (rg.RuleScope == null) ? "0" : rg.RuleScope.ToString();
                            this.ddlTarget.SelectedValue = (rg.LoanTarget == null) ? "0" : rg.LoanTarget.ToString();
                            this.ckbEnabled.Checked      = rg.Enabled;
                            this.hiReferenced.Value      = bIsReferenced ? "1" : "0";
                        }
                    }
                }
            }
        }
コード例 #3
0
ファイル: RuleGroupSetup.aspx.cs プロジェクト: PulseCRM/Pulse
 /// <summary>
 /// Load user info from the form
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 private void GetValue(ref Model.Template_RuleGroups rg)
 {
     rg.Name    = this.tbGroupName.Text.Trim();
     rg.Desc    = this.tbDescription.Text.Trim();
     rg.Enabled = this.ckbEnabled.Checked;
     if (this.ddlScope.SelectedIndex > 0)
     {
         rg.RuleScope = Convert.ToInt32(this.ddlScope.SelectedValue);
     }
     else
     {
         rg.RuleScope = 0;
     }
     if (this.ddlTarget.SelectedIndex > 0)
     {
         rg.LoanTarget = Convert.ToInt32(this.ddlTarget.SelectedValue);
     }
     else
     {
         rg.LoanTarget = 0;
     }
 }
コード例 #4
0
        /// <summary>
        /// Save rule group info from rule group setup page
        /// </summary>
        /// <param name="ruleGroup"></param>
        /// <param name="strRuleIds"></param>
        public void UpdateRuleGroupInfo(Model.Template_RuleGroups ruleGroup, string strRuleIds)
        {
            //
            Collection <SqlCommand> SqlCmdList = new Collection <SqlCommand>();

            SqlConnection  SqlConn  = null;
            SqlTransaction SqlTrans = null;

            try
            {
                SqlConn  = DbHelperSQL.GetOpenConnection();
                SqlTrans = SqlConn.BeginTransaction();

                // 1.Update rule group info
                SqlCommand    cmdItemUpdate = new SqlCommand();
                StringBuilder sbSql         = new StringBuilder();
                sbSql.Append("UPDATE Template_RuleGroups SET Name=@Name, [Desc]=@Desc, [Enabled]=@Enabled, RuleScope=@RuleScope, LoanTarget=@LoanTarget WHERE RuleGroupId=@RuleGroupId");
                SqlParameter[] parameters =
                {
                    new SqlParameter("@RuleGroupId", SqlDbType.Int),
                    new SqlParameter("@Name",        SqlDbType.NVarChar),
                    new SqlParameter("@Desc",        SqlDbType.NVarChar),
                    new SqlParameter("@Enabled",     SqlDbType.Bit),
                    new SqlParameter("@RuleScope",   SqlDbType.SmallInt,2),
                    new SqlParameter("@LoanTarget",  SqlDbType.SmallInt, 2)
                };
                parameters[0].Value = ruleGroup.RuleGroupId;
                parameters[1].Value = ruleGroup.Name;
                parameters[2].Value = ruleGroup.Desc;
                parameters[3].Value = ruleGroup.Enabled;
                parameters[4].Value = ruleGroup.RuleScope;
                parameters[5].Value = ruleGroup.LoanTarget;

                cmdItemUpdate.CommandText = sbSql.ToString();
                foreach (SqlParameter parameter in parameters)
                {
                    if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
                        (parameter.Value == null))
                    {
                        parameter.Value = DBNull.Value;
                    }
                    cmdItemUpdate.Parameters.Add(parameter);
                }
                SqlCmdList.Add(cmdItemUpdate);

                // 2.update rulegroup's rule
                SqlCommand    cmdGroupRules = new SqlCommand();
                StringBuilder sbGroupRules  = new StringBuilder();
                sbGroupRules.Append(string.Format("DELETE Template_Group_N_Rules WHERE RuleGroupId='{0}';", ruleGroup.RuleGroupId));
                if (!string.IsNullOrEmpty(strRuleIds))
                {
                    string[] arrGroupRules = strRuleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string str in arrGroupRules)
                    {
                        sbGroupRules.Append(string.Format("INSERT INTO Template_Group_N_Rules(RuleGroupId, RuleId) VALUES('{0}', '{1}');", ruleGroup.RuleGroupId, str));
                    }
                }
                cmdGroupRules.CommandText = sbGroupRules.ToString();
                SqlCmdList.Add(cmdGroupRules);

                foreach (SqlCommand cmd in SqlCmdList)
                {
                    DbHelperSQL.ExecuteNonQuery(cmd, SqlTrans);
                }

                SqlTrans.Commit();
            }
            catch (Exception ex)
            {
                SqlTrans.Rollback();
                throw ex;
            }
            finally
            {
                if (SqlConn != null)
                {
                    SqlConn.Close();
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Add rule group info, clone a rule group when the parameter nSourceID is not null
        /// </summary>
        /// <param name="ruleGroup"></param>
        /// <param name="strRuleIds"></param>
        /// <param name="nSourceID"></param>
        public int AddRuleGroupInfo(Model.Template_RuleGroups ruleGroup, string strRuleIds, int?nSourceID)
        {
            //
            Collection <SqlCommand> SqlCmdList = new Collection <SqlCommand>();

            int            nRuleGroupId = -1;
            SqlConnection  SqlConn      = null;
            SqlTransaction SqlTrans     = null;

            try
            {
                SqlConn  = DbHelperSQL.GetOpenConnection();
                SqlTrans = SqlConn.BeginTransaction();

                // 1. save rule group info
                StringBuilder sbSql     = new StringBuilder();
                SqlCommand    cmdAddNew = new SqlCommand();
                sbSql.Append("INSERT INTO Template_RuleGroups(Name, [Desc], [Enabled],RuleScope,LoanTarget)VALUES(@Name, @Desc, @Enabled,@RuleScope,@LoanTarget);");
                sbSql.Append("SELECT @@IDENTITY");
                SqlParameter[] cmdParms =
                {
                    new SqlParameter("@Name",       SqlDbType.NVarChar),
                    new SqlParameter("@Desc",       SqlDbType.NVarChar),
                    new SqlParameter("@Enabled",    SqlDbType.Bit),
                    new SqlParameter("@RuleScope",  SqlDbType.SmallInt, 2),
                    new SqlParameter("@LoanTarget", SqlDbType.SmallInt, 2)
                };
                cmdParms[0].Value = ruleGroup.Name;
                cmdParms[1].Value = ruleGroup.Desc;
                cmdParms[2].Value = ruleGroup.Enabled;
                cmdParms[3].Value = ruleGroup.RuleScope;
                cmdParms[4].Value = ruleGroup.LoanTarget;

                foreach (SqlParameter parameter in cmdParms)
                {
                    if ((parameter.Direction == ParameterDirection.InputOutput || parameter.Direction == ParameterDirection.Input) &&
                        (parameter.Value == null))
                    {
                        parameter.Value = DBNull.Value;
                    }
                    cmdAddNew.Parameters.Add(parameter);
                }

                cmdAddNew.CommandText = sbSql.ToString();
                cmdAddNew.Transaction = SqlTrans;
                cmdAddNew.Connection  = SqlConn;
                object obj = cmdAddNew.ExecuteScalar();
                cmdAddNew.Parameters.Clear();
                if (!(Object.Equals(obj, null)) && !(Object.Equals(obj, System.DBNull.Value)))
                {
                    if (!int.TryParse(obj.ToString(), out nRuleGroupId))
                    {
                        nRuleGroupId = -1;
                    }
                }

                // 2. save rulegroup's rule
                if (!string.IsNullOrEmpty(strRuleIds))
                {
                    SqlCommand    cmdGroupRule = new SqlCommand();
                    StringBuilder sbGroupRule  = new StringBuilder();
                    string[]      arrGroupIDs  = strRuleIds.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string str in arrGroupIDs)
                    {
                        sbGroupRule.Append(string.Format("INSERT INTO Template_Group_N_Rules(RuleGroupId, RuleId) VALUES('{0}', '{1}');", nRuleGroupId, str));
                    }
                    cmdGroupRule.CommandText = sbGroupRule.ToString();
                    SqlCmdList.Add(cmdGroupRule);
                }

                foreach (SqlCommand cmd in SqlCmdList)
                {
                    DbHelperSQL.ExecuteNonQuery(cmd, SqlTrans);
                }

                SqlTrans.Commit();
            }
            catch (Exception ex)
            {
                SqlTrans.Rollback();
                throw ex;
            }
            finally
            {
                if (SqlConn != null)
                {
                    SqlConn.Close();
                }
            }

            return(nRuleGroupId);
        }
コード例 #6
0
ファイル: Template_RuleGroups.cs プロジェクト: PulseCRM/Pulse
 public void UpdateRuleGroupRuleInfo(int nRuleGroupId, string strRuleIds)
 {
     Model.Template_RuleGroups ruleGroup = dal.GetModel(nRuleGroupId);
     UpdateRuleGroupInfo(ruleGroup, strRuleIds);
 }
コード例 #7
0
ファイル: Template_RuleGroups.cs プロジェクト: PulseCRM/Pulse
 /// <summary>
 /// Save rule group info from rule group setup page
 /// </summary>
 /// <param name="ruleGroup"></param>
 /// <param name="strRuleIds"></param>
 public void UpdateRuleGroupInfo(Model.Template_RuleGroups ruleGroup, string strRuleIds)
 {
     dal.UpdateRuleGroupInfo(ruleGroup, strRuleIds);
 }
コード例 #8
0
ファイル: Template_RuleGroups.cs プロジェクト: PulseCRM/Pulse
 /// <summary>
 /// Add rule group info, clone a rule group when the parameter nSourceID is not null
 /// </summary>
 /// <param name="ruleGroup"></param>
 /// <param name="strRuleIds"></param>
 /// <param name="nSourceID"></param>
 public int AddRuleGroupInfo(Model.Template_RuleGroups ruleGroup, string strRuleIds, int?nSourceID)
 {
     return(dal.AddRuleGroupInfo(ruleGroup, strRuleIds, nSourceID));
 }