public void update(string maloai, string ten) { LoaiKhach loaiKhach = db.LoaiKhaches.Single(p => p.MaLoaiKhach == maloai); loaiKhach.TenLoaiKhach = ten; db.SubmitChanges(); }
public void delete(string maloai) { LoaiKhach loaiKhach = db.LoaiKhaches.Single(p => p.MaLoaiKhach == maloai); db.LoaiKhaches.DeleteOnSubmit(loaiKhach); db.SubmitChanges(); }
public ActionResult DeleteConfirmed(string id) { LoaiKhach loaiKhach = db.LoaiKhaches.Find(id); db.LoaiKhaches.Remove(loaiKhach); db.SaveChanges(); return(RedirectToAction("Index")); }
// them loai khach public void insert(string ten) { LoaiKhach loaiKhach = new LoaiKhach(); loaiKhach.MaLoaiKhach = laymaloaikhach(); loaiKhach.TenLoaiKhach = ten; db.LoaiKhaches.InsertOnSubmit(loaiKhach); db.SubmitChanges(); }
public ActionResult Edit([Bind(Include = "MaLoaiKhach,TenLoaiKhach")] LoaiKhach loaiKhach) { if (ModelState.IsValid) { db.Entry(loaiKhach).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(loaiKhach)); }
public ActionResult Create([Bind(Include = "MaLoaiKhach,TenLoaiKhach")] LoaiKhach loaiKhach) { if (ModelState.IsValid) { db.LoaiKhaches.Add(loaiKhach); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(loaiKhach)); }
// GET: LoaiKhaches/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LoaiKhach loaiKhach = db.LoaiKhaches.Find(id); if (loaiKhach == null) { return(HttpNotFound()); } return(View(loaiKhach)); }
static public int Update(LoaiKhach lk) { if (LoadOne(lk.MaLoai) == null) { return(0); } SqlConnection cnn = new SqlConnection(App.sConnB.ConnectionString); string sql = string.Format("Update LoaiKhach Set LoaiKhach = '{0}'" + "Where MaLoai = {1}", lk.TenLoai, lk.MaLoai); SqlCommand comm = new SqlCommand(sql, cnn); cnn.Open(); int affectCount = comm.ExecuteNonQuery(); cnn.Close(); return(affectCount); }
static public int Insert(LoaiKhach lk) { if (LoadOne(lk.MaLoai) != null) { return(0); } SqlConnection cnn = new SqlConnection(App.sConnB.ConnectionString); string sql = string.Format("Insert into LoaiKhach values (N'{0}')", lk.TenLoai); SqlCommand comm = new SqlCommand(sql, cnn); cnn.Open(); int affectCount = comm.ExecuteNonQuery(); cnn.Close(); return(affectCount); }
static public LoaiKhach LoadOne(int maLoai) { SqlConnection cnn = new SqlConnection(App.sConnB.ConnectionString); string sql = "select * from LoaiKhach where MaLoai = " + maLoai; SqlDataAdapter da = new SqlDataAdapter(sql, cnn); DataTable table = new DataTable(); da.Fill(table); if (table.Rows.Count < 1) { return(null); } LoaiKhach lk = new LoaiKhach(table.Rows[0].Field <int>(0), table.Rows[0].Field <string>(1)); return(lk); }