internal HttpResponseMessage ProductionDates(HttpRequestMessage request, ProductionTotalDTO cqDTO) { string key; var aur = new AppUserRepository(); var companyId = 0; var userId = aur.ValidateUser(cqDTO.Key, out key, ref companyId); if (userId > 0) { var ur = new ProductionTotalRepository(); var u = new ProductionTotal(); if (cqDTO.ProductionDate != null) { cqDTO.Start_ProductionDate = DateTime.Parse(cqDTO.ProductionDate).ToString(); cqDTO.End_ProductionDate = DateTime.Parse(cqDTO.ProductionDate).AddDays(1).ToString(); } else { int sm = int.Parse(cqDTO.StartDateMonth); if (sm == 1) { cqDTO.Start_ProductionDate = DateTime.Parse("12/23/" + (int.Parse(cqDTO.StartDateYear) - 1).ToString()).ToString(); cqDTO.End_ProductionDate = DateTime.Parse("2/14/" + cqDTO.StartDateYear).ToString(); } else if (sm == 12) { cqDTO.Start_ProductionDate = DateTime.Parse("11/23/" + cqDTO.StartDateYear).ToString(); cqDTO.End_ProductionDate = DateTime.Parse("1/14/" + (int.Parse(cqDTO.StartDateYear) + 1).ToString()).ToString(); } else { cqDTO.Start_ProductionDate = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) - 1).ToString() + "/23/" + cqDTO.StartDateYear).ToString(); cqDTO.End_ProductionDate = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) + 1).ToString() + "/14/" + cqDTO.StartDateYear).ToString(); } cqDTO.StartDateMonth = null; cqDTO.StartDateYear = null; } var predicate = ur.GetPredicate(cqDTO, u, companyId); var data = ur.GetByPredicate(predicate); var col = new Collection <Dictionary <string, string> >(); foreach (var item in data) { var dic = new Dictionary <string, string>(); dic.Add("ProductionDate", item.ProductionDate.ToShortDateString()); col.Add(dic); } var retVal = new GenericDTO { Key = key, ReturnData = col }; return(Request.CreateResponse(HttpStatusCode.OK, retVal)); } var message = "validation failed"; return(request.CreateResponse(HttpStatusCode.NotFound, message)); }
private void UpdateProductionTotalYield(FarmYieldDTO uDto) { var pr = new ProductionTotalRepository(); var prod = new ProductionTotal(); var prodexists = pr.GetByDateAndPond(DateTime.Parse(uDto.YieldDate), int.Parse(uDto.PondID)); decimal ay = 0; var y1 = uDto.PercentYield == null ? 0 : decimal.Parse(uDto.PercentYield); var y2 = uDto.PercentYield2 == null ? 0 : decimal.Parse(uDto.PercentYield2); if (y1 > 0 || y2 > 0) { if (y2 > 0) { if (y1 > 0) { ay = (y1 + y2) / 2; } else { ay = y2; } } else { ay = y1; } } if (prodexists == null) { prod.PondId = int.Parse(uDto.PondID); prod.ProductionDate = DateTime.Parse(uDto.YieldDate); prod.AverageYield = ay; pr.Save(prod); } else { prod = prodexists; var fyr = new FarmYieldRepository(); List <FarmYield> fyl = fyr.GetByDateAndPond(DateTime.Parse(uDto.YieldDate), int.Parse(uDto.PondID)); int fycount = fyl.Where(x => x.PercentYield != null).Count(); int fycount2 = fyl.Where(x => x.PercentYield2 != null).Count(); decimal fysum1 = fyl.Where(x => x.PercentYield != null).Sum(x => x.PercentYield).Value; decimal fysum2 = fyl.Where(x => x.PercentYield2 != null).Sum(x => x.PercentYield2).Value; prod.AverageYield = (fysum1 + fysum2) / (fycount + fycount2); //if (prod.AverageYield == null) //{ // prod.AverageYield = ay; //} //else //{ // prod.AverageYield = (prod.AverageYield + ay) / 2; //} pr.Save(prod); } }
/// <summary> /// 获取文献分页数据 /// </summary> /// <param name="UserID">用户ID</param> /// <param name="pageSize">每页条数</param> /// <param name="curPage">第几页</param> /// <returns></returns> public async Task <ProductionTotal> GetProductionsList(Guid UserID, int pageSize, int curPage) { ProductionTotal productionTotal = new ProductionTotal(); using (var db = new OperationManagerDbContext()) { productionTotal.TotalCount = db.Production.Where(w => w.UserID == UserID).Count(); //List<Production> list = db.Production.OrderByDescending(o => o.CreateTime).Take(pageSize * curPage).Skip(pageSize * (curPage - 1)).ToList(); //productionTotal.ProductionList = db.Production.OrderByDescending(o => o.CreateTime).Take(pageSize * curPage).Skip(pageSize * (curPage - 1)).ToList(); productionTotal.ProductionList = await db.Production.OrderBy(c => c.CreateTime).Where(w => w.UserID == UserID).Take(pageSize * curPage).Skip(pageSize * (curPage - 1)).ToListAsync(); return(productionTotal); } }
public HttpResponseMessage ProductionTotals([FromBody] ProductionTotalDTO cqDTO) { string key; var aur = new AppUserRepository(); var companyId = 0; var userId = aur.ValidateUser(cqDTO.Key, out key, ref companyId); if (userId > 0) { var ur = new ProductionTotalRepository(); var u = new ProductionTotal(); if (cqDTO.ProductionDate != null) { cqDTO.Start_ProductionDate = DateTime.Parse(cqDTO.ProductionDate).ToString(); cqDTO.End_ProductionDate = DateTime.Parse(cqDTO.ProductionDate).AddDays(1).ToString(); } else { int sm = int.Parse(cqDTO.StartDateMonth); if (sm == 1) { cqDTO.Start_ProductionDate = DateTime.Parse("12/23/" + (int.Parse(cqDTO.StartDateYear) - 1).ToString()).ToString(); cqDTO.End_ProductionDate = DateTime.Parse("2/14/" + cqDTO.StartDateYear).ToString(); } else if (sm == 12) { cqDTO.Start_ProductionDate = DateTime.Parse("11/23/" + cqDTO.StartDateYear).ToString(); cqDTO.End_ProductionDate = DateTime.Parse("1/14/" + (int.Parse(cqDTO.StartDateYear) + 1).ToString()).ToString(); } else { cqDTO.Start_ProductionDate = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) - 1).ToString() + "/23/" + cqDTO.StartDateYear).ToString(); cqDTO.End_ProductionDate = DateTime.Parse((int.Parse(cqDTO.StartDateMonth) + 1).ToString() + "/14/" + cqDTO.StartDateYear).ToString(); } cqDTO.StartDateMonth = null; cqDTO.StartDateYear = null; } SGApp.DTOs.GenericDTO dto = new GenericDTO(); dto.StartDate = DateTime.Parse(cqDTO.Start_ProductionDate); dto.EndDate = DateTime.Parse(cqDTO.End_ProductionDate); List <DTOs.Sampling> samplingResults = new List <DTOs.Sampling>(); PondRepository pr = new PondRepository(); var client = new HttpClient { //BaseAddress = new Uri("http://323-booth-svr2:3030/") BaseAddress = new Uri("http://64.139.95.243:7846/") //BaseAddress = new Uri(baseAddress) }; try { var response = client.PostAsJsonAsync("api/Remote/GetKeithsData", dto).Result; response.EnsureSuccessStatusCode(); JavaScriptSerializer json_serializer = new JavaScriptSerializer(); //Sampling[] samplingResultsArray = json_serializer.Deserialize<Sampling[]>(response.Content.ReadAsStringAsync().Result); // new List<Sampling>(); //Sampling[] samplingResultsArray = response.Content.ReadAsAsync<Sampling[]>().Result; //samplingResults = samplingResultsArray.ToList(); //JavaScriptSerializer json_serializer = new JavaScriptSerializer(); //Sampling[] samplingResultsArray = json_serializer.Deserialize<Sampling[]>(Constants.testdata); DTOs.Sampling[] samplingResultsArray = json_serializer.Deserialize <DTOs.Sampling[]>(response.Content.ReadAsStringAsync().Result); samplingResults = samplingResultsArray.ToList(); samplingResults = samplingResults.GroupBy(x => x.farmPond).Select(group => group.First()).ToList(); //var result = response.Content.ReadAsStringAsync().Result; //return Request.CreateResponse(HttpStatusCode.OK, result); } catch (Exception e) { throw new HttpException("Error occurred: " + e.Message); } var predicate = ur.GetPredicate(cqDTO, u, companyId); var data = ur.GetByPredicate(predicate); var col = new Collection <Dictionary <string, string> >(); data = data.OrderBy(x => x.ProductionDate).ToList(); foreach (DTOs.Sampling sam in samplingResults) { ProductionTotal fy = data.Where(x => x.Pond.InnovaName == sam.farmPond).FirstOrDefault(); Pond pd = pr.GetPondFromInnovaName(sam.farmPond); var dic = new Dictionary <string, string>(); if (fy != null) { var wb = fy.WeighBacks != null ? fy.WeighBacks : 0; dic.Add("ProductionTotalId", fy.ProductionTotalID.ToString()); dic.Add("PondID", fy.PondId.ToString()); dic.Add("PondName", sam.farmPond); dic.Add("FarmID", fy.Pond.FarmId.ToString()); dic.Add("ProductionDate", fy.ProductionDate.ToShortDateString()); dic.Add("PlantWeight", fy.PlantWeight != null ? fy.PlantWeight.ToString() : "---"); dic.Add("PondWeight", fy.PondWeight != null ? fy.PondWeight.ToString() : "---"); dic.Add("WeighBacks", fy.WeighBacks != null ? fy.WeighBacks.ToString() : "---"); dic.Add("AverageYield", fy.AverageYield != null ? fy.AverageYield.ToString() : "---"); dic.Add("HeadedWeight", fy.AverageYield != null && fy.PlantWeight != null ? String.Format("{0:0.00}", ((fy.AverageYield / 100) * (fy.PlantWeight - wb))) : "---"); } else { dic.Add("ProductionTotalId", "-1"); dic.Add("PondID", pd.PondId.ToString() != null ? pd.PondId.ToString() : ""); dic.Add("PondName", sam.farmPond != null ? sam.farmPond : ""); dic.Add("FarmID", pd.FarmId.ToString() != null ? pd.FarmId.ToString() : ""); dic.Add("ProductionDate", cqDTO.ProductionDate); dic.Add("PlantWeight", "---"); dic.Add("PondWeight", "---"); dic.Add("WeighBacks", "---"); dic.Add("AverageYield", "---"); dic.Add("HeadedWeight", "---"); } col.Add(dic); } //foreach (FarmYield fy in data) //{ // Sampling samp = samplingResults.Where(x => x.farmPond == fy.Pond.InnovaName).FirstOrDefault(); // var dic = new Dictionary<string, string>(); // if (samp == null) // { // dic.Add("YieldId", fy.YieldID.ToString()); // dic.Add("PondID", fy.PondID.ToString()); // dic.Add("PondName", fy.Pond.InnovaName != null ? fy.Pond.InnovaName : fy.Pond.PondName); // dic.Add("FarmID", fy.Pond.FarmId.ToString()); // dic.Add("YieldDate", fy.YieldDate.ToShortDateString()); // dic.Add("PoundsYielded", fy.PoundsYielded.ToString()); // dic.Add("PoundsPlant", fy.PoundsPlant.ToString()); // dic.Add("PoundsHeaded", fy.PoundsHeaded.ToString()); // dic.Add("PercentYield", fy.PercentYield.ToString()); // dic.Add("PercentYield2", fy.PercentYield2.ToString()); // col.Add(dic); // } //} var retVal = new GenericDTO { Key = key, ReturnData = col }; return(Request.CreateResponse(HttpStatusCode.OK, retVal)); } var message = "validation failed"; return(Request.CreateResponse(HttpStatusCode.NotFound, message)); }