using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MetaType;
using Base;

public partial class admin_Meta_MetaTypeManage : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
        }
    }
    private void Bind()
    {
        IMetaType RMeta = new RMetaType();
        DataTable dt = RMeta.GetDataTable();
        dlstMetaType.DataSource = dt.DefaultView;
        dlstMetaType.DataBind();
    }
    protected void dlstMetaType_CancelCommand(object source, DataListCommandEventArgs e)
    {
        dlstMetaType.EditItemIndex = -1;
        Bind();
    }
    protected void dlstMetaType_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int id=int.Parse(dlstMetaType.DataKeys[e.Item.ItemIndex].ToString());
        IMetaType RMeta = new RMetaType();
        RMeta.Delete(id);
        Bind();
    }
    protected void dlstMetaType_EditCommand(object source, DataListCommandEventArgs e)
    {
        dlstMetaType.EditItemIndex = e.Item.ItemIndex;
        Bind();
    }
    protected void btbSave_Click(object sender, EventArgs e)
    {
        try
        {
            TMetaType TMeta = new TMetaType();
            TMeta.Type = txtMetaType.Text;
            IMetaType RMeta = new RMetaType();
            RMeta.Insert(TMeta);
            ShowMessage("Meta类别添加成功！", "Meta/MetaTypeManage.aspx");
        }
        catch (Exception ex)
        {
            ShowMessage("Meta类别添加失败！", "Meta/MetaTypeManage.aspx");
        }
    }
    protected void dlstMetaType_UpdateCommand(object source, DataListCommandEventArgs e)
    {
        int id = int.Parse(dlstMetaType.DataKeys[e.Item.ItemIndex].ToString());
        string type = ((TextBox)e.Item.FindControl("txtType")).Text;
        TMetaType TMeta = new TMetaType();
        TMeta.ID=id;
        TMeta.Type=type;
        IMetaType RMeta = new RMetaType();
        RMeta.Update(TMeta);
        dlstMetaType.EditItemIndex = -1;
        Bind();
    }
}
