Exemplo n.º 1
0
        public string Add()
        {
            var    userModel = AllServices.UserService.GetUserBySession();
            string strFolder = Request["Folder"].ToStr();
            var    res       = CommonResult.Instance();

            Folder folder = JsonHelper.FromJson <Folder>(strFolder);

            if (folder == null)
            {
                return(CommonResult.ToJsonStr("数据为空"));
            }

            Folder newFolder = new Folder();

            newFolder.FolderName = folder.FolderName;
            newFolder.FatherID   = folder.FatherID;
            newFolder.Creater    = userModel.UserName;
            newFolder.Editor     = userModel.UserName;
            newFolder.CreateTime = DateTime.Now;
            newFolder.EditTime   = DateTime.Now;
            newFolder.Remark     = folder.Remark;
            newFolder.State      = Convert.ToInt32(ItemState.Enable);
            res = (CommonResult)AllServices.FolderService.Add(newFolder);

            if (res.code < 1)
            {
                return(res.ToJson());
            }

            return(res.ToJson());
        }
Exemplo n.º 2
0
        public string Add()
        {
            var    userModel  = AllServices.UserService.GetUserBySession();
            string strProject = Request["Project"].ToStr();
            var    res        = CommonResult.Instance();

            Project project = JsonHelper.FromJson <Project>(strProject);

            if (project == null)
            {
                return(CommonResult.ToJsonStr("数据为空"));
            }

            Project NewProject = new Project();

            NewProject.ProjectNo   = ServiceHelper.GetKeyNum();
            NewProject.ProjectName = project.ProjectName;
            NewProject.Creater     = userModel.UserName;
            NewProject.Editor      = userModel.UserName;
            NewProject.CreateTime  = DateTime.Now;
            NewProject.EditTime    = DateTime.Now;
            NewProject.Remark      = project.Remark;
            NewProject.State       = Convert.ToInt32(ItemState.Enable);
            res = (CommonResult)AllServices.ProjectService.Add(NewProject);

            if (res.code < 1)
            {
                return(res.ToJson());
            }

            return(res.ToJson());
        }
Exemplo n.º 3
0
        public string Delete()
        {        //20 停用
            int intUID = Request["UID"].ToInt32();

            if (intUID == 0)
            {
                return(CommonResult.ToJsonStr("不能为空"));
            }
            var res = AllServices.TaskService.ModifyStatu(intUID, Enums.ItemState.Disable);

            return(res.ToJson());
        }
Exemplo n.º 4
0
        /// <summary>
        /// 合并文件
        /// </summary>
        /// <returns></returns>
        public string MergeFiles()
        {
            string root = Server.MapPath(UploadFiles);

            string guid       = Request["md5"];
            string ext        = Request["ext"];
            string fileName   = Request["fileName"];                         //已包含扩展名
            string sourcePath = Path.Combine(root, "chunk\\" + guid + "\\"); //源数据文件夹
            string targetPath = Path.Combine(root, guid + "_" + fileName);   //合并后的文件

            DirectoryInfo dicInfo = new DirectoryInfo(sourcePath);

            if (Directory.Exists(Path.GetDirectoryName(sourcePath)))
            {
                FileInfo[] files = dicInfo.GetFiles();
                foreach (FileInfo file in files.OrderBy(f => int.Parse(f.Name)))
                {
                    FileStream   addFile   = new FileStream(targetPath, FileMode.Append, FileAccess.Write);
                    BinaryWriter AddWriter = new BinaryWriter(addFile);

                    //获得上传的分片数据流
                    Stream       stream     = file.Open(FileMode.Open);
                    BinaryReader TempReader = new BinaryReader(stream);
                    //将上传的分片追加到临时文件末尾
                    AddWriter.Write(TempReader.ReadBytes((int)stream.Length));
                    //关闭BinaryReader文件阅读器
                    TempReader.Close();
                    stream.Close();
                    AddWriter.Close();
                    addFile.Close();

                    TempReader.Dispose();
                    stream.Dispose();
                    AddWriter.Dispose();
                    addFile.Dispose();
                }
                DeleteFolder(sourcePath);
                //context.Response.Write("{\"chunked\" : true, \"hasError\" : false, \"savePath\" :\"" + System.Web.HttpUtility.UrlEncode(targetPath) + "\"}");
                return(CommonResult.ToJsonStr(0, string.Empty, "{\"chunked\" : true, \"hasError\" : false, \"savePath\" :\"" + System.Web.HttpUtility.UrlEncode(targetPath) + "\"}"));
            }
            else
            {
                //context.Response.Write("{\"hasError\" : true}");
                return(CommonResult.ToJsonStr(0, string.Empty, "{\"hasError\" : true}"));
            }
        }
