コード例 #1
0
        /// <summary>
        /// 编辑树的节点
        /// </summary>
        /// <param name="condtion"></param>
        /// <returns></returns>
        public BaseTree EditBaseTree(BaseTreeAttr condtion)
        {
            ValiDatas.valiData(condtion);
            var r = CheckCode(condtion.Code, this.id);

            if (r > 0)
            {
                throw new ValiDataException(string.Format("code [{0}] 已存在,保存失败", condtion.Code));
            }

            using (var db = new DefaultContainer()) {
                var row = db.Db_BaseTreeSet.Single(p => p.Id == this.id);
                row.Code     = condtion.Code;
                row.Name     = condtion.text;
                row.ParentId = string.IsNullOrEmpty(condtion.ParentId) ? null : condtion.ParentId;
                row.Seq      = condtion.Seq;
                db.SaveChanges();
                return(BaseTree.GetBaseTreeById(this.id));
            }
        }
コード例 #2
0
        /// <summary>
        /// 获取缩略图
        /// </summary>
        /// <param name="path">目标文件的存放路径</param>
        /// <param name="condtion"></param>
        /// <returns></returns>
        public static string GetImgFileThumbnailPath(string path, GetImgFileThumbnailRequest condtion)
        {
            ValiDatas.valiData(condtion);
            int    width    = condtion.Width;
            int    height   = condtion.Height;
            string imgUrl   = path;
            string fileName = HttpContext.Current.Server.MapPath(imgUrl);

            if (!File.Exists(fileName))
            {
                throw new DataNotFundException("指定的文件不存在");
            }
            string fileExt = System.IO.Path.GetExtension(fileName).ToLower();

            string[] imgTypes = { ".gif", ".jpg", ".jpeg", ".png", ".bmp" };
            if (!imgTypes.Contains(fileExt))
            {
                throw new ValiDataException("只有图片文件才能生成缩略图");
            }
            if (imgUrl.IndexOf("thumbnail", StringComparison.OrdinalIgnoreCase) != -1)
            {
                throw new ValiDataException("传入的文件已经是缩略图地址了,不能再生成缩略图");
            }

            string imgDir  = string.Format("{0}/thumbnail/{1}_{2}", imgUrl.Substring(0, imgUrl.LastIndexOf('.')), width, height);
            string imgFile = string.Format("{0}/{1}", imgDir, imgUrl.Substring(imgUrl.LastIndexOf("/", StringComparison.OrdinalIgnoreCase)));

            //判断目录是否存在
            if (!Directory.Exists(HttpContext.Current.Server.MapPath(imgDir)))
            {
                Directory.CreateDirectory(HttpContext.Current.Server.MapPath(imgDir));
            }
            //创建缩略图
            if (!File.Exists(HttpContext.Current.Server.MapPath(imgFile)))
            {
                MakeThumbnail(fileName, HttpContext.Current.Server.MapPath(imgFile), width, height);
            }
            return(imgFile);
        }
コード例 #3
0
        /// <summary>
        /// 新增树的节点
        /// </summary>
        /// <param name="condtion"></param>
        /// <returns></returns>
        public static BaseTree CreateBaseTree(BaseTreeAttr condtion)
        {
            ValiDatas.valiData(condtion);
            var r = CheckCode(condtion.Code);

            if (r > 0)
            {
                throw new ValiDataException(string.Format("code [{0}] 已存在,新增失败", condtion.Code));
            }
            using (var db = new DefaultContainer()) {
                Db_BaseTree dbTree = new Db_BaseTree()
                {
                    Id        = Guid.NewGuid().ToString(),
                    Code      = condtion.Code,
                    CreatedOn = DateTime.Now,
                    Name      = condtion.text,
                    ParentId  = string.IsNullOrEmpty(condtion.ParentId)? null :condtion.ParentId,
                    Seq       = condtion.Seq
                };
                db.Db_BaseTreeSet.Add(dbTree);
                db.SaveChanges();
                return(new BaseTree(dbTree));
            }
        }