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();
        }
示例#3
0
        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();
        }
示例#5
0
 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));
 }
示例#6
0
        public ActionResult Create([Bind(Include = "MaLoaiKhach,TenLoaiKhach")] LoaiKhach loaiKhach)
        {
            if (ModelState.IsValid)
            {
                db.LoaiKhaches.Add(loaiKhach);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(loaiKhach));
        }
示例#7
0
        // 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));
        }
示例#8
0
        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);
        }
示例#9
0
        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);
        }
示例#10
0
        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);
        }