Exemplo n.º 5
0
        public string Add()
        {
            string strTaskName = Request["TaskName"].ToStr();
            string strRemark   = Request["Remark"].ToStr();

            if (strTaskName.IsNullOrEmpty())
            {
                return(CommonResult.ToJsonStr("不能为空"));
            }
            var res = AllServices.TaskService.Add(new Task()
            {
                TaskName = strTaskName,
                Remark   = strRemark,
                Creater  = string.Empty,
                Editor   = string.Empty,
            });

            return(res.ToJson());
        }
Exemplo n.º 6
0
        /// <summary>
        /// 获取指定文件的已上传的文件块
        /// </summary>
        /// <returns></returns>
        public string GetMaxChunk()
        {
            string root = Server.MapPath(UploadFiles);

            try
            {
                var md5           = Convert.ToString(Request["md5"]);
                var ext           = Convert.ToString(Request["ext"]);
                var fileSorceName = Request["fileName"];//已包含扩展名
                int chunk         = 0;

                var fileName = md5 + "_" + fileSorceName;

                FileInfo file = new FileInfo(root + fileName);
                if (file.Exists)
                {
                    chunk = Int32.MaxValue;
                }
                else
                {
                    if (Directory.Exists(root + "chunk\\" + md5))
                    {
                        DirectoryInfo dicInfo = new DirectoryInfo(root + "chunk\\" + md5);
                        var           files   = dicInfo.GetFiles();
                        chunk = files.Count();
                        if (chunk > 1)
                        {
                            chunk = chunk - 1; //当文件上传中时,页面刷新,上传中断,这时最后一个保存的块的大小可能会有异常,所以这里直接删除最后一个块文件
                        }
                    }
                }

                return(CommonResult.ToJsonStr(0, string.Empty, chunk));
            }
            catch
            {
                return(CommonResult.ToJsonStr(0, string.Empty, 0));
            }
        }
Exemplo n.º 7
0
        public string Update()
        {
            var    userModel   = AllServices.UserService.GetUserBySession();
            int    intUID      = Request["UID"].ToInt();
            string strTaskName = Request["TaskName"].ToStr();
            string strRemark   = Request["Remark"].ToStr();

            if (strTaskName.IsNullOrEmpty())
            {
                return(CommonResult.ToJsonStr("不能为空"));
            }
            var res = AllServices.TaskService.Update(new Task()
            {
                UID      = intUID,
                TaskName = strTaskName,
                Remark   = strRemark,
                Editor   = userModel.UserName,
                EditTime = DateTime.Now
            });

            return(res.ToJson());
        }
