Пример #1
0
 public int Remove(DMSFileSeries dmsFileSeries)
 {
     dmsFileSeries.RecordStatus       = RecordStatus.Deleted;
     dmsFileSeries.LastModifyTime     = DateTime.Now;
     dmsFileSeries.LastModifyUserName = UserInfo.UserName;
     return(m_db.Update(m_defaultTableName, m_defaultPrimaryKey, dmsFileSeries.GetTableObject()));
 }
Пример #2
0
 public DMSFileSeries Update(DMSFileSeries dmsFileSeries)
 {
     dmsFileSeries.LastModifyTime     = DateTime.Now;
     dmsFileSeries.LastModifyUserName = UserInfo.UserName;
     m_db.Update(m_defaultTableName, m_defaultPrimaryKey, dmsFileSeries.GetTableObject());
     return(dmsFileSeries);
 }
Пример #3
0
 public DMSFileSeries Create(DMSFileSeries dmsFileSeries)
 {
     dmsFileSeries.Guid         = System.Guid.NewGuid().ToString();
     dmsFileSeries.RecordStatus = RecordStatus.Valid;
     dmsFileSeries.Id           = Insert(dmsFileSeries.GetTableObject());
     return(dmsFileSeries);
 }
Пример #4
0
        private DMSFileSeries NewFileSeries(string fileSeriesName, DMSFolderLogicModel folder)
        {
            var now           = DateTime.Now;
            var dmsFileSeries = new DMSFileSeries();

            dmsFileSeries.DMSId              = folder.Instance.DMSId;
            dmsFileSeries.DMSFolderId        = folder.Instance.Id;
            dmsFileSeries.Name               = fileSeriesName;
            dmsFileSeries.LastModifyUserName = CurrentUserName;
            dmsFileSeries.LastModifyTime     = now;
            dmsFileSeries.CreateUserName     = CurrentUserName;
            dmsFileSeries.CreateTime         = now;
            return(m_dbAdapter.DMSFileSeries.Create(dmsFileSeries));
        }
Пример #5
0
        public ActionResult CreateFile(string projectGuid, string folderGuid, string fileSeriesNames,
                                       string description, string templateType)
        {
            return(ActionUtils.Json(() =>
            {
                var dms = GetDMSAndCheckPermission(projectGuid, PermissionType.Execute);
                var folder = dms.FindFolder(folderGuid);
                CommUtils.AssertNotNull(folder, "找不到文件夹[FolderGuid={0} DMSGuid={1}],请刷新后再试",
                                        folderGuid, dms.Instance.Guid);
                folder.IgnoreNull = false;

                var dict = new Dictionary <RepositoryFile, HttpPostedFileBase>();

                var fileSeriesNameList = CommUtils.Split(fileSeriesNames).ToList();

                var files = Request.Files;
                //  CommUtils.Assert(Request.Files.Count > 0, "请选择上传文件");
                fileSeriesNameList.ForEach(x =>
                {
                    ValidateUtils.FileName(x, "文档名称");
                    CommUtils.Assert(x.Length <= 100, "文档名称[{0}]不能超过100个字符数", x);
                    CommUtils.Assert(!folder.Files.Any(y => y.FileSeries.Name == x),
                                     "文件[{0}]已经存在", x);
                });
                CommUtils.AssertHasContent(fileSeriesNames, "文档名称不能为空");
                //  CommUtils.AssertEquals(fileSeriesNames.Count, files.Count, "上传文件数和fileSeriesNames数不一致");

                var fileGuids = new List <string>();
                for (int i = 0; i < files.Count; i++)
                {
                    var file = files[i];

                    var index = Math.Max(file.FileName.LastIndexOf('\\'), file.FileName.LastIndexOf('/'));
                    var fileName = index < 0 ? file.FileName : file.FileName.Substring(index + 1);

                    CommUtils.AssertHasContent(fileName, "文件名不能为空");
                    CommUtils.Assert(fileName.Length <= 100, "选择的文件名称[{0}]不能超过100个字符数", fileName);
                    CommUtils.Assert(!folder.Files.Any(x => x.FileSeries.Name == fileSeriesNameList[i]),
                                     "文件[{0}]已经存在", fileSeriesNameList[i]);

                    var memoryStream = new MemoryStream(new BinaryReader(file.InputStream).ReadBytes(file.ContentLength));
                    var newFile = Platform.Repository.AddFile(fileName, memoryStream);
                    fileGuids.Add(newFile.Guid);

                    dict[newFile] = file;
                }

                var result = new List <DMSFile>();
                string operationType = "上传";
                string fileSeriesGuid = "";

                if (dict.Keys.Count == 0)
                {
                    var isExistTemplateType = string.IsNullOrWhiteSpace(templateType);
                    var dmsFileSeriesTemplateType = DmsFileSeriesTemplateType.None;
                    if (!isExistTemplateType)
                    {
                        dmsFileSeriesTemplateType = CommUtils.ParseEnum <DmsFileSeriesTemplateType>(templateType);
                    }

                    operationType = "创建";
                    fileSeriesNameList.ForEach(x =>
                    {
                        var newFileSeries = NewFileSeries(x, folder);
                        fileSeriesGuid = newFileSeries.Guid;

                        m_dbAdapter.DMSProjectLog.AddDmsProjectLog(projectGuid, fileSeriesGuid, "文件夹[" + folder.Instance.Name + "]中" + operationType + "文件系列" + x);
                        if (!isExistTemplateType && dmsFileSeriesTemplateType != DmsFileSeriesTemplateType.None)
                        {
                            NewDMSFileSeriesTemplate(newFileSeries.Id, dmsFileSeriesTemplateType);
                        }
                    });
                }

                for (int i = 0; i < dict.Keys.Count; i++)
                {
                    var repoFile = dict.Keys.ElementAt(i);
                    var fileSeriesName = fileSeriesNameList[i];
                    var dmsFileSeries = new DMSFileSeries();
                    dmsFileSeries = NewFileSeries(fileSeriesName, folder);
                    fileSeriesGuid = dmsFileSeries.Guid;

                    var now = DateTime.Now;
                    DMSFile dmsFile = new DMSFile();
                    dmsFile.DMSId = dms.Instance.Id;
                    dmsFile.DMSFileSeriesId = dmsFileSeries.Id;

                    dmsFile.RepoFileId = repoFile.Id;
                    dmsFile.Name = repoFile.Name;
                    dmsFile.Description = description ?? string.Empty;

                    dmsFile.Size = dict[repoFile].ContentLength;
                    dmsFile.Version = 1;

                    dmsFile.LastModifyUserName = CurrentUserName;
                    dmsFile.LastModifyTime = now;
                    dmsFile.CreateUserName = CurrentUserName;
                    dmsFile.CreateTime = now;

                    result.Add(m_dbAdapter.DMSFile.Create(dmsFile));

                    m_dbAdapter.DMSProjectLog.AddDmsProjectLog(projectGuid, dmsFileSeries.Guid, "文件夹[" + folder.Instance.Name + "]中" + operationType + "文件" + fileSeriesName);
                }
                return ActionUtils.Success(fileSeriesGuid);
            }));
        }
