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_newfoods : PageBase
{
    SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["constring"].ConnectionString);


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            int i = 0;
            string strSQL = "select Classificationname,Classificationid from tabG_Classification where State = 0";
            SqlCommand com = new SqlCommand(strSQL, sqlcon);
            sqlcon.Open();

            SqlDataReader dr = com.ExecuteReader();

            //this.DropDownList1.Items.Insert(i, new ListItem("123", "456"));



            while (dr.Read())
            {

                //this.DropDownList1.Items.Add(dr["Classificationname"].ToString());
                this.DropDownList1.Items.Insert(i, new ListItem(dr["Classificationname"].ToString(), dr["Classificationid"].ToString()));
                i++;
            }
            sqlcon.Close();
        }

    }
    protected void btncz_Click(object sender, EventArgs e)
    {
        Texname.Text = "";
        Textprice.Text = "";
    }
    protected void Btnok_Click(object sender, EventArgs e)
    {
        
              string strwpms = TextBox1.Text;

        if (Texname.Text == "" || Texname.Text == null)
        {
            Response.Write("<script>alert('物品名称不能为空！')</script>");
            return;

        }
        if (Textprice.Text == "" || Textprice.Text == null)
        {
            Response.Write("<script>alert('物品价格不能为空！')</script>");
            return;

        }
        try
        {
            decimal var1 = ConvertHelper.GetDecimal(Textprice.Text);

        }
        catch
        {
            Response.Write("<script>alert('物品价格输入错误！')</script>");
            return;
        }

        int intleixingid = Convert.ToInt32(DropDownList1.SelectedValue.ToString());

        string struer = Session["uid"].ToString();
        string strname = Texname.Text;
        decimal decprice = Convert.ToDecimal(Textprice.Text);
        int intstate, intlx;
        if (Radio1.Checked == true)
        {
            intstate = 1;
        }
        else
        {
            intstate = 0;
        }
        if (RadioButton3.Checked == true)
        {
            intlx = 1;
        }
        else
        {
            intlx = 0;
        }

        string sql = "INSERT INTO tabG_Goods( GoodsName,Goodprice,State,HandlerId,Classificationid,hclx,wpms ) values( '" + strname + "','" + decprice + "','" + intstate + "','" + struer + "','" + intleixingid + "','" + intlx + "','" + strwpms + "')";

        SqlCommand cmd = new SqlCommand(sql, sqlcon);
        sqlcon.Open();
        cmd.ExecuteNonQuery();
        sqlcon.Close();
        Response.Write("<script>alert('添加成功！')</script>");
        Response.Redirect("goods.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("goods.aspx");
    }
}
