예제 #1
0
파일: BO_TINH.cs 프로젝트: vhtrieu/HLTV
        public DataTable getTinh_All()
        {
            TINH tinh = new TINH();

            // DAL_TINH dao = new DAL_TINH();

            return(dao.getAll_TINH());
        }
예제 #2
0
파일: BO_TINH.cs 프로젝트: vhtrieu/HLTV
        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));
        }
예제 #3
0
파일: BO_TINH.cs 프로젝트: vhtrieu/HLTV
        public void delete(int tID)
        {
            TINH tinh = new TINH();

            tinh.TIN_ID = tID;


            dao.delete(tinh);
        }
예제 #4
0
        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));
 }
예제 #6
0
파일: BO_TINH.cs 프로젝트: vhtrieu/HLTV
        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);
        }
예제 #7
0
파일: BO_TINH.cs 프로젝트: vhtrieu/HLTV
        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);
        }
예제 #8
0
        private void UpdateGroupThongTinTinh()
        {
            TINH tinh = GetTinhWithID();

            txtTenTinh.Text = tinh.TEN;

            indexTinh1 = indexTinh;
            indexTinh  = dgvTinhView.FocusedRowHandle;

            LoadHuyen();
        }
예제 #9
0
        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));
        }
예제 #12
0
        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);
        }
예제 #13
0
        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;
            }
        }
예제 #14
0
        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);
        }
예제 #15
0
        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;
            }
        }
예제 #16
0
        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));
        }
예제 #19
0
        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();
        }