public (bool, string) Import(System.Data.DataTable dt, long userId) { if (dt.IsNullDt()) { return(false, PubConst.Import1); } var validator = new CustomerFluent(); var list = new List <Wms_Customer>(); string[] header = { "客户编号", "客户名称", "电话", "邮箱", "联系人", "地址" }; foreach (var item in header) { if (!dt.Columns.Contains(item)) { return(false, "不包含Excel表头:" + string.Join(",", header)); } } int dtCount = dt.Rows.Count; for (int i = 0; i < dtCount; i++) { var model = new Wms_Customer { CustomerNo = dt.Rows[i]["客户编号"].ToString(), CustomerName = dt.Rows[i]["客户名称"].ToString(), Address = dt.Rows[i]["地址"].ToString(), Tel = dt.Rows[i]["电话"].ToString(), Email = dt.Rows[i]["邮箱"].ToString(), CustomerPerson = dt.Rows[i]["联系人"].ToString(), }; var results = validator.Validate(model); var success = results.IsValid; if (!success) { string msg = results.Errors.Aggregate("", (current, item) => (item.ErrorMessage + "</br>")); return(false, msg); } if (_repository.IsAny(c => c.CustomerNo == model.CustomerNo)) { return(false, PubConst.Customer1); } model.CustomerId = PubId.SnowflakeId; model.CreateBy = userId; list.Add(model); } var flag = _repository.InsertTran(list); if (flag.IsSuccess) { return(true, PubConst.Import2); } else { var _nlog = ServiceResolve.Resolve <ILogUtil>(); _nlog.Debug(flag.ErrorMessage); return(false, PubConst.Import3); } }
public void Run() { var _nlog = ServiceResolve.Resolve <ILogUtil>(); GC.Collect(); }