Exemplo n.º 1
0
        /// <summary>
        /// 批量复制分项资料库图文档,作为任务书附件(没有历史版本)
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="pageId"></param>
        /// <param name="arrId"></param>
        /// <returns></returns>
        public InvokeResult <List <int> > BatchCopyProjectDoc(int userId, int pageId, int[] arrId, List <string> thumbsImages)
        {
            InvokeResult <List <int> > res = new InvokeResult <List <int> >();
            List <int> retIds = new List <int>();

            try
            {
                using (TransactionScope trans = new TransactionScope())
                {
                    StringBuilder thumbStr = new StringBuilder();

                    //thumbStr.Append("<root>");

                    foreach (int fileId in arrId)
                    {
                        var oldFile = this._ctx.FileLibraries.FirstOrDefault(r => r.fileId == fileId);
                        if (oldFile != null)
                        {
                            #region  制文件信息
                            FileLibrary fileLib = new FileLibrary
                            {
                                createData   = DateTime.Now,
                                createUserId = userId,
                                name         = oldFile.name,
                                ext          = oldFile.ext,
                                sysObjId     = 3,//已定义好的系统对象
                                localPath    = oldFile.localPath,
                                tags         = string.Empty,
                                lastVersion  = 1,
                                size         = oldFile.size,
                                hash         = oldFile.hash
                            };

                            _ctx.FileLibraries.InsertOnSubmit(fileLib);
                            _ctx.SubmitChanges();
                            #endregion

                            #region  制版本信息
                            FileLibVersion version = new FileLibVersion()
                            {
                                fileId       = fileLib.fileId,
                                fileName     = fileLib.name,
                                localPath    = fileLib.localPath,
                                createData   = DateTime.Now,
                                createUserId = fileLib.createUserId,
                                fileVersion  = 1,
                                ext          = fileLib.ext,
                                hash         = fileLib.hash
                            };
                            this._ctx.FileLibVersions.InsertOnSubmit(version);
                            this._ctx.SubmitChanges();
                            #endregion

                            #region 添加关联信息
                            PageFile pageFile = new PageFile()
                            {
                                pageId       = pageId,
                                fileId       = fileLib.fileId,
                                fileType     = 1,
                                bizFileLibId = oldFile.fileId
                            };

                            this._ctx.PageFiles.InsertOnSubmit(pageFile);
                            this._ctx.SubmitChanges();
                            #endregion
                            #region 拷贝文件
                            string appPath     = AppDomain.CurrentDomain.BaseDirectory;
                            string filePath    = CommonBll.GetSysObjDir(oldFile.sysObjId.Value.ToString(), oldFile.sysObjId.Value, oldFile.createData);
                            string oldFileName = CommonBll.GetSysObjDocImg(oldFile.fileId, oldFile.hash, oldFile.lastVersion, "m");

                            string descPath     = CommonBll.GetSysObjDir(fileLib.sysObjId.Value.ToString(), fileLib.sysObjId.Value, fileLib.createData);
                            string descPhyPath  = FileExtension.CreateFolder(string.Format("{0}{1}", appPath, descPath));
                            string descFileName = CommonBll.GetSysObjDocImg(fileLib.fileId, fileLib.hash, fileLib.lastVersion, "m");
                            foreach (var s in thumbsImages)
                            {
                                string sourcePhyFileName = string.Format("{0}{1}{2}", appPath, filePath, oldFileName.Replace("_m.", "_" + s + "."));
                                string descPhyFileName   = string.Format("{0}{1}", descPhyPath, descFileName.Replace("_m.", "_" + s + "."));
                                if (File.Exists(sourcePhyFileName) == true)
                                {
                                    File.Copy(sourcePhyFileName, descPhyFileName);
                                }
                            }
                            #endregion
                            retIds.Add(fileLib.fileId);

                            //thumbStr.AppendFormat("<file hash=\"{0}\" size=\"{1}\" param=\"sysObject@{2}-{3}\"  />", fileLib.hash, fileLib.size, fileLib.fileId, version.verId);
                        }
                    }
                    //thumbStr.Append("</root>");

                    trans.Complete();
                    res.Status  = Status.Successful;
                    res.Message = thumbStr.ToString();
                    res.Value   = retIds;
                }
            }
            catch (Exception ex)
            {
                res.Message = ex.Message;
                res.Status  = Status.Failed;
            }

            return(res);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 批量上传
        /// </summary>
        /// <param name="supplierId"></param>
        /// <param name="filePath"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public InvokeResult <string> BatchUpload(int pageId, List <string> filePath, int userId)
        {
            InvokeResult <string> result = new InvokeResult <string>();

            try
            {
                List <FileParam> fileParams = new List <FileParam>();

                using (TransactionScope trans = new TransactionScope())
                {
                    foreach (var file in filePath)
                    {
                        #region 附件及版本
                        FileLibrary fileLib = new FileLibrary
                        {
                            createData   = DateTime.Now,
                            createUserId = userId,
                            name         = System.IO.Path.GetFileNameWithoutExtension(file),
                            ext          = System.IO.Path.GetExtension(file),
                            sysObjId     = 3,//已定义好的系统对象
                            localPath    = file,
                            tags         = string.Empty,
                            lastVersion  = 1
                        };


                        _ctx.FileLibraries.InsertOnSubmit(fileLib);
                        _ctx.SubmitChanges();
                        FileLibVersion version = new FileLibVersion()
                        {
                            fileId       = fileLib.fileId,
                            fileName     = fileLib.name,
                            localPath    = fileLib.localPath,
                            createData   = DateTime.Now,
                            createUserId = fileLib.createUserId,
                            fileVersion  = 1,
                            ext          = fileLib.ext
                        };
                        this._ctx.FileLibVersions.InsertOnSubmit(version);
                        this._ctx.SubmitChanges();

                        #endregion

                        //添加关联
                        PageFile pageFile = new PageFile()
                        {
                            pageId   = pageId,
                            fileId   = fileLib.fileId,
                            fileType = 1
                        };

                        this._ctx.PageFiles.InsertOnSubmit(pageFile);
                        this._ctx.SubmitChanges();

                        //生成参数
                        FileParam fp = new FileParam();
                        fp.docId       = fileLib.fileId;
                        fp.lastVersion = version.fileVersion;
                        fp.path        = fileLib.localPath;
                        fp.ext         = fileLib.ext;
                        fp.strParam    = "sysObject@" + fileLib.fileId + "-" + version.verId;

                        fileParams.Add(fp);
                    }

                    trans.Complete();

                    System.Web.Script.Serialization.JavaScriptSerializer script = new System.Web.Script.Serialization.JavaScriptSerializer();
                    string strJson = script.Serialize(fileParams);
                    result.Value = strJson;
                }
            }
            catch (Exception ex)
            {
                result.Status  = Status.Failed;
                result.Message = ex.Message;
            }

            return(result);
        }