Esempio n. 1
0
        public CartItem Add(int customerId, int productId, int qty)
        {
            CartItem cartItem = null;
            Product  product  = (from p in db.Product
                                 where p.ProductId == productId
                                 select p).First();

            cartItem            = new CartItem();
            cartItem.CustomerId = customerId;
            cartItem.ProId      = product.ProductId;
            cartItem.ProName    = product.Name;
            cartItem.ListPrice  = product.ListPrice.Value;
            cartItem.Qty        = qty;
            int ExistCartItemCount = (from c in db.CartItem
                                      where c.CustomerId == customerId && c.ProId == productId
                                      select c).Count();

            if (ExistCartItemCount > 0)
            {
                CartItem existCartItem = (from c in db.CartItem
                                          where c.CustomerId == customerId && c.ProId == productId
                                          select c).First();
                existCartItem.Qty += qty;
            }
            else
            {
                db.CartItem.InsertOnSubmit(cartItem);
            }
            db.SubmitChanges();
            return(cartItem);
        }
Esempio n. 2
0
        public void ChangePassword(int customerId, string password)
        {
            Customer customer = (from c in db.Customer
                                 where c.CustomerId == customerId
                                 select c).First();

            customer.Password = password;
            db.SubmitChanges();
        }
Esempio n. 3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        Category category = new Category();

        category.Name  = TextBox1.Text;
        category.Descn = TextBox2.Text;
        db.Category.InsertOnSubmit(category);
        db.SubmitChanges();
        Bind();
    }
    protected void BtnInsert_Click(object sender, EventArgs e)
    {
        Category category = new Category(); //建立Category实例category

        category.Name  = txtName.Text;
        category.Descn = txtDescn.Text;
        db.Category.InsertOnSubmit(category); //插入实体category
        db.SubmitChanges();                   //提交更改
        Bind();                               //调用自定义方法,用于在gvCategory中显示最新结果
    }
Esempio n. 5
0
        public void InsertCategory(int categoryId, string name, string descn)
        {
            Category category = new Category();

            category.CategoryId = categoryId;
            category.Name       = name;
            category.Descn      = descn;
            db.Category.InsertOnSubmit(category);
            db.SubmitChanges();
        }
Esempio n. 6
0
    protected void BtnInsert_Click(object sender, EventArgs e)
    {
        Category category = new Category
        {
            Name  = txtName.Text,
            Descn = txtDescn.Text
        };

        db.Categories.InsertOnSubmit(category);
        db.SubmitChanges();
        Bind();
    }
Esempio n. 7
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        MyPetShopDataContext db = new MyPetShopDataContext();
        //在Order表中添加记录
        Order order = new Order();

        order.UserName  = User.Identity.Name;
        order.OrderDate = DateTime.Now;
        order.Addr1     = txtAddr1.Text.Trim();
        order.Addr2     = txtAddr2.Text.Trim();
        order.City      = txtCity.Text.Trim();
        order.State     = txtState.Text.Trim();
        order.Zip       = txtZip.Text.Trim();
        order.Phone     = txtPhone.Text.Trim();
        order.Status    = "未审核";
        db.Order.InsertOnSubmit(order);
        db.SubmitChanges();

        //在OrderItem中添加记录
        int orderId = order.OrderId;

        for (int i = 0; i < Profile.Cart.ProName.Count; i++)
        {
            OrderItem orderItem = new OrderItem();
            orderItem.OrderId    = orderId;
            orderItem.ProName    = (string)Profile.Cart.ProName[i];
            orderItem.ListPrice  = (decimal)Profile.Cart.ListPrice[i];
            orderItem.Qty        = (int)Profile.Cart.Qty[i];
            orderItem.TotalPrice = (int)Profile.Cart.Qty[i] * (decimal)Profile.Cart.ListPrice[i];

            //修改Product表的商品库存
            var product = (from p in db.Product
                           where p.ProductId == (int)Profile.Cart.ProId[i]
                           select p).First();
            product.Qty -= orderItem.Qty;

            db.OrderItem.InsertOnSubmit(orderItem);
            db.SubmitChanges();
        }

        //清空各数组列表对象
        Profile.Cart.Qty.Clear();
        Profile.Cart.ProName.Clear();
        Profile.Cart.ProId.Clear();
        Profile.Cart.ListPrice.Clear();
        Profile.Cart.TotalPrice = "";
        pnlConsignee.Visible    = false;
        lblMsg.Text             = "已经成功结算,谢谢光临!";
    }
