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_keyWordAdd : System.Web.UI.Page
{
    XabaraCom xc = new XabaraCom();
    dbDataFunction db = new dbDataFunction();
    XabaraClass xClass = new XabaraClass();

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

        if (!IsPostBack)
        {
            xClass.NewsTypeData("taobaoke", classID);
            if (!string.IsNullOrEmpty(Session["classID"] as string))
            {
                this.classID.Items.FindByValue(Session["classID"].ToString().Trim()).Selected = true;

                keyWordList.DataSource = db.getDataTable("select * from keywordid where treeID=" + Session["classID"].ToString().Trim() + " order by listID ASC,id ASC");
                keyWordList.DataBind();
                keyWordList.Dispose();
            }
            else
            {
                this.classID.Items.FindByText("== 请选择分类 ==").Selected = true;
            }

            FormCheck fCheck = new FormCheck();
            startPriceRegExpre.ValidationExpression = fCheck.RegExpressionValidator("number", 0, 0, false);
            startPriceRegExpre.ErrorMessage = fCheck.RegExpressionValidator("number", 0, 0, true);
            endPriceRegExpre.ValidationExpression = fCheck.RegExpressionValidator("number", 0, 0, false);
            endPriceRegExpre.ErrorMessage = fCheck.RegExpressionValidator("number", 0, 0, true);
        }
    }

    protected void keywords_Click(object sender, EventArgs e)
    {
        string cID = classID.Text.Trim();
        Session.Add("classID", cID); //缓存

        string keyWord = keyword.Text.Trim();

        string strDim = "@treeID,@listID,@wordName,@keywords,@isTmall,@startPrice,@endPrice,@isBad,@updateDate,@postID,@postDate,@postIP,@useType";
        string[] strValue = new string[15];
        strValue[0] = cID.ToString();
        strValue[1] = "0";
        strValue[2] = wordName.Text;
        strValue[3] = keyWord;
        strValue[4] = isTmall.Text;
        strValue[5] = startPrice.Text;
        strValue[6] = endPrice.Text;
        strValue[7] = "0";
        strValue[8] = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss");
        strValue[9] = xc.adminID;
        strValue[10] = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
        strValue[11] = xc.GetIP();
        strValue[12] = useType.Text;

        DataTable dt = db.getDataTable("select * from keywordid where treeID=" + cID.ToString() + " and keyWords='" + keyWord + "'");
        if (dt.Rows.Count > 0)
        {
            db.InsertUpdateDB("keywordid", strDim, strValue, " id=" + dt.Rows[0]["id"].ToString().Trim());
        }
        else
        {
            db.InsertUpdateDB("keywordid", strDim, strValue, "");
        }
        dt.Dispose();

        Response.Redirect("keyWordAdd.aspx", true);
    }

    protected void classID_SelectedIndexChanged(object sender, EventArgs e)
    {
        string cID = classID.Text.Trim();
        Session.Add("classID", cID); //缓存

        keyWordList.DataSource = db.getDataTable("select * from keywordid where treeID=" + Session["classID"].ToString().Trim() + " order by listID ASC,id ASC");
        keyWordList.DataBind();
        keyWordList.Dispose();
    }
}