public ActionResult History(DateTime?Apply_Time, DateTime?Start_Time, DateTime?End_Time) { var cookie = Request.Cookies["userInfo"]; if (cookie != null) { ViewBag.applyTime = Apply_Time; ViewBag.startTime = Start_Time; ViewBag.endTime = End_Time; string name = cookie.Value; var user = JsonConvert.DeserializeObject <UserInfo>(UrlHelper.DecodeUrl(name)); string teacherName = UnityContainerHelper.Server <ITeacherBll>().Find(user.username).Teacher_Name; List <Use_Apply> applies = _useApplyBll.GetEntities( m => m.Teacher_Name == teacherName && (Apply_Time == null || m.Apply_Time == Apply_Time) && (Start_Time == null || m.Start_Time == Start_Time) && (End_Time == null || m.End_Time == End_Time) ); return(View(applies)); } return(Content("登录信息失效,请重新登录")); }
public string TeacherHistory() { var cookie = Request.Cookies["userInfo"]; if (cookie != null) { string name = cookie.Value; var user = JsonConvert.DeserializeObject <UserInfo>(UrlHelper.DecodeUrl(name)); string teacherName = UnityContainerHelper.Server <ITeacherBll>().Find(user.username).Teacher_Name; List <DateTime> applyTimes = _useApplyBll.ExecuteSqlCommand <DateTime>( $"select top (30) * from (select distinct(Apply_Time) from Use_Apply where Teacher_Name = '{teacherName}') as dates order by Apply_Time"); List <string> materialNames = _useApplyBll.ExecuteSqlCommand <string>( $" select top 5 Material_Name from Use_Apply where Teacher_Name = '{teacherName}' group by Material_Name order by sum(Apply_Count) desc"); List <TeacherHistoryModel> teacherHistoryModels = new List <TeacherHistoryModel>(); Dictionary <string, List <int> > yAxis = new Dictionary <string, List <int> >(); foreach (string materialName in materialNames) { List <NameToCount> nameToCounts = _useApplyBll.ExecuteSqlCommand <NameToCount>( $"select Apply_Time,Apply_Count from Use_Apply where Teacher_Name = '{teacherName}' and Material_Name='{materialName}'"); foreach (DateTime applyTime in applyTimes) { if (!yAxis.ContainsKey(materialName)) { yAxis.Add(materialName, new List <int>()); } if (nameToCounts.Where(m => m.Apply_Time.ToString("yyyy-MM-dd") == applyTime.ToString("yyyy-MM-dd")).ToList().Count == 0) { yAxis[materialName].Add(0); } else { NameToCount first = null; foreach (var m in nameToCounts) { if (m.Apply_Time.ToString("yyyy-MM-dd") == applyTime.ToString($"yyyy-MM-dd")) { first = m; break; } } if (first != null) { yAxis[materialName].Add(first.Apply_Count); } } } teacherHistoryModels.Add(new TeacherHistoryModel() { MaterialName = materialName, NameToCounts = nameToCounts }); } //foreach (TeacherHistoryModel teacherHistoryModel in teacherHistoryModels) //{ // yAxis.Add(teacherHistoryModel.MaterialName, teacherHistoryModel.NameToCounts.Select(m => m.Apply_Count).ToList()); //} List <string> xAxis = new List <string>(); foreach (DateTime applyTime in applyTimes) { xAxis.Add(applyTime.ToString("yyyy-MM-dd")); } var dataJson = new { legend = materialNames, xAxis, yAxis }; return(JsonConvert.SerializeObject(dataJson)); } return(""); }
public ActionResult Apply(string id, string count) { Dictionary <Material_Info, string> infos = new Dictionary <Material_Info, string>(); var cookie = Request.Cookies["userInfo"]; if (cookie != null) { string name = cookie.Value; var user = JsonConvert.DeserializeObject <UserInfo>(UrlHelper.DecodeUrl(name)); var teacher = UnityContainerHelper.Server <ITeacherBll>().Find(user.username); ViewBag.teacher = teacher; } if (id == null && count == null) { if (Session["materialCar"] == null) { return(Content("我的器材为空")); } if (Session["materialCar"] is Dictionary <string, int> carInfos) { foreach (string carInfosKey in carInfos.Keys) { Material_Info info = _infoBll.GetEntity(m => m.Material_Id == carInfosKey); int buyCount = carInfos[carInfosKey] > Int32.Parse(info.Material_RemainCont.ToString()) ? carInfos[carInfosKey] - Int32.Parse(info.Material_RemainCont.ToString()) : 0; string counts = carInfos[carInfosKey] + ":" + buyCount; infos.Add(info, counts); } } } else { Material_Info materialInfo = _infoBll.GetEntity(m => m.Material_Id == id); ViewBag.materialInfo = materialInfo; var buyCount = Int32.Parse(count) > Int32.Parse(materialInfo.Material_RemainCont.ToString()) ? Int32.Parse(count) - Int32.Parse(materialInfo.Material_RemainCont.ToString()) : 0; infos.Add(materialInfo, count + ":" + buyCount); if (Session["materialCar"] == null) { var carInfos = new Dictionary <string, int> { { id, int.Parse(count) } }; Session["materialCar"] = carInfos; } else { if (Session["materialCar"] is Dictionary <string, int> carInfos) { if (carInfos.ContainsKey(id)) { carInfos[id] += int.Parse(count); } else { carInfos.Add(id, int.Parse(count)); } Session["materialCar"] = carInfos; } } } ViewBag.materialInfos = infos; var model = new Material_Apply(); return(View(model)); }