using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace Reservtion
{
    public class RConection
    {
        public int num;
        public Boolean a;
        string connString = "server = (local); integrated security = true; database = Hotel;";
        public SqlConnection conn = new SqlConnection();
        public SqlDataAdapter da = new SqlDataAdapter();
        public SqlCommand cmd = new SqlCommand();
        public DataSet ds = new DataSet();

        public RConection()
        {
            try
            {
                conn.ConnectionString = connString;
                cmd.Connection = conn;
                da.SelectCommand = cmd;                   //0                                    //1                           //2                     //3                   //4                     //5
                cmd.CommandText = "SELECT Property FROM Property";
                da.Fill(ds,"Property");
                cmd.CommandText ="SELECT Property,Item FROM PropertyItems";
                da.Fill(ds, "PropertyItems");
                cmd.CommandText ="SELECT * FROM RoomPropertis";
                da.Fill(ds, "RoomPropertis");
                cmd.CommandText ="SELECT * FROM Room";
                da.Fill(ds, "Room");
                cmd.CommandText ="SELECT * FROM Estates";
                da.Fill(ds, "Estates");
                cmd.CommandText ="SELECT * FROM ReservPrice";
                da.Fill(ds, "ReservPrice");
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        public void RefreshRC()
        {
            ds.Clear();
            try
            {
                conn.ConnectionString = connString;
                cmd.Connection = conn;
                da.SelectCommand = cmd;                   //0                                    //1                           //2                     //3                   //4                     //5
                cmd.CommandText = "SELECT Property FROM Property";
                da.Fill(ds, "Property");
                cmd.CommandText = "SELECT Property,Item FROM PropertyItems";
                da.Fill(ds, "PropertyItems");
                cmd.CommandText = "SELECT * FROM RoomPropertis";
                da.Fill(ds, "RoomPropertis");
                cmd.CommandText = "SELECT * FROM Room";
                da.Fill(ds, "Room");
                cmd.CommandText = "SELECT * FROM Estates";
                da.Fill(ds, "Estates");
                cmd.CommandText = "SELECT * FROM ReservPrice";
                da.Fill(ds, "ReservPrice");
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
