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

namespace hotel
{
    public partial class Form8 : Form
    {
        public Form8()
        {
            InitializeComponent();
        }
        public string otagh;
        string otagh1;
        void darj()
        {


            string a = "provider=microsoft.jet.oledb.4.0;data source=hotel12.mdb";

            string sel = "select * from room ";
            
            OleDbConnection con = new OleDbConnection(a);
            OleDbDataAdapter da = new OleDbDataAdapter(sel, con);
            DataSet ds = new DataSet();
            da.Fill(ds, "t1");
            dataGrid1.DataSource = ds;
            dataGrid1.DataMember = "t1";
        }
        private void Form8_Load(object sender, EventArgs e)
        {
            MessageBox.Show("کاربر گرامی شما باید اطلاعات مربوط به "+otagh+" اتاق راوارد کنید","اطلاع",MessageBoxButtons.OK,MessageBoxIcon.Information);
            darj();
            Class1 c1 = new Class1();
            string sel1 = "select * from room";

            DataSet ds1 = new DataSet();
            ds1 = c1.select(sel1);

            int chek = ds1.Tables["t1"].Rows.Count;
            otagh1 = Convert.ToString(chek);
            label4.Text = otagh1;
           


          

            }
    

        
        private void button1_Click(object sender, EventArgs e)
        {
            int o = Convert.ToInt32(otagh);
            int o1 = Convert.ToInt32(otagh1);
            if (o1 < o)
            {
                Class1 c1 = new Class1();
                string sel1 = "select * from room";

                sel1 += " where noroom='" + textBox1.Text + "'";

                DataSet ds1 = new DataSet();
                ds1 = c1.select(sel1);

                int chek = ds1.Tables["t1"].Rows.Count;
                label4.Text = Convert.ToString(chek);
                if (chek == 1)
                {
                    MessageBox.Show("کاربر گرامی اطلاعات چنین اتاقی قبلا ثبت شده است", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    string text,kh;
                    kh = "خالی";
                    //string a = "provider=microsoft.jet.oledb.4.0;data source =hotel12.mdb";
                    Class1 c2 = new Class1();
                    text = "insert into room values('" + textBox1.Text;
                    text += "','" + textBox2.Text + "','" + comboBox1.Text +"','"+kh+"')";
                    c2.insert(text);


                }
            }
            else
            {
                MessageBox.Show("کاربر گرامی شما مجاز به ذخیره ی بیشتر از" + otagh + " اتاق نیستید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
               
            }

        }

        private void Form8_FormClosing(object sender, FormClosingEventArgs e)
        {
           
            
        }

        private void Form8_FormClosed(object sender, FormClosedEventArgs e)
        {
           
        }

        private void Form8_Activated(object sender, EventArgs e)
        {
            darj();
            Class1 c1 = new Class1();
            string sel1 = "select * from room";

            DataSet ds1 = new DataSet();
            ds1 = c1.select(sel1);

            int chek = ds1.Tables["t1"].Rows.Count;
            otagh1 = Convert.ToString(chek);
            label4.Text = otagh1;
            
            
        }

        private void button1_Enter(object sender, EventArgs e)
        {
            darj();
            Class1 c1 = new Class1();
            string sel1 = "select * from room";

            DataSet ds1 = new DataSet();
            ds1 = c1.select(sel1);

            int chek = ds1.Tables["t1"].Rows.Count;
            otagh1 = Convert.ToString(chek);
            label4.Text = otagh1;
        }
    }
}