Ejemplo n.º 1
0
 /// <summary>
 /// 按照数量计算利润
 /// </summary>
 /// <param name="num">数量</param>
 /// <param name="rules">规则</param>
 /// <returns>利润</returns>
 public double GetProfileByCount(int num, CalculatorRulesModel rules)
 {
     return num < rules.Num ? 0 : num * rules.SignalProfile;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 按照金额计算利润
 /// </summary>
 /// <param name="money">金额</param>
 /// <param name="rules">返利百分比</param>
 /// <returns>返利</returns>
 public double GetProfileByMoney(double money, CalculatorRulesModel rules)
 {
     return money <= rules.AllMoney ? 0 : money * rules.ProfilePercent;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 读取计算规则信息
        /// </summary>
        /// <returns>计算规则</returns>
        public static List<CalculatorRulesModel> GetRules()
        {
            string xmlPath = "rulesSheet.XML";
            XmlDocument document = new XmlDocument();
            List<CalculatorRulesModel> lstRulesModel = new List<CalculatorRulesModel>();
            try
            {
                document.Load(xmlPath);
                XmlElement rootElem = document.DocumentElement;
                XmlNodeList rulesNodes = rootElem.GetElementsByTagName("rule");
                CalculatorRulesModel model = null;
                foreach (XmlNode node in rulesNodes)
                {
                    string type = node.Attributes["type"].Value;
                    CalculatorType currentType = (CalculatorType)Enum.Parse(typeof(CalculatorType), type, true);
                    switch (currentType)
                    {
                        case CalculatorType.One:
                            model = new CalculatorRulesModel()
                            {
                                Num = int.Parse(node.Attributes["minNum"].Value),
                                RuleType = currentType,
                                SignalProfile = double.Parse(node.Attributes["signalProfile"].Value),
                                Desc = node.Attributes["Desc"].Value
                            };
                            break;
                        case CalculatorType.Two:
                            model = new CalculatorRulesModel()
                            {
                                Num = int.Parse(node.Attributes["minNum"].Value),
                                RuleType = currentType,
                                SignalProfile = double.Parse(node.Attributes["signalProfile"].Value),
                                Desc = node.Attributes["Desc"].Value
                            };
                            break;
                        case CalculatorType.Three:
                            model = new CalculatorRulesModel()
                            {
                                Num = int.Parse(node.Attributes["minMoney"].Value),
                                RuleType = currentType,
                                SignalProfile = double.Parse(node.Attributes["profilePercent"].Value),
                                Desc = node.Attributes["Desc"].Value
                            };
                            break;
                        case CalculatorType.Four:
                            model = new CalculatorRulesModel()
                            {
                                Num = int.Parse(node.Attributes["minMoney"].Value),
                                RuleType = currentType,
                                SignalProfile = double.Parse(node.Attributes["profilePercent"].Value),
                                Desc = node.Attributes["Desc"].Value
                            };
                            break;
                    }
                    lstRulesModel.Add(model);
                }

                return lstRulesModel;
            }
            catch (Exception ex)
            {
                throw new Exception("配置文件丢失");
            }
        }