using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Web.UI; using System.Web.UI.WebControls; using CB.Admin.Ajax; using CB.Common; using CB.Data; using CB.Entity; using CB.Framework; namespace CB.Admin.Plugins.Basic { public partial class TopicEdit : AdminPage { private int _tid = 0; protected void Page_Load(object sender, EventArgs e) { _tid = WRequest.GetQueryInt("Tid", 0); if (!Page.IsPostBack) { InitData(); } } protected override void InitData() { IList list = TopicClassService.ToList(); if (null != list && list.Count > 0) { foreach (var item in list) { dpCid.Items.Add(new ListItem(item.Name, item.Cid.ToString())); } } if (0 < _tid) { TopicInfo entity = TopicService.Get(_tid); if (null == entity) return; dpCid.SelectedValue = entity.Cid.ToString(); txtTitle.Text = entity.Title; txtContent.Value = entity.Context; this.Image1.ImageUrl = entity.FileURL; this.Image1.Visible = true; this.txb_FileName.Value = entity.FileName; this.txb_FileSize.Value = entity.FileSize; this.txb_FileUrl.Value = entity.FileURL; this.txb_FilteType.Value = entity.FilteType; this.txb_thumbsSize.Value = entity.thumbsSize; this.txb_thumbsURL.Value = entity.thumbsURL; labID.Text = entity.Tid.ToString(); } } //创建实体 private TopicInfo GetEntity() { TopicInfo entity = new TopicInfo(); entity.Tid = TypeConverter.StrToInt(labID.Text); entity.Cid = TypeConverter.StrToInt(dpCid.SelectedValue); entity.Title = txtTitle.Text.Trim(); entity.Context = txtContent.InnerText.Trim(); entity.Uid = Uid; entity.UserName = UserName; entity.Status = string.IsNullOrEmpty(entity.Context) ? 1 : 0; entity.FileName = txb_FileName.Value.Trim(); entity.FileSize = txb_FileSize.Value.Trim(); entity.FileURL = txb_FileUrl.Value.Trim(); entity.thumbsSize = txb_thumbsSize.Value.Trim(); entity.thumbsURL = txb_thumbsURL.Value.Trim(); entity.FilteType = txb_FilteType.Value.Trim(); return entity; } private static Tuple Violation(TopicInfo entity) { if (entity.Cid <= 0) { return new Tuple(false, "请选择文章类型"); } if (string.IsNullOrEmpty(entity.Title)) { return new Tuple(false, "请填写标题"); } return new Tuple(true, ""); } protected void btnEdit_Click(object sender, EventArgs e) { TopicInfo entity = GetEntity(); Tuple validate = Violation(entity); if (!validate.Item1) { ShowMessageBox(validate.Item2); return; } if (entity.Tid > 0) { TopicService.Update(entity); ShowMessageBox("提示:修改成功!", "TopicEdit.aspx?authPage=" + authPage + "&Tid=" + entity.Tid); } else { TopicService.Save(entity); ShowMessageBox("提示:添加成功!", "TopicEdit.aspx?authPage=" + authPage); } } protected void Button1_Click(object sender, EventArgs e) { UpLoadTopicMessageInfo info = new UpLoadTopicMessageInfo(); int imgHight = WRequest.GetInt("thumb_Hight", 320); int imgWidth = WRequest.GetInt("thumb_Width", 96); string path = "topic"; int size = 3; FileUpLoadManager fm = new FileUpLoadManager(); info = fm.UpLoadPhotoAndThumbnailByTv(path, size, 320, 0, "W"); if (info.error != 0) { ShowMessageBox(info.message); return; } Image1.Visible = true; Image1.ImageUrl = info.FileUrl; txb_FileName.Value = info.FileName; txb_FileSize.Value = info.FileSize; txb_FileUrl.Value = info.FileUrl; txb_FilteType.Value = info.FilteType; txb_thumbsSize.Value = info.thumbsSize; txb_thumbsURL.Value = info.thumbsURL; } protected void btn_ClearImg_Click(object sender, EventArgs e) { Image1.ImageUrl = ""; Image1.Visible = false; txb_FileName.Value = ""; txb_FileSize.Value = ""; txb_FileUrl.Value = ""; txb_FilteType.Value = ""; txb_thumbsSize.Value = ""; txb_thumbsURL.Value = ""; } } }