Exemple #1
0
        protected void gvAddress_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int id           = (int)e.Keys["Id"];
            var queryAddress = from address in eShop.UserShoppingAddress
                               where address.Id == id
                               select address;

            eShop.UserShoppingAddress.Remove(queryAddress.FirstOrDefault());
            eShop.SaveChanges();
            UserAddress_DataBind();
        }
Exemple #2
0
        //确认付款
        protected void btnSurePay_Click(object sender, EventArgs e)
        {
            decimal realPay = Convert.ToDecimal(this.txtPayNumber.Text.ToString());

            if (realPay >= Convert.ToDecimal(this.labPriceSum.Text))
            {
                int orderid        = int.Parse(Request.QueryString["id"]);
                var queryGoodState = from orderState in eShop.OrderState
                                     where orderState.Id == orderid
                                     select orderState;

                OrderState order = queryGoodState.FirstOrDefault();
                order.OrderState1 = 1;
                order.RealPay     = realPay;
                order.PayDate     = DateTime.Now;
                eShop.SaveChanges();
            }
        }
Exemple #3
0
        protected void gvEditGood_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            var goodsImg  = eShop.GoodsImg.Where(img => img.GoodId == (int)e.Keys["Id"]);
            var goodsInfo = eShop.GoodsInfo.Find((int)e.Keys["Id"]);

            foreach (GoodsImg img in goodsImg)
            {
                eShop.GoodsImg.Remove(img);
            }
            eShop.GoodsInfo.Remove(goodsInfo);
            eShop.SaveChanges();
        }
Exemple #4
0
        protected void gvGoodOrder_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            TextBox textBox = this.gvGoodOrder.Rows[e.RowIndex].FindControl("txtCourierNum") as TextBox;
            int     key     = (int)this.gvGoodOrder.DataKeys[e.RowIndex].Value;

            if (textBox.Text != null)
            {
                var orderState = eShop.OrderState.Find(key);
                orderState.CourierNum  = textBox.Text.Trim();
                orderState.SendDate    = DateTime.Now;
                orderState.OrderState1 = 2;
                eShop.SaveChanges();
                SellerUnsendOrder_DataBind();
            }
        }
Exemple #5
0
        protected void btnPostOrder_Click(object sender, EventArgs e)
        {
            if (this.rblUserAddress.SelectedValue != null)
            {
                //创建订单对象
                OrderState order = new OrderState();
                order.OrderNum    = DateTime.Now.ToString("yyyyMMddhhmmss") + ((Users)Session["User"]).Id;
                order.CreateDate  = DateTime.Now;
                order.OrderState1 = 0;
                order.AddressId   = int.Parse(this.rblUserAddress.SelectedValue);


                //创建商品订单对象
                string[] keys = Request.Cookies["ShoppingCart"].Values.AllKeys;
                foreach (string item in keys)
                {
                    GoodOrder goodOrder = new GoodOrder()
                    {
                        GoodId   = int.Parse(item),
                        GoodsNum = int.Parse(Request.Cookies["ShoppingCart"].Values[item])
                    };
                    order.GoodOrder.Add(goodOrder);
                }

                //添加用户订单
                int userid            = ((Users)Session["User"]).Id;
                var queryAddUserOrder = from user in eShop.Users
                                        where user.Id == userid
                                        select user;
                queryAddUserOrder.FirstOrDefault().OrderState.Add(order);
                eShop.SaveChanges();

                //清除所有购物车cookie
                Helper.CookieHelper.RemoveCookie();

                //软到支付页面
                Response.Redirect("/User/UserPayOrder.aspx?id=" + order.Id);
            }
            else
            {
                this.labMessege.Text = "请选择收货地址!";
            }
        }
Exemple #6
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            var query = from users in eShop.Users
                        where users.UserNum.Equals(this.txtUserNum.Text.Trim())
                        select users.UserNum;

            if (query.Count() == 0)
            {
                Users user = new Users();
                user.UserNum = this.txtUserNum.Text.Trim();

                string passwdMD5 = pwdMD5.PasswdMD5Locker.MD5Encrypt(this.txtUserPasswd.Text.Trim());
                if (pwdMD5.PasswdMD5Locker.MD5Verify(this.txtUserPasswd.Text.Trim(), passwdMD5))
                {
                    user.UserPasswd = passwdMD5;
                }

                user.UserName = this.txtUserName.Text.Trim();
                if (this.radSex.SelectedValue == "1")
                {
                    user.Gender = true;
                }
                else
                {
                    user.Gender = false;
                }

                user.Identification = this.txtUserIdentification.Text.Trim();
                user.Telephone      = this.txtUserTelephone.Text.Trim();

                eShop.Users.Add(user);
                eShop.SaveChanges();

                Response.Redirect("~/User/UserLogin.aspx");
            }
            else
            {
                this.labError.Text = "账户已存在!";
            }
        }
