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

namespace TtNum1.team_buying
{
    public partial class goods : System.Web.UI.Page
    {
        TtNum1.BLL.GoodsInfo bllgoodsinfo = new TtNum1.BLL.GoodsInfo();
        TtNum1.Model.GoodsInfo modgoodsinfo = new TtNum1.Model.GoodsInfo();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["Goods_ID"] == null)
                {
                    Response.Write("<script>window.alert('您没有选择公告，无法传值');window.location=index.aspx;</script>");
                }
                else
                {
                   
                  
                    ViewState["BackUrl"] = Request.UrlReferrer.ToString();
                    string a = Request.QueryString["Goods_ID"].ToString();
                    modgoodsinfo = bllgoodsinfo.GetModel(Convert.ToInt16(a));
                    Goods_ID.Text = modgoodsinfo.Goods_ID.ToString();
                    DataTable dt = bllgoodsinfo.GetList1(a).Tables[0];
                    if (dt.Rows.Count > 0)
                    {
                        Goods_ID.Text = dt.Rows[0]["Goods_ID"].ToString();
                        Goods_name.Text = dt.Rows[0]["Goods_name"].ToString();
                        
                        Market_price.Text = dt.Rows[0]["Market_price"].ToString();
                       
                        In_store_price.Text = dt.Rows[0]["In_store_price"].ToString();
                        
                        Stock.Text = dt.Rows[0]["Stock"].ToString();
                        
                        Image1.ImageUrl = dt.Rows[0]["Goods_pic"].ToString();
                        Image2.ImageUrl = dt.Rows[0]["Goods_pic"].ToString();
                        Goods_info.Text = dt.Rows[0]["Goods_info"].ToString();
                       
                        Good_Brand.Text = dt.Rows[0]["Good_Brand"].ToString();
                      
                        Qqp.Text = dt.Rows[0]["Qqp"].ToString();
                        TextBox12.Text = dt.Rows[0]["Qqp"].ToString();
                        if (dt.Rows[0]["IN_group_buying"].ToString() == "1")
                        {
                            IN_group_buying.Text = "是";
                           
                        }
                        else
                        {
                            IN_group_buying.Text = "否";
                           
                        }
                        Sales_volume.Text = dt.Rows[0]["Sales_volume"].ToString();
                        TextBox9.Text = dt.Rows[0]["Sales_volume"].ToString();
                        if (dt.Rows[0]["Group_Buying_Price"].ToString() == "" || dt.Rows[0]["Group_Buying_Price"].ToString() == null)
                        {
                            Group_Buying_Price.Text = "该商品未设置团购信息";
                        }
                        else
                        {
                            Group_Buying_Price.Text = dt.Rows[0]["Group_Buying_Price"].ToString();
                        }

                        TextBox10.Text = dt.Rows[0]["Group_Buying_Price"].ToString();
                        GS1.Text = dt.Rows[0]["Sort_name"].ToString();
                       
                        GS2.Text = dt.Rows[0]["GS_name1"].ToString();

                        Image3.ImageUrl = dt.Rows[0]["Img_1"].ToString();
                        Image4.ImageUrl = dt.Rows[0]["Img_1"].ToString();
                        Image5.ImageUrl = dt.Rows[0]["Img_2"].ToString();
                        Image6.ImageUrl = dt.Rows[0]["Img_2"].ToString();
                       
                        uptime.Text = dt.Rows[0]["uptime"].ToString();
                    }
                }

            }
        }

        protected void RadButton2_Click1(object sender, EventArgs e)
        {
           // Response.Write("<script>history.back(-1)</script>"); 
            Response.Redirect(ViewState["BackUrl"].ToString());
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["TtNum"].ConnectionString;
            SqlConnection conn = new SqlConnection(connectionString);

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = new SqlCommand("select * from GoodSort2 where GoodSort2.GS_ID='" + DropDownList1.SelectedValue + "'", conn);
            DataSet ds = new DataSet();
            try
            {
                conn.Open();
                da.Fill(ds, "GoodSort2");
                conn.Close();
            }
            catch (SqlException e2)
            {
                Response.Write(e2.ToString());
            }
            PagedDataSource obj = new PagedDataSource();
            obj.DataSource = ds.Tables["GoodSort2"].DefaultView;
            DropDownList2.DataSource = obj;
            this.DropDownList2.DataTextField = "Sort_name";
            this.DropDownList2.DataValueField = "Sort_ID";
            DropDownList2.DataBind();
           
        }

    
    }
}