public static string TeachingClassStudent_List(string fileUrl, string OCClassID) { DataTable dt = new DataTable(); dt = NPOIHandler.ExcelToDataTable(fileUrl, "Student"); OCClassBLL oCClassBLL = new OCClassBLL(); List <OCClassStudent> newList = new List <OCClassStudent>(); string UserNos = ""; //int sucessnum = 0; //int lostNum = 0; //int allnum = dt.Rows.Count; for (int i = 0; i < dt.Rows.Count; i++) { //int result = oCClassBLL.OCClassStudent_Import(teachingclassid, dt.Rows[i]["UserNo"].ToString()); //if (result == 1) //{ // sucessnum++; //} //else if (result == 0) //{ // lostNum++; //} UserNos += dt.Rows[i]["UserNo"].ToString() + ","; } if (UserNos != "" && UserNos.IndexOf(',') > 0) { UserNos = UserNos.Substring(0, UserNos.Length - 1); } //return "成功导入学生:"sucessnum.ToString() + "@" + lostNum.ToString(); return(oCClassBLL.OCClassStudent_Import(UserNos, OCClassID)); //end检查用户 }
/// <summary> /// 导入习题 /// 每次仅上传一个文件 /// </summary> public static System.Data.DataTable ExerciseUpload() { HttpFileCollection files = HttpContext.Current.Request.Files; if (files.Count == 0) { return(new System.Data.DataTable()); } HttpPostedFile postFile = files[0]; string filehead = Guid.NewGuid().ToString().Replace("-", ""); string Ext = Path.GetExtension(postFile.FileName); string newFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp", filehead + Ext); postFile.SaveAs(newFileName); System.Data.DataTable table = NPOIHandler.ExcelToDataTable(newFileName, "Sheet1", true); return(table); }
public static string ExportAllClassStudent(string teachingClassID, int oCID, bool isHistory) { if (!UserService.OC_IsRole(oCID)) { return(""); } string fileUrl = ""; DataSet ds = new DataSet(); List <ExportOCClassStudent> occlassstudentlist = new List <ExportOCClassStudent>(); OCClassBLL oCClassBLL = new OCClassBLL(); occlassstudentlist = oCClassBLL.ExportAllClassStudent(teachingClassID, oCID, isHistory); foreach (var item in occlassstudentlist) { ds.Tables.Add(IES.Common.ListToDateUtil.ListToDataTable <OCClassStudent>(item.ClassStudent)); } string sheetNames = ""; string headerName = "学号,姓名,专业,行政班,年级"; for (int i = 0; i < ds.Tables.Count; i++) { sheetNames += "政班" + i + ds.Tables[i].Rows[0]["TeachingClassName"] + ","; ds.Tables[i].Columns.Remove("EntryDate"); ds.Tables[i].Columns.Remove("MOOCLearningPace"); } if (!string.IsNullOrEmpty(sheetNames)) { sheetNames = sheetNames.Substring(0, sheetNames.Length - 1); } try { fileUrl = NPOIHandler.ExportDataSetToExcelMVC(ds, "StudentAll.xls", sheetNames, headerName); } catch (Exception e) { fileUrl = ""; } return(fileUrl); }
public static List <OCClassStudent> ImportStudent_List(string fileUrl, int teachingclassid, List <OCClassStudent> occlassstudentlist) { DataTable dt = new DataTable(); dt = NPOIHandler.ExcelToDataTable(fileUrl, "Student"); OCClassBLL oCClassBLL = new OCClassBLL(); List <OCClassStudent> newList = new List <OCClassStudent>(); //newList = IES.Common.ListToDateUtil.ConvertTo<OCClassStudent>(dt); //begin检查用户 string userNo = ""; for (int i = 0; i < dt.Rows.Count; i++) { userNo += dt.Rows[i]["UserNo"].ToString() + ","; } if (userNo != "" && userNo.IndexOf(',') > 0) { userNo = userNo.Substring(0, userNo.Length - 1); } newList = oCClassBLL.CheckUserExice(userNo, teachingclassid); //end检查用户 return(oCClassBLL.SelectSelectedStudent_List(newList, occlassstudentlist)); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; context.Response.AddHeader("Cache-Control", "no-cache,must-revalidate"); //FROM 1 资料 2 附件 var from = context.Request.QueryString["FROM"]; if (from.Equals("2")) { ///习题附件 List <IES.Resource.Model.Attachment> attachMentList = IES.Service.FileService.AttachmentUpload(); context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(attachMentList)); } else if (from.Equals("3")) { try { ///习题验证 ///读取Excel文件内容 HttpFileCollection files = HttpContext.Current.Request.Files; HttpPostedFile postFile = files[0]; string filehead = Guid.NewGuid().ToString().Replace("-", ""); string Ext = Path.GetExtension(postFile.FileName); string newFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp", filehead + Ext); postFile.SaveAs(newFileName); System.Data.DataTable table = NPOIHandler.ExcelToDataTable(newFileName, "Sheet1", true); DataTable resultTable = ImportCheck(table, int.Parse(context.Request.Form["Category"])); var obj = new { fileName = filehead + Ext, data = resultTable }; context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(obj)); } catch (Exception ex) { DataTable resultTable = BuildResultTable(); DataRow newRow = resultTable.NewRow(); newRow["Message"] = "导入文件格式错误!"; newRow["Status"] = "-2"; newRow["RowNumber"] = 1; resultTable.Rows.Add(newRow); var obj = new { fileName = "", data = resultTable }; context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(obj)); } } else if (from.Equals("4")) { ///习题导入 string serverFileName = context.Request.QueryString["fileName"]; int ocid = int.Parse(context.Request.QueryString["OCID"]); int courseId = int.Parse(context.Request.QueryString["CourseID"]); int category = int.Parse(context.Request.QueryString["Category"]); if (string.IsNullOrEmpty(serverFileName)) { context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(new { status = -2 }));; return; } string newFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Temp", serverFileName); System.Data.DataTable table = NPOIHandler.ExcelToDataTable(newFileName, "Sheet1", true); ///导入数据至数据库 DataTable resultTable = ExerciseInfo_Import(table, ocid, courseId, category); context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(new { status = 1, data = resultTable }));; } else { ///资料库文件导入 IES.Resource.Model.File fileModel = new IES.Resource.Model.File(); fileModel.OCID = int.Parse(context.Request.Form["OCID"]); fileModel.CourseID = int.Parse(context.Request.Form["CourseID"]); fileModel.FolderID = int.Parse(context.Request.Form["FolderID"] == "undefined" ? "0" : context.Request.Form["FolderID"]); fileModel.ShareRange = int.Parse(context.Request.Form["ShareRange"]); List <IES.Resource.Model.File> fileList = IES.Service.FileService.ResourceFileUpload(fileModel); context.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(fileList)); } context.Response.End(); }