示例#1
0
        public DataTable LoadTimKiem(PhongDTO p, LoaiPhongDTO lp, LoaiTinhTrangDTO tt)
        {
            Provider provider = new Provider();

            try
            {
                provider.Connect();

                string strSql   = "select distinct p.TenPhong, lp.TenLoaiPhong, lp.DonGia, tt.TenTinhTrang from Phong p join LoaiPhong lp on p.MaLoaiPhong = lp.MaLoaiPhong join LOAITINHTRANG tt on p.MaTinhTrang = tt.MaTinhTrang WHERE BiXoa = 1  ";
                string sqlwhere = " ";



                if (p.MaPhong != "1")
                {
                    sqlwhere += "AND p.MaPhong = @MaPhong";
                    sqlwhere += " ";
                }
                if (p.TenPhong != "1")
                {
                    sqlwhere += "AND p.TenPhong = @TenPhong";
                    sqlwhere += " ";
                }
                if (lp.DonGia != 1)
                {
                    sqlwhere += "AND lp.DonGia = @DonGia";
                    sqlwhere += " ";
                }
                if (lp.MaLoaiPhong != "1")
                {
                    sqlwhere += "AND lp.MaLoaiPhong = @MaLoaiPhong";
                    sqlwhere += " ";
                }
                if (tt.TenTinhTrang != "1")
                {
                    sqlwhere += "AND tt.TenTinhTrang = @TenTinhTrang";
                    sqlwhere += " ";
                }
                string sql = strSql + sqlwhere;

                DataTable dt = provider.Select(CommandType.Text, sql,
                                               new SqlParameter {
                    ParameterName = "@MaPhong", Value = p.MaPhong
                },
                                               new SqlParameter {
                    ParameterName = "@TenPhong", Value = p.TenPhong
                },
                                               new SqlParameter {
                    ParameterName = "@DonGia", Value = lp.DonGia
                },
                                               new SqlParameter {
                    ParameterName = "@TenTinhTrang", Value = tt.TenTinhTrang
                },
                                               new SqlParameter {
                    ParameterName = "@MaLoaiPhong", Value = lp.MaLoaiPhong
                });
                return(dt);
                // return sqlTruyVan;
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                provider.DisConnect();
            }
        }
        public DataTable LoadTimKiem(PhongDTO p, LoaiPhongDTO lp, LoaiTinhTrangDTO tt)
        {
            xlTraCuuPhongDAL xl = new xlTraCuuPhongDAL();

            return(xl.LoadTimKiem(p, lp, tt));
        }
示例#3
0
        private void btnaddCSDL_Click(object sender, EventArgs e)
        {
            PhongDTO         p   = new PhongDTO();
            LoaiPhongDTO     lp  = new LoaiPhongDTO();
            LoaiTinhTrangDTO ltt = new LoaiTinhTrangDTO();


            int n = 0;



            if (dgvds.Rows.Count > 0)
            {
                foreach (DataGridViewRow row in dgvds.Rows)
                {
                    string MaPhongCuoi = xl.DuLieuMCuoiDanhSach();
                    int    num         = int.Parse(MaPhongCuoi.Substring(1)) + 1;
                    string MaPhong     = "P" + num.ToString();

                    p.MaPhong        = MaPhong;
                    p.TenPhong       = (row.Cells["TenPhong"].Value.ToString());
                    lp.TenLoaiPhong  = (row.Cells["TenLoaiPhong"].Value.ToString());
                    lp.DonGia        = float.Parse(row.Cells["DonGia"].Value.ToString());
                    ltt.TenTinhTrang = (row.Cells["TenTinhTrang"].Value.ToString());
                    DataTable loaiphong     = xl.DanhSachLoaiPhong();
                    DataTable loaitinhtrang = xl.DanhSachLoaiTinhTrang();



                    foreach (DataRow row1 in loaiphong.Rows)
                    {
                        if (row1["TenLoaiPhong"].ToString() == lp.TenLoaiPhong)
                        {
                            p.MaLoaiPhong = row1["MaLoaiPhong"].ToString();
                        }
                    }

                    foreach (DataRow row2 in loaitinhtrang.Rows)
                    {
                        if (row2["TenTinhTrang"].ToString() == ltt.TenTinhTrang)
                        {
                            p.MaLoaiTinhTrang = row2["MaTinhTrang"].ToString();
                        }
                    }


                    n = xl.ThemPhong(p);
                }
            }
            else
            {
            }
            if (n < 0)
            {
                MessageBox.Show("Không Thêm Vào CSDL");
            }
            else
            {
                MessageBox.Show("Đã Thêm Vào CSDL");
            }
        }