public ActionResult ImportWorkOrder(int type) { var result = new ResultInfoModel() { IsSuccess = false }; StringBuilder strbuild = new StringBuilder(); string FileName; string savePath; HttpPostedFileBase file = Request.Files["file"]; if (file == null || file.ContentLength <= 0) { result.Message = "please choose file"; return(Content(JsonHelper.JsonSerializer(result))); } else { string fileName = Path.GetFileName(file.FileName); int filesize = file.ContentLength; //获取上传文件的大小单位为字节byte string fileEx = Path.GetExtension(fileName); //获取上传文件的扩展名 string NoFileName = Path.GetFileNameWithoutExtension(fileName); //获取无扩展名的文件名 int Maxsize = 4000 * 1024; //定义上传文件的最大空间大小为4M string FileType = ".xls,.xlsx"; //定义上传文件的类型字符串 FileName = NoFileName + fileEx; if (!FileType.Contains(fileEx)) { result.Message = "please upload .xls and .xlsx"; return(Content(JsonHelper.JsonSerializer(result))); } if (filesize >= Maxsize) { result.Message = string.Format("file size can't big than {0}", Maxsize); return(Content(JsonHelper.JsonSerializer(result))); } string path = Server.MapPath("~/App_Data/uploads"); savePath = Path.Combine(path, FileName); file.SaveAs(savePath); string strConn; strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + savePath + ";Extended Properties=Excel 12.0;"; using (OleDbConnection conn = new OleDbConnection(strConn)) { conn.Open(); OleDbDataAdapter myCommand = new OleDbDataAdapter("select * from [Sheet1$]", strConn); DataSet myDataSet = new DataSet(); try { myCommand.Fill(myDataSet, "ExcelInfo"); } catch (Exception ex) { result.Message = ex.Message; return(Content(JsonHelper.JsonSerializer(result))); } DataTable table = myDataSet.Tables["ExcelInfo"].DefaultView.ToTable(); try { for (int i = 0; i < table.Rows.Count; i++) { WorkOrderInfo model = new WorkOrderInfo(); model.WIWorkOrder = table.Rows[i][0].ToString(); model.WISapPN = table.Rows[i][1].ToString(); model.WIProductName = table.Rows[i][2].ToString(); model.WIReceiptTime = table.Rows[i][3].ToString(); model.WIReceiptBy = table.Rows[i][4].ToString(); model.WICloseDateShift = table.Rows[i][5].ToString(); model.WIOrderArchived = table.Rows[i][6].ToString(); model.WIParameterRecord = table.Rows[i][7].ToString(); model.WIToolMaintenanceRecord = table.Rows[i][8].ToString(); model.WIToolMachineCheck = table.Rows[i][9].ToString(); model.WIQuantityConfirm = table.Rows[i][10].ToString(); model.WIArchivedBy = table.Rows[i][11].ToString(); model.WIWeeklyCheck = table.Rows[i][12].ToString(); model.WIRemarks = table.Rows[i][7].ToString(); model.WIGetBy = table.Rows[i][8].ToString(); model.WIGetTime = table.Rows[i][9].ToString(); model.WIType = type; MaterialBusiness.SaveWorkOrder(model, this.LoginUser); } result.IsSuccess = true; } catch (Exception ex) { result.Message = ex.Message; return(Content(JsonHelper.JsonSerializer(result))); } conn.Close(); } return(Content(JsonHelper.JsonSerializer(result))); } }
public ActionResult WorkOrderSubmmit(WorkOrderInfo model) { var result = MaterialBusiness.SaveWorkOrder(model, this.LoginUser); return(Json(result)); }