Exemple #1
0
        //
        // 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 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);
        }
        //
        // 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);
        }
Exemple #4
0
        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/");
                }
            }
        }
Exemple #5
0
        public ActionResult TaoCanHo(CanHo canho)
        {
            if (isLogin() == -1)
            {
                return Redirect("/DangNhap");
            }
            else if (isLogin() == 2)
            {
                return Redirect("/");
            }
            else
            {
                try
                {
                    TaiKhoan tk = new TaiKhoan();
                    tk = (TaiKhoan)Session["taikhoan"];

                    canho.NguoiDang = tk.MaTaiKhoan;
                    canho.NgayDang = DateTime.Now;

                    SqlParameter[] param = new SqlParameter[10];
                    param[0] = new SqlParameter("@tencanho", SqlDbType.NVarChar);
                    param[0].Value = canho.TenCanHo;

                    param[1] = new SqlParameter("@maduong", SqlDbType.Int);
                    param[1].Value = canho.MaDuong;

                    param[2] = new SqlParameter("@diachi", SqlDbType.NVarChar);
                    param[2].Value = canho.DiaChi;

                    param[3] = new SqlParameter("@mieuta", SqlDbType.NVarChar);
                    param[3].Value = canho.MieuTa;

                    param[4] = new SqlParameter("@toado", SqlDbType.NVarChar);
                    param[4].Value = canho.ToaDo;

                    param[5] = new SqlParameter("@giathue", SqlDbType.Float);
                    param[5].Value = canho.GiaThue;

                    param[6] = new SqlParameter("@dientich", SqlDbType.Float);
                    param[6].Value = canho.DienTich;

                    param[7] = new SqlParameter("@matrangthaicanho", SqlDbType.Int);
                    param[7].Value = canho.MaTrangThaiCanHo;

                    param[8] = new SqlParameter("@ngaydang", SqlDbType.DateTime);
                    param[8].Value = canho.NgayDang;

                    param[9] = new SqlParameter("@nguoidang", SqlDbType.Int);
                    param[9].Value = canho.NguoiDang;

                    DataProvider dp = new DataProvider();
                    dp.ExecuteProcNonQuery("sp_TaoCanHo", ref param);

                    ViewBag.ErrorMessage = "Đăng tin căn hộ thành công";
                    return Redirect("/Admin/CanHo/");
                }
                catch (Exception ex)
                {
                    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");

                    ViewBag.ErrorMessage = "Khởi tạo không thành công";
                    return View("~/Views/Admin/CanHo/TaoCanHo.cshtml");
                }

            }
        }
Exemple #6
0
        //
        // 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/");
                }
                //*/
            }
        }