Exemplo n.º 8
0
        public string AddList()
        {
            var    userModel   = AllServices.UserService.GetUserBySession();
            string strTaskList = Request["TaskList"].ToStr();
            var    res         = CommonResult.Instance();

            List <TaskList> listTaskList = JsonHelper.FromJsonList <TaskList>(strTaskList);

            if (listTaskList == null)
            {
                return(CommonResult.ToJsonStr("数据为空"));
            }
            foreach (TaskList tasklistModel in listTaskList)
            {
                TaskList tasklist = new TaskList();
                tasklist.TaskListNo        = ServiceHelper.GetRandom();
                tasklist.TaskListName      = tasklistModel.TaskListName;
                tasklist.TaskUID           = tasklistModel.TaskUID;
                tasklist.DocumentUID       = 0;           //tasklistModel.DocumentUID;
                tasklist.PictureSize       = tasklistModel.PictureSize;
                tasklist.PictureResolution = tasklistModel.PictureResolution;
                tasklist.PictureBackground = tasklistModel.PictureBackground;
                tasklist.DocumentType      = tasklistModel.DocumentType;
                tasklist.Creater           = userModel.UserName;
                tasklist.Editor            = userModel.UserName;
                tasklist.CreateTime        = DateTime.Now;
                tasklist.EditTime          = DateTime.Now;
                tasklist.Remark            = tasklistModel.Remark;
                tasklist.State             = Convert.ToInt32(ItemState.Enable);
                tasklist.ProjectId         = 0;        //Convert.ToInt32(ItemState.Enable);
                res = (CommonResult)AllServices.TaskListService.Add(tasklist);
                if (res.code < 1)
                {
                    return(res.ToJson());
                }
            }
            return(res.ToJson());
        }
        /// <summary>
        /// 上传文件
        /// </summary>
        /// <param name="fileData"></param>
        /// <returns></returns>
        public string Upload(HttpPostedFileBase file)
        {
            string s       = Request.Files[0].FileName;
            string root    = Server.MapPath(UploadFiles);
            string md5_key = string.Format("{0}md5", Request["id"]);
            string md5_val = Request[md5_key];

            //如果进行了分片
            if (Request.Form.AllKeys.Any(m => m == "chunk"))
            {
                root = Server.MapPath(temporary);
                //取得chunk和chunks
                int chunk  = Convert.ToInt32(Request.Form["chunk"]);  //当前分片在上传分片中的顺序(从0开始)
                int chunks = Convert.ToInt32(Request.Form["chunks"]); //总分片数
                //根据GUID创建用该GUID命名的临时文件夹
                //string folder = Server.MapPath("~/UploadFiles/" + Request["md5"] + "/");
                string folder = root + "chunk\\" + md5_val + "\\";
                string path   = folder + chunk;

                //建立临时传输文件夹
                if (!Directory.Exists(Path.GetDirectoryName(folder)))
                {
                    Directory.CreateDirectory(folder);
                }

                FileStream   addFile    = null;
                BinaryWriter AddWriter  = null;
                Stream       stream     = null;
                BinaryReader TempReader = null;

                try
                {
                    //addFile = new FileStream(path, FileMode.Append, FileAccess.Write);
                    addFile   = new FileStream(path, FileMode.Create, FileAccess.Write);
                    AddWriter = new BinaryWriter(addFile);
                    //获得上传的分片数据流
                    stream     = file.InputStream;
                    TempReader = new BinaryReader(stream);
                    //将上传的分片追加到临时文件末尾
                    AddWriter.Write(TempReader.ReadBytes((int)stream.Length));
                }
                finally
                {
                    if (addFile != null)
                    {
                        addFile.Close();
                        addFile.Dispose();
                    }
                    if (AddWriter != null)
                    {
                        AddWriter.Close();
                        AddWriter.Dispose();
                    }
                    if (stream != null)
                    {
                        stream.Close();
                        stream.Dispose();
                    }
                    if (TempReader != null)
                    {
                        TempReader.Close();
                        TempReader.Dispose();
                    }
                }
                return(CommonResult.ToJsonStr(0, string.Empty, "{\"chunked\" : true, \"ext\" : \"" + Path.GetExtension(file.FileName) + "\"}"));
            }
            else//没有分片直接保存
            {
                //根据md5加密后的文件名保存
                string path = root + md5_val + Path.GetExtension(Request.Files[0].FileName);
                //根据上传的文件名保存
                //string path = root + Request.Files[0].FileName;
                file.SaveAs(path);
                return(CommonResult.ToJsonStr(0, string.Empty, "{\"chunked\" : false}"));
            }
        }
Exemplo n.º 10
0
 public string AddUploadRecord()
 {
     //...
     return(CommonResult.ToJsonStr());
 }