protected void btndangki_Click(object sender, EventArgs e) { TenDangNhap = Request.QueryString["TenDangNhap"]; var kh = db.tbl_KhachHangs.Where(x => x.TaiKhoan == TenDangNhap).First(); if (txtpassword.Text != "" && txtrepressPassword.Text != "" && txtrepressPassword.Text == txtpassword.Text) { kh.MatKhau = txtpassword.Text; } kh.tenKH = txthovaten.Text; if (rdobtnNam.Checked == true) { kh.GioiTinh = true; } else { kh.GioiTinh = false; } kh.NgaySinh = Convert.ToDateTime(txtngaysinh.Text); kh.SDT = txtdienthoai.Text.Trim(); kh.Tinh = ddlthanhpho.SelectedItem.ToString(); kh.Quan = ddlquan.SelectedItem.ToString(); kh.DiaChi = txtdiachi.Text.Trim(); db.SubmitChanges(); Response.Write("<script>alert('Cật nhật thành công')</script>"); Response.Redirect("TrangChu.aspx"); }
protected void Page_Load(object sender, EventArgs e) { remenu.DataSource = NhomHangService.NhomHang_GetByTop("", " Active='True'", ""); remenu.DataBind(); tbl_KhachHang kh = new tbl_KhachHang(); GoogleConnect.ClientId = "520808312902-5al7h79mvjmk9jil2du85jenb6stla5q.apps.googleusercontent.com"; GoogleConnect.ClientSecret = "QF8LkNiAPNTvAvbJJvQqTR9E"; GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0]; if (!string.IsNullOrEmpty(Request.QueryString["code"])) { string code = Request.QueryString["code"]; string json = GoogleConnect.Fetch("me", code); GoogleProfile profile = new JavaScriptSerializer().Deserialize <GoogleProfile>(json); Session["TenDangNhap"] = profile.Id; Session["display_name"] = profile.DisplayName; Session["email"] = profile.Emails.Find(email => email.Type == "account").Value; kh.TaiKhoan = profile.Id; kh.Email = profile.Emails.Find(email => email.Type == "account").Value.ToString(); kh.tenKH = profile.DisplayName; var a = from i in db.tbl_KhachHangs where i.TaiKhoan == profile.Id select i; if (a.Count() <= 0) { db.tbl_KhachHangs.InsertOnSubmit(kh); db.SubmitChanges(); } Response.Redirect("TrangChu.aspx"); } if (Request.QueryString["error"] == "access_denied") { ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true); } }
protected void btnSave_Top_Click(object sender, EventArgs e) { Entity.SanPham dts = new Entity.SanPham(); tbl_Hang dt = new tbl_Hang(); if (insert == true) { dt.TenHang = txttenhang.Text; dt.id_Menu = int.Parse(ddltennhomhang.SelectedValue); dt.ChatLieu = txtchatlieu.Text; dt.giaMoi = decimal.Parse(txtgiamoi.Text); dt.giaCu = decimal.Parse(txtgiacu.Text); dt.Soluong = int.Parse(txtsoluong.Text); dt.TomTat = txttomtat.Text; if (int.Parse(txtsoluong.Text) > 0) { dt.TinhTrang = "Còn"; } dt.Mota = txtNoidung.Text; if (ful_hinhanhlon.HasFile) { try { string Duoi_filename = Path.GetExtension(ful_hinhanhlon.FileName); string filename = ful_hinhanhlon.FileName.ToString();; if (Duoi_filename == ".jpeg" || Duoi_filename == ".jpg" || Duoi_filename == ".png" || Duoi_filename == ".PNG" || Duoi_filename == ".JPG" || filename == ".JPEG") { ful_hinhanhlon.SaveAs(Server.MapPath("~/images/") + filename); dt.image_large = "images/" + filename; } else { Response.Write("<script>alert('Bạn chỉ được upload jpg,png,jpeg')</script>"); return; } } catch (Exception ex) { } } if (ful_hinhanhnho.HasFile) { try { string Duoi_filename = Path.GetExtension(ful_hinhanhnho.FileName); string filename = ful_hinhanhnho.FileName.ToString();; if (Duoi_filename == ".jpeg" || Duoi_filename == ".jpg" || Duoi_filename == ".png" || Duoi_filename == ".PNG" || Duoi_filename == ".JPG" || filename == ".JPEG") { ful_hinhanhnho.SaveAs(Server.MapPath("~/images/") + filename); dt.image = "images/" + filename; } else { Response.Write("<script>alert('Bạn chỉ được upload jpg,png,jpeg')</script>"); return; } } catch (Exception ex) { } } dt.Active = bool.Parse(ckbActive.Checked == true ? "True" : "False"); //SanPhamService.SanPham_Insert(dts); db.tbl_Hangs.InsertOnSubmit(dt); db.SubmitChanges(); Response.Write("<script>alert('Thêm mới thành công!!!')</script>"); getData(); } else { dts.Id = txtID.Text; dts.TenHang = txttenhang.Text; dts.Id_Menu = ddltennhomhang.SelectedValue; dts.ChatLieu = txtchatlieu.Text; dts.GiaMoi = txtgiamoi.Text; dts.GiaCu = txtgiacu.Text; dts.Soluong = txtsoluong.Text; dts.TomTat = txttomtat.Text; if (int.Parse(txtsoluong.Text) > 0) { dts.TinhTrang = "Còn"; } dts.Mota = txtNoidung.Text; if (ful_hinhanhlon.HasFile) { try { string Duoi_filename = Path.GetExtension(ful_hinhanhlon.FileName); string filename = ful_hinhanhlon.FileName.ToString();; if (Duoi_filename == ".jpeg" || Duoi_filename == ".jpg" || Duoi_filename == ".png" || Duoi_filename == ".PNG" || Duoi_filename == ".JPG" || filename == ".JPEG") { ful_hinhanhlon.SaveAs(Server.MapPath("~/images/") + filename); dts.ImageLarge = "images/" + filename; } else { Response.Write("<script>alert('Bạn chỉ được upload jpg,png,jpeg')</script>"); return; } } catch (Exception ex) { } } else { dts.Image = fileUpLoad_nho; } if (ful_hinhanhnho.HasFile) { try { string Duoi_filename = Path.GetExtension(ful_hinhanhnho.FileName); string filename = ful_hinhanhnho.FileName.ToString();; if (Duoi_filename == ".jpeg" || Duoi_filename == ".jpg" || Duoi_filename == ".png" || Duoi_filename == ".PNG" || Duoi_filename == ".JPG" || filename == ".JPEG") { ful_hinhanhnho.SaveAs(Server.MapPath("~/images/") + filename); dts.Image = "images/" + filename; } else { Response.Write("<script>alert('Bạn chỉ được upload jpg,png,jpeg')</script>"); return; } } catch (Exception ex) { } } else { dts.ImageLarge = fileUpLoad_lon; } dts.Active = ckbActive.Checked == true ? "True" : "False"; SanPhamService.SanPham_Update(dts); Response.Write("<script>alert('Update thành công!!!')</script>"); getData(); } insert = true; pnData.Visible = true; pnInfo.Visible = false; ClearText(); }
protected void btndathang_Click(object sender, EventArgs e) { List <Entity.KhachHang> lstKh = new List <Entity.KhachHang>(); Entity.DatHang dh = new Entity.DatHang(); List <Entity.DatHang> lstdh = new List <Entity.DatHang>(); Entity.ChiTietDatHang lstctdh = new Entity.ChiTietDatHang(); string Id_SP; if (txtdiachi.Text == "" || txtdienthoai.Text == "" || txtemail.Text == "" || txthovaten.Text == "") //|| ddlquan.SelectedIndex == 0 || ddlthanhpho.SelectedIndex == 0 { Response.Write("<script>alert('" + ddlquan.SelectedValue + "')</script>"); Response.Write("<script>alert('Bạn phải nhập đầy đủ thông tin!!1')</script>"); return; } else { if (Session["TenDangNhap"] == null) { Entity.KhachHang obj = new Entity.KhachHang(); //Response.Write("<script>alert('Vào đây')</script>"); obj.TenKH = txthovaten.Text; obj.TaiKhoan = ""; obj.MatKhau = ""; obj.NgaySinh = ""; obj.GioiTinh = "True"; obj.Email = txtemail.Text; obj.SDT = txtdienthoai.Text; obj.DiaChi = txtdiachi.Text; obj.Tinh = ddlthanhpho.SelectedItem.ToString(); obj.Quan = ddlquan.SelectedItem.ToString(); obj.Link_Fb = "false"; KhachHangService.KhachHang_Insert(obj); lstKh = KhachHangService.KhachHang_GetByTop("", " id=(SELECT MAX(id) from tbl_KhachHang) ", ""); tbl_DatHang dhs = new tbl_DatHang(); dhs.id_KhachHang = int.Parse(lstKh[0].Id); dhs.NgaylapHD = DateTime.Now; dhs.IdPay = int.Parse(ddlhinhthucthanhtoan.SelectedValue); /////////////////////////////////////////////////////////////////// dbs.tbl_DatHangs.InsertOnSubmit(dhs); dbs.SubmitChanges(); lstdh = DatHangService.DatHang_GetByTop("", " id=(SELECT MAX(id) from tbl_DatHang)", ""); lstctdh.Id_hoadon = lstdh[0].Id; for (int i = 0; i < tbGioHang.Rows.Count; i++) { string tenSP = tbGioHang.Rows[i]["TenSP"].ToString(); Id_SP = SanPhamService.SanPham_GetByTop("", " TenHang=N'" + tenSP + "'", "")[0].Id; lstctdh.Id_hang = Id_SP; lstctdh.Size = tbGioHang.Rows[i]["Size"].ToString(); lstctdh.SoLuongMua = tbGioHang.Rows[i]["SoLuong"].ToString(); lstctdh.ThanhTien = tbGioHang.Rows[i]["TongGia"].ToString(); lstctdh.Gia = tbGioHang.Rows[i]["Gia"].ToString(); ChiTietDatHangService.ChiTietDatHang_Insert(lstctdh); } } else { string TenDangNhap = Session["TenDangNhap"].ToString(); lstKh = KhachHangService.KhachHang_GetByTop("", " TaiKhoan='" + TenDangNhap + "'", ""); Entity.KhachHang kh = new Entity.KhachHang(); kh.Id = lstKh[0].Id; kh.TenKH = txthovaten.Text; kh.Email = txtemail.Text; kh.DiaChi = txtdiachi.Text; kh.SDT = txtdienthoai.Text; kh.Tinh = ddlthanhpho.SelectedItem.ToString(); kh.Quan = ddlquan.SelectedItem.ToString(); KhachHangService.KhachHang_UpdateDatHang(kh); tbl_DatHang dhs = new tbl_DatHang(); dhs.id_KhachHang = int.Parse(kh.Id); dhs.NgaylapHD = DateTime.Now; dhs.IdPay = int.Parse(ddlhinhthucthanhtoan.SelectedValue); /////////////////////////////////////////////////////////////////// dbs.tbl_DatHangs.InsertOnSubmit(dhs); dbs.SubmitChanges(); lstdh = DatHangService.DatHang_GetByTop("", " id=(SELECT MAX(id) from tbl_DatHang where id_KhachHang=" + kh.Id + ")", ""); lstctdh.Id_hoadon = lstdh[0].Id; for (int i = 0; i < tbGioHang.Rows.Count; i++) { string tenSP = tbGioHang.Rows[i]["TenSP"].ToString(); Id_SP = SanPhamService.SanPham_GetByTop("", " TenHang=N'" + tenSP + "'", "")[0].Id; lstctdh.Id_hang = Id_SP; lstctdh.Size = tbGioHang.Rows[i]["Size"].ToString(); lstctdh.SoLuongMua = tbGioHang.Rows[i]["SoLuong"].ToString(); lstctdh.ThanhTien = tbGioHang.Rows[i]["TongGia"].ToString(); lstctdh.Gia = tbGioHang.Rows[i]["Gia"].ToString(); ChiTietDatHangService.ChiTietDatHang_Insert(lstctdh); } } } Response.Write("<script>alert('Đặt hàng thành công!! Cảm ơn bạn nhiều nhé!! ')</script>"); // MailMessage message = new MailMessage("*****@*****.**",txtemail.Text, "Shop Fashion(Clothing Store) ",grvsanpham.Rows[0].Cells[0].Text); // message.IsBodyHtml = true; // SmtpClient client = new SmtpClient("smtp.gmail.com", 587); //client.EnableSsl = true; //client.UseDefaultCredentials = false; //client.DeliveryMethod = SmtpDeliveryMethod.Network; //client.Credentials = new System.Net.NetworkCredential("*****@*****.**", "Baonguyen741999@!"); //client.Send(message); for (int i = 0; i < tbGioHang.Rows.Count; i++) { var from = "*****@*****.**"; var to = txtemail.Text; const string Password = "******"; string mail_subject = "Clothing Store"; string mail_message = "From : Clothing Store" + "\n"; mail_message += "From : [email protected] " + "\n"; mail_message += "Thông tin mua hàng của quý khách" + "\n"; string tenSP = tbGioHang.Rows[i]["TenSP"].ToString(); Id_SP = SanPhamService.SanPham_GetByTop("", " TenHang=N'" + tenSP + "'", "")[0].Id; mail_message += "ID sản phẩm : " + Id_SP + "\n"; mail_message += "Tên sản phẩm :" + tbGioHang.Rows[i]["TenSP"].ToString() + "\n"; mail_message += "Size: " + tbGioHang.Rows[i]["Size"].ToString() + "\n"; mail_message += "Số lượng: " + tbGioHang.Rows[i]["SoLuong"].ToString() + "\n"; mail_message += "Tổng giá: " + tbGioHang.Rows[i]["TongGia"].ToString() + "\n"; mail_message += "Giá: " + tbGioHang.Rows[i]["Gia"].ToString() + "\n"; var smtp = new SmtpClient(); { smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Credentials = new NetworkCredential(from, Password); smtp.Timeout = 10000; } smtp.Send(from, to, mail_subject, mail_message); } Session["GioHang"] = null; Session["slspgiohang"] = null; lblsl = (Label)Master.FindControl("lblslgiohang"); lblsl.Text = "0"; lbltongtien.Text = "0 VNĐ"; tbGioHang = null; grvsanpham.DataSource = tbGioHang; grvsanpham.DataBind(); Response.AddHeader("REFRESH", "1;URL=TrangChu.aspx"); }