private void btnThem_Click(object sender, EventArgs e) { if (txtTenHieuXe.Text != "") { try { HieuXe hx = new HieuXe() { TenHieuXe = txtTenHieuXe.Text }; HieuXeBUS.HieuXe_Insert(hx); MessageBox.Show("Thêm thành công"); dgvDanhSachHieuXe.DataSource = HieuXeBUS.HieuXe_GetHieuXe(); txtTenHieuXe.Text = null; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("Chưa nhập tên hiệu xe!", "Lỗi!!!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } btnXoa.Enabled = false; }
void LoadHieuXe() { List <HieuXe> list = new List <HieuXe> { }; list = HieuXeDAO.Instance.GetListHieuXe(); cbbHieuXe.DataSource = list; cbbHieuXe.DisplayMember = "TenHieuXe"; int id = XeDangChon.MaHieuXe; HieuXe h = HieuXeDAO.Instance.GetHieuXeByMaHieuXe(id); int index = -1; int i = 0; foreach (HieuXe item in cbbHieuXe.Items) { if (item.MaHieuXe == h.MaHieuXe) { index = i; break; } i++; } cbbHieuXe.SelectedIndex = index; }
private void txbMaXe_TextChanged(object sender, EventArgs e) { try { if (dtgvXe.SelectedCells.Count > 0) { int id = (int)dtgvXe.SelectedCells[0].OwningRow.Cells["Mã hiệu xe"].Value; HieuXe h = HieuXeDAO.Instance.GetHieuXeByMaHieuXe(id); int index = -1; int i = 0; foreach (HieuXe item in cbbHieuXe.Items) { if (item.MaHieuXe == h.MaHieuXe) { index = i; break; } i++; } cbbHieuXe.SelectedIndex = index; } } catch { } try { DataTable dt = new DataTable(); dt = XeDAO.Instance.GetXeByMaXe(Int32.Parse(txbMaXe.Text)); dtgvXe.DataSource = dt; } catch { } }
public ActionResult DeleteConfirmed(int id) { HieuXe hieuXe = db.HieuXes.Find(id); db.HieuXes.Remove(hieuXe); db.SaveChanges(); return(RedirectToAction("Index")); }
public void HieuXe_Delete(HieuXe Data) { using (var cmd = new SqlCommand("sp_HieuXe_Delete", GetConnection())) { cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter("@HieuXe", Data.TenHieuXe)); cmd.ExecuteNonQuery(); connection.Close(); } }
public ActionResult Edit([Bind(Include = "IDHieuXe,TenHieuXe")] HieuXe hieuXe) { if (ModelState.IsValid) { db.Entry(hieuXe).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hieuXe)); }
public ActionResult Create([Bind(Include = "IDHieuXe,TenHieuXe")] HieuXe hieuXe) { if (ModelState.IsValid) { db.HieuXes.Add(hieuXe); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hieuXe)); }
public HieuXe GetHieuXeByMaHieuXe(int MaHieuXe) { string query = "select * from dbo.HIEUXE where MaHieuXe =" + MaHieuXe; DataTable data = DataProvider.Instance.ExecuteQuery(query); HieuXe h = null; foreach (DataRow item in data.Rows) { h = new HieuXe(item); return(h); } return(h); }
public ActionResult SuaHieuXe(int id, HieuXe hieuXe) { if (ModelState.IsValid) { database.Entry(hieuXe).State = System.Data.Entity.EntityState.Modified; database.SaveChanges(); return(RedirectToAction("QuanLyHieuXe")); } else { return(View()); } }
public ActionResult ThemHieuXe(HieuXe hieuXe) { if (ModelState.IsValid) { database.HieuXes.Add(hieuXe); database.SaveChanges(); return(RedirectToAction("QuanLyHieuXe")); } else { return(View()); } }
public List <HieuXe> GetListHieuXe() { List <HieuXe> list = new List <HieuXe> { }; string query = "select * from dbo.HieuXe"; DataTable data = DataProvider.Instance.ExecuteQuery(query); foreach (DataRow item in data.Rows) { HieuXe h = new HieuXe(item); list.Add(h); } return(list); }
// GET: HieuXe/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HieuXe hieuXe = db.HieuXes.Find(id); if (hieuXe == null) { return(HttpNotFound()); } return(View(hieuXe)); }
public ActionResult XoaHieuXe(int id, HieuXe hieuXe) { try { hieuXe = database.HieuXes.Where(s => s.maHieuXe == id).FirstOrDefault(); database.HieuXes.Remove(hieuXe); database.SaveChanges(); return(RedirectToAction("QuanLyHieuXe")); } catch { return(Content("This data is using in other table, Error Delete!")); } }
private void btnXoa_Click(object sender, EventArgs e) { try { HieuXe hx = new HieuXe() { TenHieuXe = txtTenHieuXe.Text }; HieuXeBUS.HieuXe_Delete(hx); MessageBox.Show("Xóa thành công"); dgvDanhSachHieuXe.DataSource = HieuXeBUS.HieuXe_GetHieuXe(); } catch (Exception ex) { MessageBox.Show(ex.Message); } btnXoa.Enabled = false; txtTenHieuXe.Text = ""; }
public static void HieuXe_Insert(HieuXe Data) { db.HieuXe_Insert(Data); }
public static void HieuXe_Delete(HieuXe Data) { db.HieuXe_Delete(Data); }
public static void HieuXe_Update(HieuXe Data) { db.HieuXe_Update(Data); }