/// <summary> /// 读取所有信息 /// </summary> /// <param name="_scoreRuleTable">评分表</param> /// <param name="_gradeTable">等级表</param> /// <param name="structNames">字段类</param> /// <param name="loadDealerInfo">读取信息方法</param> /// <param name="engineConnection">引擎连接串</param> /// <returns>评分引擎实例</returns> public static ScoreManage LoadGradeObject(string _scoreRuleTable, string _gradeTable, StructNames structNames, LoadDealerInfo loadDealerInfo, string engineConnection = "") { if (_engine == null) { SetEngin(engineConnection); } ScoreManage scoreManage = new ScoreManage(); DataTable groupTable = null; try { groupTable = Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable("select * from " + _scoreRuleTable); } catch (Exception e) { Console.Write(e.Message); } foreach (DataRow row in groupTable.Rows) { scoreManage.PushScoreIntoGroup(row, structNames); } foreach (ScoreGroup group in scoreManage.Scores) { DataTable gradeTable = Engine.EngineConfig.CommandFactory.CreateCommand().ExecuteDataTable(string.Format("SELECT {0},{1},{2},{3},{4} FROM {6} WHERE States=1 AND PID='{5}'", structNames.GradeNames.ObjectId, structNames.GradeNames.GroupId, structNames.GradeNames.Grade, structNames.GradeNames.RangeFrom, structNames.GradeNames.RangeTo, group.ObjectId, _gradeTable)); foreach (DataRow row in gradeTable.Rows) { group.GradeList.Add(new Grade() { ObjectId = row[structNames.GradeNames.ObjectId].ToString(), Name = row[structNames.GradeNames.Grade].ToString(), ScoreFrom = row[structNames.GradeNames.RangeFrom].ToString().IndexOf('?') >= 0 ? double.MinValue : double.Parse(row[structNames.GradeNames.RangeFrom].ToString()), ScoreTo = row[structNames.GradeNames.RangeTo].ToString().IndexOf('?') >= 0 ? double.MaxValue : double.Parse(row[structNames.GradeNames.RangeTo].ToString()), }); } } scoreManage.Dealers = loadDealerInfo(scoreManage.Dealers); return(scoreManage); }
/// <summary> /// 读取评分结构 /// </summary> /// <param name="row">行数据</param> /// <param name="structNames">字段结构</param> public void PushScoreIntoGroup(DataRow row, StructNames structNames) { try { ScoreGroup group = Scores.FirstOrDefault(x => x.ObjectId == row[structNames.GroupNames.ObjectId].ToString()); if (group == null) { group = new ScoreGroup() { ObjectId = row[structNames.GroupNames.ObjectId].ToString(), DealerIntranet = row[structNames.GroupNames.DealerIntranet].ToString(), DealerType = row[structNames.GroupNames.DealerType].ToString() }; Scores.Add(group); } Score score = group.ScoreList.FirstOrDefault(x => x.ObjectId == row[structNames.ScoreNames.ObjectId].ToString()); if (score == null) { float weight; if (!float.TryParse(row[structNames.ScoreNames.Weight].ToString(), out weight)) { weight = 0; } score = new Score() { ObjectId = row[structNames.ScoreNames.ObjectId].ToString(), Expression = row[structNames.ScoreNames.Expression].ToString(), ScoreName = row[structNames.ScoreNames.ScoreName].ToString(), Weight = weight }; group.ScoreList.Add(score); } Detail detail = score.DetailList.FirstOrDefault(x => x.ObjectId == row[structNames.DetailNames.ObjectId].ToString()); if (detail == null) { float rate; if (!float.TryParse(row[structNames.DetailNames.Rate].ToString(), out rate)) { rate = 0; } detail = new Detail() { ObjectId = row[structNames.DetailNames.ObjectId].ToString(), Rate = rate }; score.DetailList.Add(detail); } Option option = detail.Options.FirstOrDefault(x => x.ObjectId == row[structNames.OptionNames.ObjectId].ToString()); if (option == null) { double value; if (!double.TryParse(row[structNames.OptionNames.Value].ToString(), out value)) { value = 0; } option = new Option() { ObjectId = row[structNames.OptionNames.ObjectId].ToString(), Memo = row[structNames.OptionNames.Memo].ToString(), Value = value }; detail.Options.Add(option); } } catch (Exception ex) { Scores = new List <ScoreGroup>(); } }