protected void gvHoaDon_SelectedIndexChanging(object sender, GridViewSelectEventArgs e) { int mahd = int.Parse(gvHoaDon.DataKeys[e.NewSelectedIndex].Value.ToString()); Session["MaHoaDon"] = mahd; HoaDon hd = new HoaDon(); BUS_HoaDon bus = new BUS_HoaDon(); hd = bus.LayThongTinHD(mahd); txtMaHD.Text = hd.MAHD.ToString(); txtTenKH.Text = hd.HOTEN; txtNgayLapHD.Text = hd.NGAYLAPHD; txtNgayGiaoHang.Text = hd.NGAYGIAOHANG; txtDiaChi.Text = hd.DIACHIGIAOHANG; ddlTrangThai.SelectedValue = hd.TRANGTHAI.ToString(); //load chi tiet hoa don DataTable dt = new DataTable(); BUS_CTHD busCTHD = new BUS_CTHD(); dt = busCTHD.LoadCTHD(mahd); gvCTHD.DataSource = dt.DefaultView; gvCTHD.DataBind(); lblThongBao.Text = ""; }
protected void gvCTHD_RowUpdating(object sender, GridViewUpdateEventArgs e) { int mahd = int.Parse(Session["MaHoaDon"].ToString()); GridViewRow row = gvCTHD.Rows[e.RowIndex]; BUS_SanPham busSp = new BUS_SanPham(); int masp = int.Parse(row.Cells[1].Text); int masize = 0; string s = row.Cells[3].Text; switch (row.Cells[3].Text) { case "s": masize = 0; break; case "m": masize = 1; break; case "l": masize = 2; break; case "xl ": masize = 3; break; case "xxl": masize = 4; break; } TextBox txtSoLuong = row.FindControl("txtSoLuong") as TextBox; string soluong = txtSoLuong.Text.Trim(); CTHD ct = new CTHD(); ct.MAHD = mahd; ct.MASP = masp; ct.MASIZE = masize; ct.SOLUONG = int.Parse(soluong); BUS_CTHD bus = new BUS_CTHD(); bus.CapNhatCTHD(ct); gvCTHD.EditIndex = -1; DataTable dt = new DataTable(); BUS_CTHD busCTHD = new BUS_CTHD(); dt = busCTHD.LoadCTHD(mahd); gvCTHD.DataSource = dt.DefaultView; gvCTHD.PageIndex = int.Parse(Session["cthdPage"].ToString()); gvCTHD.DataBind(); }
protected void gvCTHD_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { gvCTHD.EditIndex = -1; int mahd = int.Parse(Session["MaHoaDon"].ToString()); DataTable dt = new DataTable(); BUS_CTHD busCTHD = new BUS_CTHD(); dt = busCTHD.LoadCTHD(mahd); gvCTHD.DataSource = dt.DefaultView; gvCTHD.PageIndex = int.Parse(Session["cthdPage"].ToString()); gvCTHD.DataBind(); }
protected void gvCTHD_PageIndexChanging(object sender, GridViewPageEventArgs e) { //load chi tiet hoa don DataTable dt = new DataTable(); BUS_CTHD busCTHD = new BUS_CTHD(); int mahd = int.Parse(Session["MaHoaDon"].ToString()); Session["cthdPage"] = e.NewPageIndex; dt = busCTHD.LoadCTHD(mahd); gvCTHD.DataSource = dt.DefaultView; gvCTHD.PageIndex = e.NewPageIndex; gvCTHD.DataBind(); }
protected void btnXacNhan_Click(object sender, EventArgs e) { if (Page.IsValid) { if (DateTime.Now.CompareTo(DateTime.Parse(txtNgayGiao.Text.Trim())) > 0) { lblNgayGiaoHang.Text = "Ngày giao hàng nhỏ hơn ngày hiện tại !"; return; } if (Session["Username"] != null && Session["GioHang"] != null) { string uname = (string)Session["Username"]; BUS_KhachHang busKH = new BUS_KhachHang(); int MaKH = busKH.LayMaKH(uname); string ngaylaphd = DateTime.Now.ToShortDateString(); string ngaygiaohang = txtNgayGiao.Text.Trim(); string dc = txtDCNhan.Text.Trim(); // them hoa don BUS_HoaDon busHD = new BUS_HoaDon(); HoaDon hd = new HoaDon(); hd.MAHD = int.Parse(DateTime.Now.Millisecond.ToString() + DateTime.Now.Second.ToString() + DateTime.Now.Minute.ToString()); hd.NGAYLAPHD = ngaylaphd; hd.NGAYGIAOHANG = ngaygiaohang; hd.MAKH = MaKH; hd.DIACHIGIAOHANG = dc; busHD.ThemHD(hd); //them chi tiet hoa don BUS_CTHD busCTHD = new BUS_CTHD(); ArrayList giohang = (ArrayList)Session["GioHang"]; ArrayList chitietHD = new ArrayList(); foreach (SanPham sp in giohang) { CTHD cthd = new CTHD(); cthd.MAHD = hd.MAHD; cthd.MASP = sp.MaSP; cthd.MASIZE = sp.MASIZE; cthd.SOLUONG = sp.SoLuong; cthd.DONGIA = sp.GiaBan; busCTHD.ThemCTHD(cthd); chitietHD.Add(cthd); } Session["chitietHD"] = chitietHD; Session["GioHang"] = null; Response.Redirect("thanhcong.htm"); } } }
protected void gvCTHD_RowDeleting(object sender, GridViewDeleteEventArgs e) { int mahd = int.Parse(gvCTHD.DataKeys[e.RowIndex].Value.ToString()); BUS_CTHD bus = new BUS_CTHD(); bus.XoaCTHD(mahd); gvCTHD.EditIndex = -1; DataTable dt = new DataTable(); BUS_CTHD busCTHD = new BUS_CTHD(); dt = busCTHD.LoadCTHD(mahd); gvCTHD.DataSource = dt.DefaultView; gvCTHD.PageIndex = int.Parse(Session["cthdPage"].ToString()); gvCTHD.DataBind(); }