Esempio n. 1
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     String name = TextBox1.Text.Trim();
     decimal price = Convert.ToDecimal(TextBox2.Text.Trim());
     decimal marketprice = Convert.ToDecimal(TextBox3.Text.Trim());
     int qty = Convert.ToInt32(TextBox4.Text.Trim());
     int brandId = Convert.ToInt32(DropDownList1.SelectedValue);
     int genderId = Convert.ToInt32(DropDownList2.SelectedValue);
     int id;
     using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
     {
         Cloth cloth = new Cloth();
         cloth.Name = name;
         cloth.Price = price;
         cloth.OriginalPrice = marketprice;
         cloth.Qty = qty;
         cloth.BrandId = brandId;
         cloth.GenderId = genderId;
         context.AddToClothes(cloth);
         context.SaveChanges();
         id = cloth.Id;
         foreach (ListItem item in CheckBoxList1.Items)
         {
             if (item.Selected)
             {
                 ClothSzie size = new ClothSzie();
                 size.Cloth = cloth;
                 size.SizeId = Convert.ToInt32(item.Value);
                 context.AddToClothSzies(size);
             }
         }
         context.SaveChanges();
         foreach (ListItem item in CheckBoxList2.Items)
         {
             if (item.Selected)
             {
                 ColthColor color = new ColthColor();
                 color.Cloth = cloth;
                 color.ColorId = Convert.ToInt32(item.Value);
                 context.AddToColthColors(color);
             }
         }
         context.SaveChanges();
     }
     Response.Redirect(String.Format("~/AddClothStep2.aspx?id={0}", id));
 }
Esempio n. 2
0
 /// <summary>
 /// Create a new Cloth object.
 /// </summary>
 /// <param name="id">Initial value of the Id property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="price">Initial value of the Price property.</param>
 /// <param name="qty">Initial value of the Qty property.</param>
 /// <param name="originalPrice">Initial value of the OriginalPrice property.</param>
 /// <param name="brandId">Initial value of the BrandId property.</param>
 /// <param name="genderId">Initial value of the GenderId property.</param>
 public static Cloth CreateCloth(global::System.Int32 id, global::System.String name, global::System.Decimal price, global::System.Int32 qty, global::System.Decimal originalPrice, global::System.Int32 brandId, global::System.Int32 genderId)
 {
     Cloth cloth = new Cloth();
     cloth.Id = id;
     cloth.Name = name;
     cloth.Price = price;
     cloth.Qty = qty;
     cloth.OriginalPrice = originalPrice;
     cloth.BrandId = brandId;
     cloth.GenderId = genderId;
     return cloth;
 }
Esempio n. 3
0
 /// <summary>
 /// Deprecated Method for adding a new object to the Clothes EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToClothes(Cloth cloth)
 {
     base.AddObject("Clothes", cloth);
 }
Esempio n. 4
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //检查当前用户类型是否为注册用户
            if (((Site1)Page.Master).CurrentUserType == UserType.RegUser)
            {
                //如果是
                //隐藏编辑按钮
                ModifyButton.Visible = false;
                //隐藏删除按钮
                DeleteButton.Visible = false;
            }
            else if (((Site1)Page.Master).CurrentUserType == UserType.Admin)
            {
                //否则,显示"添加到购物车"按钮
                AddToCartButton.Visible = false;
            }
            else
            {
                //隐藏编辑按钮
                ModifyButton.Visible = false;
                //隐藏删除按钮
                DeleteButton.Visible = false;
                AddToCartButton.Visible = false;
            }
            if (!IsPostBack)
            {

                using (LiBoClothesShopEntities context = new LiBoClothesShopEntities())
                {
                    //获取该商品的信息
                    var query = from product in context.Clothes
                                where product.Id == ProductId
                                select product;
                    //如果找不到该软件
                    if (query.Count() == 0)
                    {
                        //显示"找不到"
                        Table1.Visible = false;
                        MessageLabel.Visible = true;
                        MessageLabel.Text = "找不到这个服装";
                    }
                    else
                    {
                        //否则
                        //当前商品为查询结果的第一个
                        CurrentProduct = query.First();
                        //显示商品的信息
                        NameLabel.Text = CurrentProduct.Name;
                        PriceLabel.Text = ((Site1)Page.Master).PriceFormater(CurrentProduct.Price);
                        MarketPriceLabel.Text = ((Site1)Page.Master).PriceFormater(CurrentProduct.OriginalPrice);
                        BrandLabel.Text = CurrentProduct.Brand.Name;
                        GenderLabel.Text = CurrentProduct.GenderInfo.Name;
                        var query2 = from p in CurrentProduct.ColthColors
                                     select new
                                     {
                                         ColorId = p.ColorId,
                                         ColorName = p.ColorInfo.Name
                                     };
                        DropDownListColor.DataSource = query2;
                        DropDownListColor.DataTextField = "ColorName";
                        DropDownListColor.DataValueField = "ColorId";
                        DropDownListColor.DataBind();

                        var query3 = from p in CurrentProduct.ClothSzies
                                     select new
                                     {
                                         SizeId = p.SizeId,
                                         SizeName = p.SizeInfo.Name
                                     };
                        DropDownListSize.DataSource = query3;
                        DropDownListSize.DataTextField = "SizeName";
                        DropDownListSize.DataValueField = "SizeId";
                        DropDownListSize.DataBind();

                        Label1.Text = "<table>";
                        foreach (ColthColor c in CurrentProduct.ColthColors)
                        {
                            Label1.Text += "<tr><td><img src='./Upload/";
                            Label1.Text += c.PicFileName;
                            Label1.Text += "' /></td></tr><tr><td>";
                            Label1.Text += c.ColorInfo.Name;
                            Label1.Text += "</td></tr>";
                        }
                        Label1.Text += "</table>";
                    }
                }
            }
        }