public async Task <IActionResult> PutLoaiHang([FromRoute] int id, [FromBody] LoaiHang loaiHang) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != loaiHang.IdLoaiHang) { return(BadRequest()); } _context.Entry(loaiHang).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoaiHangExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult DeleteConfirmed(string id) { LoaiHang loaiHang = db.LoaiHangs.Find(id); db.LoaiHangs.Remove(loaiHang); db.SaveChanges(); return RedirectToAction("Index"); }
public async Task <IActionResult> Edit(string id, [Bind("MaLH,Ten,MaCL")] LoaiHang loaiHang) { if (id != loaiHang.MaLH) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(loaiHang); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LoaiHangExists(loaiHang.MaLH)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MaCL"] = new SelectList(_context.ChungLoais, "MaCL", "MaCL", loaiHang.MaCL); return(View(loaiHang)); }
public IHttpActionResult PutLoaiHang(int id, LoaiHang loaiHang) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != loaiHang.LoaiHang_ID) { return(BadRequest()); } db.Entry(loaiHang).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!LoaiHangExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
private void cboLoaiHang_SelectedIndexChanged(object sender, EventArgs e) { txtMaSanPham.Text = ""; if (cboLoaiHang.SelectedIndex == -1) { return; } try { LoaiHang lh = cboLoaiHang.SelectedItem as LoaiHang; SanPhamBLL spBLL = new SanPhamBLL(); int soLuongSanPhamCuaMaSinh = spBLL.ValidMaSanPhamToAdd(lh.MaSanPhamTuSinh); txtMaSanPham.Text = lh.MaSanPhamTuSinh + soLuongSanPhamCuaMaSinh; txtTenSanPham.Focus(); //current san pham currentSanPham = new SanPham() { MaLoaiHang = lh.MaLoaiHang, MaSanPham = txtMaSanPham.Text }; } catch (Exception ex) { MessageBox.Show("Lỗi sản phẩm Lấy valid mã sinh\n" + ex.Message); } }
private void btnThem_Click(object sender, EventArgs e) { if (tbTenLoaiHang.Text.Length == 0) { erpName.SetError(tbTenLoaiHang, "Không được để trống"); } else { erpName.SetError(tbTenLoaiHang, ""); } if (erpName.GetError(tbTenLoaiHang).Length == 0) { var lh = new LoaiHang(); lh.TenLoaiHang = tbTenLoaiHang.Text; if (LoaiHangBus.createLoaiHang(lh)) { MessageBox.Show("Thêm mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); _frmLoaiHang.data = LoaiHangBus.getListLoaiHang(); _frmLoaiHang.dgvLoaiHang.DataSource = _frmLoaiHang.data; this.Close(); } else { MessageBox.Show("Thêm mới thất bại", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } }
public async Task <ActionResult> LH_Sua(LoaiHang lh, HttpPostedFileBase fileUpload) { if (fileUpload == null) { ViewBag.ThongBao = "Vui lòng chọn ảnh"; return(View()); } else { if (ModelState.IsValid) { var fileName = Path.GetFileName(fileUpload.FileName); var path = Path.Combine(Server.MapPath("~/HinhAnh/HinhAnh(LoaiHang)"), fileName); if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hình ảnh đã tồn tại"; } else { fileUpload.SaveAs(path); } LoaiHang lhh = db.LoaiHangs.Where(x => x.MSLH == lh.MSLH).Single <LoaiHang>(); lhh.TenLoaiHang = lh.TenLoaiHang; lhh.HinhAnh = fileName; await db.SaveChangesAsync(); } } return(RedirectToAction("LoaiHang")); }
public async Task <ActionResult> LH_Them(LoaiHang lh, HttpPostedFileBase fileupload) { if (fileupload == null) { ViewBag.ThongBao = "Vui lòng chọn ảnh"; return(View()); } else { if (ModelState.IsValid) { var fileName = Path.GetFileName(fileupload.FileName); var path = Path.Combine(Server.MapPath("~/HinhAnh/HinhAnh(LoaiHang)"), fileName); if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hình ảnh đã tồn tại"; } else { fileupload.SaveAs(path); } lh.HinhAnh = fileName; db.LoaiHangs.Add(lh); await db.SaveChangesAsync(); } return(RedirectToAction("LoaiHang")); } }
private void frmAddLoaiHang_Load(object sender, EventArgs e) { if (ID != null) { obj = db.LoaiHangs.Single(p => p.ID == ID); txtTenLoai.Text = obj.TenLoai; } }
private void dgvLoaiHang_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex > -1) { LoaiHang lh = bll.GetLoaiHangByID(dgvLoaiHang.Rows[e.RowIndex].Cells[0].Value.ToString()); txtMaLoai.Text = lh.MaLoai; txtTenLoai.Text = lh.TenLoai; } }
public async Task <ActionResult> DeleteConfirmed(int id) { LoaiHang loaiHang = await db.LoaiHangs.FindAsync(id); db.LoaiHangs.Remove(loaiHang); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public int Update(LoaiHang obj) { SqlParameter[] para = { new SqlParameter("IDLoaiHang", obj.IDLoaiHang), new SqlParameter("TenLoaiHang", obj.TenLoai), new SqlParameter("MoTa", obj.Mota) }; return(db.ExcuteSQL("sp_LoaiHang_Insert", para)); }
private void frmLoaiHang_Load(object sender, EventArgs e) { dgvLoaiHang.DataSource = bll.LoadAll(); if (dgvLoaiHang.Rows.Count > 0) { LoaiHang lh = bll.GetLoaiHangByID(dgvLoaiHang.Rows[0].Cells[0].Value.ToString()); txtMaLoai.Text = lh.MaLoai; txtTenLoai.Text = lh.TenLoai; } }
private void cmbLoaiHang_SelectedIndexChanged(object sender, EventArgs e) { if (cboLoaiHang.SelectedIndex == -1) { return; } LoaiHang lh = cboLoaiHang.SelectedItem as LoaiHang; HienThiSanPham(lh); }
private void btnXoaLoaiHang2_Click(object sender, EventArgs e) { LoaiHang lh = new LoaiHang(); lh.MaLoai = dgvLoaiHang.SelectedRows[0].Cells[0].Value.ToString(); frmXoaLoaiHang formXoaLoaiHang = new frmXoaLoaiHang(lh); formXoaLoaiHang.ShowDialog(); loadDuLieu(); }
public int Insert(LoaiHang obj) { SqlParameter[] param = { new SqlParameter("TenLoaiHang", obj.TenLoaiHang), new SqlParameter("MoTa", obj.MoTa), new SqlParameter("TinhTrang", obj.TinhTrang) }; return(DBConnect.Instance.ExecuteSQL("sp_LoaiHang_Insert", param)); }
public bool Update(LoaiHang lh) { string spName = "Update_LoaiHang"; string[] pNames = { "@ID", "@TenLoai" }; object[] pValues = { lh.MaLoai, lh.TenLoai }; int count = db.ExecuteStoredProcedure(spName, pNames, pValues); return(count > 0); }
public ActionResult Edit([Bind(Include = "IDLoaiHang,TenLoaiHang,GhiChu")] LoaiHang loaiHang) { if (ModelState.IsValid) { db.Entry(loaiHang).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(loaiHang)); }
public ActionResult Create([Bind(Include = "IDLoaiHang,TenLoaiHang,GhiChu")] LoaiHang loaiHang) { if (ModelState.IsValid) { db.LoaiHangs.Add(loaiHang); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(loaiHang)); }
public IHttpActionResult GetLoaiHang(int id) { LoaiHang loaiHang = db.LoaiHang.Find(id); if (loaiHang == null) { return(NotFound()); } return(Ok(loaiHang)); }
// Hàm tăng giá trị thuộc tính mã hàng hóa private void TangKeyValueHH(LoaiHang cat) { string maHHmax = BLL_HangHoa.Instance.FindProductMaxKey_BLL(cat); var maHH = Regex.Match(maHHmax, @"\d+").Value; var intmaHH = Int32.Parse(maHH); intmaHH++; maHHmax = cat.Mã_Loại + intmaHH.ToString("D4"); maHHmax = maHHmax.Replace(" ", string.Empty); txtMahang.Text = maHHmax; }
public ActionResult Edit([Bind(Include = "MaLH,Ten,MaCL")] LoaiHang loaiHang) { if (ModelState.IsValid) { db.Entry(loaiHang).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MaCL = new SelectList(db.ChungLoais, "MaCL", "Ten", loaiHang.MaCL); return(View(loaiHang)); }
public async Task <ActionResult> Edit([Bind(Include = "MSLH,TenLoaiHang,HinhAnh")] LoaiHang loaiHang) { if (ModelState.IsValid) { db.Entry(loaiHang).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(loaiHang)); }
private void btnLuuVaoDS_Click(object sender, EventArgs e) { LoaiHang lh = new LoaiHang(); lh.MaLoai = txtMaLoai.Text; lh.TenLoai = txtTenLoai.Text; bll.Update(lh); dgvLoaiHang.DataSource = bll.LoadAll(); MessageBoxEx.Show("Cập nhật thành công", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); }
public bool Delete(LoaiHang lh) { string spName = "Delete_LOAIHANG"; string[] pNames = { "@ID" }; object[] pValues = { lh.MaLoai }; int count = db.ExecuteStoredProcedure(spName, pNames, pValues); return(count > 0); }
public bool Insert(LoaiHang lh) { string spName = "Insert_LOAIHANG"; string[] pNames = { "@TenLoai" }; object[] pValues = { lh.TenLoai }; int count = db.ExecuteStoredProcedure(spName, pNames, pValues); return(count > 0); }
public static void ThemLoaiHang(LoaiHang Lh) { SqlConnection conn = SqlConnect.Connect(); SqlCommand cmd = new SqlCommand("THEM_LOAI_HANG", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add("@LOAI_HANG", SqlDbType.NVarChar, 50); cmd.Parameters["@LOAI_HANG"].Value = Lh.Tenlh; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); }
public async Task <IActionResult> PostLoaiHang([FromBody] LoaiHang loaiHang) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.LoaiHang.Add(loaiHang); await _context.SaveChangesAsync(); return(CreatedAtAction("GetLoaiHang", new { id = loaiHang.IdLoaiHang }, loaiHang)); }
public async Task <ActionResult> Create([Bind(Include = "MSLH,TenLoaiHang,HinhAnh")] LoaiHang loaiHang) { if (ModelState.IsValid) { db.LoaiHangs.Add(loaiHang); await db.SaveChangesAsync(); return(RedirectToAction("Index")); } return(View(loaiHang)); }
public List <LoaiHang> GetAll() { List <LoaiHang> list = new List <LoaiHang>(); DataTable data = DataProvider.Instance.ExecuteQuery("SP_LoaiHang_GetAll"); foreach (DataRow item in data.Rows) { LoaiHang entry = new LoaiHang(item); list.Add(entry); } return(list); }