Example #1
0
 /// <summary>
 /// 构造方法 (从数据库)
 /// </summary>
 /// <param name="row"></param>
 public BaseFile(Db_BaseFile row)
 {
     this.Id              = row.Id;
     this.Path            = row.Path;
     this.FileName        = row.FileName;
     this.ExName          = row.ExName;
     this.CreatedOn       = row.CreatedOn;
     this.CreatedOnString = this.CreatedOn.ToString("yyyy-MM-dd HH:mm");
 }
Example #2
0
 /// <summary>
 /// 使用数据库的行构造
 /// </summary>
 /// <param name="row"></param>
 /// <param name="file"></param>
 public BaseDocImgFile(Db_BaseDocFile row, Db_BaseFile file)
 {
     this.Id        = row.Id;
     this.FileId    = row.FileId;
     this.DocId     = row.Db_BaseDocId;
     this.FilePath  = file.Path;
     this.Caption   = row.Caption;
     this.Seq       = row.Seq;
     this.Descript  = row.Descript;
     this.CreatedOn = row.CreatedOn;
 }
Example #3
0
        /// <summary>
        /// 创建基本文件信息
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static BaseFile CreateBaseFile(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ValiDataException("文件的存放路径不能为空,path is null");
            }

            string fileName;
            int    x = path.LastIndexOf("/");

            if (x > 0)
            {
                fileName = path.Substring(x + 1);
            }
            else
            {
                fileName = path;
            }
            if (string.IsNullOrEmpty(fileName))
            {
                throw new ValiDataException(string.Format("路径:{0},格式不正确", path));
            }
            string exName = string.Empty;

            x = fileName.LastIndexOf(".");
            if (x > 0)
            {
                exName = fileName.Substring(x);
            }

            Db_BaseFile dbFile = new Db_BaseFile()
            {
                Id        = Guid.NewGuid().ToString(),
                CreatedOn = DateTime.Now,
                Path      = path,
                FileName  = fileName,
                ExName    = string.IsNullOrEmpty(exName) ? null : exName
            };

            using (var db = new DefaultContainer()) {
                db.Db_BaseFileSet.Add(dbFile);
                db.SaveChanges();
            }
            return(new BaseFile(dbFile));
        }