public void Index(string type, int ma) { DataProvider dp = new DataProvider(); type = type.Trim().ToLower(); if (type.CompareTo("loaddsquan") == 0) { //Load danh sach thanh pho string sql = @"SELECT * FROM quan WHERE mathanhpho = " + ma; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); List<Quan> dsQuan = new List<Quan>(); Response.Write("<option value='0'>Tất cả</option>"); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Quan item = new Quan(); item.MaQuan = (int)dt.Rows[i]["maquan"]; item.TenQuan = dt.Rows[i]["tenquan"].ToString(); item.MaThanhPho = (int)dt.Rows[i]["mathanhpho"]; dsQuan.Add(item); Response.Write("<option value='" + item.MaQuan.ToString() + "'>" + item.TenQuan + "</option>"); } } } else if (type.CompareTo("loaddsduong") == 0) { //Load danh sach Duong string sql = @"SELECT * FROM duong WHERE maquan = " + ma; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); List<Duong> dsDuong = new List<Duong>(); Response.Write("<option value='0'>Tất cả</option>"); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Duong item = new Duong(); item.MaDuong = (int)dt.Rows[i]["maduong"]; item.TenDuong = dt.Rows[i]["tenduong"].ToString(); item.MaQuan = (int)dt.Rows[i]["maquan"]; dsDuong.Add(item); Response.Write("<option value='" + item.MaDuong.ToString() + "'>" + item.TenDuong + "</option>"); } } } }
public static List<Quan> ListQuan() { List<Quan> ls = new List<Quan>(); try { DataProvider dp = new DataProvider(); string sql = @"SELECT * FROM quan ORDER BY maquan"; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Quan item = new Quan(); item.MaQuan = (int)dt.Rows[i]["maquan"]; item.TenQuan = (string)dt.Rows[i]["tenquan"]; item.MaThanhPho = (int)dt.Rows[i]["mathanhpho"]; ls.Add(item); } } return ls; } catch (Exception ex) { return ls; } }
public static List<Duong> ListDuong() { List<Duong> ls = new List<Duong>(); try { DataProvider dp = new DataProvider(); string sql = @"SELECT * FROM duong ORDER BY maduong"; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Duong item = new Duong(); item.MaDuong = (int)dt.Rows[i]["maduong"]; item.TenDuong = (string)dt.Rows[i]["tenduong"]; item.MaQuan = (int)dt.Rows[i]["maquan"]; ls.Add(item); } } return ls; } catch (Exception ex) { return ls; } }
public ActionResult Index() { try { DataProvider dp = new DataProvider(); string sql= @"SELECT * FROM duong ORDER BY tenduong"; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); List<Duong> ls = new List<Duong>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Duong item = new Duong(); item.MaDuong = (int)dt.Rows[i]["maduong"]; item.TenDuong = (string)dt.Rows[i]["tenduong"]; item.MaQuan = (int)dt.Rows[i]["maquan"]; ls.Add(item); } } return PartialView("~/Views/Shared/Duong.cshtml", ls); } catch (Exception ex) { return PartialView("~/Views/Shared/Duong.cshtml"); } }
// // GET: /TimKiem/ public ActionResult Index() { DataProvider dp = new DataProvider(); //Load danh sach thanh pho string sql = @"SELECT * FROM thanhpho t "; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); List<ThanhPho> dsThanhPho = new List<ThanhPho>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ThanhPho item = new ThanhPho(); item.MaThanhPho = (int)dt.Rows[i]["mathanhpho"]; item.TenThanhPho = dt.Rows[i]["tenthanhpho"].ToString(); dsThanhPho.Add(item); } } ViewBag.dsThanhPho = dsThanhPho; ViewBag.txtTimKiem = ""; ViewBag.cmbDienTich = 0; ViewBag.cmbGia = 0; ViewBag.cmbThanhPho = 0; ViewBag.cmbQuan = 0; ViewBag.cmbDuong = 0; ViewBag.isTimKiem = false; ViewBag.dsCanHoCount = 0; return View("~/Views/Shared/TimKiem.cshtml"); }
public ActionResult Index() { try { DataProvider dp = new DataProvider(); string sql = @"SELECT * FROM quan ORDER BY maquan"; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); List<Quan> ls = new List<Quan>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Quan item = new Quan(); item.MaQuan = (int)dt.Rows[i]["maquan"]; item.TenQuan = (string)dt.Rows[i]["tenquan"]; item.MaThanhPho = (int)dt.Rows[i]["mathanhpho"]; ls.Add(item); } } return PartialView("~/Views/Shared/Duong.cshtml", ls); } catch (Exception ex) { return PartialView("~/Views/Shared/Duong.cshtml"); } }
public ActionResult Index() { try { DataProvider dp = new DataProvider(); string sql = @"SELECT * FROM thanhpho ORDER BY tenthanhpho"; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); List<ThanhPho> ls = new List<ThanhPho>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ThanhPho item = new ThanhPho(); item.MaThanhPho = (int)dt.Rows[i]["mathanhpho"]; item.TenThanhPho = (string)dt.Rows[i]["tenthanhpho"]; ls.Add(item); } } ViewBag.MaThanhPho = new SelectList(ls, "mathanhpho", "tenthanhpho", 1); return PartialView("~/Views/Shared/ThanhPho.cshtml", ls); } catch (Exception ex) { ViewBag.ErrorMessage = ex.Message; return PartialView("~/Views/Shared/ThanhPho.cshtml"); } }
public static List<ThanhPho> ListThanhPho() { List<ThanhPho> ls = new List<ThanhPho>(); try { DataProvider dp = new DataProvider(); string sql = @"SELECT * FROM thanhpho ORDER BY tenthanhpho"; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ThanhPho item = new ThanhPho(); item.MaThanhPho = (int)dt.Rows[i]["mathanhpho"]; item.TenThanhPho = (string)dt.Rows[i]["tenthanhpho"]; ls.Add(item); } } return ls; } catch (Exception ex) { return ls; } }
// // GET: /Index/ public ActionResult Index() { //Load danh sach thanh pho DataProvider dp = new DataProvider(); string sql = @"SELECT TOP 8 ch.*, d.tenduong, q.tenquan, tp.tenthanhpho FROM canho ch, duong d, quan q, thanhpho tp WHERE ch.kichhoat = 1 AND ch.matrangthaicanho = 2 AND ch.maduong = d.maduong AND d.maquan = q.maquan AND q.mathanhpho = tp.mathanhpho ORDER BY ch.ngaydang DESC "; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); List<CanHo> dsCanHo = new List<CanHo>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { CanHo item = new CanHo(); item.MaCanHo = (int)dt.Rows[i]["macanho"]; item.TenCanHo = dt.Rows[i]["tencanho"].ToString(); item.MaDuong = (int)dt.Rows[i]["maduong"]; item.DiaChi = dt.Rows[i]["diachi"].ToString() + " " + dt.Rows[i]["tenduong"].ToString() + ", " + dt.Rows[i]["tenquan"].ToString() + ", " + dt.Rows[i]["tenthanhpho"].ToString(); item.MieuTa = dt.Rows[i]["mieuta"].ToString(); item.ToaDo = dt.Rows[i]["toado"].ToString(); item.GiaThue = (double)dt.Rows[i]["giathue"]; item.DienTich = (double)dt.Rows[i]["dientich"]; item.MaTrangThaiCanHo = (int)dt.Rows[i]["matrangthaicanho"]; item.TrangThaiCanHo = (TrangThaiCanHo)dt.Rows[i]["matrangthaicanho"]; item.NgayDang = DateTime.Parse(dt.Rows[i]["ngaydang"].ToString()); item.NguoiDang = (int)dt.Rows[i]["nguoidang"]; item.GhiChu = dt.Rows[i]["ghichu"].ToString(); item.KichHoat = (int)dt.Rows[i]["kichhoat"]; dsCanHo.Add(item); } } return View("~/Views/Index.cshtml", dsCanHo); //return Request.Url.Host; }
public ActionResult ListDuong(int maquan) { try { DataProvider dp = new DataProvider(); string sql = @"SELECT * FROM duong WHERE maquan = " + maquan.ToString() + @" ORDER BY maduong"; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); List<Duong> ls = new List<Duong>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Duong item = new Duong(); item.MaDuong = (int)dt.Rows[i]["maduong"]; item.TenDuong = (string)dt.Rows[i]["tenduong"]; item.MaQuan = (int)dt.Rows[i]["maquan"]; ls.Add(item); } } return Json(ls); } catch (Exception ex) { return null; } }
public ActionResult Index(string txtTimKiem, int cmbDienTich, int cmbGia, int cmbDuong, int cmbQuan, int cmbThanhPho, string chkSuaLoi) { //Load danh sach thanh pho DataProvider dp = new DataProvider(); string sql = @"SELECT * FROM thanhpho t "; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); List<ThanhPho> dsThanhPho = new List<ThanhPho>(); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ThanhPho item = new ThanhPho(); item.MaThanhPho = (int)dt.Rows[i]["mathanhpho"]; item.TenThanhPho = dt.Rows[i]["tenthanhpho"].ToString(); dsThanhPho.Add(item); } } ViewBag.dsThanhPho = dsThanhPho; ViewBag.txtTimKiem = txtTimKiem; ViewBag.cmbDienTich = cmbDienTich; ViewBag.cmbGia = cmbGia; ViewBag.cmbThanhPho = cmbThanhPho; ViewBag.cmbQuan = cmbQuan; ViewBag.cmbDuong = cmbDuong; ViewBag.chkSuaLoi = chkSuaLoi; //TRUY VAN TIM KIEM CAN HO sql = @"FROM canho ch, duong d, quan q, thanhpho tp WHERE ch.kichhoat = 1 AND ch.matrangthaicanho = 2 AND ch.maduong = d.maduong AND d.maquan = q.maquan AND q.mathanhpho = tp.mathanhpho AND ch.tencanho LIKE N'%" + txtTimKiem + @"%' "; switch (cmbGia) { case 1: sql += " AND ch.giathue < 1000000 "; break; case 2: sql += " AND 1000000 <= ch.giathue AND ch.giathue < 3000000 "; break; case 3: sql += " AND 3000000 <= ch.giathue AND ch.giathue < 5000000 "; break; case 4: sql += " AND 5000000 <= ch.giathue AND ch.giathue < 10000000 "; break; case 5: sql += " AND ch.giathue >= 10000000 "; break; default: break; } switch (cmbDienTich) { case 1: sql += " AND ch.dientich < 30 "; break; case 2: sql += " AND 30 <= ch.dientich AND ch.dientich < 50 "; break; case 3: sql += " AND 50 <= ch.dientich AND ch.dientich < 80 "; break; case 4: sql += " AND 80 <= ch.dientich AND ch.dientich < 100 "; break; case 5: sql += " AND ch.dientich >= 100 "; break; default: break; } if (cmbThanhPho != 0) { sql += " AND tp.mathanhpho = " + cmbThanhPho + " "; } if (cmbQuan != 0) { sql += " AND q.maquan = " + cmbQuan + " "; } if (cmbDuong != 0) { sql += " AND d.maduong = " + cmbDuong + " "; } //Tao lenh moi string sqlHeader = "SELECT COUNT(ch.macanho) "; SqlCommand cmd = new SqlCommand(sqlHeader + sql, dp.Connect); SqlDataReader reader = null; List<CanHo> dsCanHo = new List<CanHo>(); dp.OpenConnect(); //Tao transaction moi if (chkSuaLoi != null) { //Set level = Serializable để giải quyết Phantom cmd.Transaction = cmd.Connection.BeginTransaction(IsolationLevel.Serializable); } else { //Set level = ReadCommitted mức mặc định cmd.Transaction = cmd.Connection.BeginTransaction(IsolationLevel.ReadCommitted); } try { reader = cmd.ExecuteReader(); //Doc so dong du lieu while (reader.Read()) { ViewBag.dsCanHoCount = reader.GetValue(0); } reader.Close(); Thread.Sleep(5000); //Wait for 15 seconds //truy van tim kiem sqlHeader = "SELECT ch.*, d.tenduong, q.tenquan, tp.tenthanhpho "; cmd.CommandText = sqlHeader + sql; reader = cmd.ExecuteReader(); /* 0 macanho 1 tencanho 2 maduong 3 diachi 4 mieuta 5 toado 6 giathue 7 dientich 8 matrangthaicanho 9 ngaydang 10 nguoidang 11 ghichu 12 kichhoat 13 tenduong 14 tenquan 15 tenthanhpho */ while (reader.Read()) { //Tao mang luu tru dong du lieu (FieldCount = so cot du lieu) object[] row = new object[reader.FieldCount]; //Doc gia tri vao mang reader.GetValues(row); CanHo item = new CanHo(); item.MaCanHo = int.Parse(row[0].ToString()); item.TenCanHo = row[1].ToString(); item.MaDuong = int.Parse(row[2].ToString()); item.DiaChi = row[3].ToString() + " " + row[13].ToString() + ", " + row[14].ToString() + ", " + row[15].ToString(); item.MieuTa = row[4].ToString(); item.ToaDo = row[5].ToString(); item.GiaThue = double.Parse(row[6].ToString()); item.DienTich = double.Parse(row[7].ToString()); item.MaTrangThaiCanHo = int.Parse(row[8].ToString()); item.TrangThaiCanHo = (TrangThaiCanHo)int.Parse(row[8].ToString()); item.NgayDang = DateTime.Parse(row[9].ToString()); item.NguoiDang = int.Parse(row[10].ToString()); item.GhiChu = row[11].ToString(); item.KichHoat = int.Parse(row[12].ToString()); dsCanHo.Add(item); } reader.Close(); cmd.Transaction.Commit(); } catch (Exception ex) { //Roll back neu bi loi if (cmd.Transaction != null) { cmd.Transaction.Rollback(); } } finally { //Dong ket noi dp.Connect.Close(); } ViewBag.isTimKiem = true; return View("~/Views/Shared/TimKiem.cshtml", dsCanHo); }
public ActionResult ListQuan(int mathanhpho) { List<Quan> ls = new List<Quan>(); try { DataProvider dp = new DataProvider(); string sql = @"SELECT * FROM quan WHERE mathanhpho = " + mathanhpho.ToString() + @" ORDER BY maquan"; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { Quan item = new Quan(); item.MaQuan = (int)dt.Rows[i]["maquan"]; item.TenQuan = (string)dt.Rows[i]["tenquan"]; item.MaThanhPho = (int)dt.Rows[i]["mathanhpho"]; ls.Add(item); } } return Json(ls); } catch (Exception ex) { return null; } }
// // GET: /DatThueCanHo/ public ActionResult Index() { TaiKhoan tk = isLogin(); if (tk == null) { return Redirect("/DangNhap"); } int canHoID = 0; CanHo ch = new CanHo(); if (!Int32.TryParse(Request.Params["id"], out canHoID)) { ch.MaTrangThaiCanHo = -999; } else { DataProvider dp = new DataProvider(); //Load danh sach thanh pho string sql = @"SELECT ch.*, d.tenduong, q.tenquan, tp.tenthanhpho FROM canho ch, duong d, quan q, thanhpho tp WHERE ch.kichhoat = 1 AND ch.matrangthaicanho = 2 AND ch.maduong = d.maduong AND d.maquan = q.maquan AND q.mathanhpho = tp.mathanhpho AND ch.macanho = " + canHoID.ToString() + @" "; DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); if (dt.Rows.Count > 0) { ch.MaCanHo = (int)dt.Rows[0]["macanho"]; ch.TenCanHo = dt.Rows[0]["tencanho"].ToString(); ch.MaDuong = (int)dt.Rows[0]["maduong"]; ch.DiaChi = dt.Rows[0]["diachi"].ToString() + " " + dt.Rows[0]["tenduong"].ToString() + ", " + dt.Rows[0]["tenquan"].ToString() + ", " + dt.Rows[0]["tenthanhpho"].ToString(); ch.MieuTa = dt.Rows[0]["mieuta"].ToString(); ch.ToaDo = dt.Rows[0]["toado"].ToString(); ch.GiaThue = (double)dt.Rows[0]["giathue"]; ch.DienTich = (double)dt.Rows[0]["dientich"]; ch.MaTrangThaiCanHo = (int)dt.Rows[0]["matrangthaicanho"]; ch.TrangThaiCanHo = (TrangThaiCanHo)dt.Rows[0]["matrangthaicanho"]; ch.NgayDang = DateTime.Parse(dt.Rows[0]["ngaydang"].ToString()); ch.NguoiDang = (int)dt.Rows[0]["nguoidang"]; ch.GhiChu = dt.Rows[0]["ghichu"].ToString(); ch.KichHoat = (int)dt.Rows[0]["kichhoat"]; } else { ch.MaTrangThaiCanHo = -999; } } ViewBag.taiKhoan = tk; ViewBag.ketQuaThueCanHo = false; ViewBag.isThueCanHo = false; return View("~/Views/Shared/DatThueCanHo.cshtml", ch); }
// // GET: /CanHo/ public ActionResult Index() { bool fixDirtyRead = true; Boolean.TryParse(Request.Params["dirtyread"], out fixDirtyRead); int canHoID = 0; CanHo ch = new CanHo(); if (!Int32.TryParse(Request.Params["id"], out canHoID)) { ch.MaTrangThaiCanHo = -999; } else { DataProvider dp = new DataProvider(); string sql = ""; //Load danh sach thanh pho /*string sql = @"SELECT ch.*, d.tenduong, q.tenquan, tp.tenthanhpho FROM canho ch, duong d, quan q, thanhpho tp WHERE ch.kichhoat = 1 AND ch.matrangthaicanho = 2 AND ch.maduong = d.maduong AND d.maquan = q.maquan AND q.mathanhpho = tp.mathanhpho AND ch.macanho = " + canHoID.ToString() + @" ORDER BY ch.ngaydang DESC ";*/ SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@macanho", SqlDbType.Int); param[0].Value = canHoID.ToString(); DataTable dt = new DataTable(); if (fixDirtyRead == true) { dt = dp.ExecuteProcQuery("sp_XemCanHo_Fixed", ref param); } else { dt = dp.ExecuteProcQuery("sp_XemCanHo", ref param); } if (dt.Rows.Count > 0) { ch.MaCanHo = (int)dt.Rows[0]["macanho"]; ch.TenCanHo = dt.Rows[0]["tencanho"].ToString(); ch.MaDuong = (int)dt.Rows[0]["maduong"]; ch.DiaChi = dt.Rows[0]["diachi"].ToString() + " " + dt.Rows[0]["tenduong"].ToString() + ", " + dt.Rows[0]["tenquan"].ToString() + ", " + dt.Rows[0]["tenthanhpho"].ToString(); ch.MieuTa = dt.Rows[0]["mieuta"].ToString(); ch.ToaDo = dt.Rows[0]["toado"].ToString(); ch.GiaThue = (double)dt.Rows[0]["giathue"]; ch.DienTich = (double)dt.Rows[0]["dientich"]; ch.MaTrangThaiCanHo = (int)dt.Rows[0]["matrangthaicanho"]; ch.TrangThaiCanHo = (TrangThaiCanHo)dt.Rows[0]["matrangthaicanho"]; ch.NgayDang = DateTime.Parse(dt.Rows[0]["ngaydang"].ToString()); ch.NguoiDang = (int)dt.Rows[0]["nguoidang"]; ch.GhiChu = dt.Rows[0]["ghichu"].ToString(); ch.KichHoat = (int)dt.Rows[0]["kichhoat"]; //Lay hinh anh sql = @"SELECT * FROM hinhanhcanho WHERE macanho = " + canHoID.ToString(); dt = new DataTable(); dt = dp.ExecuteQuery(sql); List<HinhAnhCanHo> dsHinhAnhCanHo = new List<HinhAnhCanHo>(); for (int i = 0; i < dt.Rows.Count; i++) { HinhAnhCanHo h = new HinhAnhCanHo(); h.MaHinhAnh = (int)dt.Rows[i]["mahinhanh"]; h.LienKet = dt.Rows[i]["lienket"].ToString(); h.MaCanHo = canHoID; dsHinhAnhCanHo.Add(h); } ViewBag.dsHinhAnhCanHo = dsHinhAnhCanHo; //Lay thong tin nguoi dang tin sql = @"SELECT * FROM taikhoan WHERE mataikhoan = " + ch.NguoiDang.ToString(); dt = new DataTable(); dt = dp.ExecuteQuery(sql); TaiKhoan tk = new TaiKhoan(); tk.MaTaiKhoan = (int)dt.Rows[0]["mataikhoan"]; tk.Email = dt.Rows[0]["email"].ToString(); tk.MaLoaiTaiKhoan = (int)dt.Rows[0]["maloaitaikhoan"]; tk.LoaiTaiKhoan = (LoaiTaiKhoan)dt.Rows[0]["maloaitaikhoan"]; tk.Ten = dt.Rows[0]["ten"].ToString(); tk.NgaySinh = (DateTime)dt.Rows[0]["ngaysinh"]; tk.DiaChi = dt.Rows[0]["diachi"].ToString(); tk.DienThoai = dt.Rows[0]["dienthoai"].ToString(); tk.NgayDangKy = (DateTime)dt.Rows[0]["ngaydangky"]; tk.MaTrangThai = (int)dt.Rows[0]["trangthai"]; tk.TrangThai = (TrangThaiTaiKhoan)dt.Rows[0]["trangthai"]; ViewBag.taiKhoan = tk; } else { ch.MaTrangThaiCanHo = -999; } } return View("~/Views/Shared/ChiTietCanHo.cshtml", ch); }
// hiển thị thông tin tài khoản // // POST/TaiKhoan/ChinhSuaTaiKhoan public ActionResult ChinhSuaTaiKhoan(int id) { if (isLogin() == -1) { return Redirect("/DangNhap"); } else if (isLogin() == 2) { return Redirect("/"); } else { try { string sql = @"SELECT * FROM taikhoan tk WHERE tk.mataikhoan = " + id.ToString(); DataProvider dp = new DataProvider(); DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); TaiKhoan tk = new TaiKhoan(); if (dt.Rows.Count == 1) { tk.MaTaiKhoan = (int)dt.Rows[0]["mataikhoan"]; tk.Email = (string)dt.Rows[0]["email"]; tk.Ten = (string)dt.Rows[0]["ten"]; tk.NgaySinh = (DateTime)dt.Rows[0]["ngaysinh"]; tk.DiaChi = (string)dt.Rows[0]["diachi"]; tk.DienThoai = (string)dt.Rows[0]["dienthoai"]; tk.NgayDangKy = (DateTime)dt.Rows[0]["ngaydangky"]; tk.MaLoaiTaiKhoan = (int)dt.Rows[0]["maloaitaikhoan"]; switch (tk.MaLoaiTaiKhoan) { case 1: tk.LoaiTaiKhoan = LoaiTaiKhoan.Admin; break; case 2: tk.LoaiTaiKhoan = LoaiTaiKhoan.Member; break; case 3: tk.LoaiTaiKhoan = LoaiTaiKhoan.Sales; break; } tk.MaTrangThai = (int)dt.Rows[0]["trangthai"]; switch ((int)dt.Rows[0]["trangthai"]) { case 1: tk.TrangThai = TrangThaiTaiKhoan.Active; break; case 0: tk.TrangThai = TrangThaiTaiKhoan.Deactive; break; } return View("~/Views/Admin/TaiKhoan/ChinhSuaTaiKhoan.cshtml", tk); } return Redirect("/Admin/TaiKhoan/"); } catch (Exception ex) { return Redirect("/Admin/TaiKhoan/"); } } }
public ActionResult XoaCanHo(int id) { if (isLogin() == -1) { return Redirect("/DangNhap"); } else if (isLogin() == 2) { return Redirect("/"); } else { try { DataProvider dp = new DataProvider(); string sql = "SELECT * FROM canho WHERE macanho = " + id.ToString(); DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); CanHo item = new CanHo(); if (dt.Rows.Count == 1) { item.MaCanHo = (int)dt.Rows[0]["macanho"]; item.TenCanHo = (string)dt.Rows[0]["tencanho"]; item.MaDuong = (int)dt.Rows[0]["maduong"]; item.DiaChi = (string)dt.Rows[0]["diachi"]; if (dt.Rows[0]["mieuta"] != DBNull.Value) { item.MieuTa = (string)dt.Rows[0]["mieuta"]; } item.ToaDo = (string)dt.Rows[0]["toado"]; item.GiaThue = (double)dt.Rows[0]["giathue"]; item.DienTich = (double)dt.Rows[0]["dientich"]; item.MaTrangThaiCanHo = (int)dt.Rows[0]["matrangthaicanho"]; switch ((int)dt.Rows[0]["matrangthaicanho"]) { case 1: item.TrangThaiCanHo = TrangThaiCanHo.Da_Duoc_Thue; break; case 2: item.TrangThaiCanHo = TrangThaiCanHo.Chua_Duoc_Thue; break; case 3: item.TrangThaiCanHo = TrangThaiCanHo.Dang_Xay_Dung; break; } item.NgayDang = (DateTime)dt.Rows[0]["ngaydang"]; item.NguoiDang = (int)dt.Rows[0]["nguoidang"]; if (dt.Rows[0]["ghichu"] != DBNull.Value) { item.GhiChu = (string)dt.Rows[0]["ghichu"]; } item.KichHoat = (int)dt.Rows[0]["kichhoat"]; return View("~/Views/Admin/CanHo/XoaCanHo.cshtml", item); } else { ViewBag.ErrorMessage = "Không tìm thấy căn hộ"; return Redirect("/Admin/CanHo/"); } } catch (Exception ex) { ViewBag.ErrorMessage = ex.Message; return Redirect("/Admin/CanHo/"); } } }
// // POST: /CanHo/ChinhSuaCanHo public ActionResult ChinhSuaCanHo(int id) { if (isLogin() == -1) { return Redirect("/DangNhap"); } else if (isLogin() == 2) { return Redirect("/"); } else { //*/ try { string sql = @"SELECT * , tk.ten as tennguoidang FROM canho ch, taikhoan tk WHERE tk.mataikhoan = ch.nguoidang AND ch.macanho = " + id.ToString() + @" AND ch.kichhoat = 1 "; DataProvider dp = new DataProvider(); DataTable dt = new DataTable(); dt = dp.ExecuteQuery(sql); CanHo item = new CanHo(); if (dt.Rows.Count == 1) { item.MaCanHo = (int)dt.Rows[0]["macanho"]; item.TenCanHo = (string)dt.Rows[0]["tencanho"]; item.MaDuong = (int)dt.Rows[0]["maduong"]; item.DiaChi = (string)dt.Rows[0]["diachi"]; if (dt.Rows[0]["mieuta"] != DBNull.Value) { item.MieuTa = (string)dt.Rows[0]["mieuta"]; } item.ToaDo = (string)dt.Rows[0]["toado"]; item.GiaThue = (double)dt.Rows[0]["giathue"]; item.DienTich = (double)dt.Rows[0]["dientich"]; item.MaTrangThaiCanHo = (int)dt.Rows[0]["matrangthaicanho"]; switch ((int)dt.Rows[0]["matrangthaicanho"]) { case 1: item.TrangThaiCanHo = TrangThaiCanHo.Da_Duoc_Thue; break; case 2: item.TrangThaiCanHo = TrangThaiCanHo.Chua_Duoc_Thue; break; case 3: item.TrangThaiCanHo = TrangThaiCanHo.Dang_Xay_Dung; break; } item.NgayDang = (DateTime)dt.Rows[0]["ngaydang"]; item.NguoiDang = (int)dt.Rows[0]["nguoidang"]; item.TenNguoiDang = (string)dt.Rows[0]["tennguoidang"]; if (dt.Rows[0]["ghichu"] != DBNull.Value) { item.GhiChu = (string)dt.Rows[0]["ghichu"]; } item.KichHoat = (int)dt.Rows[0]["kichhoat"]; List<ThanhPho> lsThanhPho = new List<ThanhPho>(); lsThanhPho = ThanhPhoController.ListThanhPho(); ViewBag.MaThanhPho = new SelectList(lsThanhPho, "mathanhpho", "tenthanhpho"); List<Quan> lsQuan = new List<Quan>(); lsQuan = QuanController.ListQuan(); ViewBag.MaQuan = new SelectList(lsQuan, "maquan", "tenquan"); List<Duong> lsDuong = new List<Duong>(); lsDuong = DuongController.ListDuong(); ViewBag.MaDuong = new SelectList(lsDuong, "maduong", "tenduong", item.MaDuong); return View("~/Views/Admin/CanHo/ChinhSuaCanHo.cshtml", item); } return Redirect("/Admin/CanHo/"); } catch (Exception ex) { return Redirect("/Admin/CanHo/"); } //*/ } }