Esempio n. 8
0
        public void InsertSupplier(int suppId, string name, string addr1, string addr2, string city, string state, string zip, string phone)
        {
            Supplier supplier = new Supplier();

            supplier.SuppId = suppId;
            supplier.Name   = name;
            supplier.Addr1  = addr1;
            supplier.Addr2  = addr2;
            supplier.City   = city;
            supplier.State  = state;
            supplier.Zip    = zip;
            supplier.Phone  = phone;
            db.Supplier.InsertOnSubmit(supplier);
            db.SubmitChanges();
        }
Esempio n. 9
0
        public void Add(string imageFile, string name, int categoryId, int supplierId, decimal listPrice, decimal unitCost, string descn, int qty)
        {
            Product product = new Product();

            product.Image      = imageFile;
            product.Name       = name;
            product.CategoryId = categoryId;
            product.SuppId     = supplierId;
            product.ListPrice  = listPrice;
            product.UnitCost   = unitCost;
            product.Descn      = descn;
            product.Qty        = qty;
            db.Product.InsertOnSubmit(product);
            db.SubmitChanges();
        }
Esempio n. 10
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["ProductId"] != null)
        {
            int productId = int.Parse(Request.QueryString["ProductId"]);
            var product   = (from p in db.Product
                             where p.ProductId == productId
                             select p).First();
            product.Name       = txtName.Text.Trim();
            product.CategoryId = int.Parse(ddlCategoryId.SelectedValue);
            product.SuppId     = int.Parse(ddlSuppId.SelectedValue);
            product.ListPrice  = decimal.Parse(txtListPrice.Text.Trim());
            product.UnitCost   = decimal.Parse(txtUnitCost.Text.Trim());
            product.Descn      = txtDescn.Text.Trim();
            product.Qty        = int.Parse(txtQty.Text.Trim());

            //如果有上传文件,就删除原来的图片,保存上传的图片
            if (fupImage.PostedFile.ContentLength != 0)
            {
                string filePath = Server.MapPath("~/") + product.Image.Substring(2);
                File.Delete(filePath);
                fupImage.PostedFile.SaveAs(filePath);
            }
            db.SubmitChanges();
            //清空页面缓存
            Response.Buffer = true;
            //重定向到Admin文件夹中的Default.aspx
            Response.Redirect("ProductMaster.aspx");
        }
    }
Esempio n. 11
0
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        var category = (from c in db.Category where c.CategoryId == int.Parse(txtCategoryId.Text) select c).First();

        category.Name  = txtName.Text;
        category.Descn = txtDescn.Text;
        db.SubmitChanges();
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        var results = from c in db.Category where c.CategoryId == int.Parse(txtCategoryId.Text) select c;

        db.Category.DeleteAllOnSubmit(results);
        db.SubmitChanges();
        Bind();
    }
Esempio n. 13
0
    /// <summary>
    /// 将指定orderId的订单状态设置为“已审核”
    /// </summary>
    /// <param name="orderId">订单编号</param>
    protected void UpdataOrder(int orderId)
    {
        var order = (from o in db.Order
                     where o.OrderId == orderId
                     select o).First();

        order.Status = "已审核";
        db.SubmitChanges();
    }
    protected void btnInsert_Click(object sender, EventArgs e)
    {
        MyPetShopDataContext db       = new MyPetShopDataContext();
        Category             category = new Category();

        category.Name  = txtName.Text;
        category.Descn = txtDescn.Text;
        db.Category.InsertOnSubmit(category);
        db.SubmitChanges();
    }
Esempio n. 15
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        MyPetShopDataContext db       = new MyPetShopDataContext();
        Category             category = new Category();

        category.Name  = TextBox1.Text;
        category.Descn = TextBox2.Text;
        db.Category.InsertOnSubmit(category);
        db.SubmitChanges();
        GridView1.DataBind();
    }
Esempio n. 16
0
    protected void BtnUpdate_Click(object sender, EventArgs e)
    {
        MyPetShopDataContext db = new MyPetShopDataContext();
        var category            = (from r in db.Category
                                   where r.CategoryId == int.Parse(txtCategoryId.Text)
                                   select r).First();

        category.Name  = txtName.Text;
        category.Descn = txtDescn.Text;
        db.SubmitChanges();
        Response.Redirect("~/Chap8/GridUpdate.aspx");
    }
