private void btnThem_Click(object sender, EventArgs e) { if (btnThem.Text == "Thêm") { UnlockControl(); EmptyControl(); btnThem.Text = "Lưu"; btnSua.Enabled = false; btnXoa.Text = "Hủy"; } else { PhongChieu item = new PhongChieu(); item.TenPhongChieu = txbTen.Text; item.ViTri = txbViTri.Text; item.TongSoGhe = Convert.ToInt32(txbSoGhe.Text); if (new PhongChieuDAO().AddPhongChieu(item)) { MessageBox.Show("Thêm thành công"); } else { MessageBox.Show("Không thành công"); } LockControl(); loadPhongChieu(); } }
public bool AddPhongChieu(PhongChieu item) { try { db.PhongChieux.Add(item); db.SaveChanges(); return(true); } catch { return(false); } }
// GET: Admin/PhongChieux/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PhongChieu phongChieu = db.Database.SqlQuery <PhongChieu>("exec sp_loadChiTietPhongChieu {0}", id).First <PhongChieu>(); if (phongChieu == null) { return(HttpNotFound()); } return(View(phongChieu)); }
public bool EditPhongChieu(PhongChieu item) { try { PhongChieu temp = db.PhongChieux.Find(item.ID); temp.TenPhongChieu = item.TenPhongChieu; temp.ViTri = item.ViTri; temp.TongSoGhe = item.TongSoGhe; db.SaveChanges(); return(true); } catch { return(false); } }
public ActionResult Edit([Bind(Include = "maphong,tenphong,soghebandau")] PhongChieu phongChieu) { try { if (ModelState.IsValid) { //db.Entry(phongChieu).State = EntityState.Modified; db.Database.SqlQuery <PhongChieu>("exec sp_editPhongChieu {0},{1},{2}", phongChieu.maphong, phongChieu.tenphong, phongChieu.soghebandau).ToList(); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (EntityCommandExecutionException ex) { return(RedirectToAction("Index")); } return(View(phongChieu)); }
public ActionResult Create([Bind(Include = "maphong,tenphong,soghebandau")] PhongChieu phongChieu) { try { if (ModelState.IsValid) { //db.PhongChieux.Add(phongChieu); db.Database.SqlQuery <PhongChieu>("exec sp_addPhongChieu {0}", phongChieu.tenphong).ToList(); db.SaveChanges(); return(RedirectToAction("Index")); } } catch (EntityCommandExecutionException ex) { return(RedirectToAction("Index")); } return(View(phongChieu)); }