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 Form6 : Form
    {
        public Form6()
        {
            InitializeComponent();
        }
        public string x;
        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 button1_Click(object sender, EventArgs e)
        {
            this.Hide();
            Form9 f9 = new Form9();
            f9.ShowDialog();
            button3.Visible = true;

        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                if (textBox3.Text == "")

                    MessageBox.Show("کاربر گرامی کد ملی را وارد کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (textBox4.Text == "")
                    MessageBox.Show("کاربر گرامی شماره اتاق را وارد کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                else if (textBox5.Text == "")
                    MessageBox.Show("کاربر گرامی مدت اقامت را مشخص کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);

                else
                {
                    string text;
                    Class1 c2 = new Class1();
                    text = "insert into rezerv values('" + textBox4.Text;
                    text += "','" + textBox1.Text + "','" + textBox5.Text + "')";
                    c2.insert(text);
                    Close();
                    string nootagh;
                    nootagh = "پر";
                    //string sh, t, f;
                    //f = "3";
                    //sh = "3";
                    //label11.Text = "10";
                    string text1;
                    string a = "provider=microsoft.jet.oledb.4.0;data source =hotel12.mdb";

                    text1 = "update room set SS='" + nootagh + "'" + " where noroom='" + textBox4.Text + "'";

                    OleDbConnection con = new OleDbConnection(a);
                    OleDbCommand cmd = new OleDbCommand(text1, con);

                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                }
            }
            catch
            {
                MessageBox.Show("کاربر گرامی ابتدا تنظیمات مربوط به اتاق را تکمیل کنید", "اطلاع", MessageBoxButtons.OK, MessageBoxIcon.None);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            panel1.Visible = true;
            button3.Visible = false;
            button5.Visible = true;
        }

        private void Form6_Load(object sender, EventArgs e)
        {
            darj();

        }

        private void textBox9_TextChanged_1(object sender, EventArgs e)
        {
            if (textBox9.Text == "" && textBox8.Text == "")
            {
                darj();
            }
            else
            {
                Class1 c1 = new Class1();
                string sel = "select * from room";
                Boolean flag = false;

                if (textBox8.Text != "" || textBox9.Text != "")
                {
                    sel += " where ";
                    if (textBox9.Text != "")
                    {
                        sel += "noroom='" + textBox9.Text + "'";
                        flag = true;

                    }
                    if (textBox8.Text != "")
                    {
                        if (flag)
                            sel += " and ";
                        sel += "notabagh='" + textBox8.Text + "'";
                        flag = true;

                    }

                    DataSet ds = new DataSet();
                    ds = c1.select(sel);


                    if (ds.Tables["t1"].Rows.Count == 1)
                    {

                        dataGrid1.DataSource = ds;
                        dataGrid1.DataMember = "t1";
                    }
                    else
                    {


                        dataGrid1.DataSource = ds;
                        dataGrid1.DataMember = "t1";

                    }

                }
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {

            //Class1 c1 = new Class1();
            //string sel = "select * from room";
            //Boolean flag = false;
            string x, y;
           
            x = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 0]);
            y = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 3]);
            label10.Text = y;
            if (label10.Text == "پر")
            {
                MessageBox.Show("کاربر گرامی این اتاق پراست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                panel1.Visible = false;
                button5.Visible = false;
                textBox4.Text = x;
                button3.Visible = true;

            }
           
            

        }

        private void button4_Click(object sender, EventArgs e)
        {
            try
            {
                //Boolean flag = false;
                string x, y;

                x = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 0]);
                y = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 3]);
                label10.Text = y;
                if (label10.Text == "پر")
                {
                    MessageBox.Show("کاربر گرامی این اتاق پر است,اتاق دیگری را انتخاب کنید", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    panel1.Visible = false;
                    button5.Visible = false;
                    textBox4.Text = x;
                    button3.Visible = true;

                }
            }

            catch
            {
                MessageBox.Show("کاربر گرامی ابتدا تنظیمات مربوط به اتاق را تکمیل کنید", "اطلاع", MessageBoxButtons.OK, MessageBoxIcon.None);
            }
          
           
        }
           


        

    }
}