List <Knowledge> ICedts_HomeRepository.KPMaster() { List <Knowledge> knowList = new List <Knowledge>(); var Kp = db.CEDTS_SampleKnowledgeInfomation; foreach (var m in Kp) { Knowledge know = new Knowledge(); var kpname = (from s in db.CEDTS_KnowledgePoints where s.KnowledgePointID == m.KnowledgePointID select s.Title).FirstOrDefault(); Regex regex = new Regex(@"[.\d]");//去除数字 kpname = regex.Replace(kpname, ""); double KP_MasterRate1 = m.KP_MasterRate.Value * 100; string KP_MasterRate = KP_MasterRate1 + ""; if (KP_MasterRate.Length > 4) { KP_MasterRate = KP_MasterRate.Substring(0, KP_MasterRate.IndexOf('.') + 2); } m.KP_MasterRate = Convert.ToDouble(KP_MasterRate); if (knowList.Count == 0) { know.KPName = kpname; know.UMi = m.KP_MasterRate.Value; knowList.Add(know); } else { int Right = 0; for (int i = 0; i < knowList.Count; i++) { if (knowList[i].KPName == kpname) { knowList[i].UMi = (knowList[i].UMi + m.KP_MasterRate.Value) / 2; Right = 1; } } if (Right != 1) { know.KPName = kpname; know.UMi = m.KP_MasterRate.Value; knowList.Add(know); } } } return(knowList); }
List <Knowledge> ICedts_HomeRepository.UserKpMaster(string UserName) { List <Knowledge> KnowList = new List <Knowledge>(); var UserID = (from m in db.CEDTS_User where m.UserAccount == UserName select m.UserID).FirstOrDefault(); var KpName = (from m in db.CEDTS_KnowledgePoints orderby m.Title select m); foreach (var kp in KpName) { string Name = string.Empty; Knowledge kown = new Knowledge(); Regex regex = new Regex(@"[.\d]"); Name = regex.Replace(kp.Title, ""); var SMiInfo = (from m in db.CEDTS_SampleKnowledgeInfomation where m.KnowledgePointID == kp.KnowledgePointID select m.KP_MasterRate).FirstOrDefault(); var UMiInfo = (from m in db.CEDTS_UserKnowledgeInfomation where m.UserID == UserID && m.KnowledgePointID == kp.KnowledgePointID select m.KP_MasterRate).FirstOrDefault(); if (UMiInfo != null) { double SMi1 = SMiInfo.Value * 100; double UMi1 = UMiInfo.Value * 100; string SMi = SMi1 + ""; string UMi = UMi1 + ""; if (SMi.Length > 4) { SMi = SMi.Substring(0, SMi.IndexOf('.') + 2); } if (UMi.Length > 4) { UMi = UMi.Substring(0, UMi.IndexOf('.') + 2); } kown.KPName = Name; kown.SMi = double.Parse(SMi); kown.UMi = double.Parse(UMi); KnowList.Add(kown); } } return(KnowList); }