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

public partial class goods_updategoods : System.Web.UI.Page
{
    SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["constring"].ConnectionString);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string strnumber, Classificationname,strwpms;
            int intstate, intClassificationid;
            strnumber = Request.QueryString["name"];
            labid.Text = strnumber;
            string strSQL = "select GoodsName,Goodprice,State,Classificationid,Classificationname,wpms  from v_tabG_Goods where Gid = '" + Convert.ToInt32(strnumber) + "'";
            SqlCommand com = new SqlCommand(strSQL, sqlcon);
            sqlcon.Open();
            SqlDataReader dr = com.ExecuteReader();
            while (dr.Read())
            {
                Texname.Text = ConvertHelper.GetString(dr["GoodsName"]);
                Textprice.Text = ConvertHelper.GetString(dr["Goodprice"]);
                intstate = ConvertHelper.GetInteger(dr["State"]);
                Classificationname = ConvertHelper.GetString(dr["Classificationname"]);
                intClassificationid = ConvertHelper.GetInteger(dr["Classificationid"]);
                Textwpms.Text = ConvertHelper.GetString(dr["wpms"]);

                if (intstate == 1)
                {
                    Radio1.Checked = true;
                }
                else
                {
                    Radio2.Checked = true;
                }
                
                this.DropDownList1.Items.Insert(0, new ListItem(Classificationname, intClassificationid.ToString()));
            }
            dr.Close();
            string strSQL1 = "select Classificationname,Classificationid from tabG_Classification where State = 0 ";
            SqlCommand comd = new SqlCommand(strSQL1, sqlcon);
            SqlDataReader dr1 = comd.ExecuteReader();
           
           
            int i;
            string strids, strids1;
            i = 1;
            while (dr1.Read())
            {
                strids1 = DropDownList1.Items[0].ToString();
                strids = ConvertHelper.GetString(dr1["Classificationname"]);
                if (strids == strids1)
                {

                }
                else
                {
                    this.DropDownList1.Items.Insert(i, new ListItem(dr1["Classificationname"].ToString(), dr1["Classificationid"].ToString()));
                    i++;
                }
            }
            sqlcon.Close();
        }

    }
    protected void Btnok_Click(object sender, EventArgs e)
    {
        string strwpms;
        strwpms = Textwpms.Text;
        if (Texname.Text == "")
        {
            Response.Write("<script>alert('物品名称不能为空！')</script>");
            return;
        }
        if (Textprice.Text == "")
        {
            Response.Write("<script>alert('物品价格不能为空！')</script>");
            return;
        }
        string strname;
        decimal decprice;
        int intfenlei;
        int intstate;
        strname = Texname.Text;
        decprice = ConvertHelper.GetDecimal(Textprice.Text);
        intfenlei = ConvertHelper.GetInteger(DropDownList1.SelectedValue);
        if (Radio1.Checked == true)
        {
            intstate = 1;
        }
        else
        {
            intstate = 0;
        }
        string strsq;
        strsq = "update tabG_Goods set GoodsName='" + strname + "', Goodprice ='" + decprice + "',Classificationid ='" + intfenlei + "',State ='" + intstate + "',wpms='" + strwpms + "' where Gid ='" + Convert.ToInt32(labid.Text) + "'";
        SqlCommand sqlcmd = new SqlCommand(strsq, sqlcon);
        sqlcon.Open();
        sqlcmd.ExecuteScalar();
        sqlcon.Close();
        Response.Redirect("goods.aspx");
    }
    protected void btncz_Click(object sender, EventArgs e)
    {
        Response.Redirect("goods.aspx");
    }

}