Exemple #1
0
 /// <summary>
 /// 用于向 Uto_Attachment EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToUto_Attachment(Uto_Attachment uto_Attachment)
 {
     base.AddObject("Uto_Attachment", uto_Attachment);
 }
Exemple #2
0
 /// <summary>
 /// 创建新的 Uto_Attachment 对象。
 /// </summary>
 /// <param name="attachmentId">AttachmentId 属性的初始值。</param>
 /// <param name="type">Type 属性的初始值。</param>
 /// <param name="userId">UserId 属性的初始值。</param>
 /// <param name="url">Url 属性的初始值。</param>
 /// <param name="belongId">BelongId 属性的初始值。</param>
 public static Uto_Attachment CreateUto_Attachment(global::System.Int64 attachmentId, global::System.String type, global::System.Int64 userId, global::System.String url, global::System.Int64 belongId)
 {
     Uto_Attachment uto_Attachment = new Uto_Attachment();
     uto_Attachment.AttachmentId = attachmentId;
     uto_Attachment.Type = type;
     uto_Attachment.UserId = userId;
     uto_Attachment.Url = url;
     uto_Attachment.BelongId = belongId;
     return uto_Attachment;
 }
Exemple #3
0
        /// <summary>
        /// 保存图片
        /// </summary>
        /// <param name="file">文件</param>
        /// <param name="AttachmentType">附件类型</param>
        public static void SavePic(HttpPostedFileBase file, string attachmentType, out string attachmentUrl, out long attachmentId)
        {
            string extenseName = file.FileName.Substring(file.FileName.LastIndexOf('.'));
            if (!CheckExtensionName(extenseName))
            {
                attachmentUrl = "0";
                attachmentId = 0;
                return;
            }

            UtopiaService utopiaService = new UtopiaService();

            Uto_Attachment attachment = new Uto_Attachment();
            attachment.UserId = UserContext.CurrentUser.UserId;
            attachment.BelongId = 0;
            attachment.Type = attachmentType;
            attachment.Url = string.Empty;

            //创建附件记录
            utopiaService.AddAttachment(attachment);

            //每100张图片在一个目录
            long i = 100;
            while (true)
            {
                if (attachment.AttachmentId < i)
                    break;
                else
                    i = i + 100;
            }

            string path = HttpContext.Current.Server.MapPath("~/Content/Attachment/" + attachmentType + "/" + i.ToString() + "/");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            //获取上传图片的宽与高
            System.Drawing.Image img = System.Drawing.Image.FromStream(file.InputStream);
            attachment.Width = img.Width;
            attachment.Height = img.Height;
            //更新附件URL
            attachment.Url = "../../Content/Attachment/" + attachmentType + "/" + i.ToString() + "/" + attachment.AttachmentId.ToString() + extenseName;
            utopiaService.UpdateAttachment(attachment);

            //设置 attachmentUrl attachmentId
            attachmentUrl = attachment.Url;
            attachmentId = attachment.AttachmentId;

            file.SaveAs(path + attachment.AttachmentId.ToString() + extenseName);
        }