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


namespace HotelProject
{
    public partial class FrmRooms : Form
    {
        public FrmRooms()
        {
            InitializeComponent();
        }

        SqlConnection con;
        string StrType = "";
        public string RoomNumber = "";
        public string RoomType = "";

        private void FrmRooms_Load(object sender, EventArgs e)
        {
            con = new SqlConnection("Server = .\\SQLEXPRESS ; DataBase = DbHotel ; Integrated Security = True");
            SqlDataAdapter da = new SqlDataAdapter("SelectAllRooms", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;

            DataTable dt = new DataTable();
            da.Fill(dt);

            GrdRooms.DataSource = dt;


            SqlDataAdapter da2 = new SqlDataAdapter("SelectRoomTypes", con);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;

            DataTable dt2 = new DataTable();
            da2.Fill(dt2);

            CmbRoomType.DataSource = dt2;
            CmbRoomType.DisplayMember = "RoomType";

            
        }

        private void TxtRoomNum_TextChanged(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = con;

            cmd.CommandText = "Select * From TblRooms Where RoomNum like '" + TxtRoomNum.Text + "%' and RoomType = N'" + CmbRoomType.Text + "'";
           

            DataTable dt = new DataTable();

            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;


            da.Fill(dt);

            GrdRooms.DataSource = dt;

            con.Close();
        }

        private void CmbRoomType_SelectedIndexChanged(object sender, EventArgs e)
        {
            StrType = CmbRoomType.Text;
            TxtRoomNum_TextChanged(null, null);
        }

        private void textBoxX1_TextChanged(object sender, EventArgs e)
        {
          
        }

        private void GrdRooms_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
           
        }

        private void GrdRooms_DoubleClick(object sender, EventArgs e)
        {
            if (GrdRooms.CurrentRow.Cells[2].Value.ToString() != "خالی")
            {
                FrmMessage Fm = new FrmMessage();
                Fm.LblText.Text = "اتاق خالی نیست";
                Fm.PicClose.Visible = true;
                Fm.PicNO.Visible = false;
                Fm.PicYes.Visible = false;
                Fm.ShowDialog();
                return;
            }


            RoomNumber = GrdRooms.CurrentRow.Cells[0].Value.ToString();
            RoomType = GrdRooms.CurrentRow.Cells[1].Value.ToString();

            this.Close();
        }
    }
}
