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 System.Data.SqlClient;
namespace norke
{
    public partial class viste_qqproductedit : System.Web.UI.Page
    {       
        protected void Page_Load(object sender, EventArgs e)
        {
              //权限检查
            HttpCookie cookie = Request.Cookies["norkeyangjian"];
            if (cookie == null)
            {
                Response.Redirect("~/login.aspx");
                return;
            }

            if( !IsPostBack )
            {
                try
                {
                    getCategory();
                    read();
                }
                catch 
                {
                    Response.Redirect("Error.aspx");
                }
        }
        }
        private void getCategory()//绑定类别下拉列表
        {
            DBConn myDB = new DBConn();
            string sql="select * from Category";
            ddlCategory.DataSource  = myDB.getDataReader(sql);
            ddlCategory.DataTextField = "CName";
            ddlCategory.DataValueField = "CID";
            ddlCategory.DataBind();
            myDB.Close();
        }
        public void read()
        {            
            string sql = "select * from qqproduct where uname='" + Request.Cookies["norkeyangjian"].Value+ "' and qid=" + Request.QueryString["id"].ToString();
            DBConn mydb = new DBConn();
            SqlDataReader dr= mydb.getDataReader(sql);
            if (dr.Read())
            {
                txtName.Text = dr["qname"].ToString();
                ddlCategory.SelectedIndex = Convert.ToInt32(dr["qlb"].ToString());
                txtNPrice.Text = dr["qjiage"].ToString();
                txtFPrice.Text = dr["qxh"].ToString();
                txtBewrite.Text = dr["qjs"].ToString();            

            }
            dr.Close();
            mydb.Close();
        }
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            try
            {
                string sql = "update qqproduct set qname='" + txtName.Text + "',qlb='" + ddlCategory.SelectedValue + "',qjiage='" + txtNPrice.Text + "',qxh='" + txtFPrice.Text + "',qjs='" + txtBewrite.Text + "' where uname='" + Request.Cookies["norkeyangjian"].Value+ "' and qid="+Request.QueryString["id"].ToString();
                DBConn mydb = new DBConn();
                mydb.Update(sql);
                mydb.Close();
                Response.Redirect("qqproductmanager.aspx");
            }
            catch
            { 
            }
        }
        protected void btnReset_Click(object sender, EventArgs e)
        {

        }
}
}