Esempio n. 17
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        MyPetShopDataContext db = new MyPetShopDataContext();
        var category            = (from r in db.Category
                                   where r.CategoryId == int.Parse(TextBox1.Text)
                                   select r).First();

        category.Name  = TextBox2.Text;
        category.Descn = TextBox3.Text;
        db.SubmitChanges();
        Response.Redirect("~/GridUpdate.aspx");
    }
Esempio n. 18
0
 public void CreateOrderFromCart(int customertId, string customerName, string addr1, string addr2, string city, string state, string zip, string phone)
 {
     using (TransactionScope ts = new TransactionScope())
     {
         List <CartItem> cartItemList = (from c in db.CartItem
                                         where c.CustomerId == customertId
                                         select c).ToList();
         Order order = new Order();
         order.CustomerId = customertId;
         order.UserName   = customerName;
         order.OrderDate  = DateTime.Now;
         order.Addr1      = addr1;
         order.Addr2      = addr2;
         order.City       = city;
         order.State      = state;
         order.Zip        = zip;
         order.Phone      = phone;
         order.Status     = "未审核";
         OrderItem orderItem = null;
         Product   product   = null;
         foreach (CartItem cartItem in cartItemList)
         {
             orderItem            = new OrderItem();
             orderItem.OrderId    = order.OrderId;
             orderItem.ProName    = cartItem.ProName;
             orderItem.ListPrice  = cartItem.ListPrice;
             orderItem.Qty        = cartItem.Qty;
             orderItem.TotalPrice = cartItem.Qty * cartItem.ListPrice;
             order.OrderItem.Add(orderItem);
             product = (from p in db.Product
                        where p.ProductId == cartItem.ProId
                        select p).First();
             product.Qty = product.Qty - cartItem.Qty;
             db.CartItem.DeleteOnSubmit(cartItem);
         }
         db.Order.InsertOnSubmit(order);
         db.SubmitChanges();
         ts.Complete();
     }
 }
Esempio n. 19
0
    /// <summary>
    /// 删除指定商品编号的产品信息
    /// </summary>
    /// <param name="productId">指定的商品编号</param>
    protected void DeletePro(int productId)
    {
        var product = (from p in db.Product
                       where p.ProductId == productId
                       select p).First();
        string filePath = Server.MapPath("~") + product.Image.Substring(1);

        if (File.Exists(filePath))
        {
            File.Delete(filePath);
        }
        db.Product.DeleteOnSubmit(product);
        db.SubmitChanges();
    }
Esempio n. 20
0
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (IsExitProduct(txtName.Text.Trim())) //输入的商品名已存在
        {
            lblNameErr.Text = "商品已经存在";
        }
        else //添加商品到Product表
        {
            Product product = new Product();
            string  fileName;
            string  fileFolder;
            string  dateTime = "";
            fileName   = Path.GetFileName(fupImage.PostedFile.FileName);
            dateTime  += DateTime.Now.Year.ToString();
            dateTime  += DateTime.Now.Month.ToString();
            dateTime  += DateTime.Now.Day.ToString();
            dateTime  += DateTime.Now.Hour.ToString();
            dateTime  += DateTime.Now.Minute.ToString();
            dateTime  += DateTime.Now.Second.ToString();
            fileName   = dateTime + fileName;
            fileFolder = Server.MapPath("~/") + "Prod_Images\\" + ddlCategoryId.SelectedItem.Text + "\\";
            fileFolder = fileFolder + fileName;
            fupImage.PostedFile.SaveAs(fileFolder);

            product.Image      = "~\\Prod_Images\\" + ddlCategoryId.SelectedItem.Text + "\\" + fileName;
            product.Name       = txtName.Text.Trim();
            product.CategoryId = int.Parse(ddlCategoryId.SelectedValue);
            product.SuppId     = int.Parse(ddlSuppId.SelectedValue);
            product.ListPrice  = decimal.Parse(txtListPrice.Text.Trim());
            product.UnitCost   = decimal.Parse(txtUnitCost.Text.Trim());
            product.Descn      = txtDescn.Text.Trim();
            product.Qty        = int.Parse(txtQty.Text.Trim());

            db.Product.InsertOnSubmit(product);
            db.SubmitChanges();
            Response.Redirect("ProductMaster.aspx");
        }
    }