protected void btnNhap_Click(object sender, EventArgs e) { CustomValidator2.IsValid = true; try { DateTime dt = Convert.ToDateTime(txtNgayNhap.Text); } catch { CustomValidator2.ErrorMessage = "Ngày nhập không đúng định dạng"; CustomValidator2.IsValid = false; return; } HoaDonNhap hoadon; hoadon = new HoaDonNhap(); hoadon.NgayNhap = txtNgayNhap.Text; hoadon.MaNhanVien = 1; db.HoaDonNhaps.InsertOnSubmit(hoadon); db.SubmitChanges(); load(); }
protected void dl1_ItemCommand(object source, DataListCommandEventArgs e) { LinkButton lable = (LinkButton)e.Item.FindControl("lbtTenSP"); SanPhams sanpham = db.SanPhams.SingleOrDefault(p => p.TenSP == lable.Text); string clickdangnhap = Request.QueryString["ClickDangNhap"]; if (clickdangnhap == null) { Response.Redirect("~/TrangDangNhap.aspx?MaSanPham=" + sanpham.MaSanPham); } else { string makh = Request.QueryString["MaKhachHang"]; GioHangs giohang = db.GioHangs.SingleOrDefault(p => p.MaKhachHang.ToString() == makh && p.MaSanPham == sanpham.MaSanPham); if (giohang != null) { giohang.SoLuong = giohang.SoLuong + 1; db.SubmitChanges(); } else { giohang = new GioHangs(); giohang.SoLuong = 1; giohang.MaSanPham = Convert.ToInt32(sanpham.MaSanPham); giohang.MaKhachHang = Convert.ToInt32(makh); db.GioHangs.InsertOnSubmit(giohang); db.SubmitChanges(); } Response.Redirect("~/GioHang.aspx?MaKhachHang=" + makh); } }
protected void btnNhap_Click(object sender, EventArgs e) { if (kiemtra() == false) { db = new WedMayTinhDataContext(); return; } else { NhaCungCap nhacungcap = new NhaCungCap(); nhacungcap.TenNhaCungCap = txtTenNhaCungCap.Text; nhacungcap.DiaChi = txtDiaChi.Text; nhacungcap.SoDienThoai = txtSoDienThoai.Text; if ((from p in db.NhaCungCaps select p.MaNhaCungCap).Count() == 0) { nhacungcap.MaNhaCungCap = 0; } else { nhacungcap.MaNhaCungCap = (from p in db.NhaCungCaps select p.MaNhaCungCap).Max() + 1; } db.NhaCungCaps.InsertOnSubmit(nhacungcap); db.SubmitChanges(); HienThi(); } }
protected void btnNhap_Click(object sender, EventArgs e) { //Response.Write("<script language='javascript' > if ( confirm('Are you sure to delete?') ){} else { return false } </script>"); if (kiemtra() != false) { KhuyenMai khuyenmai = new KhuyenMai(); khuyenmai.TenKhuyenMai = txtTenKhuyenMai.Text; khuyenmai.NoiDungKhuyenMai = txtNoiDungKhuyenMai.Text; khuyenmai.NgayTao = DateTime.Now.ToShortDateString(); if (txtNgayBatDau.Text != "") { khuyenmai.NgayBatDau = txtNgayBatDau.Text; } if (txtNgayKetThuc.Text != "") { khuyenmai.NgayKetThuc = txtNgayKetThuc.Text; } if (txtGiaCanGiam.Text != "") { khuyenmai.GiaCanGiam = txtGiaCanGiam.Text; } db.KhuyenMais.InsertOnSubmit(khuyenmai); luucheck(khuyenmai); db.SubmitChanges(); // KhuyenMai khuyenmai1 = db.KhuyenMais.SingleOrDefault(p => p.MaKhuyenMai == khuyenmai.MaKhuyenMai); lammoi(); LoadTrang(); clearcheck(); CheckBox chkhd = (CheckBox)GridView3.HeaderRow.FindControl("chkApDunghd"); chkhd.Checked = false; Response.Write("<script> alert('Nhập thành công') </script>"); } }
protected void btnXuLy_Click(object sender, EventArgs e) { DonDatHangs dondathang = db.DonDatHangs.SingleOrDefault(p => p.MaDonHang.ToString() == GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text); dondathang.TinhTrang = "Đang sử lý"; db.SubmitChanges(); var dsdonhang = from p in db.DonDatHangs select new { p.MaDonHang, p.KhachHang.TenKhachHang, p.NgayDatHang, p.TongTien, p.TinhTrang }; GridView1.DataSource = dsdonhang; GridView1.DataBind(); }
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { string MaKhachHang1 = Request.QueryString["MaKhachHang"]; int MaKhachHang = Convert.ToInt32(MaKhachHang1); GioHangs giohang = db.GioHangs.SingleOrDefault(p => p.MaSanPham.ToString() == GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text && p.MaKhachHang == MaKhachHang); if (giohang != null) { db.GioHangs.DeleteOnSubmit(giohang); db.SubmitChanges(); load(); } }
protected void bntDangNhap_Click(object sender, EventArgs e) { var dskhachanh = from p in db.KhachHangs select p; foreach (KhachHang khachhang in dskhachanh) { if (khachhang.TenDangNhap == txtUser.Text && khachhang.MatKhau == txtPass.Text) { string masp = Request.QueryString["MaSanPham"]; if (masp != null) { GioHangs giohang = db.GioHangs.SingleOrDefault(p => p.MaKhachHang == khachhang.MaKhachHang && p.MaSanPham.ToString() == masp); if (giohang != null) { giohang.SoLuong = giohang.SoLuong + 1; db.SubmitChanges(); } else { giohang = new GioHangs(); giohang.SoLuong = 1; giohang.MaSanPham = Convert.ToInt32(masp); giohang.MaKhachHang = khachhang.MaKhachHang; db.GioHangs.InsertOnSubmit(giohang); db.SubmitChanges(); } } string clickdangnhap = Request.QueryString["ClickDangNhap"]; if (clickdangnhap == null) { Response.Redirect("~/GioHang.aspx?MaKhachHang=" + khachhang.MaKhachHang); } else { Response.Redirect("~/Default3.aspx?ClickDangNhap=true+&MaKhachHang=" + khachhang.MaKhachHang); } } else { CustomValidator1.ErrorMessage = "Tên đăng nhập hoặc mật khẩu không đúng"; CustomValidator1.IsValid = false; } } }
protected void btnGui_Click(object sender, EventArgs e) { int makhachhang = Convert.ToInt16(Request.QueryString["MaKhachHang"]); var dsgiohang = from p in db.GioHangs where p.MaKhachHang == makhachhang select new { p.MaSanPham, p.SanPhams.TenSP, p.SoLuong, DonGia = TinhGiamGia(p.SanPhams.SanPham_KhuyenMai.KhuyenMai.GiaCanGiam, p.SanPhams.GiaBan) }; double tongtien = 0; foreach (var giohang in dsgiohang) { tongtien = tongtien + Convert.ToDouble(giohang.DonGia); } DonDatHangs dondathang = new DonDatHangs(); dondathang.MaKhachHang = makhachhang; dondathang.NgayDatHang = DateTime.Now.ToShortDateString(); dondathang.TinhTrang = "Chưa xử lý"; dondathang.TongTien = tongtien; dondathang.YeuCauKhachHang = TextArea1.Value; db.DonDatHangs.InsertOnSubmit(dondathang); db.SubmitChanges(); foreach (var giohang in dsgiohang) { ChiTietDonHang chitiet = new ChiTietDonHang(); chitiet.MaDonHang = dondathang.MaDonHang; chitiet.MaSanPham = giohang.MaSanPham; chitiet.SoLuong = Convert.ToInt16(giohang.SoLuong); db.ChiTietDonHangs.InsertOnSubmit(chitiet); db.SubmitChanges(); } Response.Write("<script> alert('Gửi thành công') </script>"); Response.Redirect("~/GioHang.aspx?MaKhachHang=" + makhachhang); }
protected void btnHuyBo_Click(object sender, EventArgs e) { string makh = Request.QueryString["MaKhachHang"]; DonDatHangs dondathang = db.DonDatHangs.SingleOrDefault(p => p.MaDonHang.ToString() == GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text); dondathang.TinhTrang = "Chưa sử lý"; db.SubmitChanges(); var dsdonhang = from p in db.DonDatHangs where p.MaKhachHang.ToString() == makh select new { p.MaDonHang, p.KhachHang.TenKhachHang, p.NgayDatHang, p.TongTien, p.TinhTrang }; GridView1.DataSource = dsdonhang; GridView1.DataBind(); }
void updatesoluongsp(string type, ChiTietNhap chitietnhap) { SanPhams sp = db.SanPhams.SingleOrDefault(p => p.MaSanPham == chitietnhap.MaSanPham); if (type == "insert") { sp.SoLuong = sp.SoLuong + Convert.ToInt16(txtSoLuong.Text); db.SubmitChanges(); } if (type == "update") { sp.SoLuong = sp.SoLuong - chitietnhap.SoLuongNhap + Convert.ToInt32(txtSoLuong.Text); db.SubmitChanges(); } if (type == "delete") { sp.SoLuong = sp.SoLuong - chitietnhap.SoLuongNhap; db.SubmitChanges(); } }
protected void btnNhap_Click(object sender, EventArgs e) { if (kiemtra() != false) { CustomValidator1.IsValid = true; var dstennv = from p in db.NhanViens select p.TenDangNhap; foreach (string ten in dstennv) { if (txtTenTaiKhoan.Text == ten) { CustomValidator1.ErrorMessage = "Đã tồn tại tên tài khoản"; CustomValidator1.IsValid = false; return; } } NhanVien nhanvien = new NhanVien(); nhanvien.TenDangNhap = txtTenTaiKhoan.Text; nhanvien.MatKhau = txtMatKhau.Text; nhanvien.HoTen = txtTenNhanVien.Text; nhanvien.ViTri = txtViTri.Text; nhanvien.NgaySinh = txtNgaySinh.Text; nhanvien.SoDienThoai = Convert.ToDouble(txtSoDienThoai.Text); nhanvien.DiaChi = txtDiaChi.Text; nhanvien.GioiTinh = txtGioiTinh.Text; nhanvien.HinhAnh = hinhanh.ImageUrl; db.NhanViens.InsertOnSubmit(nhanvien); db.SubmitChanges(); ChucNang chucnang = new ChucNang(); if (CheckBoxList1.Items[0].Selected == true) { chucnang.QuanLyNhapHang = "true"; } else { chucnang.QuanLyNhapHang = "false"; } if (CheckBoxList1.Items[1].Selected == true) { chucnang.QuanLyMatHang = "true"; } else { chucnang.QuanLyMatHang = "false"; } if (CheckBoxList1.Items[2].Selected == true) { chucnang.QuanLyKhuyenMai = "true"; } else { chucnang.QuanLyKhuyenMai = "false"; } if (CheckBoxList1.Items[3].Selected == true) { chucnang.QuanLyTaiKhoan = "true"; } else { chucnang.QuanLyTaiKhoan = "false"; } if (CheckBoxList1.Items[4].Selected == true) { chucnang.QuanLyNhaCungCap = "true"; } else { chucnang.QuanLyNhaCungCap = "false"; } if (CheckBoxList1.Items[5].Selected == true) { chucnang.QuanLyDonHang = "true"; } else { chucnang.QuanLyDonHang = "false"; } if (CheckBoxList1.Items[6].Selected == true) { chucnang.ThongKe = "true"; } else { chucnang.ThongKe = "false"; } chucnang.MaNhanVien = nhanvien.MaNhanVien; db.ChucNangs.InsertOnSubmit(chucnang); db.SubmitChanges(); } load(); }