private void dgvHoaDon_CellClick(object sender, DataGridViewCellEventArgs e) { textBoxNSX.Visible = true; textBoxLoaiSP.Visible = true; textBoxDSP.Visible = true; textBoxMauKieu.Visible = true; textBoxMaKieuSP.Visible = true; textBoxSP.Visible = true; int r = dgvHoaDon.CurrentCell.RowIndex; string id = dgvHoaDon.Rows[r].Cells[1].Value.ToString(); USP_GETAllInfoSPNew_Result sp = ChiTietSPBUS.GetMaSPByMaKieuSP(id); textBoxNSX.Text = sp.TenHSX; textBoxLoaiSP.Text = sp.TenLSP; textBoxDSP.Text = sp.TenDong; textboxGiaBan.Text = dgvHoaDon.Rows[r].Cells[3].Value.ToString(); textBoxSLTon.Text = ChiTietSPBUS.GetChiTietSPOderByMaCHByIDKieuSP(textBoxMaCH.Text, id).SoluongSP.ToString(); textBoxMaKieuSP.Text = sp.MaKieu; textBoxTenSP.Text = sp.TenSP; textBoxSLMua.Text = dgvHoaDon.Rows[r].Cells[2].Value.ToString(); ChiTietSP ct = ChiTietSPBUS.Get1ChiTietSPByIDMaKieu(id); textBoxSP.Text = ct.MaSP.ToString(); textBoxMauKieu.Text = ct.MaMau.ToString(); try { pictureBox.BackgroundImage = ConverBinaryToImage(ct.Anh); } catch { pictureBox.BackgroundImage = null; } }
// them gio hang public RedirectResult addToCart(string sMaSanpham) { ChiTietSP sp = db.ChiTietSPs.Find(sMaSanpham); GioHang item = new GioHang() { sMaSP = sMaSanpham, sTenSP = sp.TenSP, iSoLuong = 1, dDonGia = (double)sp.DonGia, sAnhDaiDien = sp.Anh }; if (Session["GioHang"] == null) { Session["GioHang"] = new List <GioHang>(); (Session["GioHang"] as List <GioHang>).Add(item); } else { GioHang itemInCart = (Session["GioHang"] as List <GioHang>).SingleOrDefault(m => m.sMaSP == sMaSanpham); if (itemInCart != null) { itemInCart.iSoLuong++; } else { (Session["GioHang"] as List <GioHang>).Add(item); } } return(Redirect(HttpContext.Request.UrlReferrer.ToString())); }
private void comboBoxMaKieu_SelectedIndexChanged(object sender, EventArgs e) { try { string id = comboBoxMaKieu.SelectedValue.ToString(); ChiTietSP ct = ChiTietSPBUS.GetChiTietSPOderByMaCHByIDKieuSP(textBoxMaCH.Text, id); if (ct != null) { textBoxSLTon.Text = ct.SoluongSP.ToString(); textboxGiaBan.Text = ct.Gia.ToString(); comboBoxMau.SelectedValue = ct.MaMau; try { pictureBox.BackgroundImage = ConverBinaryToImage(ct.Anh); } catch { pictureBox.BackgroundImage = null; } } else { textBoxSLTon.Text = ""; textboxGiaBan.Text = ""; } } catch { textBoxSLTon.Text = ""; textboxGiaBan.Text = ""; } }
public ActionResult DeleteConfirmed(int id) { ChiTietSP chiTietSP = db.ChiTietSPs.Find(id); db.ChiTietSPs.Remove(chiTietSP); db.SaveChanges(); return(RedirectToAction("Index")); }
public void ThemKieuSp(ChiTietSP obj) { using (GalaxyMobileEntities db = new GalaxyMobileEntities()) { db.ChiTietSPs.Add(obj); db.SaveChangesAsync(); } }
public ActionResult Edit([Bind(Include = "MaCTSP,ChungLoai,XuatXu,NamSanXuat,KichThuoc,ChieuDaiCoSo,TuTrong,DungTichXiLanh,KieuDongCo,HopSo,CongSuatLonNhat,Momen,TocDoToiDa,NhienLieu,KieuDanDong,SoChoNgoi,TieuThu,CoLop,MoTa")] ChiTietSP chiTietSP) { if (ModelState.IsValid) { db.Entry(chiTietSP).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(chiTietSP)); }
void LoadSP() { try { Sp = ChiTietSPBUS.GetMaSPByIDKieuSP(IDMaKieu); CtSp = ChiTietSPBUS.Get1ChiTietSPByIDMaKieu(IDMaKieu); DSp = DongSanPhamBUS.Get1DongSPByMaSP(Sp.MaDSP); } catch { } }
// GET: ViewDetail public ActionResult ViewDetails(string _id) { ChiTietSP sanphamDC = db.ChiTietSPs.FirstOrDefault(m => m.MaSP == _id); if (sanphamDC == null) { Response.StatusCode = 404; return(null); } return(View(sanphamDC)); }
// GET: ChiTietSPs/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChiTietSP chiTietSP = db.ChiTietSPs.Find(id); if (chiTietSP == null) { return(HttpNotFound()); } return(View(chiTietSP)); }
// GET: ManagerSanPham/Details/5 public ActionResult Details(string _id) { if (_id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChiTietSP chiTietSP = db.ChiTietSPs.Find(_id); if (chiTietSP == null) { return(HttpNotFound()); } return(View(chiTietSP)); }
// GET: ManagerSanPham/Edit/5 public ActionResult Edit(string _id) { if (_id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ChiTietSP chiTietSP = db.ChiTietSPs.Find(_id); if (chiTietSP == null) { return(HttpNotFound()); } ViewBag.MaNSX = new SelectList(db.ChiTietNSXes, "MaNSX", "TenNSX", chiTietSP.MaNSX); ViewBag.MaSP = new SelectList(db.SanPhams, "MaSP", "MaSP", chiTietSP.MaSP); return(View(chiTietSP)); }
private void comboBoxCHPP_SelectedIndexChanged(object sender, EventArgs e) { try { textBoxSLTonCHPP.Text = ""; string id = comboBoxCHPP.SelectedValue.ToString(); ChiTietSP ct = new ChiTietSP(); if (textBoxMaKieu.Text.Trim(' ') != "") { ct = ChiTietSPBUS.GetChiTietSPOderByMaCHByIDKieuSP(id, textBoxMaKieu.Text); } else { ct = null; } textBoxSLTonCHPP.Text = ct.SoluongSP.ToString(); } catch { } }
private void cmBoxMaKieuSP_SelectedIndexChanged(object sender, EventArgs e) { try { string id = cmBoxMaKieuSP.SelectedValue.ToString(); //ChiTietSP sp = ChiTietSPBUS.Get1ChiTietSPByIDMaKieu(id); if (IDMode == "ts") { ChiTietSP sp = ChiTietSPBUS.Get1ChiTietSPByIDMaKieu(id); cmBoxMauSP.DataSource = ChiTietSPBUS.GetAllMauSP(); cmBoxMauSP.ValueMember = "MaMau"; cmBoxMauSP.DisplayMember = "Mau"; cmBoxMauSP.SelectedValue = sp.MaMau; txtBoxGiaSP.Text = sp.Gia.ToString(); txtboxSoLuongAll.Text = sp.SoluongSP.ToString(); //picBoxKieuSP.Image = null; picBoxKieuSP.BackgroundImage = null; textBoxPathAnh.Text = ""; //picBoxKieuSP.Image = ConverBinaryToImage(sp.Anh); picBoxKieuSP.BackgroundImage = ConverBinaryToImage(sp.Anh); } else { ChiTietSP sp = ChiTietSPBUS.GetChiTietSPOderByMaCHByIDKieuSP(IDMode, id); cmBoxMauSP.SelectedValue = sp.MaMau; txtBoxGiaSP.Text = sp.Gia.ToString(); txtboxSoLuongAll.Text = sp.SoluongSP.ToString(); //picBoxKieuSP.Image = null; picBoxKieuSP.BackgroundImage = null; textBoxPathAnh.Text = ""; //picBoxKieuSP.Image = ConverBinaryToImage(sp.Anh); picBoxKieuSP.BackgroundImage = ConverBinaryToImage(sp.Anh); } //cmBoxMauSP.SelectedValue = sp.MaMau; //txtBoxGiaSP.Text = sp.Gia.ToString(); //txtboxSoLuongAll.Text = sp.SoluongSP.ToString(); //picBoxKieuSP.Image = null; //textBoxPathAnh.Text = ""; //picBoxKieuSP.Image = ConverBinaryToImage(sp.Anh); } catch { } }
private void comboBoxMaKieu_SelectedIndexChanged(object sender, EventArgs e) { try { textBoxSLTonKieu.Text = ""; pictureBox.BackgroundImage = null; khoHangBindingSource.DataSource = null; textBoxMaKieu.Text = ""; string id = comboBoxMaKieu.SelectedValue.ToString(); CtSp = ChiTietSPBUS.Get1ChiTietSPByIDMaKieu(id); textBoxMaKieu.Text = CtSp.MaKieu; textBoxSLTonKieu.Text = CtSp.SoluongSP.ToString(); try { pictureBox.BackgroundImage = ConverBinaryToImage(CtSp.Anh); } catch { pictureBox.BackgroundImage = null; } khoHangBindingSource.DataSource = KhoHangBUS.GetAllKhoHangByMaKieu(CtSp.MaKieu); } catch { } }
public ActionResult Create([Bind(Include = "MaSP,TenSP,MaNSX,CPU,RAM,HDD,Screen,DonGia")] ChiTietSP chiTietSP, HttpPostedFileBase file) { if (file == null || file.ContentLength == 0) { ModelState.AddModelError("", "Chưa chọn hình"); } else { string extend = System.IO.Path.GetExtension(file.FileName); if (extend != ".jpg" && extend != ".jpeg" && extend != ".png") { ModelState.AddModelError("", "Hình ảnh phải có đuôi .jpg hoặc .jpeg hoặc .png"); } else { chiTietSP.Anh = chiTietSP.MaSP + extend; try { file.SaveAs(Server.MapPath("~/Content/Images/" + chiTietSP.Anh)); } catch { ModelState.AddModelError("", "Xảy ra lỗi khi lưu hình"); } } } if (ModelState.IsValid) { db.ChiTietSPs.Add(chiTietSP); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaNSX = new SelectList(db.ChiTietNSXes, "MaNSX", "TenNSX", chiTietSP.MaNSX); ViewBag.MaSP = new SelectList(db.SanPhams, "MaSP", "MaSP", chiTietSP.MaSP); return(View(chiTietSP)); }
public void LoadChiTietSP() { //try //{ LoadSP(); //} //catch //{ //} comboBoxCHNhan.DataSource = CuaHangBUS.GetAllCuaHang(); comboBoxCHNhan.DisplayMember = "TenCuaHang"; comboBoxCHNhan.ValueMember = "MaCuaHang"; comboBoxCHPP.DataSource = CuaHangBUS.GetAllCuaHang(); comboBoxCHPP.DisplayMember = "TenCuaHang"; comboBoxCHPP.ValueMember = "MaCuaHang"; comboBoxNXS.DataSource = HSXBUS.GetAllHSX(); comboBoxNXS.DisplayMember = "TenHSX"; comboBoxNXS.ValueMember = "MaHSX"; comboBoxNXS.SelectedValue = DSp.MaHSX; comboBoxDSP.DataSource = DongSanPhamBUS.GetAllDongSPByMaHSX(DSp.MaHSX); comboBoxDSP.DisplayMember = "TenDong"; comboBoxDSP.ValueMember = "MaDSP"; comboBoxDSP.SelectedValue = DSp.MaDSP; comboBoxSP.DataSource = SanPhamBUS.GetSanPhamByMaDSP(DSp.MaDSP); comboBoxSP.DisplayMember = "TenSP"; comboBoxSP.ValueMember = "MaSP"; comboBoxSP.SelectedValue = Sp.MaSP; comboBoxMaKieu.DataSource = ChiTietSPBUS.GetChiTietSPByIDSP(Sp.MaSP); comboBoxMaKieu.DisplayMember = "MaKieu"; comboBoxMaKieu.ValueMember = "MaKieu"; CtSp = ChiTietSPBUS.Get1ChiTietSPByIDMaKieu(IDMaKieu); comboBoxMaKieu.SelectedValue = CtSp.MaKieu; textBoxSLTonKieu.Text = CtSp.SoluongSP.ToString(); pictureBox.BackgroundImage = ConverBinaryToImage(CtSp.Anh); khoHangBindingSource.DataSource = KhoHangBUS.GetAllKhoHangByMaKieu(CtSp.MaKieu); }
private void cmBoxKieuSP_SelectedIndexChanged(object sender, EventArgs e) { try { string id = cmBoxKieuSP.SelectedValue.ToString(); ChiTietSP ct = ChiTietSPBUS.Get1ChiTietSPByIDMaKieu(id); if (ct != null) { txtBoxSLTon.Text = ct.SoluongSP.ToString(); txtboxGiaBan.Text = ct.Gia.ToString(); } else { txtBoxSLTon.Text = ""; txtboxGiaBan.Text = ""; } } catch { txtBoxSLTon.Text = ""; txtboxGiaBan.Text = ""; } }
private async void btnLuuKieuSP_Click(object sender, EventArgs e) { using (GalaxyMobileEntities db = new GalaxyMobileEntities()) { ChiTietSP sp = new ChiTietSP(); try { // sp.Anh = CovertImageToBinary(picBoxKieuSP.Image); sp.Anh = CovertImageToBinary(picBoxKieuSP.BackgroundImage); } catch { } sp.Gia = 0; sp.SoluongSP = 0; sp.MaKieu = textBoxMaKieu.Text; sp.MaSP = /*textBoxMaSP.Text;*/ cmBoxMaSP.SelectedValue.ToString(); sp.MaMau = cmBoxMauSP.SelectedValue.ToString(); try { if (NewCTSP) { db.ChiTietSPs.Add(sp); db.SaveChanges(); // await db.SaveChangesAsync(); MessageBox.Show("Thêm Thành Công!", "Thông Báo"); ChiTietSPBUS.Them_CTSPMoi_Into_KhoHang_(sp.MaKieu); } else { try { // sp.Anh = CovertImageToBinary(picBoxKieuSP.Image); sp.Anh = CovertImageToBinary(picBoxKieuSP.BackgroundImage); } catch { sp.Anh = ChiTietSPBUS.LayAnhKieuSP(cmBoxMaKieuSP.SelectedValue.ToString(), cmBoxMaSP.SelectedValue.ToString()); } int r = dgvCTSP.CurrentCell.RowIndex; //sp.Gia = Convert.ToDecimal(dgvCTSP.Rows[r].Cells[3].Value.ToString()); sp.Gia = Convert.ToDecimal(txtBoxGiaSP.Text); sp.SoluongSP = Convert.ToInt32(txtboxSoLuongAll.Text); db.ChiTietSPs.Attach(sp); db.Entry(sp).State = System.Data.Entity.EntityState.Modified; await db.SaveChangesAsync(); MessageBox.Show("Thay Đổi Thành Công!", "Thông Báo"); string id = cmBoxMaSP.SelectedValue.ToString(); chiTietSPBindingSource.DataSource = ChiTietSPBUS.GetChiTietSPByIDSP(id); } } catch { MessageBox.Show("Không Thể Thực Hiện Thao Tác!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } } btnLuuKieuSP.Visible = false; btnHuyKieuSP.Visible = false; btnThemKieuSP.Visible = true; btnChinhSuaKieuSP.Visible = true; btnXoaKieuSP.Visible = true; textBoxMaKieu.ReadOnly = false; textBoxMaSP.ReadOnly = false; textBoxMaKieu.Visible = false; textBoxMaSP.Visible = false; txtBoxGiaSP.ReadOnly = true; textBoxMau.Visible = false; dgvCTSP.Enabled = true; }
//public IEnumerable<ChiTietSP> ListAll(string searchString, int page, int pageSize) //{ // IQueryable<ChiTietSP> x = context.ChiTietSPs; // if (!string.IsNullOrEmpty(searchString)) // { // x = x.Where(y => y.ChungLoai.Contains(searchString)); // } // //context.Database.SqlQuery<Category>("Sp_Category_ListAll"); Lay tu proceduce ra se nhu tn // var list = x.OrderByDescending(y => y.NamSanXuat).ToPagedList(page, pageSize); // return list; //} public long Insert(ChiTietSP lh) { context.ChiTietSPs.Add(lh); context.SaveChanges(); return(lh.MaCTSP); }