private void getDonHang() { String sql_DH = "select * from DonDatHang where TrangThai = 0"; DataTable donhang = XLDL.GetData(sql_DH); lbDH.Text = "(" + donhang.Rows.Count.ToString() + ")"; }
private void getKH() { String sql = "select * from KhachHang where Xoa = 0"; gvFG.DataSource = XLDL.GetData(sql); gvFG.DataBind(); }
private void getTinNhan() { String sql_TN = "select * from ThongTinLienHe where DaDuyet = 0"; DataTable tinnhan = XLDL.GetData(sql_TN); lbTN.Text = "(" + tinnhan.Rows.Count.ToString() + ")"; }
protected void Page_Load(object sender, EventArgs e) { maDH = Guid.NewGuid().ToString(); Session["info"] = new object(); dt = (DataTable)Session["Giohang"]; if (Session["TaiKhoan"] != null) { hoten = Session["TaiKhoan"].ToString(); DataTable Tk = XLDL.GetData("select * from KhachHang where TaiKhoan = '" + hoten + "'"); if (!IsPostBack) { txtDC.Value = Tk.Rows[0]["DiaChi"].ToString(); txtEM.Value = Tk.Rows[0]["Email"].ToString(); txtSDT.Value = Tk.Rows[0]["SodienThoai"].ToString(); txtHT.Value = hoten.ToString(); } id_DN.Visible = false; } else { id_DN.Visible = true; } if (Session["Giohang"] != null) { dt_Cart.DataSource = dt; dt_Cart.DataBind(); XuLyDonHang.getCart(dt, ref TongThanhTien); lbTongCong.Text = String.Format("{0:0,00}₫", int.Parse(TongThanhTien.ToString())); } }
protected void btnDN_Click1(object sender, EventArgs e) { try { DataTable data = new DataTable(); String sql = "select * from KhachHang where TaiKhoan = '" + txtTK.Value + "' and MaKhau = '" + getMD5.GetMD5(txtPW.Value) + "'"; data = XLDL.GetData(sql); if (data.Rows.Count > 0) { if (int.Parse(data.Rows[0]["Admin"].ToString()) == 1) { Session["Admin"] = data.Rows[0]["TaiKhoan"].ToString(); Response.Redirect("Default_Admin.aspx"); } else { Session["TaiKhoan"] = data.Rows[0]["TaiKhoan"].ToString(); Response.Redirect("Default.aspx"); } } else { lbError.Text = "Sai mật khẩu"; lbError.Visible = true; lbError.ForeColor = Color.Red; } } catch { lbError.Text = "Đăng nhập thất bại"; lbError.Visible = true; lbError.ForeColor = Color.Red; } }
private void getTitle() { DataTable dt = XLDL.GetData("select * from Hang_San_Xuat where MSX = '" + maSX + "'"); DataTable dt2 = XLDL.GetData("select count(*) from San_Pham where MSX = '" + maSX + "'"); lbLoaiSP.Text = dt.Rows[0]["HanSanXuat"].ToString(); lbSoLuong.Text = dt2.Rows[0][0].ToString(); }
private void getSP() { DataTable dt = new DataTable(); dt = XLDL.GetData("select * from San_Pham S join San_Pham_Image I on S.Ma_SP = I.MaSP where S.MSX = '" + maSX + "' and Position = 0"); dtSP.DataSource = dt; dtSP.DataBind(); maSP = dt.Rows[0]["Ma_SP"].ToString(); }
private void getDH() { if (Session["TaiKhoan"] != null) { String select_DH = "select * from DonDatHang D join CT_DonHang C on D.MaDH = C.MaDH join San_Pham S on C.MaSP = S.Ma_SP join San_Pham_Image I on I.MaSP = S.Ma_SP" + " where D.TaiKhoan = '" + Session["TaiKhoan"].ToString() + "' and TrangThai = 0 and Position = 0"; gvDGH.DataSource = XLDL.GetData(select_DH); gvDGH.DataBind(); } }
private void loadAdmin() { DataTable dt = new DataTable(); dt = XLDL.GetData("select * from KhachHang where Admin = 1"); for (int i = 0; i < dt.Rows.Count; i++) { ddlAdmin.Items.Add("i"); ddlAdmin.Items[i].Text = dt.Rows[i]["HoTen"].ToString(); ddlAdmin.Items[i].Value = dt.Rows[i]["TaiKhoan"].ToString(); } }
protected void gvFG_RowUpdating(object sender, GridViewUpdateEventArgs e) { String tk = gvFG.DataKeys[e.RowIndex].Value.ToString(); String hoten = (gvFG.Rows[e.RowIndex].Cells[0].Controls[0] as TextBox).Text; String sdt = (gvFG.Rows[e.RowIndex].Cells[4].Controls[0] as TextBox).Text; String email = (gvFG.Rows[e.RowIndex].Cells[3].Controls[0] as TextBox).Text; XLDL.Execute(@"update KhachHang set HoTen= N'" + hoten + "',Email = '" + email + "', SodienThoai = '" + sdt + "' where TaiKhoan='" + tk + "'"); gvFG.EditIndex = -1; getKH(); }
private void getMG() { DataTable dt = new DataTable(); dt = XLDL.GetData("select MSX,HanSanXuat from Hang_San_Xuat"); for (int i = 0; i < dt.Rows.Count; i++) { ddlMaMSX.Items.Add("i"); ddlMaMSX.Items[i].Text = dt.Rows[i][1].ToString(); ddlMaMSX.Items[i].Value = dt.Rows[i][0].ToString(); } }
public static List <string> GetCompletionList(string pre) { List <string> TenSP = new List <string>(); String sql = "select * from San_Pham where TenSP like '%" + pre + "%'"; DataTable dtSP = XLDL.GetData(sql); foreach (DataRow dr in dtSP.Rows) { TenSP.Add(dr["TenSP"].ToString()); } return(TenSP); }
protected void btThem_Click(object sender, EventArgs e) { try { String maSP = Request.QueryString["MaSP"].ToString(); XLDL.Execute("update San_Pham set TenSP = '" + txtTenSP.Text + "',DonGia='" + txtDonGia.Text + "',SoLuong='" + txtConLai.Text + "',GiamGia='" + txtMaGiamGia.Text + "',MSX='" + ddlMaMSX.SelectedItem.Value + "',NgayNhapHang='" + txtNgay.Text + "',MoTa='" + txtMoTa.InnerText + "' where Ma_SP ='" + maSP + "'"); Response.Write("<script>alert('Sửa thành công!')</script>"); } catch { Response.Write("<script>alert('Sửa thất bại!')</script>"); } }
public void GH() { DataTable dt = new DataTable(); maSP = Request.QueryString["MaSP"].ToString(); dt = XLDL.GetData("select Ma_SP,TenSP,DonGia,Image from San_Pham inner join San_Pham_Image on Ma_SP = MaSP where Ma_SP= '" + maSP + "' and Position = 0 "); string TenSP = dt.Rows[0][1].ToString(); float DonGia = float.Parse(dt.Rows[0][2].ToString()); String Image = "/Image/San_Pham/" + dt.Rows[0][3].ToString() + ".jpg"; int SoLuong = int.Parse(txtSL.Text); ThemVaoGioHang(maSP, TenSP, DonGia, SoLuong, Image); }
protected void btnSua_Click(object sender, EventArgs e) { try { String sql = "update TrangLienHe set TrangLienHe = N'" + txtLienHe.InnerText + "' where id = 1"; XLDL.GetData(sql); Response.Write("<script>alert('Sửa thành công!');</script>"); Page.ClientScript.RegisterStartupScript(this.GetType(), "OpenWindow", "window.open('LienHe.aspx','_newtab');", true); } catch { Response.Write("<script>alert('Sửa không thành công');</script>"); } }
private void getSP() { String maSP = Request.QueryString["MaSP"].ToString(); DataTable dt = new DataTable(); getMG(); dt = XLDL.GetData("select * from San_Pham where Ma_SP ='" + maSP + "'"); txtTenSP.Text = dt.Rows[0]["TenSP"].ToString(); txtNgay.Text = dt.Rows[0]["NgayNhapHang"].ToString(); txtConLai.Text = dt.Rows[0]["SoLuong"].ToString(); txtMoTa.InnerText = dt.Rows[0]["MoTa"].ToString(); txtMaGiamGia.Text = dt.Rows[0]["GiamGia"].ToString(); ddlMaMSX.SelectedValue = dt.Rows[0]["MSX"].ToString(); txtDonGia.Text = dt.Rows[0]["DonGia"].ToString(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { try { String sql = "select * from TrangLienhe"; text = (XLDL.GetData(sql)).Rows[0][0].ToString(); } catch { text = "Design cho mình một trang liên hệ!"; } txtLienHe.InnerText = text; } }
public static void getDonDatHang(int daThanhToan, String sdt, String hoten, String maDH, Decimal TongThanhTien, String datetime, DataTable dt, String email, String diachi, int TrangThai) { String maSP; int soluong; String insert_DonHang = "INSERT INTO DonDatHang (SDT, TaiKhoan, MaDH, TongTien, NgayDatHang, TrangThai, ThanhToan, Choduyet, email, diachi)" + "VALUES(" + "'" + sdt + "'" + ",'" + hoten + "'" + ",'" + maDH + "'" + "," + TongThanhTien + "" + ",'" + datetime + "'" + ",0" + "," + daThanhToan + ",0" + ",'" + email + "'" + ",N'" + diachi + "')"; String insert_CT_DH; String update_SP; XLDL.GetData(insert_DonHang); foreach (DataRow dr in dt.Rows) { DataTable up_SP = new DataTable(); int daban = 0; int conlai = 0; maSP = dr["MaSP"].ToString(); soluong = int.Parse(dr["SoLuong"].ToString()); insert_CT_DH = "insert into CT_DonHang (MaDH,MaSP,SoLuong)" + "values(" + "'" + maDH + "'" + ",'" + maSP + "'" + "," + soluong + ")"; up_SP = XLDL.GetData("select * from San_Pham where Ma_SP ='" + maSP + "'"); daban = int.Parse(up_SP.Rows[0]["DaBan"].ToString()); conlai = int.Parse(up_SP.Rows[0]["SoLuong"].ToString()); daban += soluong; conlai -= soluong; update_SP = "UPDATE San_Pham" + " SET DaBan = " + daban + ", SoLuong = " + conlai + " WHERE Ma_SP ='" + maSP + "'"; XLDL.GetData(insert_CT_DH); XLDL.GetData(update_SP); } }
protected void gvFG_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Xoa") { try { int chiso = int.Parse(e.CommandArgument.ToString()); String maFG = gvFG.Rows[chiso].Cells[1].Text; XLDL.Execute("delete from San_Pham where TenSP='" + maFG + "'"); Response.Redirect("QuanLy_SP.aspx"); } catch { Response.Write("<script>alert('Xóa thất bại!!!')</script>"); } } }
protected void gvFG_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Xoa") { try { int chiso = int.Parse(e.CommandArgument.ToString()); String tk = gvFG.Rows[chiso].Cells[1].Text; XLDL.GetData("update KhachHang set Xoa = 1 where TaiKhoan = '" + tk + "'"); Response.Write("<script>alert('Xóa thành công!!!')</script>"); } catch { Response.Write("<script>alert('Xóa thất bại!!!')</script>"); } } }
private void getDH() { dt_DonHang = XLDL.GetData("select * from DonDatHang"); DataTable dt2_DonHang = dt_DonHang.Clone(); dt2_DonHang.Columns["ThanhToan"].DataType = typeof(String); dt2_DonHang.Columns["TrangThai"].DataType = typeof(String); dt2_DonHang.Columns["Choduyet"].DataType = typeof(String); for (int i = 0; i < dt_DonHang.Rows.Count; i++) { dt2_DonHang.ImportRow(dt_DonHang.Rows[i]); int thanhtoan = int.Parse(dt_DonHang.Rows[i]["ThanhToan"].ToString()); int choduyet = int.Parse(dt_DonHang.Rows[i]["Choduyet"].ToString()); switch (thanhtoan) { case 0: dt2_DonHang.Rows[i]["ThanhToan"] = "Thanh toán sau khi nhận hàng"; break; case 1: dt2_DonHang.Rows[i]["ThanhToan"] = "ví điện tử momo"; break; case 2: dt2_DonHang.Rows[i]["ThanhToan"] = "onepay nội địa"; break; case 3: dt2_DonHang.Rows[i]["ThanhToan"] = "onepay quốc tế"; break; } switch (choduyet) { case 0: dt2_DonHang.Rows[i]["Choduyet"] = "Chưa duyệt"; break; case 1: dt2_DonHang.Rows[i]["Choduyet"] = "Chờ giao hàng"; break; } dt2_DonHang.Rows[i]["TrangThai"] = "Chưa giao hàng"; } gvDH.DataSource = dt2_DonHang; gvDH.DataBind(); }
private void register() { String sql = "insert into KhachHang(HoTen,GioiTinh,DiaChi,TaiKhoan,MaKhau,Email,Xoa,Avarta,Sodienthoai,Admin) values" + "(N'" + hoten + "'" + "," + gioitinh + ",N'" + diachi + "'" + ",'" + taikhoan + "'" + ",'" + getMD5.GetMD5(matkhau) + "'" + ",'" + email + "'" + "," + 0 + ",'" + "not" + "'" + ",'" + sdt + "'" + ",0)"; try { if (checkPass() == 1) { lbError.Visible = true; } else if (checkEmail() == 1) { lbError.Visible = true; } else if (checkUser() == 1) { lbError.Visible = true; } else if (checkSDT() == 1) { lbError.Visible = true; } else { XLDL.GetData(sql); lbError.Visible = false; Response.Redirect("~/Login.aspx"); } } catch { lbError.Text = "Đăng ký không thành công!"; lbError.Visible = true; } }
private void getSP() { String tenSP = Request.QueryString["Search"].ToString(); DataTable dt = new DataTable(); try { dt = XLDL.GetData("select * from San_Pham S join San_Pham_Image I on S.Ma_SP = I.MaSP where Position = 0 and TenSP like '%" + tenSP + "%'"); dtSPNB.DataSource = dt; dtSPNB.DataBind(); maSP = dt.Rows[0]["Ma_SP"].ToString(); } catch { } lbTiTle.Text = tenSP; }
protected void gvDH_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Duyet") { try { int chiso = int.Parse(e.CommandArgument.ToString()); String tk = gvDH.Rows[chiso].Cells[0].Text; XLDL.GetData("update DonDatHang set Choduyet = 1 where MaDH = '" + tk + "'"); getDH(); Response.Write("<script>alert('Đã duyệt!!!')</script>"); } catch { Response.Write("<script>alert('Xóa thất bại!!!')</script>"); } } }
protected void btnGui_Click(object sender, EventArgs e) { String binhluan; binhluan = txtCmt.InnerText; String datetime = DateTime.Now.ToString(); if (Session["TaiKhoan"] == null) { Response.Write("<script>alert('Bạn phải đăng nhập trước khi bình luận!')</script>"); } else { DataTable check = new DataTable(); check = XLDL.GetData("select * from BinhLuan where TaiKhoan = '" + Session["TaiKhoan"].ToString() + "' and Ma_SP = '" + maSP + "'"); if (check.Rows.Count == 1) { String sql_update = "UPDATE BinhLuan" + " SET NgayGio = '" + datetime + "', NoiDung =N'" + binhluan + "', DanhGia =" + danhgia + " WHERE TaiKhoan = '" + Session["TaiKhoan"].ToString() + "' and Ma_SP = '" + maSP + "'"; XLDL.GetData(sql_update); } else { try { String sql = "insert into BinhLuan(NgayGio,Ma_SP,TaiKhoan,NoiDung,DanhGia) values" + "('" + datetime + "'" + ",'" + maSP + "'" + ",'" + Session["TaiKhoan"].ToString() + "'" + ",N'" + binhluan + "'" + "," + danhgia + ")"; XLDL.GetData(sql); } catch { Response.Write("<script>alert('Gửi thất bại!')</script>"); } } Response.Write("<script>alert('Gửi thành công!')</script>"); Page.Response.Redirect(Page.Request.Url.ToString(), true); } }
private void getTaiKhoan() { int admin = 0, khachhang = 0; String sql = "select * from KhachHang"; DataTable taikhoan = XLDL.GetData(sql); foreach (DataRow dr in taikhoan.Rows) { if (int.Parse(dr["Admin"].ToString()) == 1) { admin++; } else { khachhang++; } } lbad.Text = admin.ToString(); lbkh.Text = khachhang.ToString(); }
protected void btThem_Click(object sender, EventArgs e) { try { String sql = "INSERT INTO San_Pham (TenSP, DonGia, SoLuong, GiamGia, MSX, NgayNhapHang,MoTa)" + "VALUES('" + txtTenSP.Text + "', '" + txtDonGia.Text + "', '" + txtConLai.Text + "', '" + txtMaGiamGia.Text + "', '" + ddlMaMSX.SelectedItem.Value + "', '" + txtNgay.Text + "', '" + txtMoTa.InnerText + "')"; XLDL.GetData(sql); Response.Write("<script><alert('Thêm thành công!!')/script>"); } catch { Response.Write("<script><alert('Thêm thất bại!!')/script>"); } }
private void checkEmail() { String sql = "select * from KhachHang where TaiKhoan = '" + txtTK.Value + "' and Email = '" + txtEM.Value + "'"; DataTable dt = new DataTable(); dt = XLDL.GetData(sql); if (dt.Rows.Count < 1) { lbError.Text = "Kiểm tra tài khoản và email bạn nhập chính xác chưa!"; } else { using (SmtpClient client = new SmtpClient("smtp.gmail.com")) { client.Port = 587; // Tạo xác thực bằng địa chỉ gmail và password client.Credentials = new NetworkCredential("*****@*****.**", "Chet123456"); client.EnableSsl = true; } } }
private int checkSDT() { String sql_SelectEmail = "select * from KhachHang where SodienThoai = '" + sdt + "'"; DataTable dt = new DataTable(); try { dt = XLDL.GetData(sql_SelectEmail); if (dt.Rows.Count > 0) { lbError.Text = "Số điện thoại đã sử dụng"; txtEmail.Focus(); return(1); } } catch { return(1); } return(0); }
private int checkEmail() { String sql_SelectEmail = "select * from KhachHang where Email = '" + email + "'"; DataTable dt = new DataTable(); try { dt = XLDL.GetData(sql_SelectEmail); if (dt.Rows.Count > 0) { lbError.Text = "Email đã tồn tại"; txtEmail.Focus(); return(1); } } catch { return(1); } return(0); }