Exemplo n.º 1
0
 public CrmPromDecMoneyRule GetRule(int ruleId)
 {
     lock (RuleList)
     {
         foreach (CrmPromDecMoneyRule rule in RuleList)
         {
             if (rule.RuleId == ruleId)
             {
                 return(rule);
             }
         }
         CrmPromDecMoneyRule rule2 = CreateRule(ruleId);
         if (rule2 != null)
         {
             RuleList.Add(rule2);
         }
         return(rule2);
     }
 }
Exemplo n.º 2
0
        private CrmPromDecMoneyRule CreateRule(int ruleId)
        {
            CrmPromDecMoneyRule rule = null;
            DbConnection        conn = DbConnManager.GetDbConnection("CRMDB");
            DbCommand           cmd  = conn.CreateCommand();
            StringBuilder       sql  = new StringBuilder();

            sql.Append("select QDJE,FFXE,BJ_TY from MBJZGZ where MBJZGZID = ").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 CrmPromDecMoneyRule();
                        rule.RuleId       = ruleId;
                        rule.MinSaleMoney = DbUtils.GetDouble(reader, 0);
                        rule.MaxDecMoney  = DbUtils.GetDouble(reader, 1);
                        rule.IsNoDecMoney = (DbUtils.GetBool(reader, 2));
                        reader.Close();

                        sql.Length = 0;
                        sql.Append("select XSJE,ZKJE from MBJZGZITEM where MBJZGZID = ").Append(ruleId);
                        sql.Append("  and XSJE > 0 and ZKJE >= 0 order by XSJE desc ");
                        cmd.CommandText = sql.ToString();
                        reader          = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            CrmPromDecMoneyRuleItem ruleItem = new CrmPromDecMoneyRuleItem();
                            rule.Items.Add(ruleItem);
                            ruleItem.SaleMoney = DbUtils.GetDouble(reader, 0);
                            ruleItem.DecMoney  = DbUtils.GetDouble(reader, 1);
                        }
                        reader.Close();
                    }
                    reader.Close();
                }
                catch (Exception e)
                {
                    if (e is MyDbException)
                    {
                        throw e;
                    }
                    else
                    {
                        throw new MyDbException(e.Message, cmd.CommandText);
                    }
                }
            }
            finally
            {
                conn.Close();
            }
            return(rule);
        }