private void ItemsGet() { int sl = Convert.ToInt32(DropDownList1.SelectedValue); List <Products_info> list;; PagedDataSource objPds = new PagedDataSource(); list = Products_info.TimKiem(key); count = list.Count.ToString(); //phan trang objPds.DataSource = list; objPds.AllowPaging = true; objPds.PageSize = sl; objPds.CurrentPageIndex = CurrentPage; Label2.Text = (CurrentPage + 1).ToString() + "\\" + objPds.PageCount.ToString(); //Disable tien va lui buttons bntTroLai.Enabled = !objPds.IsFirstPage; bntNext.Enabled = !objPds.IsLastPage; if (objPds.DataSourceCount == 0) { Label2.Text = "0"; bntNext.Visible = false; bntTroLai.Visible = false; } DataList1.DataSource = objPds; DataList1.DataBind(); }
//cập nhật đơn hàng protected void bntCapNhat_Click(object sender, EventArgs e) { Orders_Info order = Orders_Info.getbyid(HiddenField1.Value); order.status = checklisstbox.SelectedValue; //update số lượng sản phẩm if (Orders_Info.Update_TrangThai(order)) { if (order.status == "2" || order.status == "1") { Orders_Info m = new Orders_Info(); List <OrderDetails_Info> list = Orders_Info.GetListOrdetails(Convert.ToInt32(HiddenField1.Value)); foreach (var item in list) { Products_info p = Products_info.getby_id(item.ProductsId.ToString()); p.pcount = p.pcount - item.SoLuong; int stt = 0; if (p.active == true) { stt = 1; } var result = Products_info.Update(p.id, p.id_item, p.pname, p.pmota, p.pchitiet, p.ppricecurrent.ToString(), p.ppriceold.ToString(), p.pimage, p.pnew, p.pkhuyenmai, p.phot, p.pngaydang, stt, p.pcount); if (result == true) { lblThongBao.Text = "Cập Nhật Thành Công"; } else { lblThongBao.Text = "Lỗi hệ thống"; } } } } }
protected void Page_Load(object sender, EventArgs e) { try { duongdan = Request.Url.ToString(); id = Request.QueryString["id"].ToString(); pro = Products_info.getby_id(id); gia = String.Format("{0:0,0 VND}", pro.ppricecurrent); Page.Title = pro.pname; //san pham cung loai int idcategori = pro.id_item; List <Products_info> list = Products_info.SanPhamCungLoai(4, idcategori, Convert.ToInt32(id)); if (list.Count > 0) { Repeater1.DataSource = list; Repeater1.DataBind(); } } catch (Exception) { Response.Redirect("Default.aspx"); } }
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { Cart_Temp ct = null; if (id != null) { ct = new Cart_Temp(); ct.pro = Products_info.getby_id(id); ct.amount = 1; if (Session["cart"] == null) { List <Cart_Temp> listP = new List <Cart_Temp>(); listP.Add(ct); Session["cart"] = listP; } else { List <Cart_Temp> listP2 = new List <Cart_Temp>(); listP2 = Session["cart"] as List <Cart_Temp>; if (!Cart_Temp.UpdateAmount(listP2, ct, 1)) { listP2.Add(ct); } Session["cart"] = listP2; } ScriptManager.RegisterStartupScript( this, this.GetType(), "alert", "alert('Sản phẩm đả được thêm vào giỏ hàng của bạn');location.href='default.aspx';", true); } }
protected void btn_Insert_Click(object sender, EventArgs e) { int pnew = 0, pkhuyenmai = 0, phot = 0, pactive = 0; string pngaydang = DateTime.Now.ToShortDateString(); int id_item = Convert.ToInt32(DropDownList1.SelectedValue); if (chkisnew.Checked) { pnew = 1; } if (chkissaleoff.Checked) { pkhuyenmai = 1; } if (chkbestsell.Checked) { phot = 1; } if (chk_enable.Checked) { pactive = 1; } string image = "no_picture.gif"; string pname = txt_tieude.Text.Trim(); string pmota = txt_mota.Text.Trim(); string pchitiet = FreeTextBox2.Text.Trim(); string pgiahientai = txtgiahientai.Text.Trim(); string pgiacu = txtgiacu.Text.Trim(); int pcount = Convert.ToInt32(txtcount.Text.Trim()); if (flimg.HasFile == true) { image = flimg.FileName; } if (Products_info.Add(id_item, pname, pmota, pchitiet, pgiahientai, pgiacu, image, pnew, pkhuyenmai, phot, pngaydang, pactive, pcount )) { upload(); ScriptManager.RegisterStartupScript( this, this.GetType(), "alert", "alert('Sản phẩm đã được thêm mới thành công');location.href='admin.aspx?page=sanpham';", true); } else { ScriptManager.RegisterStartupScript( this, this.GetType(), "alert", "alert('thêm sản phẩm không thành công');", true); } }
private void ItemsGet() { PagedDataSource objPds = new PagedDataSource(); List <Products_info> list = Products_info.GetHot(); objPds.DataSource = list; objPds.AllowPaging = true; objPds.PageSize = 8; objPds.CurrentPageIndex = CurrentPage; DataList1.DataSource = objPds; DataList1.DataBind(); }
protected void rptcartV_ItemCommand(object source, RepeaterCommandEventArgs e) { if (e.CommandName.ToLower() == "update") { TextBox txtSl = (TextBox)e.Item.FindControl("txtSoluong"); string pid = e.CommandArgument.ToString(); Cart_Temp ct = Cart_Temp.FindProduct(list, int.Parse(pid)); if (ct != null) { ct.amount = int.Parse(txtSl.Text); if (Products_info.getby_id(pid).pcount < ct.amount) { ScriptManager.RegisterStartupScript( this, this.GetType(), "alert", "alert('Số lượng sản phẩm vượt quá số lượng cho phép');" + "location.href='default.aspx?page=cart';", true); ct.amount = 1; BindRepeater(); } else { BindRepeater(); } } } if (e.CommandName.ToLower() == "remove") { string pid = e.CommandArgument.ToString(); if (pid != null) { Cart_Temp.Delete(list, int.Parse(pid)); } BindRepeater(); } if (e.CommandName.ToLower() == "checkout") { if (Session["user"] == null) { Response.Redirect("AccLogin.aspx"); return; } Session["Cart"] = null; Response.Redirect("Default.aspx"); } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { try { PagedDataSource objPds = new PagedDataSource(); List <Products_info> dt = Products_info.GetNew(); objPds.DataSource = dt; objPds.AllowPaging = true; objPds.PageSize = 8; objPds.CurrentPageIndex = CurrentPage; DataList2.DataSource = objPds; DataList2.DataBind(); } catch { } } }
//tìm kiếm protected void btnTimKiem_Click(object sender, ImageClickEventArgs e) { string key = TextBox1.Text.Trim(); MultiView1.ActiveViewIndex = 0; List <Products_info> list = Products_info.TimKiem(key); if (list.Count > 0) { GridView1.DataSource = list; GridView1.DataBind(); Label5.Text = ""; } else { GridView1.DataSource = list; GridView1.DataBind(); Label5.Text = "Rất tiếc!Chúng tôi không tìm thấy kết quả nào!"; } }
//bắt sự kiện 2 nút trong gridview1 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { string name = e.CommandName; int id = Convert.ToInt32(e.CommandArgument.ToString()); Products_info pr = Products_info.getby_id(id.ToString()); switch (name) { case "kichhoat": bool active; if (pr.active == true) { active = false; } else { active = true; } Products_info.Active_pro(active, id); Response.Redirect("admin.aspx?page=sanpham"); break; case "del": Products_info.Delete(id.ToString()); Response.Redirect("admin.aspx?page=sanpham"); break; case "sua": e_ddlitem.DataSource = category_info.category_GetDanhMucCon(true);; e_ddlitem.DataTextField = "names"; e_ddlitem.DataValueField = "id"; e_ddlitem.DataBind(); //e_ddlitem.SelectedValue = dt_cata_item.Rows[0][2].ToString(); // if (pr != null) { HiddenField1.Value = pr.pimage; HiddenField2.Value = pr.pngaydang; e_image.ImageUrl = "../uploads/products/" + pr.pimage; e_id.Text = pr.id.ToString(); e_tieudeu.Text = pr.pname; e_mota.Text = pr.pmota; e_chitiet.Text = pr.pchitiet; e_giahientai.Text = pr.ppricecurrent.ToString(); e_giacu.Text = pr.ppriceold.ToString(); e_chnew.Checked = Convert.ToBoolean(pr.pnew); e_chkhuyenmai.Checked = Convert.ToBoolean(pr.pkhuyenmai); e_chhot.Checked = Convert.ToBoolean(pr.phot); e_chactive.Checked = Convert.ToBoolean(pr.active); e_ddlitem.SelectedValue = pr.id_item.ToString(); // e_chngaydang.Checked = Convert.ToBoolean(dt.Rows[0][11].ToString()); MultiView1.ActiveViewIndex = 2; } break; } }
protected void Page_Load(object sender, EventArgs e) { MultiView1.ActiveViewIndex = 0; GridView1.DataSource = Products_info.getall(); GridView1.DataBind(); }
//// update san pham protected void Button2_Click(object sender, EventArgs e) { int pnew = 0, pkhuyenmai = 0, phot = 0, pactive = 0; string image, e_pngaydang; int id_item = Convert.ToInt32(e_ddlitem.SelectedValue); if (e_chnew.Checked) { pnew = 1; } if (e_chkhuyenmai.Checked) { pkhuyenmai = 1; } if (e_chhot.Checked) { phot = 1; } if (e_chactive.Checked) { pactive = 1; } if (e_chngaydang.Checked) { e_pngaydang = DateTime.Now.ToShortDateString(); } else { e_pngaydang = HiddenField2.Value; } if ((e_id.Text == "") || (e_tieudeu.Text == "") || (e_mota.Text == "") || (e_chitiet.Text == "") || (e_giahientai.Text == "")) { Response.Write("<script>window.alert('Lỗi!Hãy kiểm tra lại dữ liệu của bạn')</script>"); } else { if (e_FileUpload1.HasFile) { image = e_FileUpload1.FileName; upload_update(); } else { image = HiddenField1.Value; } int id = Convert.ToInt32(e_id.Text.Trim()); string pnameu = e_tieudeu.Text.Trim(); string pmota = e_mota.Text.Trim(); string pchitiet = e_chitiet.Text.Trim(); string giamoi = e_giahientai.Text.Trim(); string giahientai = e_giacu.Text.Trim(); if (Products_info.Update(id, id_item, pnameu, pmota, pchitiet, giamoi, giahientai, image, pnew, pkhuyenmai, phot, e_pngaydang, pactive)) { ScriptManager.RegisterStartupScript( this, this.GetType(), "alert", "alert('Sản phẩm đả được Cập nhật thành công');location.href='admin.aspx?page=sanpham';", true); } else { ScriptManager.RegisterStartupScript( this, this.GetType(), "alert", "alert('Lổi cập nhật');location.href='admin.aspx?page=sanpham';", true); } } }