Beispiel #1
0
        /// <summary>
        /// 资料上传
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static List <IES.Resource.Model.File> ResourceFileUpload(IES.Resource.Model.File model)
        {
            HttpFileCollection             files            = HttpContext.Current.Request.Files;
            List <IES.Resource.Model.File> resourcefilelist = new List <IES.Resource.Model.File>();

            for (int i = 0; i < files.Count; i++)
            {
                IESFile file = Upload(files[i]);
                if (file.FileGuid != null && file.FileGuid != string.Empty)
                {
                    if (RemoteFileExists(file))
                    {
                        FileBLL bll = new FileBLL();
                        file.FileType = file.GetFileType();
                        IES.Resource.Model.File resourcefile = new IES.Resource.Model.File
                        {
                            FileName       = file.FileName,
                            ServerID       = file.ServerID,
                            FileSize       = file.FileSize,
                            FileTitle      = file.FileTitle,
                            OCID           = model.OCID,
                            FolderID       = model.FolderID,
                            CourseID       = model.CourseID,
                            CreateUserID   = UserService.CurrentUser.UserID,
                            CreateUserName = UserService.CurrentUser.UserName,
                            Ext            = file.Ext,
                            FileType       = file.FileType,
                            ShareRange     = model.ShareRange
                        };
                        resourcefile = bll.File_ADD(resourcefile);
                        if (resourcefile.FileID > 0)
                        {
                            resourcefilelist.Add(resourcefile);
                        }
                    }
                }
            }
            return(resourcefilelist);
        }
Beispiel #2
0
        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();
        }