/// <summary> /// DataTable转换为list /// </summary> /// <param name="dt"></param> /// <returns></returns> protected static List <ImageAlbum> DataTableToList(DataTable dt) { List <ImageAlbum> Ms = new List <ImageAlbum>(); for (int i = 0; i < dt.Rows.Count; i++) { ImageAlbum M = new ImageAlbum(); M.ID = dt.Rows[i]["ID"].ToInt32(); M.ClassID = dt.Rows[i]["ClassID"].ToInt32(); M.ZtID = dt.Rows[i]["ZtID"].ToInt32(); M.AuthorID = dt.Rows[i]["AuthorID"].ToInt32(); M.Author = dt.Rows[i]["Author"].ToString(); M.Title = dt.Rows[i]["Title"].ToString(); M.CreateTime = dt.Rows[i]["CreateTime"].ToDateTime(); M.UpdateTime = dt.Rows[i]["UpdateTime"].ToDateTime(); M.Intro = dt.Rows[i]["Intro"].ToString(); M.Size = dt.Rows[i]["Size"].ToInt32(); M.Folder = dt.Rows[i]["Folder"].ToString(); M.ClickCount = dt.Rows[i]["ClickCount"].ToInt32(); M.ReplyCount = dt.Rows[i]["ReplyCount"].ToInt32(); M.SetTop = dt.Rows[i]["SetTop"].ToBoolean(); M.ShotCut = dt.Rows[i]["ShotCut"].ToString(); M.KeyWords = dt.Rows[i]["KeyWords"].ToString(); Ms.Add(M); } return(Ms); }
/// <summary> /// 根据条件语句取得第一个实体 /// </summary> /// <param name="m_where">条件语句,不包含“where”</param> /// <returns></returns> public static ImageAlbum Find(string m_where) { IDbHelper Sql = GetHelper(); ImageAlbum M = new ImageAlbum(); DbDataReader Rs = Sql.ExecuteReader(CommandType.Text, "select [ID],[ClassID],[ZtID],[AuthorID],[Author],[Title],[CreateTime],[UpdateTime],[Intro],[Size],[Folder],[ClickCount],[ReplyCount],[SetTop],[ShotCut],[KeyWords] from [ImageAlbum] where " + m_where, true); if (!Rs.Read()) { M.ID = 0; } else { M.ID = Rs["ID"].ToInt32(); M.ClassID = Rs["ClassID"].ToInt32(); M.ZtID = Rs["ZtID"].ToInt32(); M.AuthorID = Rs["AuthorID"].ToInt32(); M.Author = Rs["Author"].ToString(); M.Title = Rs["Title"].ToString(); M.CreateTime = Rs["CreateTime"].ToDateTime(); M.UpdateTime = Rs["UpdateTime"].ToDateTime(); M.Intro = Rs["Intro"].ToString(); M.Size = Rs["Size"].ToInt32(); M.Folder = Rs["Folder"].ToString(); M.ClickCount = Rs["ClickCount"].ToInt32(); M.ReplyCount = Rs["ReplyCount"].ToInt32(); M.SetTop = Rs["SetTop"].ToBoolean(); M.ShotCut = Rs["ShotCut"].ToString(); M.KeyWords = Rs["KeyWords"].ToString(); } Rs.Close(); Rs = null; return(M); }
/// <summary> /// 获取图片内容页面地址 /// </summary> /// <param name="img"></param> /// <param name="cls"></param> /// <returns></returns> public string GetImageUrl(ImageAlbum img, Class cls) { string result = ""; string fileName = img.ID.ToString(); string sitrurl = "/"; string parentForder = cls.ClassForder; if (!parentForder.IsNullOrEmpty()) { parentForder += "/"; } string newsFolder = img.Folder; if (newsFolder.IsNullOrEmpty()) { newsFolder = "/"; } result = string.Format("{0}{1}{2}/{3}/{4}{5}", sitrurl, cls.ParentClassForder.IsNullOrEmpty() ? "" : cls.ParentClassForder + "/", cls.ClassForder, newsFolder, fileName, BasePage.SystemSetting.ExtName ); result = Regex.Replace(result, "[/]{2,}", "/"); return(result); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate(Resource.Layout.BrowseFragment, null); ((AppCompatActivity)Activity).SupportActionBar.SetTitle(Resource.String.frag3Title); var ignored = base.OnCreateView(inflater, container, savedInstanceState); //make a new imageAlbum imageAlbum = new ImageAlbum(); targetAreas = db.getCategories(); //setup recyclerview and adapters browseRecyclerView = view.FindViewById <RecyclerView>(Resource.Id.recyclerView); //browseLayoutManager = new LinearLayoutManager(Activity); browseLayoutManager = new GridLayoutManager(Activity, 2); browseRecyclerView.SetLayoutManager(browseLayoutManager); imageAdapter = new ImageAlbumAdapter(targetAreas, Activity); imageAdapter.ItemClick += OnItemClick; browseRecyclerView.SetAdapter(imageAdapter); return(view); }
public void DeleteRecord(int imageID, int albumID) { ImageAlbum imageAlbum = (from record in socialNet.ImageAlbum where record.IDAlbum == albumID && record.IDImage == imageID select record).First(); socialNet.ImageAlbum.Remove(imageAlbum); socialNet.SaveChanges(); }
/// <summary> /// 生成内容页--图片 /// </summary> /// <param name="album"></param> /// <param name="cls"></param> public static void CreateContentPage(ImageAlbum album, Class cls) { TemplateHelper h = new TemplateHelper(); string FileName = BasePage.GetImageUrl(album, cls); Voodoo.IO.File.Write(System.Web.HttpContext.Current.Server.MapPath("~" + FileName), h.CreateContentPage(album, cls)); ping(BasePage.SystemSetting.SiteUrl.TrimEnd('/') + FileName); CreatePagesByCrateWith(3); }
public void AddRecord(int imageID, int albumID) { ImageAlbum imageAlbum = new ImageAlbum { IDAlbum = albumID, IDImage = imageID }; socialNet.ImageAlbum.Add(imageAlbum); socialNet.SaveChanges(); }
public IHttpActionResult CreateNewImageAlbum([FromBody] ImageAlbumCreateBindingModel model) { if (model == null) { return(this.BadRequest("No data.")); } if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } var user = this.Data.Users.Find(this.User.Identity.GetUserId()); var imageAlbum = new ImageAlbum() { Title = model.Title, CreatedById = user.Id, DateCreated = DateTime.Now }; if (this.Data.ImageAlbums.All().Any(a => a.CreatedById == user.Id && a.Title == imageAlbum.Title)) { return(this.BadRequest(string.Format("A image album with the specified title already exists."))); } this.Data.ImageAlbums.Add(imageAlbum); this.Data.SaveChanges(); var userFollowers = user.FollowedBy.Select(u => u.Id); foreach (var userId in userFollowers) { var notification = new Notification() { ImageAlbumId = imageAlbum.Id, RecipientId = userId, NotificationType = NotificationType.CreatedImageAlbum, DateCreated = DateTime.Now, Message = user.UserName + " created image album " + imageAlbum.Title + "." }; this.Data.Notifications.Add(notification); } this.Data.SaveChanges(); var returnItem = Mapper.Map <ImageAlbumViewModel>(imageAlbum); returnItem.IsMine = true; return(this.Ok(returnItem)); }
public ActionResult Create(ProductSizeVm product) { int checkProduct = db.Products.Where(p => p.ProductName.Trim() == product.ProductName.Trim()).Count(); if (checkProduct > 0) { ModelState.AddModelError("", "Product Already Exists!"); } else { if (product.ImageUpload != null) { string filename = Path.GetFileNameWithoutExtension(product.ImageUpload.FileName); string extension = Path.GetExtension(product.ImageUpload.FileName); filename = filename + "_" + DateTime.Now.ToString("yymmssfff") + extension; Product p = new Product(); p.ProductName = product.ProductName; p.Unit = product.Unit; p.Price = product.Price; p.OtherPrice = product.OtherPrice; p.Discount = product.Discount; p.Vat = product.Vat; p.BrandID = product.BrandID; p.SubCategoryID = product.SubCategoryID; p.IsDeleted = false; db.Products.Add(p); db.SaveChanges(); int lasProductId = p.ProductID; ImageAlbum im = new ImageAlbum(); im.ProductID = lasProductId; im.ImageUrl = filename; db.ImageAlbums.Add(im); db.SaveChanges(); for (var i = 0; i < product.SizeID.Count(); i++) { ProductSizeHeader psh = new ProductSizeHeader(); psh.ProductID = lasProductId; psh.SizeID = product.SizeID[i]; db.ProductSizeHeaders.Add(psh); db.SaveChanges(); } product.ImageUpload.SaveAs(Path.Combine(Server.MapPath("~/App_File/ProductImage"), filename)); return(RedirectToAction("Index")); } } ViewBag.SubCategoryID = new SelectList(db.SubCategories, "SubCategoryID", "SubCategoryName", product.SubCategoryID); return(View(product)); }
/// <summary> /// 获取下一个相册 /// </summary> /// <param name="img"></param> /// <param name="cls"></param> /// <returns></returns> public static ImageAlbum GetNextImages(ImageAlbum img, Class cls) { List <ImageAlbum> lresult = ImageAlbumView.GetModelList(string.Format("classID={0} and ID>{1} order by ID Asc", cls.ID, img.ID), 1); if (lresult.Count == 0) { return(null); } else { return(lresult.First()); } }
public void Update(ImageAlbum obj, out OperationResult operationResult) { lock (Lock) { if (obj == null) { operationResult = new OperationResult { Type = OperationResult.ResultType.Warning }; return; } Common.Instance.Update (obj, objs => objs.ImageAlbumId == obj.ImageAlbumId && objs.LanguageId == obj.LanguageId, out operationResult); } }
/// <summary> /// 获取下一个相册 /// </summary> /// <param name="img"></param> /// <param name="cls"></param> /// <returns></returns> public static ImageAlbum GetNextImages(ImageAlbum img, Class cls) { using (DataEntities ent = new DataEntities()) { List <ImageAlbum> lresult = //ImageAlbumView.GetModelList(string.Format("classID={0} and ID>{1} order by ID Asc", cls.ID, img.ID), 1); (from l in ent.ImageAlbum where l.ClassID == cls.ID && l.ID > img.ID orderby l.ID select l).ToList(); if (lresult.Count == 0) { return(null); } else { return(lresult.First()); } } }
public void Insert(ImageAlbum obj, out OperationResult operationResult) { lock (Lock) { if (obj == null) { operationResult = new OperationResult { Type = OperationResult.ResultType.Warning }; } else { Common.Instance.Insert(obj, out operationResult); } } }
/// <summary> /// 加载信息 /// </summary> protected void LoadInfo() { using (DataEntities ent = new DataEntities()) { ddl_Class.DataSource = ClassAction.Classes.Where(p => p.IsLeafClass == true && p.ModelID == 2); ddl_Class.DataTextField = "ClassName"; ddl_Class.DataValueField = "ID"; ddl_Class.DataBind(); ddl_Class.SelectedValue = cls.ToS(); ddl_Author.DataSource = from l in ent.SysUser select l; ddl_Author.DataTextField = "UserName"; ddl_Author.DataValueField = "ID"; ddl_Author.DataBind(); var images = (from l in ent.ImageAlbum where l.ID == id select l).ToList(); ImageAlbum imga = new ImageAlbum(); if (images.Count > 0) { imga = images.FirstOrDefault(); } if (images.Count > 0) { ddl_Class.SelectedValue = imga.ClassID.ToS(); txt_Title.Text = imga.Title; ddl_Author.Text = imga.AuthorID.ToS(); txt_Keyword.Text = imga.KeyWords; txt_ClickCount.Text = imga.ClickCount.ToS(); txt_ReplyCount.Text = imga.ClickCount.ToS(); txt_Intro.Text = imga.Intro; rp_list.DataSource = from l in ent.Images where l.AlbumID == id select l; rp_list.DataBind(); } else { //ImageAlbumView.Del("AuthorID=0 and CreateTime<'" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + "'"); //imga = new ImageAlbum() { ClassID = cls, ClickCount = 0, ReplyCount = 0, ZtID = 0, CreateTime = DateTime.Now, AuthorID = 0, UpdateTime = DateTime.Now }; //ImageAlbumView.Insert(imga); Response.Redirect(string.Format("ImageEdit.aspx?class={0}&id={1}", cls, imga.ID)); } } }
/// <summary> /// 加载信息 /// </summary> protected void LoadInfo() { ddl_Class.DataSource = NewsAction.NewsClass.Where(p => p.IsLeafClass && p.ModelID == 2); ddl_Class.DataTextField = "ClassName"; ddl_Class.DataValueField = "ID"; ddl_Class.DataBind(); ddl_Class.SelectedValue = cls.ToS(); ddl_Author.DataSource = SysUserView.GetModelList(); ddl_Author.DataTextField = "UserName"; ddl_Author.DataValueField = "ID"; ddl_Author.DataBind(); ImageAlbum imga = ImageAlbumView.GetModelByID(id.ToS()); //txt_Title.Text = imga.Title; //ddl_Author.SelectedValue = imga.AuthorID.ToS(); //txt_Folder.Text = imga.Folder; //txt_Keyword.Text=imga. if (id > 0) { ddl_Class.SelectedValue = imga.ClassID.ToS(); txt_Title.Text = imga.Title; ddl_Author.Text = imga.AuthorID.ToS(); //txt_Folder.Text = imga.Folder; txt_Keyword.Text = imga.KeyWords; txt_ClickCount.Text = imga.ClickCount.ToS(); txt_ReplyCount.Text = imga.ClickCount.ToS(); txt_Intro.Text = imga.Intro; rp_list.DataSource = ImagesView.GetModelList(string.Format("AlbumID={0} order by id", imga.ID)); rp_list.DataBind(); } else { ImageAlbumView.Del("AuthorID=0 and CreateTime<'" + DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd") + "'"); imga = new ImageAlbum() { ClassID = cls, ClickCount = 0, ReplyCount = 0, ZtID = 0, CreateTime = DateTime.Now, AuthorID = 0, UpdateTime = DateTime.Now }; ImageAlbumView.Insert(imga); Response.Redirect(string.Format("ImageEdit.aspx?class={0}&id={1}", cls, imga.ID)); } }
/// <summary> /// Adds the images. /// </summary> /// <param name="albumImage">images of album.</param> /// <returns>images identity</returns> public bool Add_Images(ImageAlbum albumImage) { using (var data = new Entities()) { bool rt; try { data.ImageAlbums.Add(albumImage); data.SaveChanges(); rt = true; } catch (Exception) { rt = false; } return(rt); } }
public IActionResult SaveEntity(ImageAlbum imageAlbum) { if (!ModelState.IsValid) { IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors); return(new BadRequestObjectResult(allErrors)); } else { if (imageAlbum.Id == 0) { _imageAlbumService.Add(imageAlbum); } else { _imageAlbumService.Update(imageAlbum); } _imageAlbumService.Save(); return(new OkObjectResult(imageAlbum)); } }
public ActionResult List_album_images(int?parent, int?id, string type, string act, string ctrl, string type_act, string lang, string search, int?page, int?page_size, string order_by, string order_type) { CatalogModels cateModels = new CatalogModels(); GalleryModels galleryModels = new GalleryModels(); C_Catalog cate = new C_Catalog(); ImageAlbum img = new ImageAlbum(); StringBuilder sb = new StringBuilder(); List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var list_album_images_view = new Web.Areas.Admin.ViewModels.List_album_images_view(); int total_record = 0; int level = 0; /////type is get type catalog /////ex : LB - Lookbook ///// : GL - Gallery /////parent is array parent id if (string.IsNullOrEmpty(type)) { type = Request.QueryString["type"] != null ? Request.QueryString["type"].ToString() : CommonGlobal.CateLookBook; } if (string.IsNullOrEmpty(act)) { act = Request.QueryString["act"] != null ? Request.QueryString["act"].ToString() : "list_album_images"; } if (string.IsNullOrEmpty(ctrl)) { ctrl = Request.QueryString["ctrl"] != null ? Request.QueryString["ctrl"].ToString() : "adminLink"; } if (page == null || page == 0) { page = Request.QueryString["page"] != null?Convert.ToInt32(Request.QueryString["page"].ToString()) : 1; } if (page_size == null) { page_size = int.Parse(Util.GetConfigValue("NumberPageSizeAdmin", "30")); } if (parent == null) { parent = Request.QueryString["parent"] != null?Convert.ToInt32(Request.QueryString["parent"].ToString()) : 0; } if (string.IsNullOrEmpty(lang)) { lang = LanguageModels.ActiveLanguage().LangCultureName; } if (id != null && type_act != null && type_act == CommonGlobal.Delete) { ////check permission delete if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, act, ctrl, type_act, type)) { img = galleryModels.GetImageById((int)id); if (img != null) { ////delete old image if (!string.IsNullOrEmpty(img.Images)) { string strImg = img.Images; strImg = "~" + strImg; string fileDelete = Server.MapPath(strImg); if (System.IO.File.Exists(fileDelete)) { System.IO.File.Delete(fileDelete); } string fileDelete2 = Server.MapPath(strImg.Replace("sc_small_", "sc_full_")); if (System.IO.File.Exists(fileDelete2)) { System.IO.File.Delete(fileDelete2); } } ////delete imgage album bool rt = galleryModels.Delete_Images((int)id); if (rt) { list_album_images_view.Message = "Bạn đã xóa ảnh " + id; } else { list_album_images_view.Message = "Xóa không thành công"; } } else { list_album_images_view.Message = "Không tìm thấy ảnh : " + id; } } else { list_album_images_view.Message = " Bạn không có quyền thực thi hành động xóa."; } } if (string.IsNullOrEmpty(order_by) || string.IsNullOrEmpty(order_type)) { order_by = "ID"; order_type = "asc"; } if (parent != 0) { cate = cateModels.GetbyID((int)parent); list_album_images_view.Category_name = cate.CategoryName; } list_album_images_view.Type = type; list_album_images_view.Cate_type = CommonGlobal.GetCatalogTypeName(type); list_album_images_view.Parent = (int)parent; list_album_images_view.Lang = lang; list_album_images_view.Type_act = type_act; ////tab sb.Append("<li class=\"active\"><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type = type, page = "1", parent = parent }) + "\"><span><span>Danh sách " + CommonGlobal.GetCatalogTypeName(type) + "</span></span></a></li>"); list_album_images_view.Html_link_tab = sb.ToString(); ////list language list_album_images_view.List_language = this.List_select_language(this.Lang); ////list category for filter cateModels.List_catalog_parent(0, level, (int)parent, type, lang, ref list_select_catalog); list_album_images_view.List_parent = list_select_catalog; ////list page size and paging list_album_images_view.List_page_size = this.GetSizePagingPublic((int)page_size); list_album_images_view.Page = (int)page; list_album_images_view.Page_size = (int)page_size; ////list product list_album_images_view.Page_list_image = galleryModels.AdminGetAllImageGallery((int)parent, type, lang, (int)page, (int)page_size, order_by, order_type, out total_record); list_album_images_view.Order_by = order_by; list_album_images_view.Order_type = order_type; list_album_images_view.Total_record = total_record; ////acton and parent action list_album_images_view.Act = act; list_album_images_view.Ctrl = ctrl; list_album_images_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); list_album_images_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); return(this.PartialView("../control/list_album_images", list_album_images_view)); }
public static Class GetClass(this ImageAlbum album) { return(ClassView.GetModelByID(album.ClassID.ToS())); }
public static Class GetClass(this ImageAlbum imga) { return(ClassAction.Classes.Where(p => p.ID == imga.ClassID).FirstOrDefault()); }
/// <summary> /// 获取图片内容页面地址 /// </summary> /// <param name="img"></param> /// <param name="cls"></param> /// <returns></returns> public static string GetImageUrl(ImageAlbum img, Class cls) { return(GetConverter().GetImageUrl(img, cls)); }
public void Update(ImageAlbum imageAlbum) { _imageAlbumRepository.Update(imageAlbum); }
/// <summary> /// 获取图片内容页面地址 /// </summary> /// <param name="img"></param> /// <param name="cls"></param> /// <returns></returns> public string GetImageUrl(ImageAlbum img, Class cls) { return(string.Format("/Dynamic/Image/Image.aspx?id={0}", img.ID)); }
/// <summary> /// 获取图片内容页面地址 /// </summary> /// <param name="img"></param> /// <param name="cls"></param> /// <returns></returns> public string GetImageUrl(ImageAlbum img, Class cls) { string result = ""; string fileName = img.ID.ToString(); string sitrurl = "/"; string parentForder = cls.ClassForder; if (!parentForder.IsNullOrEmpty()) { parentForder += "/"; } string newsFolder = img.Folder; if (newsFolder.IsNullOrEmpty()) { newsFolder = "/"; } result = string.Format("{0}{1}{2}/{3}/{4}{5}", sitrurl, cls.ParentClassForder.IsNullOrEmpty() ? "" : cls.ParentClassForder + "/", cls.ClassForder, newsFolder, fileName, BasePage.SystemSetting.ExtName ); result = Regex.Replace(result, "[/]{2,}", "/"); return result; }
public ImageAlbum Add(ImageAlbum imageAlbum) { _imageAlbumRepository.Add(imageAlbum); return(imageAlbum); }
/// <summary> /// 将数据插入表 /// </summary> /// <param name="M">赋值后的实体</param> /// <returns></returns> public static void Insert(ImageAlbum M) { IDbHelper Sql = GetHelper(); StringBuilder sb = new StringBuilder(); sb.Append("insert into [ImageAlbum]([ClassID],[ZtID],[AuthorID],[Author],[Title],[CreateTime],[UpdateTime],[Intro],[Size],[Folder],[ClickCount],[ReplyCount],[SetTop],[ShotCut],[KeyWords]) values("); sb.Append(M.ClassID.ToS()); sb.Append(","); sb.Append(M.ZtID.ToS()); sb.Append(","); sb.Append(M.AuthorID.ToS()); sb.Append(","); sb.Append("N'" + M.Author + "'"); sb.Append(","); sb.Append("N'" + M.Title + "'"); sb.Append(","); sb.Append("N'" + M.CreateTime + "'"); sb.Append(","); sb.Append("N'" + M.UpdateTime + "'"); sb.Append(","); sb.Append("N'" + M.Intro + "'"); sb.Append(","); sb.Append(M.Size.ToS()); sb.Append(","); sb.Append("N'" + M.Folder + "'"); sb.Append(","); sb.Append(M.ClickCount.ToS()); sb.Append(","); sb.Append(M.ReplyCount.ToS()); sb.Append(","); sb.Append(M.SetTop.ToS()); sb.Append(","); sb.Append("N'" + M.ShotCut + "'"); sb.Append(","); sb.Append("N'" + M.KeyWords + "'"); sb.Append(")"); if (DataBase.CmsDbType == DataBase.DbType.SqlServer) { sb.Append(";select @@Identity"); } if (DataBase.CmsDbType == DataBase.DbType.SQLite) { sb.Append(";select last_insert_rowid()"); } if (DataBase.CmsDbType == DataBase.DbType.MySql) { sb.Append(";select LAST_INSERT_ID()"); } if (DataBase.CmsDbType == DataBase.DbType.Access) { sb.Append(";select max(ID) from ImageAlbum"); } if (DataBase.CmsDbType == DataBase.DbType.Oracle) { sb.Append(";select LAST_INSERT_ID()"); } M.ID = Sql.ExecuteScalar(CommandType.Text, sb.ToString()).ToInt32(); }
/// <summary> /// 将修改过的实体修改到数据库 /// </summary> /// <param name="M">赋值后的实体</param> /// <returns></returns> public static int Update(ImageAlbum M) { IDbHelper Sql = GetHelper(); StringBuilder sb = new StringBuilder(); sb.Append("update [ImageAlbum] set "); sb.Append("[ClassID]=" + M.ClassID.ToS()); sb.Append(","); sb.Append("[ZtID]=" + M.ZtID.ToS()); sb.Append(","); sb.Append("[AuthorID]=" + M.AuthorID.ToS()); sb.Append(","); sb.Append("[Author]=N'" + M.Author + "'"); sb.Append(","); sb.Append("[Title]=N'" + M.Title + "'"); sb.Append(","); sb.Append("[CreateTime]=N'" + M.CreateTime + "'"); sb.Append(","); sb.Append("[UpdateTime]=N'" + M.UpdateTime + "'"); sb.Append(","); sb.Append("[Intro]=N'" + M.Intro + "'"); sb.Append(","); sb.Append("[Size]=" + M.Size.ToS()); sb.Append(","); sb.Append("[Folder]=N'" + M.Folder + "'"); sb.Append(","); sb.Append("[ClickCount]=" + M.ClickCount.ToS()); sb.Append(","); sb.Append("[ReplyCount]=" + M.ReplyCount.ToS()); sb.Append(","); sb.Append("[SetTop]=" + M.SetTop.ToS()); sb.Append(","); sb.Append("[ShotCut]=N'" + M.ShotCut + "'"); sb.Append(","); sb.Append("[KeyWords]=N'" + M.KeyWords + "'"); sb.Append(" where ID='" + M.ID + "'"); sb.Append(""); if (DataBase.CmsDbType == DataBase.DbType.SqlServer) { sb.Append(";select @@ROWCOUNT"); } if (DataBase.CmsDbType == DataBase.DbType.SQLite) { sb.Append(";select 0"); } if (DataBase.CmsDbType == DataBase.DbType.MySql) { sb.Append(";SELECT ROW_COUNT()"); } if (DataBase.CmsDbType == DataBase.DbType.Access) { sb.Append(";select 0"); } if (DataBase.CmsDbType == DataBase.DbType.Oracle) { sb.Append(";select SQL%ROWCOUNT"); } return(Sql.ExecuteScalar(CommandType.Text, sb.ToString()).ToInt32()); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Save_Click(object sender, EventArgs e) { Class cls = ClassView.GetModelByID(ddl_Class.SelectedValue); ImageAlbum imga = ImageAlbumView.GetModelByID(WS.RequestString("id")); imga.ClassID = ddl_Class.SelectedValue.ToInt32(); imga.Title = txt_Title.Text.TrimDbDangerousChar(); imga.AuthorID = ddl_Author.SelectedValue.ToInt32(); imga.Author = ddl_Author.SelectedItem.Text; imga.ClickCount = txt_ClickCount.Text.ToInt32(0); if (imga.ID <= 0) { imga.CreateTime = DateTime.Now; imga.Folder = DateTime.Now.ToString("yyyy-MM-dd"); } imga.Intro = txt_Intro.Text.TrimDbDangerousChar(); imga.KeyWords = txt_Keyword.Text.TrimDbDangerousChar(); imga.ReplyCount = txt_ReplyCount.Text.ToInt32(0); imga.SetTop = false; //imga.ShotCut = ""; //imga.Size = 0; imga.Title = txt_Title.Text; imga.UpdateTime = DateTime.Now; imga.ZtID = 0; if (imga.ID > 0) { ImageAlbumView.Update(imga); } else { ImageAlbumView.Insert(imga); } //保存单个图片设置 string[] t**s = WS.RequestString("tit[]").Split(','); string[] intrs = WS.RequestString("intro[]").Split(','); var imgs = ImagesView.GetModelList(string.Format("AlbumID={0} order by id", imga.ID)); for (int i = 0; i < imgs.Count; i++) { try { imgs[i].Title = t**s[i].ToS(); imgs[i].Intro = intrs[i].ToS(); ImagesView.Update(imgs[i]); } catch { } } //生成页面 CreatePage.CreateContentPage(imga, cls); ImageAlbum pre = GetPreImage(imga, cls); if (pre != null) { CreatePage.CreateContentPage(pre, cls); } CreatePage.CreateListPage(cls, 1); Js.AlertAndChangUrl("保存成功!", url); }
/// <summary> /// 上传图片 /// </summary> /// <param name="file"></param> /// <param name="ClassID"></param> /// <returns></returns> public static Result UpLoadImage(HttpPostedFile file, int ImageAlbumID) { Result r = new Result(); SysSetting ss = BasePage.SystemSetting; string FileName = file.FileName.GetFileNameFromPath().ToLower(); //文件名 string ExtName = file.FileName.GetFileExtNameFromPath().ToLower(); //扩展名 string NewName = @string.GetGuid() + ExtName; //新文件名 if (!ExtName.Replace(".", "").IsInArray(ss.FileExtNameFilter.Split(','))) { r.Success = false; r.Text = "不允许上传此类文件"; return(r); } if (file.ContentLength > ss.MaxPostFileSize) { r.Success = false; r.Text = "文件太大"; return(r); } string Folder = ss.FileDir + "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/"; //文件目录 string FolderShotCut = Folder + "ShortCut/"; //缩略图目录 string FilePath = Folder + NewName; //文件路径 string FilePath_ShortCut = FolderShotCut + NewName; //缩略图路径 file.SaveAs(System.Web.HttpContext.Current.Server.MapPath(FilePath), true); if (ExtName.ToLower().Replace(".", "").IsInArray("jpg,jpeg,png,gif,bmp".Split(','))) { ImageHelper.MakeThumbnail(System.Web.HttpContext.Current.Server.MapPath(FilePath), System.Web.HttpContext.Current.Server.MapPath(FilePath_ShortCut), 105, 118, "Cut"); } ImageAlbum album = ImageAlbumView.GetModelByID(ImageAlbumID.ToS()); Images img = new Images(); img.AlbumID = album.ID; img.ClickCount = 0; img.ExtName = ExtName; img.FilePath = FilePath; img.FileSize = file.ContentLength; img.Intro = ""; img.ReplyCount = 0; img.SmallPath = FilePath_ShortCut; img.Title = ""; img.UploadTime = DateTime.Now; ImagesView.Insert(img); ImageAlbum imga = ImageAlbumView.GetModelByID(ImageAlbumID.ToString()); imga.Size = ImagesView.Count(string.Format("AlbumID={0}", imga.ID)); ImageAlbumView.Update(imga); r.Success = true; r.Text = FilePath; return(r); }
public void AddToImageAlbum(ImageAlbum imageAlbum) { base.AddObject("ImageAlbum", imageAlbum); }
public static ImageAlbum CreateImageAlbum(int id) { ImageAlbum imageAlbum = new ImageAlbum(); imageAlbum.ID = id; return imageAlbum; }
public ActionResult List_album_images(FormCollection collection) { CatalogModels cateModels = new CatalogModels(); GalleryModels galleryModels = new GalleryModels(); C_Catalog cate = new C_Catalog(); ImageAlbum imgPro = new ImageAlbum(); StringBuilder sb = new StringBuilder(); List <SelectListItem> list_select_catalog = new List <SelectListItem>(); var list_album_images_view = new Web.Areas.Admin.ViewModels.List_album_images_view(); this.TryUpdateModel(list_album_images_view); int total_record = 0; int level = 0; bool rt = true; bool is_valid = true; list_album_images_view.Cate_type = CommonGlobal.GetCatalogTypeName(list_album_images_view.Type); ////tab sb.Append("<li class=\"active\"><a class=\"active\" href=\"" + Url.Action("index", "dashboard", new { act = "list_catalog", ctrl = "adminCatalog", type = list_album_images_view.Type, page = "1", parent = list_album_images_view.Parent }) + "\"><span><span>Danh sách " + CommonGlobal.GetCatalogTypeName(list_album_images_view.Type) + "</span></span></a></li>"); list_album_images_view.Html_link_tab = sb.ToString(); ////list page size and paging list_album_images_view.List_page_size = this.GetSizePagingPublic(list_album_images_view.Page_size); ////acton and parent action list_album_images_view.Act = "list_album_images"; list_album_images_view.Ctrl = "adminLink"; list_album_images_view.Parent_action = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); list_album_images_view.Parent_controller = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); ////delete image if (list_album_images_view.Id > 0 && list_album_images_view.Type_act == CommonGlobal.Delete) { ////check permission delete if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, list_album_images_view.Act, list_album_images_view.Ctrl, list_album_images_view.Type_act, list_album_images_view.Type)) { imgPro = galleryModels.GetImageById(list_album_images_view.Id); if (imgPro != null) { ////delete old image if (!string.IsNullOrEmpty(imgPro.Images)) { string strImg = imgPro.Images; strImg = "~" + strImg; string fileDelete = Server.MapPath(strImg); if (System.IO.File.Exists(fileDelete)) { System.IO.File.Delete(fileDelete); } string fileDelete2 = Server.MapPath(strImg.Replace("sc_small_", "sc_full_")); if (System.IO.File.Exists(fileDelete2)) { System.IO.File.Delete(fileDelete2); } } ////delete image product rt = galleryModels.Delete_Images(list_album_images_view.Id); if (rt) { list_album_images_view.Message = "Bạn đã xóa ảnh " + list_album_images_view.Id; } else { list_album_images_view.Message = "Xóa không thành công"; } } else { list_album_images_view.Message = "Không tìm thấy ảnh : " + list_album_images_view.Id; } } else { list_album_images_view.Message = " Bạn không có quyền thực thi hành động xóa."; } } else { if (list_album_images_view.Type_act == CommonGlobal.Add) { ////check permission add if (UserModels.CheckPermission(this.Session["mem"] != null ? this.Session["mem"].ToString() : string.Empty, list_album_images_view.Act, list_album_images_view.Ctrl, list_album_images_view.Type_act, list_album_images_view.Type)) { ////validation server if (list_album_images_view.Album == 0) { is_valid = false; list_album_images_view.Message = "Bạn cần lựa chọn album"; } if (list_album_images_view.File_image == null) { is_valid = false; list_album_images_view.Message = "Bạn cần chọn ảnh"; } var max_length = 1024 * 1024 * 10; ////10MB var length_all = 0; foreach (HttpPostedFileBase fi in list_album_images_view.File_image) { if (fi != null) { length_all = length_all + fi.ContentLength; } } if (length_all == 0) { is_valid = false; } if (length_all > max_length) { is_valid = false; list_album_images_view.Message = "Bạn đã không thể đăng quá nhiều ảnh (Tổng dung lượng tối đa 10MB)"; } if (is_valid) { ////upload multi images foreach (HttpPostedFileBase fi in list_album_images_view.File_image) { if (fi != null && fi.ContentLength > 0 && CommonGlobal.IsImage(fi) == true) { ////add new image var imgPathTemp = "images/photogallery/" + DateTime.Now.Year.ToString() + "/" + DateTime.Now.Month.ToString() + "/"; var name_time = DateTime.Now.Day + DateTime.Now.Month + DateTime.Now.Year + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Ticks + string.Empty; imgPro = new ImageAlbum(); string image_small = imgPathTemp + "sc_small_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(fi.FileName); string image_lager = imgPathTemp + "sc_full_" + name_time + "_" + CommonGlobal.CompleteNamefileImages(fi.FileName); //////save images for multi file this.Savephoto(null, fi, imgPathTemp, image_small, image_lager); imgPro.Images = "/" + image_small; imgPro.ImagesFull = "/" + image_lager; imgPro.CatalogID = list_album_images_view.Album; list_album_images_view.ImagePath = "/" + image_small; rt = galleryModels.Add_Images(imgPro); if (rt) { list_album_images_view.Message = "Bạn đã thêm ảnh thành công!"; } else { if (list_album_images_view.Message != string.Empty) { list_album_images_view.Message = "updload ảnh không thành công: " + CommonGlobal.CompleteNamefileImages(fi.FileName); } else { list_album_images_view.Message += "; " + CommonGlobal.CompleteNamefileImages(fi.FileName); } } list_album_images_view.File_image = null; } } } } else { list_album_images_view.Message = " Bạn không có quyền thực thi thêm ảnh cho album "; } } else { list_album_images_view.Message = string.Empty; } } ////list language list_album_images_view.List_language = this.List_select_language(list_album_images_view.Lang); ////list category cateModels.List_catalog_parent(0, level, list_album_images_view.Parent, list_album_images_view.Type, list_album_images_view.Lang, ref list_select_catalog); list_album_images_view.List_parent = list_select_catalog; ////get list product list_album_images_view.Page_list_image = galleryModels.AdminGetAllImageGallery(list_album_images_view.Parent, list_album_images_view.Type, list_album_images_view.Lang, list_album_images_view.Page, list_album_images_view.Page_size, list_album_images_view.Order_by, list_album_images_view.Order_type, out total_record); list_album_images_view.Total_record = total_record; list_album_images_view.Order_by = list_album_images_view.Order_by; list_album_images_view.Order_type = list_album_images_view.Order_type; return(this.PartialView("../control/list_album_images", list_album_images_view)); }
/// <summary> /// 保存 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btn_Save_Click(object sender, EventArgs e) { Class cls = ClassAction.Classes.Where(p => p.ID.ToString() == ddl_Class.SelectedValue).FirstOrDefault(); DataEntities ent = new DataEntities(); int id = WS.RequestInt("id"); var images = from l in ent.ImageAlbum where l.ID == id select l; ImageAlbum imga = new ImageAlbum(); if (images.Count() > 0) { imga = images.FirstOrDefault(); } imga.ClassID = ddl_Class.SelectedValue.ToInt32(); imga.Title = txt_Title.Text.TrimDbDangerousChar(); imga.AuthorID = ddl_Author.SelectedValue.ToInt32(); imga.Author = ddl_Author.SelectedItem.Text; imga.ClickCount = txt_ClickCount.Text.ToInt32(0); if (imga.ID <= 0) { imga.CreateTime = DateTime.Now; imga.Folder = DateTime.Now.ToString("yyyy-MM-dd"); } imga.Intro = txt_Intro.Text.TrimDbDangerousChar(); imga.KeyWords = txt_Keyword.Text.TrimDbDangerousChar(); imga.ReplyCount = txt_ReplyCount.Text.ToInt32(0); imga.SetTop = false; //imga.ShotCut = ""; //imga.Size = 0; imga.Title = txt_Title.Text; imga.UpdateTime = DateTime.Now; imga.ZtID = 0; if (images.Count() == 0) { ent.AddToImageAlbum(imga); ent.SaveChanges(); } //保存单个图片设置 string[] t**s = WS.RequestString("tit[]").Split(','); string[] intrs = WS.RequestString("intro[]").Split(','); var imgs = //ImagesView.GetModelList(string.Format("AlbumID={0} order by id", imga.ID)); (from l in ent.Images where l.AlbumID == imga.ID select l).ToList(); for (int i = 0; i < imgs.Count; i++) { try { imgs[i].Title = t**s[i].ToS(); imgs[i].Intro = intrs[i].ToS(); } catch { } } ent.SaveChanges(); //生成页面 CreatePage.CreateContentPage(imga, cls); ImageAlbum pre = GetPreImage(imga, cls); if (pre != null) { CreatePage.CreateContentPage(pre, cls); } CreatePage.CreateListPage(cls, 1); Js.AlertAndChangUrl("保存成功!", url); }