/// <summary> /// 校验Excel数据,这个方法一般用于重写校验逻辑 /// </summary> public virtual bool CheckImportData(string fileName, List<Spl_WarehouseWarrantDetailsModel> list,ref ValidationErrors errors ) { var targetFile = new FileInfo(fileName); if (!targetFile.Exists) { errors.Add("导入的数据文件不存在"); return false; } var excelFile = new ExcelQueryFactory(fileName); //对应列头 excelFile.AddMapping<Spl_WarehouseWarrantDetailsModel>(x => x.WareDetailsId, "WareDetailsId"); excelFile.AddMapping<Spl_WarehouseWarrantDetailsModel>(x => x.WarehouseId, "WarehouseId"); excelFile.AddMapping<Spl_WarehouseWarrantDetailsModel>(x => x.WarehouseWarrantId, "WarehouseWarrantId"); excelFile.AddMapping<Spl_WarehouseWarrantDetailsModel>(x => x.Quantity, "Quantity"); excelFile.AddMapping<Spl_WarehouseWarrantDetailsModel>(x => x.Price, "Price"); excelFile.AddMapping<Spl_WarehouseWarrantDetailsModel>(x => x.TotalPrice, "TotalPrice"); excelFile.AddMapping<Spl_WarehouseWarrantDetailsModel>(x => x.Defined, "Defined"); excelFile.AddMapping<Spl_WarehouseWarrantDetailsModel>(x => x.CreateTime, "CreateTime"); //SheetName var excelContent = excelFile.Worksheet<Spl_WarehouseWarrantDetailsModel>(0); int rowIndex = 1; //检查数据正确性 foreach (var row in excelContent) { var errorMessage = new StringBuilder(); var entity = new Spl_WarehouseWarrantDetailsModel(); entity.Id = row.Id; entity.WareDetailsId = row.WareDetailsId; entity.WarehouseId = row.WarehouseId; entity.WarehouseWarrantId = row.WarehouseWarrantId; entity.Quantity = row.Quantity; entity.Price = row.Price; entity.TotalPrice = row.TotalPrice; entity.Defined = row.Defined; entity.CreateTime = row.CreateTime; //============================================================================= if (errorMessage.Length > 0) { errors.Add(string.Format( "第 {0} 列发现错误:{1}{2}", rowIndex, errorMessage, "<br/>")); } list.Add(entity); rowIndex += 1; } if (errors.Count > 0) { return false; } return true; }
public JsonResult Edit(Spl_WarehouseWarrantModel model, string inserted) { var detailsList = JsonHandler.DeserializeJsonToList <Spl_WarehouseWarrantDetailsModel>(inserted); if (detailsList != null && detailsList.Count != 0) { //计算总价 model.PriceTotal = detailsList.Sum(a => a.Quantity * a.Price); model.ModifyTime = DateTime.Now; if (model != null && ModelState.IsValid) { if (m_BLL.Edit(ref errors, model)) { var detailsResultList = new List <Spl_WarehouseWarrantDetailsModel>(); //新加 foreach (var r in detailsList) { //过滤无效数据 if (string.IsNullOrEmpty(r.WareDetailsId)) { continue; } Spl_WarehouseWarrantDetailsModel entity = new Spl_WarehouseWarrantDetailsModel(); entity.Id = r.Id; entity.WareDetailsId = r.WareDetailsId; entity.WarehouseId = model.WarehouseId; entity.WarehouseWarrantId = model.Id; entity.Quantity = r.Quantity; entity.Price = r.Price; entity.TotalPrice = r.Quantity * r.Price; entity.Defined = string.IsNullOrWhiteSpace(r.Defined) ? "" : r.Defined; entity.CreateTime = ResultHelper.NowTime; detailsResultList.Add(entity); } try { m_BLL.SaveEditData(detailsResultList, model.Id); LogHandler.WriteServiceLog(GetUserId(), "保存成功", "成功", "保存", "Spl_WarehouseWarrant"); return(Json(JsonHandler.CreateMessage(1, Resource.InsertSucceed))); } catch (Exception ex) { LogHandler.WriteServiceLog(GetUserId(), ex.Message, "失败", "保存", "Spl_WarehouseWarrant"); return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ex.Message))); } } else { string ErrorCol = errors.Error; LogHandler.WriteServiceLog(GetUserId(), "Id" + model.Id + ",InTime" + model.InTime + "," + ErrorCol, "失败", "创建", "Spl_WarehouseWarrant"); return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ErrorCol))); } } } return(Json(JsonHandler.CreateMessage(0, Resource.InsertFail + ":没有明细"))); }
public virtual async Task <Tuple <ValidationErrors, bool> > CreateAsync(Spl_WarehouseWarrantDetailsModel model) { ValidationErrors errors = new ValidationErrors(); try { Spl_WarehouseWarrantDetails entity = await m_Rep.GetByIdAsync(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return(new Tuple <ValidationErrors, bool>(errors, false)); } entity = new Spl_WarehouseWarrantDetails(); entity.Id = model.Id; entity.WareDetailsId = model.WareDetailsId; entity.WarehouseId = model.WarehouseId; entity.WarehouseWarrantId = model.WarehouseWarrantId; entity.Quantity = model.Quantity; entity.Price = model.Price; entity.TotalPrice = model.TotalPrice; entity.Defined = model.Defined; entity.CreateTime = model.CreateTime; if (await m_Rep.CreateAsync(entity)) { return(new Tuple <ValidationErrors, bool>(errors, true)); } else { errors.Add(Resource.InsertFail); return(new Tuple <ValidationErrors, bool>(errors, false)); } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return(new Tuple <ValidationErrors, bool>(errors, false)); } }
public virtual bool Edit(ref ValidationErrors errors, Spl_WarehouseWarrantDetailsModel model) { try { Spl_WarehouseWarrantDetails entity = m_Rep.GetById(model.Id); if (entity == null) { errors.Add(Resource.Disable); return false; } entity.Id = model.Id; entity.WareDetailsId = model.WareDetailsId; entity.WarehouseId = model.WarehouseId; entity.WarehouseWarrantId = model.WarehouseWarrantId; entity.Quantity = model.Quantity; entity.Price = model.Price; entity.TotalPrice = model.TotalPrice; entity.Defined = model.Defined; entity.CreateTime = model.CreateTime; if (m_Rep.Edit(entity)) { return true; } else { errors.Add(Resource.NoDataChange); return false; } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return false; } }
public virtual bool Create(ref ValidationErrors errors, Spl_WarehouseWarrantDetailsModel model) { try { Spl_WarehouseWarrantDetails entity = m_Rep.GetById(model.Id); if (entity != null) { errors.Add(Resource.PrimaryRepeat); return false; } entity = new Spl_WarehouseWarrantDetails(); entity.Id = model.Id; entity.WareDetailsId = model.WareDetailsId; entity.WarehouseId = model.WarehouseId; entity.WarehouseWarrantId = model.WarehouseWarrantId; entity.Quantity = model.Quantity; entity.Price = model.Price; entity.TotalPrice = model.TotalPrice; entity.Defined = model.Defined; entity.CreateTime = model.CreateTime; if (m_Rep.Create(entity)) { return true; } else { errors.Add(Resource.InsertFail); return false; } } catch (Exception ex) { errors.Add(ex.Message); ExceptionHander.WriteException(ex); return false; } }
public virtual Spl_WarehouseWarrantDetailsModel GetById(object id) { if (IsExists(id)) { Spl_WarehouseWarrantDetails entity = m_Rep.GetById(id); Spl_WarehouseWarrantDetailsModel model = new Spl_WarehouseWarrantDetailsModel(); model.Id = entity.Id; model.WareDetailsId = entity.WareDetailsId; model.WarehouseId = entity.WarehouseId; model.WarehouseWarrantId = entity.WarehouseWarrantId; model.Quantity = entity.Quantity; model.Price = entity.Price; model.TotalPrice = entity.TotalPrice; model.Defined = entity.Defined; model.CreateTime = entity.CreateTime; return model; } else { return null; } }
public virtual async Task <Spl_WarehouseWarrantDetailsModel> GetByIdAsync(object id) { if (IsExists(id)) { Spl_WarehouseWarrantDetails entity = await m_Rep.GetByIdAsync(id); Spl_WarehouseWarrantDetailsModel model = new Spl_WarehouseWarrantDetailsModel(); model.Id = entity.Id; model.WareDetailsId = entity.WareDetailsId; model.WarehouseId = entity.WarehouseId; model.WarehouseWarrantId = entity.WarehouseWarrantId; model.Quantity = entity.Quantity; model.Price = entity.Price; model.TotalPrice = entity.TotalPrice; model.Defined = entity.Defined; model.CreateTime = entity.CreateTime; return(model); } else { return(null); } }