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_keyWordEdit : 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);

            DataTable dt = db.getDataTable("select * from keywordid where id=" + xc.SafeNum(Request.QueryString["id"]).ToString());
            if (dt.Rows.Count > 0)
            {
                string treeID = dt.Rows[0]["treeID"].ToString();
                this.classID.Items.FindByValue(treeID).Selected = true;
                keyWordList.DataSource = db.getDataTable("select * from keywordid where treeID=" + treeID + " order by listID ASC,id ASC");
                keyWordList.DataBind();
                keyWordList.Dispose();

                wordName.Text = dt.Rows[0]["wordName"].ToString().Trim();
                keyword.Text = dt.Rows[0]["keywords"].ToString().Trim();
                this.isTmall.Items.FindByValue(dt.Rows[0]["isTmall"].ToString().Trim()).Selected = true;
                this.isBad.Items.FindByValue(dt.Rows[0]["isBad"].ToString().Trim()).Selected = true;
                this.useType.Items.FindByValue(dt.Rows[0]["useType"].ToString().Trim()).Selected = true;
                startPrice.Text = dt.Rows[0]["startPrice"].ToString().Trim();
                endPrice.Text = dt.Rows[0]["endPrice"].ToString().Trim();
            }
            dt.Dispose();            

            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] = isBad.Text;
        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;

        db.InsertUpdateDB("keywordid", strDim, strValue, " id=" + xc.SafeNum(Request.QueryString["id"]).ToString());

        Response.Redirect("keyWord.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();
    }
}