Exemple #7
0
        protected void btnGoodUpdate_Click(object sender, EventArgs e)
        {
            var goodInfo = eShop.GoodsInfo.Find(int.Parse(Request.QueryString["id"]));

            goodInfo.GoodName  = this.txtGoodName.Text.Trim();
            goodInfo.GoodPrice = Convert.ToDecimal(this.txtGoodPrice.Text.Trim());

            //如果checkbox选中则更新图片
            if (this.checkUploadImg.Checked == true)
            {
                //上传图片前的检查
                if (uploadImg.HasFile)
                {
                    string savePath = Server.MapPath("~/Images/Goods/");

                    //检查文件保存路径是否存在
                    if (!System.IO.Directory.Exists(savePath))
                    {
                        System.IO.Directory.CreateDirectory(savePath);
                    }

                    //判断文件是否合法
                    //读取合法文件列表
                    string[] allowExtension = ConfigurationManager.AppSettings["ImgType"].ToString().Split('|');
                    string   fileExtension  = System.IO.Path.GetExtension(uploadImg.FileName).ToLower();
                    bool     checkImg       = false;
                    foreach (string str in allowExtension)
                    {
                        if (fileExtension == str)
                        {
                            checkImg = true;
                            break;
                        }
                    }
                    //上传文件
                    if (checkImg)
                    {
                        try
                        {
                            this.uploadImg.PostedFile.SaveAs(savePath + uploadImg.FileName);
                            this.imgGoodImg.Src    = savePath + uploadImg.FileName;
                            this.labUploadImg.Text = "上传成功!";

                            //更新图片链接
                            goodInfo.GoodsImg.Where(img => img.ImgLevel == 0).FirstOrDefault().ImgUrl = "/Images/Goods/" + this.uploadImg.FileName;
                        }
                        catch
                        {
                            this.labUploadImg.Text = "上传失败!";
                        }
                    }
                    else
                    {
                        this.labUploadImg.Text = "文件扩展名不合法";
                    }
                }
            }

            goodInfo.Remark    = this.txtRemark.Text.Trim();
            goodInfo.AddedDate = DateTime.Now;

            try
            {
                eShop.SaveChanges();
                this.labMessenge.Text = "商品数据更新成功!";
            }
            catch
            {
                this.labMessenge.Text = "更新发生错误,数据未改变!";
            }
        }
Exemple #8
0
        protected void btnGoodAdd_Click(object sender, EventArgs e)
        {
            //图片上传
            //判断是否有文件上传
            if (uploadImg.HasFile)
            {
                string savePath = Server.MapPath("~/Images/Goods/");

                if (!System.IO.Directory.Exists(savePath))
                {
                    System.IO.Directory.CreateDirectory(savePath);
                }

                //判断文件是否合法
                //读取合法文件列表
                string[] allowExtension = ConfigurationManager.AppSettings["ImgType"].ToString().Split('|');
                string   fileExtension  = System.IO.Path.GetExtension(uploadImg.FileName).ToLower();
                bool     checkImg       = false;
                foreach (string str in allowExtension)
                {
                    if (fileExtension == str)
                    {
                        checkImg = true;
                        break;
                    }
                }
                //上传文件
                if (checkImg)
                {
                    try
                    {
                        this.uploadImg.PostedFile.SaveAs(savePath + uploadImg.FileName);
                        this.labUploadImg.Text = "上传成功!";
                    }
                    catch
                    {
                        this.labUploadImg.Text = "上传失败!";
                    }
                }
                else
                {
                    this.labUploadImg.Text = "文件扩展名不合法";
                }
            }
            GoodsImg goodImg = new GoodsImg();

            goodImg.ImgLevel = 0;
            goodImg.ImgUrl   = "/Images/Goods/" + this.uploadImg.FileName;

            GoodsInfo good = new GoodsInfo();

            good.GoodName  = this.txtGoodName.Text.Trim();
            good.GoodPrice = Convert.ToDecimal(this.txtGoodPrice.Text.Trim());
            good.GoodsImg.Add(goodImg);
            good.Remark    = this.txtRemark.Text.Trim();
            good.AddedDate = DateTime.Now;
            good.AdderId   = ((Sellers)Session["Seller"]).Id;

            eShop.GoodsInfo.Add(good);
            eShop.SaveChanges();
        }