Пример #6
0
        public ActionResult CreateFile(string shortCode, string folderGuid, List <string> fileSeriesNames, string description)
        {
            return(ActionUtils.Json(() =>
            {
                var dms = GetDMSAndCheckPermission(shortCode, PermissionType.Execute);
                var folder = dms.FindFolder(folderGuid);
                CommUtils.AssertNotNull(folder, "找不到文件夹[FolderGuid={0} DMSGuid={1}],请刷新后再试",
                                        folderGuid, dms.Instance.Guid);

                ValidateUtils.Name(fileSeriesNames, "文档名称", 100).FileName();

                var dict = new Dictionary <RepositoryFile, HttpPostedFileBase>();
                var files = Request.Files;
                var fileGuids = new List <string>();
                for (int i = 0; i < files.Count; i++)
                {
                    var file = files[i];

                    var index = Math.Max(file.FileName.LastIndexOf('\\'), file.FileName.LastIndexOf('/'));
                    var fileName = index < 0 ? file.FileName : file.FileName.Substring(index + 1);

                    CommUtils.AssertHasContent(fileName, "文件名不能为空");
                    CommUtils.Assert(fileName.Length <= 100, "选择的文件名称[{0}]不能超过100个字符数", fileName);
                    CommUtils.Assert(!folder.Files.Any(x => x.FileSeries.Name == fileSeriesNames[i]),
                                     "文件[{0}]已经存在", fileSeriesNames[i]);

                    var memoryStream = new MemoryStream(new BinaryReader(file.InputStream).ReadBytes(file.ContentLength));
                    var newFile = Platform.Repository.AddFile(fileName, memoryStream);
                    fileGuids.Add(newFile.Guid);

                    dict[newFile] = file;
                }

                var result = new List <DMSFile>();
                string operationType = "上传";

                if (dict.Keys.Count == 0)
                {
                    operationType = "创建";
                    fileSeriesNames.ForEach(x =>
                    {
                        NewFileSeries(x, folder);
                    });
                }


                for (int i = 0; i < dict.Keys.Count; i++)
                {
                    var repoFile = dict.Keys.ElementAt(i);
                    var fileSeriesName = fileSeriesNames[i];
                    var dmsFileSeries = new DMSFileSeries();
                    dmsFileSeries = NewFileSeries(fileSeriesName, folder);

                    var now = DateTime.Now;
                    DMSFile dmsFile = new DMSFile();
                    dmsFile.DMSId = dms.Instance.Id;
                    dmsFile.DMSFileSeriesId = dmsFileSeries.Id;

                    dmsFile.RepoFileId = repoFile.Id;
                    dmsFile.Name = repoFile.Name;
                    dmsFile.Description = description ?? string.Empty;

                    dmsFile.Size = dict[repoFile].ContentLength;
                    dmsFile.Version = 1;

                    dmsFile.LastModifyUserName = CurrentUserName;
                    dmsFile.LastModifyTime = now;
                    dmsFile.CreateUserName = CurrentUserName;
                    dmsFile.CreateTime = now;

                    result.Add(m_dbAdapter.DMSFile.Create(dmsFile));
                }

                var task = new TaskLogicModel(dms.ProjectLogicModel, shortCode);
                task.Start();

                var fileSeriesNamesArray = fileSeriesNames.ConvertAll(x => "[" + x + "]").ToArray();
                m_dbAdapter.Task.AddTaskLog(task.Instance, "文件夹[" + folder.Instance.Name + "]中" + operationType + "文件" + string.Join(",", fileSeriesNamesArray));

                return ActionUtils.Success(result.Select(x => x.Guid));
            }));
        }