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 Base;
using MetaInfo;


public partial class Admin_Meta_MetaInfoManage : BasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        CheckRights("Basic", "A1");
        if (!IsPostBack)
        {
            Bind();
        }
    }
    private void Bind()
    {
        string strWhere = " 1=1";
        string select = "a.ID,a.Keywords,a.Descriptions,b.Type";
        string table = "";
        if (Request.QueryString["type"] != null && Request.QueryString["type"] != "")
        {
            string type = Request.QueryString["type"].ToString();
            switch (type.ToLower())
            {
                case "company":
                    table = "W_MetaInfo as a inner join W_MetaType b on a.TypeID=b.id and b.type like '%Co%'";
                    break;
                case "supply":
                    table = "W_MetaInfo as a inner join W_MetaType b on a.TypeID=b.id and b.type like '%Supply%'";
                    break;
                case "purchase":
                    table = "W_MetaInfo as a inner join W_MetaType b on a.TypeID=b.id and b.type like '%Purchase%'";
                    break;
                case "consultative":
                    table = "W_MetaInfo as a inner join W_MetaType b on a.TypeID=b.id and b.type like '%News%'";
                    break;
                case "expo":
                    table = "W_MetaInfo as a inner join W_MetaType b on a.TypeID=b.id and b.type like '%Expo%'";
                    break;
                case "agent":
                    table = "W_MetaInfo as a inner join W_MetaType b on a.TypeID=b.id and b.type like '%Agent%'";
                    break;
                case "product":
                    table = "W_MetaInfo as a inner join W_MetaType b on a.TypeID=b.id and b.type like '%Product%'";
                    break;
                default:
                    table = "W_MetaInfo as a inner join W_MetaType b on a.TypeID=b.id and b.type like 'Index%'";
                    break;
            }
        }
        else
        {
            table = "W_MetaInfo as a inner join W_MetaType b on a.TypeID=b.id and b.type like 'index%'";
        }
        DataTable dt = PageList.GetDataTable(strWhere, table, 0, "a.ID", select, 10, 1, 0);
        grdMetaInfo.DataSource = dt.DefaultView;
        grdMetaInfo.DataBind();
    }
    protected string GetName(string strName)
    {
        if (strName != string.Empty)
        {
            switch (strName)
            {
                case "Index":
                    return "首页";
                    break;
                case "Company_Trade":
                    return "公司分类页";
                    break;
                case "Corporation_Detail":
                    return "公司详细页";
                    break;
                case "Supply_Trade":
                    return "供应分类页";
                    break;
                case "Supply_Detail":
                    return "供应详细页";
                    break;
                case "Purchase_Trade":
                    return "求购分类页";
                    break;
                case "Purchase_Detail":
                    return "求购详细页";
                    break;
                case "News_Index":
                    return "资讯首页";
                    break;
                case "News_Trade":
                    return "资讯分类页";
                    break;
                case "News_Detail":
                    return "资讯详细页";
                    break;
                case "Expo_Index":
                    return "展会首页";
                    break;
                case "Expo_Trade":
                    return "展会分类页";
                    break;
                case "Expo_Detail":
                    return "展会详细页";
                    break;
                case "Agent_Index":
                    return "招商加盟首页";
                    break;
                case "Agent_Trade":
                    return "招商加盟分类页";
                    break;
                case "Agent_Detail":
                    return "招商加盟详细页";
                case "Product_Trade":
                    return "产品库分类页";
                    break;
                case "Product_Detail":
                    return "产品库详细页";
                    break;
            }
        }
        return string.Empty;
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < grdMetaInfo.Rows.Count; i++)
        {
            string Keyword = ((TextBox)grdMetaInfo.Rows[i].FindControl("txtKeyWords")).Text;
            string Desc = ((TextBox)grdMetaInfo.Rows[i].FindControl("txtDescriptions")).Text;
            int id = Convert.ToInt32(grdMetaInfo.DataKeys[i].Value.ToString());
            IMetaInfo RMeta = new RMetaInfo();
            TMetaInfo TMeta = new TMetaInfo();
            TMeta.ID = id;
            TMeta.Keywords = Keyword;
            TMeta.Descriptions = Desc;
            RMeta.Update(TMeta);
            ShowMessage("保存成功!");
        }
        Bind();
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < grdMetaInfo.Rows.Count; i++)
        {
            ((TextBox)grdMetaInfo.Rows[i].FindControl("txtKeyWords")).Text = string.Empty;
            ((TextBox)grdMetaInfo.Rows[i].FindControl("txtDescriptions")).Text = string.Empty;

        }
    }

    protected void grdMetaInfo_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);");
            e.Row.Attributes.Add("onMouseOut", "SetOldColor(this)");
        }
    }
}
