예제 #1
0
 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;
 }
예제 #2
0
        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;
        }
예제 #3
0
        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 { }
        }
예제 #4
0
        public ActionResult DeleteConfirmed(int id)
        {
            HieuXe hieuXe = db.HieuXes.Find(id);

            db.HieuXes.Remove(hieuXe);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
예제 #5
0
 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();
     }
 }
예제 #6
0
 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));
 }
예제 #7
0
        public ActionResult Create([Bind(Include = "IDHieuXe,TenHieuXe")] HieuXe hieuXe)
        {
            if (ModelState.IsValid)
            {
                db.HieuXes.Add(hieuXe);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hieuXe));
        }
예제 #8
0
        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);
        }
예제 #9
0
 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());
     }
 }
예제 #10
0
 public ActionResult ThemHieuXe(HieuXe hieuXe)
 {
     if (ModelState.IsValid)
     {
         database.HieuXes.Add(hieuXe);
         database.SaveChanges();
         return(RedirectToAction("QuanLyHieuXe"));
     }
     else
     {
         return(View());
     }
 }
예제 #11
0
        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);
        }
예제 #12
0
        // 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));
        }
예제 #13
0
 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!"));
     }
 }
예제 #14
0
 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);
 }
예제 #17
0
 public static void HieuXe_Update(HieuXe Data)
 {
     db.HieuXe_Update(Data);
 }