using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class webXabara_shop_keyWord : System.Web.UI.Page
{
    XabaraCom xc = new XabaraCom();
    XabaraClass xClass = new XabaraClass();
    dbDataFunction db = new dbDataFunction();

    protected void Page_Load(object sender, EventArgs e)
    {
        xc.CheckAdminLogin("");

        if (!IsPostBack)
        {
            xClass.NewsTypeData("taobaoke", classID);

            string ifStr = string.Empty;
            string pageStr = string.Empty;
            string orderBy = " Order By updateDate ASC";

            long cidTemp = xc.SafeNum(Request.QueryString["cid"]);
            if (cidTemp > 0)
            {
                this.classID.Items.FindByValue(cidTemp.ToString()).Selected = true;
                pageStr += "&cid=" + cidTemp.ToString();
            }

            if (cidTemp > 0)
            {
                string cidStr = xClass.getClassAllID("taobaoke", cidTemp); //得到所有ID
                if (cidStr.IndexOf(",") > 0)
                {
                    string[] ids = cidStr.Split(new char[] { ',' });
                    for (int i = 0; i <= ids.GetUpperBound(0); i++)
                    {
                        ifStr += " select * from keywordid where treeID=" + ids[i].ToString().Trim() + " union ";
                    }
                }
                else
                {
                    ifStr = " select * from keywordid where treeID=" + cidTemp.ToString().Trim() + " union ";
                }
            }
            else
            {
                ifStr = " select * from keywordid union ";
            }

            ifStr = "(" + ifStr.Substring(0, ifStr.Length - 6) + ") as news";

            string strSql = "select * from " + ifStr + orderBy;
            //Response.Write(strSql);
            //Response.End();
            lblCurrentPage.Text = db.RepeaterDB(RepeaterList, strSql, pageStr, 30, "page", "center", true);
            if (this.RepeaterList.Items.Count < 1)
            {
                errInfo.Text = "目前暂没有任何信息！";
                errDiv.Visible = true;
            }
            else
            {
                errDiv.Visible = false;
            }
        }
    }

    protected void classID_SelectedIndexChanged(object sender, EventArgs e)
    {
        Response.Redirect("keyWord.aspx?cid=" + classID.Text, true);
    }

    public string getTreeName(string cid)
    {
        return xClass.getClass(xc.SafeNum(cid), "", "");
    }

    protected void del_Click(object sender, EventArgs e)
    {
        string ids = Request["batDel"];
        if (!string.IsNullOrEmpty(ids as string))
        {
            string returnStr = db.DelDB("keywordid", "id", ids, "", false, "");
            Response.Redirect(Server.UrlDecode(xc.errorUrlTwo), true);
        }
        else
        {
            xc.divError("", "请先选择后再操作！", 350, 150, Server.UrlDecode(xc.errorUrlTwo), "goto");
        }
    }

    protected void good_Click(object sender, EventArgs e)
    {
        string[] strValue = new string[1];
        strValue[0] = "0";

        string ids = Request["batDel"];
        if (!string.IsNullOrEmpty(ids as string))
        {
            ids = ids.Replace(",", " or id=");
            ids = "id=" + ids;

            string returnStr = db.InsertUpdateDB("keywordid", "@isBad", strValue, ids);
            Response.Redirect(Server.UrlDecode(xc.errorUrlTwo), true);
        }
        else
        {
            xc.divError("", "请先选择后再操作！", 350, 150, Server.UrlDecode(xc.errorUrlTwo), "goto");
        }
    }

    protected void unGood_Click(object sender, EventArgs e)
    {
        string[] strValue = new string[1];
        strValue[0] = "1";

        string ids = Request["batDel"];
        if (!string.IsNullOrEmpty(ids as string))
        {
            ids = ids.Replace(",", " or id=");
            ids = "id=" + ids;

            string returnStr = db.InsertUpdateDB("keywordid", "@isBad", strValue, ids);
            Response.Redirect(Server.UrlDecode(xc.errorUrlTwo), true);
        }
        else
        {
            xc.divError("", "请先选择后再操作！", 350, 150, Server.UrlDecode(xc.errorUrlTwo), "goto");
        }
    }
}