using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Model;
using BLL;
namespace ComResProSystem
{
    public partial class AnnouncementEdit:BasePage
    {
        BaseBLL bll = new BaseBLL();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindAnnouncement();
            }
        }
        protected void BindAnnouncement()
        {
            string ID = Request.QueryString["ID"];
            List<object> list=bll.SelectObject(typeof(Announcement), "Announcement","Title,Contents","ID="+ID);
            Tb_Title.Text = ((Announcement)list[0]).Title;
            Ed_Contents.Content = ((Announcement)list[0]).Contents;
        }

        protected void Ibt_Submit_Click(object sender, ImageClickEventArgs e)
        {
            string ID = Request.QueryString["ID"];
            Dictionary<string,string> dic=FindControls(this.form1);
            object obj=bll.CreateObject(typeof(Announcement),dic);
            if (bll.UpdateObject(obj, "Announcement", "ID=" + ID) == 0)
            {
                Response.Write("<script>alert('操作成功！');window.parent.returnValue='1';window.close();</script>");
            }
        }
        protected override Dictionary<string, string> FindControls(Control ct)
        {
            Dictionary<string,string> dic=base.FindControls(ct);
            foreach (Control ctl in ct.Controls)
            {
                if (ctl is AjaxControlToolkit.HTMLEditor.Editor)
                {
                    AjaxControlToolkit.HTMLEditor.Editor editor = (AjaxControlToolkit.HTMLEditor.Editor)ctl;
                    string Name = editor.ID.Substring(3, editor.ID.Length - 3);
                    string value = editor.Content;
                    dic.Add(Name, value);
                }
            }
            return dic;
        }
    }
}