private CrmPromPayCouponRule CreateRule(int ruleId) { CrmPromPayCouponRule rule = null; DbConnection conn = DbConnManager.GetDbConnection("CRMDB"); DbCommand cmd = conn.CreateCommand(); StringBuilder sql = new StringBuilder(); sql.Append("select YQBL_XFJE,YQBL_YHQJE,ZDYQJE,BJ_TY from YHQSYGZ where YHQSYGZID = ").Append(ruleId); cmd.CommandText = sql.ToString(); try { try { conn.Open(); } catch (Exception e) { throw new MyDbException(e.Message, true); } try { DbDataReader reader = cmd.ExecuteReader(); if (reader.Read()) { rule = new CrmPromPayCouponRule(); rule.RuleId = ruleId; rule.SaleMoneyBase = DbUtils.GetDouble(reader, 0); rule.PayLimitMoneyBase = DbUtils.GetDouble(reader, 1); rule.MaxPayMoney = DbUtils.GetDouble(reader, 2); rule.IsValid = (!DbUtils.GetBool(reader, 3)); } reader.Close(); } catch (Exception e) { if (e is MyDbException) { throw e; } else { throw new MyDbException(e.Message, cmd.CommandText); } } } finally { conn.Close(); } return(rule); }
public CrmPromPayCouponRule GetRule(int ruleId) { lock (RuleList) { foreach (CrmPromPayCouponRule rule in RuleList) { if (rule.RuleId == ruleId) { return(rule); } } CrmPromPayCouponRule rule2 = CreateRule(ruleId); if (rule2 != null) { RuleList.Add(rule2); } return(rule2); } }