Exemple #7
0
        //
        // GET: /CanHo/
        public ActionResult Index()
        {
            if (isLogin() == -1)
            {
                return Redirect("/DangNhap");
            }
            else if (isLogin() == 2)
            {
                return Redirect("/");
            }
            else
            {
                try
                {
                    DataProvider dp = new DataProvider();

                    int page = 1;
                    if (Request.QueryString["page"] != null)
                    {
                        page = int.Parse(Request.QueryString["page"]);
                    }

                    SqlParameter[] param = new SqlParameter[3];
                    param[0] = new SqlParameter("@page", SqlDbType.Int);
                    param[0].Value = page;

                    param[1] = new SqlParameter("@pagesize", SqlDbType.Int);
                    param[1].Value = RowPerPage;

                    param[2] = new SqlParameter("@count", SqlDbType.Int);
                    param[2].Value = DBNull.Value;
                    param[2].Direction = ParameterDirection.Output;
                    DataTable dt = new DataTable();

                    dt = dp.ExecuteProcQuery("sp_DanhSachCanHo", ref param);

                    List<CanHo> ls = new List<CanHo>();
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        CanHo item = new CanHo();

                        item.MaCanHo = (int)dt.Rows[i]["macanho"];
                        item.TenCanHo = (string)dt.Rows[i]["tencanho"];
                        item.MaDuong = (int)dt.Rows[i]["maduong"];
                        item.DiaChi = (string)dt.Rows[i]["diachi"];

                        if (dt.Rows[i]["mieuta"] != DBNull.Value)
                        {
                            item.MieuTa = (string)dt.Rows[i]["mieuta"];
                        }

                        item.ToaDo = (string)dt.Rows[i]["toado"];
                        item.GiaThue = (double)dt.Rows[i]["giathue"];
                        item.DienTich = (double)dt.Rows[i]["dientich"];

                        switch ((int)dt.Rows[i]["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[i]["ngaydang"];
                        item.NguoiDang = (int)dt.Rows[i]["nguoidang"];

                        if (dt.Rows[i]["ghichu"] != DBNull.Value)
                        {
                            item.GhiChu = (string)dt.Rows[i]["ghichu"];
                        }

                        item.KichHoat = (int)dt.Rows[i]["kichhoat"];

                        ls.Add(item);
                    }

                    ViewBag.RowPerPage = RowPerPage;
                    ViewBag.Page = page;
                    //Console.Write(param[3].Value.ToString());
                    ViewBag.Count = (int)param[2].Value;

                    return View("~/Views/Admin/CanHo/Index.cshtml", ls);
                }
                catch (Exception ex)
                {
                    ViewBag.ErrorMessage = ex.Message;
                    return Redirect("/Admin/");
                }

            }
        }
Exemple #8
0
        public ActionResult ChinhSuaCanHo(CanHo canho, string chkSuaLoi, string chkDirtyRead)
        {
            if (isLogin() == -1)
            {
                return Redirect("/DangNhap");
            }
            else if (isLogin() == 2)
            {
                return Redirect("/");
            }
            else
            {
                //*/
                try
                {
                    ViewBag.chkDirtyRead = chkDirtyRead;
                    ViewBag.chkSuaLoi = chkSuaLoi;
                    DataProvider dp = new DataProvider();

                    SqlParameter[] param = new SqlParameter[9];
                    param[0] = new SqlParameter("@macanho", SqlDbType.Int);
                    param[0].Value = canho.MaCanHo;

                    param[1] = new SqlParameter("@tencanho", SqlDbType.NVarChar);
                    param[1].Value = canho.TenCanHo;

                    param[2] = new SqlParameter("@maduong", SqlDbType.Int);
                    param[2].Value = canho.MaDuong;

                    param[3] = new SqlParameter("@diachi", SqlDbType.NVarChar);
                    param[3].Value = canho.DiaChi;

                    param[4] = new SqlParameter("@mieuta", SqlDbType.NVarChar);
                    param[4].Value = canho.MieuTa;

                    param[5] = new SqlParameter("@toado", SqlDbType.NVarChar);
                    param[5].Value = canho.ToaDo;

                    param[6] = new SqlParameter("@giathue", SqlDbType.Float);
                    param[6].Value = canho.GiaThue;

                    param[7] = new SqlParameter("@dientich", SqlDbType.Float);
                    param[7].Value = canho.DienTich;

                    param[8] = new SqlParameter("@matrangthaicanho", SqlDbType.Int);
                    param[8].Value = canho.MaTrangThaiCanHo;

                    if (chkSuaLoi != null)
                    {
                        //Set level = Serializable để giải quyết Unrepeatable Read
                        dp.ExecuteProcNonQuery("sp_ChinhSuaCanHo_Fixed", ref param);
                    }
                    else if (chkDirtyRead != null)
                    {
                        //Set waitfor delay
                        dp.ExecuteProcNonQuery("sp_ChinhSuaCanHo_DirtyRead", ref param);
                    }
                    else
                    {
                        //Set level = ReadCommitted mức mặc định
                        dp.ExecuteProcNonQuery("sp_ChinhSuaCanHo", ref param);
                    }

                    ViewBag.ErrorMessage = "Cập nhật thành công!";
                    return Redirect("/Admin/CanHo/");

                }
                catch (Exception ex)
                {
                    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", canho.MaDuong);
                    ViewBag.ErrorMessage = ex.Message;
                    return View("~/Views/Admin/CanHo/ChinhSuaCanHo.cshtml", canho);
                }
                //*/
            }
        }
        //
        // 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);
        }
        public ActionResult Index(string txtNgayBatDauThue, int txtThoiGianThue,
                                string txtNgayKetThuc, double txtTienThue,
                                double txtGiamGia, double txtTienPhaiTra,
                                double txtTienCoc, string txtHoTen,
                                string txtEmail, string txtDiaChi,
                                string txtDienThoai)
        {
            TaiKhoan tk = isLogin();
            if (tk == null)
            {
                return Redirect("/DangNhap");
            }

            int maCanHo = 0;
            CanHo ch = new CanHo();

            if (!Int32.TryParse(Request.Params["id"], out maCanHo))
            {
                ch.MaTrangThaiCanHo = -999;
                return null;
            }

            DateTime ngaybatdau = DateTime.ParseExact(txtNgayBatDauThue, "yyyy-M-d", null);
            DateTime ngayketthuc = DateTime.ParseExact(txtNgayKetThuc, "d/M/yyyy", null);

            DataProvider dp = new DataProvider();

            SqlParameter[] param = new SqlParameter[9];
            param[0] = new SqlParameter("@mataikhoan", SqlDbType.Int);
            param[0].Value = tk.MaTaiKhoan;

            param[1] = new SqlParameter("@macanho", SqlDbType.Int);
            param[1].Value = maCanHo;

            param[2] = new SqlParameter("@tiencoc", SqlDbType.Float);
            param[2].Value = txtTienCoc;

            param[3] = new SqlParameter("@thoigianthue", SqlDbType.DateTime);
            param[3].Value = ngaybatdau;

            param[4] = new SqlParameter("@thoigiankethuc", SqlDbType.DateTime);
            param[4].Value = ngayketthuc;

            param[5] = new SqlParameter("@thoigiangiaodich", SqlDbType.DateTime);
            param[5].Value = DateTime.Now;

            param[6] = new SqlParameter("@dienthoai", SqlDbType.NVarChar);
            param[6].Value = txtDienThoai;

            param[7] = new SqlParameter("@diachi", SqlDbType.NVarChar);
            param[7].Value = txtDiaChi;

            param[8] = new SqlParameter("@ghichu", SqlDbType.Text);
            param[8].Value = "";

            ViewBag.taiKhoan = tk;
            ViewBag.ketQuaThueCanHo = dp.ExecuteProcNonQuery("sp_thuecanho", ref param);
            ViewBag.isThueCanHo = true;

            return View("~/Views/Shared/DatThueCanHo.cshtml", new CanHo());
        }