private void CheckPath() { if (!AppUtils.CheckPath(GetPath())) { Message.Alert(Page, "Không tạo được thư mục!"); } }
protected void btUpload_Click(object sender, EventArgs e) { if (!AppUtils.CheckPath()) { Message.Alert(Page, "Không tạo được thư mục!"); } if (fuFileUpload.PostedFile == null || fuFileUpload.PostedFile.ContentLength == 0) { return; } MediaFile _MediaFile = new MediaFile(); _MediaFile.Name = AppUtils.MediaFileName(fuFileUpload.PostedFile.FileName.ToLower()); _MediaFile.Ext = Path.GetExtension(_MediaFile.Name).Replace(".", ""); _MediaFile.Path = DateTime.Now.ToString("yyyy/MM/dd/") + _MediaFile.Name; _MediaFile.Size = fuFileUpload.PostedFile.ContentLength; _MediaFile.UserID = AppUtils.UserID(); _MediaFile.Description = txtDescription.Text.Trim(); _MediaFile.Tags = txtTags.Text.Trim(); try { fuFileUpload.SaveAs(Server.MapPath(Constant.MEDIA_PATH + _MediaFile.Path)); _MediaFile.Add(); txtKeyword.Text = ""; BindData(); } catch { Message.Alert(Page, "Có lỗi khi upload file!"); } txtPath.Text = Constant.MEDIA_URL + _MediaFile.Path; imgMediaUpload.ImageUrl = Constant.MEDIA_URL + _MediaFile.Path; Response.Redirect(Constant.ADMIN_PATH + Resources.Url.Gallery); }
protected void btUpload_Click(object sender, EventArgs e) { if (!AppUtils.CheckPath()) { Message.Alert(Page, "Không tạo được thư mục!"); } if (fuFileUpload.PostedFile == null || fuFileUpload.PostedFile.ContentLength == 0) { Message.Alert(Page, "Bạn chưa chọn file!"); return; } MediaFile _MediaFile = new MediaFile(); _MediaFile.Name = AppUtils.MediaFileName(fuFileUpload.PostedFile.FileName.ToLower()); _MediaFile.Ext = Path.GetExtension(_MediaFile.Name).Replace(".", ""); _MediaFile.Path = DateTime.Now.ToString("yyyy/MM/dd/") + _MediaFile.Name; _MediaFile.Size = fuFileUpload.PostedFile.ContentLength; _MediaFile.UserID = AppUtils.UserID(); _MediaFile.Description = txtDescription.Text.Trim(); _MediaFile.Tags = txtTags.Text.Trim(); try { fuFileUpload.SaveAs(Server.MapPath(Constant.MEDIA_PATH + _MediaFile.Path)); _MediaFile.Add(); BindData(); } catch { Message.Alert(Page, "Có lỗi khi upload file!"); } txtPath.Text = Constant.MEDIA_URL + _MediaFile.Path; btSave.Visible = true; btUpload.Visible = false; }
protected void btImageUpload_Click(object sender, EventArgs e) { // Kiểm tra đã tạo thư mục lưu ảnh, dạng thư mục yyyy/mm/dd/newsid/ if (!AppUtils.CheckPath(lblMediaPathFull.Text)) { Message.Alert(Page, "Không tạo được thư mục lưu trữ ảnh, vui lòng báo người quản trị!"); return; } if (FileUpload1.PostedFile != null && FileUpload1.PostedFile.ContentLength > 0) { Upload(FileUpload1, txtImageDescription1, cbIsAvatar1); } if (FileUpload2.PostedFile != null && FileUpload2.PostedFile.ContentLength > 0) { Upload(FileUpload2, txtImageDescription2, cbIsAvatar2); } if (FileUpload3.PostedFile != null && FileUpload3.PostedFile.ContentLength > 0) { Upload(FileUpload3, txtImageDescription3, cbIsAvatar3); } if (FileUpload4.PostedFile != null && FileUpload4.PostedFile.ContentLength > 0) { Upload(FileUpload4, txtImageDescription4, cbIsAvatar4); } if (FileUpload5.PostedFile != null && FileUpload5.PostedFile.ContentLength > 0) { Upload(FileUpload5, txtImageDescription5, cbIsAvatar5); } BindMedia(); }
private void init() { if (!AppUtils.CheckPath()) { Message.Alert(Page, "Không tạo được thư mục!"); } News _News = new News() { NewsID = AppUtils.Request("id") }; _News = _News.Get(); if (_News == null || _News.Status < 2) { Response.Redirect(Constant.ADMIN_PATH + Resources.Url.SignOut); } txtTitle.Text = _News.Title; txtSubTitle.Text = _News.SubTitle; txtLead.Text = _News.Lead; txtSubLead.Text = _News.SubLead; ftbContent.Text = _News.Content; chkIsPhoto.Checked = _News.IsPhoto; chkIsVideo.Checked = _News.IsVideo; chkIsAudio.Checked = _News.IsAudio; txtPublishTime.Text = _News.PublishedTime.ToString(); imgImageUrl.ImageUrl = Constant.MEDIA_PATH + _News.ImageUrl; txtTags.Text = _News.Tags; lblMediaPath.Text = _News.CreatedTime.ToString("yyyy/MM/dd/") + _News.NewsID.ToString() + "/"; lblMediaPathFull.Text = Constant.MEDIA_PATH + lblMediaPath.Text; NewsPublish _NewsPublish = new NewsPublish(); List <NewsPublish> list = _NewsPublish.GetList(_News.NewsID); var _NewsAdmin = new NewsAdmin(); List <NewsAdmin> listNews; for (int i = 0; i < list.Count; i++) { _NewsPublish = (NewsPublish)list[i]; string title = _News.Title; if (title.Length > 50) { title = title.Substring(0, 50); } switch (i) { case 0: drpCate1.SelectedValue = _NewsPublish.CateID.ToString(); drpOrder1.Items.Clear(); drpOrder1.Items.Insert(0, new ListItem("Thứ tự:", "0")); listNews = _NewsAdmin.GetList(Convert.ToInt32(drpCate1.SelectedValue), 100); for (int j = 0; j < listNews.Count; j++) { _NewsAdmin = listNews[j]; if (_NewsAdmin.Title.Length > 50) { _NewsAdmin.Title = _NewsAdmin.Title.Substring(0, 50) + "..."; } drpOrder1.Items.Add(new ListItem("(" + _NewsAdmin.Order.ToString() + ") " + _NewsAdmin.Title, _NewsAdmin.Order.ToString())); } drpOrder1.SelectedValue = _NewsPublish.Order.ToString(); if (drpOrder1.SelectedIndex == 0) { drpOrder1.Items.Add(new ListItem("(" + _NewsPublish.Order.ToString() + ") " + title, _NewsPublish.Order.ToString())); drpOrder1.SelectedValue = _NewsPublish.Order.ToString(); } break; case 1: drpCate2.SelectedValue = _NewsPublish.CateID.ToString(); drpOrder2.Items.Clear(); drpOrder2.Items.Insert(0, new ListItem("Thứ tự:", "0")); listNews = _NewsAdmin.GetList(Convert.ToInt32(drpCate2.SelectedValue), 100); for (int j = 0; j < listNews.Count; j++) { _NewsAdmin = listNews[j]; if (_NewsAdmin.Title.Length > 50) { _NewsAdmin.Title = _NewsAdmin.Title.Substring(0, 50) + "..."; } drpOrder2.Items.Add(new ListItem("(" + _NewsAdmin.Order.ToString() + ") " + _NewsAdmin.Title, _NewsAdmin.Order.ToString())); } drpOrder2.SelectedValue = _NewsPublish.Order.ToString(); if (drpOrder2.SelectedIndex == 0) { drpOrder2.Items.Add(new ListItem("(" + _NewsPublish.Order.ToString() + ") " + title, _NewsPublish.Order.ToString())); drpOrder2.SelectedValue = _NewsPublish.Order.ToString(); } break; case 2: drpCate3.SelectedValue = _NewsPublish.CateID.ToString(); drpOrder3.Items.Clear(); drpOrder3.Items.Insert(0, new ListItem("Thứ tự:", "0")); listNews = _NewsAdmin.GetList(Convert.ToInt32(drpCate3.SelectedValue), 100); for (int j = 0; j < listNews.Count; j++) { _NewsAdmin = listNews[j]; if (_NewsAdmin.Title.Length > 50) { _NewsAdmin.Title = _NewsAdmin.Title.Substring(0, 50) + "..."; } drpOrder3.Items.Add(new ListItem("(" + _NewsAdmin.Order.ToString() + ") " + _NewsAdmin.Title, _NewsAdmin.Order.ToString())); } drpOrder3.SelectedValue = _NewsPublish.Order.ToString(); if (drpOrder3.SelectedIndex == 0) { drpOrder3.Items.Add(new ListItem("(" + _NewsPublish.Order.ToString() + ") " + title, _NewsPublish.Order.ToString())); drpOrder3.SelectedValue = _NewsPublish.Order.ToString(); } break; case 3: drpCate4.SelectedValue = _NewsPublish.CateID.ToString(); drpOrder4.Items.Clear(); drpOrder4.Items.Insert(0, new ListItem("Thứ tự:", "0")); listNews = _NewsAdmin.GetList(Convert.ToInt32(drpCate4.SelectedValue), 100); for (int j = 0; j < listNews.Count; j++) { _NewsAdmin = listNews[j]; if (_NewsAdmin.Title.Length > 50) { _NewsAdmin.Title = _NewsAdmin.Title.Substring(0, 50) + "..."; } drpOrder4.Items.Add(new ListItem("(" + _NewsAdmin.Order.ToString() + ") " + _NewsAdmin.Title, _NewsAdmin.Order.ToString())); } drpOrder4.SelectedValue = _NewsPublish.Order.ToString(); if (drpOrder4.SelectedIndex == 0) { drpOrder4.Items.Add(new ListItem("(" + _NewsPublish.Order.ToString() + ") " + title, _NewsPublish.Order.ToString())); drpOrder4.SelectedValue = _NewsPublish.Order.ToString(); } break; case 4: drpCate5.SelectedValue = _NewsPublish.CateID.ToString(); drpOrder5.Items.Clear(); drpOrder5.Items.Insert(0, new ListItem("Thứ tự:", "0")); listNews = _NewsAdmin.GetList(Convert.ToInt32(drpCate5.SelectedValue), 100); for (int j = 0; j < listNews.Count; j++) { _NewsAdmin = listNews[j]; if (_NewsAdmin.Title.Length > 50) { _NewsAdmin.Title = _NewsAdmin.Title.Substring(0, 50) + "..."; } drpOrder5.Items.Add(new ListItem("(" + _NewsAdmin.Order.ToString() + ") " + _NewsAdmin.Title, _NewsAdmin.Order.ToString())); } drpOrder5.SelectedValue = _NewsPublish.Order.ToString(); if (drpOrder5.SelectedIndex == 0) { drpOrder5.Items.Add(new ListItem("(" + _NewsPublish.Order.ToString() + ") " + title, _NewsPublish.Order.ToString())); drpOrder5.SelectedValue = _NewsPublish.Order.ToString(); } break; default: break; } } // Tin liên quan NewsRelated _NewsRelated = new NewsRelated(); rptRelatedList.DataSource = _NewsRelated.GetList(_News.NewsID); rptRelatedList.DataBind(); ftbContent.ImageGalleryPath = lblMediaPathFull.Text; if (_News.Status == 3) { btPublish.Visible = false; } // Lấy danh sách ảnh BindMedia(); }