public DataTable getTinh_All() { TINH tinh = new TINH(); // DAL_TINH dao = new DAL_TINH(); return(dao.getAll_TINH()); }
public DataTable getTinh_ByID(int tID) { TINH tinh = new TINH(); tinh.TIN_ID = tID; //DAL_TINH dao = new DAL_TINH(); return(dao.getByID_TINH(tinh)); }
public void delete(int tID) { TINH tinh = new TINH(); tinh.TIN_ID = tID; dao.delete(tinh); }
private void btnThemHuyen_Click(object sender, EventArgs e) { TINH tinh = GetTinhWithID(); if (tinh.ID == 0) { MessageBox.Show("Chưa có Tỉnh nào được chọn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (btnThemHuyen.Text == "Thêm Huyện") { btnThemHuyen.Text = "Lưu"; btnXoaHuyen.Text = "Hủy"; btnSuaHuyen.Enabled = false; dgvHuyenMain.Enabled = false; txtTenHuyen.Enabled = true; panelTinh.Enabled = false; panelXa.Enabled = false; ClearControlHuyen(); return; } if (btnThemHuyen.Text == "Lưu") { if (CheckHuyen()) { /// cập nhật lại trạng thái các control btnThemHuyen.Text = "Thêm Huyện"; btnXoaHuyen.Text = "Xóa Huyện"; btnSuaHuyen.Enabled = true; dgvHuyenMain.Enabled = true; txtTenHuyen.Enabled = false; panelTinh.Enabled = true; panelXa.Enabled = true; /// thêm huyện HUYEN huyen = new HUYEN(); huyen.TEN = txtTenHuyen.Text; huyen.TINHID = tinh.ID; db.HUYENs.Add(huyen); db.SaveChanges(); MessageBox.Show("Thêm thông tin Huyện thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadHuyen(); } return; } }
public ActionResult Edit([Bind(Include = "MaTinh,TenTinh")] TINH tINH) { if (ModelState.IsValid) { db.Entry(tINH).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tINH)); }
public void insert(string tCode, string tName) { TINH tinh = new TINH(); tinh.TIN_Code = tCode; tinh.TIN_Name = tName; //DAL_TINH dao = new DAL_TINH(); dao.insert(tinh); }
public void update(int tID, string tCode, string tName) { TINH tinh = new TINH(); tinh.TIN_ID = tID; tinh.TIN_Code = tCode; tinh.TIN_Name = tName; // DAL_TINH dao = new DAL_TINH(); dao.update(tinh); }
private void UpdateGroupThongTinTinh() { TINH tinh = GetTinhWithID(); txtTenTinh.Text = tinh.TEN; indexTinh1 = indexTinh; indexTinh = dgvTinhView.FocusedRowHandle; LoadHuyen(); }
private void btnSuaTinh_Click(object sender, EventArgs e) { /// kiểm tra xem có tỉnh nào được chọn không TINH tinh = GetTinhWithID(); if (tinh.ID == 0) { MessageBox.Show("Chưa có tỉnh nào được chọn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } /// code if (btnSuaTinh.Text == "Sửa Tỉnh") { btnSuaTinh.Text = "Lưu"; btnThemTinh.Enabled = false; btnXoaTinh.Text = "Hủy"; dgvTinhMain.Enabled = false; txtTenTinh.Enabled = true; panelHuyen.Enabled = false; panelXa.Enabled = false; return; } if (btnSuaTinh.Text == "Lưu") { if (CheckTinh()) { btnSuaTinh.Text = "Sửa Tỉnh"; btnThemTinh.Enabled = true; btnXoaTinh.Text = "Xóa Tỉnh"; dgvTinhMain.Enabled = true; txtTenTinh.Enabled = false; panelHuyen.Enabled = true; panelXa.Enabled = true; TINH ti = db.TINHs.Where(p => p.ID == tinh.ID).FirstOrDefault(); ti.TEN = txtTenTinh.Text; db.SaveChanges(); MessageBox.Show("Sửa thông tin tỉnh thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadTinh(); } return; } }
public ActionResult DeleteConfirmed(string id) { try { TINH tINH = db.TINHs.Find(id); db.TINHs.Remove(tINH); db.SaveChanges(); return(RedirectToAction("Index")); } catch (Exception e) { return(RedirectToAction("Delete", "TINHs", new { id = id, ed = 1 })); } }
// GET: PDT/TINHs/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TINH tINH = db.TINHs.Find(id); if (tINH == null) { return(HttpNotFound()); } return(View(tINH)); }
private TINH GetTinhWithID() { TINH ans = new TINH(); try { int ID = (int)dgvTinhView.GetFocusedRowCellValue("ID"); TINH tinh = db.TINHs.Where(p => p.ID == ID).FirstOrDefault(); return(tinh); } catch { } return(ans); }
private void btnXoaTinh_Click(object sender, EventArgs e) { if (btnXoaTinh.Text == "Xóa Tỉnh") { TINH tinh = GetTinhWithID(); if (tinh.ID == 0) { MessageBox.Show("Chưa có tỉnh nào được chọn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } DialogResult rs = MessageBox.Show("Bạn có chắc chắn xóa thông tin của tỉnh " + tinh.TEN + "?", "Thông báo", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (rs == DialogResult.Cancel) { return; } try { db.TINHs.Remove(tinh); db.SaveChanges(); MessageBox.Show("Xóa thông tin của tỉnh thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadTinh(); } catch { MessageBox.Show("Xóa thông tin của tỉnh thất bại\n", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } return; } if (btnXoaTinh.Text == "Hủy") { btnXoaTinh.Text = "Xóa Tỉnh"; btnSuaTinh.Enabled = true; btnSuaTinh.Text = "Sửa Tỉnh"; btnThemTinh.Enabled = true; btnThemTinh.Text = "Thêm Tỉnh"; dgvTinhMain.Enabled = true; txtTenTinh.Enabled = false; panelHuyen.Enabled = true; panelXa.Enabled = true; UpdateGroupThongTinTinh(); return; } }
public void CreatePostTinh() { TINHsController tinhController = new TINHsController(); tinhController.DeleteConfirmed("0002"); TINH tinh = new TINH { MaTinh = "0002", TenTinh = "Hồ Chí Minh" }; RedirectToRouteResult result = tinhController.Create(tinh) as RedirectToRouteResult; Assert.IsNotNull(result); string expected = "Index"; string actual = result.RouteValues["action"].ToString(); Assert.AreEqual(expected, actual); }
private void btnThemTinh_Click(object sender, EventArgs e) { if (btnThemTinh.Text == "Thêm Tỉnh") { btnThemTinh.Text = "Lưu"; btnXoaTinh.Text = "Hủy"; btnSuaTinh.Enabled = false; dgvTinhMain.Enabled = false; txtTenTinh.Enabled = true; panelHuyen.Enabled = false; panelXa.Enabled = false; ClearControl(); return; } if (btnThemTinh.Text == "Lưu") { if (CheckTinh()) { /// cập nhật lại trạng thái các control btnThemTinh.Text = "Thêm Tỉnh"; btnXoaTinh.Text = "Xóa Tỉnh"; btnSuaTinh.Enabled = true; dgvTinhMain.Enabled = true; txtTenTinh.Enabled = false; panelHuyen.Enabled = true; panelXa.Enabled = true; /// thêm tỉnh TINH tinh = new TINH(); tinh.TEN = txtTenTinh.Text; db.TINHs.Add(tinh); db.SaveChanges(); MessageBox.Show("Thêm thông tin Tỉnh thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); LoadTinh(); } return; } }
public void EditViewTinh() { TINHsController tinhController = new TINHsController(); TINH tinh = new TINH { MaTinh = "0002", TenTinh = "Hồ Chí Minh" }; tinhController.Create(tinh); ViewResult result = tinhController.Edit("0002") as ViewResult; Assert.IsNotNull(result); string expected = ""; string actual = result.ViewName; Assert.AreEqual(expected, actual); }
public ActionResult Create([Bind(Include = "MaTinh,TenTinh")] TINH tINH) { try { if (ModelState.IsValid) { db.TINHs.Add(tINH); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tINH)); } catch (Exception e) { return(RedirectToAction("Create", "TINHs", new { id = 1 })); } }
// GET: PDT/TINHs/Delete/5 public ActionResult Delete(string id, int ed = 0) { ViewBag.m = "Dung"; if (ed == 1) { ViewBag.m = "Sai"; } if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } TINH tINH = db.TINHs.Find(id); if (tINH == null) { return(HttpNotFound()); } return(View(tINH)); }
private void LoadHuyen() { TINH tinh = GetTinhWithID(); int i = 1; dgvHuyenMain.DataSource = db.HUYENs.Where(p => p.TINHID == tinh.ID).ToList() .OrderBy(p => p.TEN).Select(p => new { STT = i++, ID = p.ID, TenHuyen = p.TEN }).ToList(); // chỉnh lại index indexHuyen = indexHuyen1; dgvHuyenView.FocusedRowHandle = indexHuyen; dgvHuyenMain.Select(); /// txtHuyen txtTenHuyen.Enabled = false; UpdateGroupThongTinHuyen(); }