/// <summary> /// 导入Excell数据 /// </summary> /// <returns></returns> public ActionResult ImportExel() { int IsOk = 1; //导入状态 DataTable Result = new DataTable(); //导入错误记录表 try { string moduleId = Request["moduleId"];//表名 StringBuilder sb_table = new StringBuilder(); HttpFileCollectionBase files = Request.Files; HttpPostedFileBase file = files["filePath"]; //获取上传的文件 string fullname = file.FileName; string IsXls = System.IO.Path.GetExtension(fullname).ToLower(); //System.IO.Path.GetExtension获得文件的扩展名 if (IsXls != ".xls" && IsXls != ".xlsx") { IsOk = 0; } else { string filename = Guid.NewGuid().ToString() + ".xls"; if (fullname.IndexOf(".xlsx", StringComparison.Ordinal) > 0) { filename = Guid.NewGuid().ToString() + ".xlsx"; } if (file.FileName != "") { string errMessage = string.Empty; bool flag = UploadHelper.FileUpload(file, Server.MapPath("~/Resource/UploadFile/ImportExcel/"), filename, out errMessage); } DataTable dt = ImportExcel.ImportExcelFile(Server.MapPath("~/Resource/UploadFile/ImportExcel/") + filename); IsOk = base_exceliportbll.ImportExcel(moduleId, dt, out Result); } } catch (Exception ex) { BaseSysLogBll.Instance.WriteLog("", OperationType.Add, "-1", "异常错误:" + ex.Message); IsOk = 0; } if (Result.Rows.Count > 0) { IsOk = 0; } var JsonData = new { Status = IsOk > 0 ? "true" : "false", ResultData = Result }; return(Content(JsonData.ToJson())); }
/// <summary> /// 商品导入 /// </summary> /// <returns></returns> public ActionResult SubmitImportProduct() { bool isSuccess = false; //导入状态 string errMessage; var dataResult = new DataTable(); //导入错误记录表 try { HttpFileCollectionBase files = Request.Files; HttpPostedFileBase file = files["filePath"];//获取上传的文件 if (file != null && file.FileName != "") { string fullname = file.FileName; var extension = System.IO.Path.GetExtension(fullname); if (extension != null) { string fileType = extension.ToLower(); if (fileType == ".xls" || fileType == ".xlsx") { string fileId = Guid.NewGuid().ToString(); string filename = fileId + fileType; bool flag = UploadHelper.FileUpload(file, Server.MapPath("~/UploadFile/ImportProduct/"), filename, out errMessage); if (flag) { ProductImportFileEntity importFile = new ProductImportFileEntity(); importFile.Create(); importFile.FileId = fileId; importFile.FileName = fullname; DataTable dt = ImportExcel.ImportExcelFile(Server.MapPath("~/UploadFile/ImportProduct/") + filename); flag = _productService.ImportProduct(importFile, dt, out dataResult, out errMessage); if (flag) { isSuccess = true; } } else { throw new Exception("商品导入失败:" + errMessage); } } else { throw new Exception("商品导入失败:文件格式不正确"); } } else { throw new Exception("商品导入失败:文件格式不正确"); } } else { throw new Exception("请选择上传文件"); } } catch (Exception ex) { BaseSysLogBll.Instance.WriteLog("", OperationType.Add, "-1", "异常错误:" + ex.Message); errMessage = ex.Message; isSuccess = false; } if (dataResult.Rows.Count > 0) { isSuccess = false; } var data = new { status = isSuccess ? "true" : "false", result = dataResult, message = errMessage }; return(Content(data.ToJson())); }
/// <summary> /// 订单导入 /// </summary> /// <returns></returns> public ActionResult SubmitImportOrder() { bool isSuccess = false; //导入状态 string errMessage = string.Empty; var dataResult = new DataTable(); //导入错误记录表 try { string WarehouseId = Request.Form["WarehouseId"]; if (string.IsNullOrEmpty(WarehouseId)) { throw new Exception("上传文件失败:请选择默认出货仓库"); } string MerchantId = HttpContext.Request.Form["MerchantId"]; if (string.IsNullOrEmpty(MerchantId)) { throw new Exception("上传文件失败:请选择订单所属商户"); } string MerchantMallId = HttpContext.Request.Form["MerchantMallId"]; if (string.IsNullOrEmpty(MerchantMallId)) { throw new Exception("上传文件失败:请选择订单所属店铺"); } HttpFileCollectionBase files = Request.Files; HttpPostedFileBase file = files["filePath"];//获取上传的文件 if (file != null && file.FileName != "") { string fullname = file.FileName; var extension = System.IO.Path.GetExtension(fullname); if (extension != null) { string fileType = extension.ToLower(); if (fileType == ".xls" || fileType == ".xlsx") { string fileId = Guid.NewGuid().ToString(); string filename = fileId + fileType; bool flag = UploadHelper.FileUpload(file, Server.MapPath("~/UploadFile/ImportOrder/"), filename, out errMessage); if (flag) { SaleOrderImportFileEntity importFile = new SaleOrderImportFileEntity(); importFile.Create(); importFile.FileId = fileId; importFile.WarehouseId = WarehouseId; importFile.MerchantId = MerchantId; importFile.MerchantMallId = MerchantMallId; importFile.FileName = fullname; DataTable dt = ImportExcel.ImportExcelFile(Server.MapPath("~/UploadFile/ImportOrder/") + filename); flag = _orderService.ImportOrder(importFile, dt, out dataResult, out errMessage); if (flag) { isSuccess = true; } } else { throw new Exception("订单导入失败:" + errMessage); } } else { throw new Exception("订单导入失败:文件格式不正确"); } } else { throw new Exception("订单导入失败:文件格式不正确"); } } else { throw new Exception("请选择上传文件"); } } catch (Exception ex) { BaseSysLogBll.Instance.WriteLog("", OperationType.Add, "-1", "异常错误:" + ex.Message); errMessage = ex.Message; isSuccess = false; } if (dataResult.Rows.Count > 0) { isSuccess = false; } var data = new { status = isSuccess ? "true" : "false", result = dataResult, message = errMessage }; return(Content(data.ToJson())); }