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 Form9 : Form
    {
        public Form9()
        {
            InitializeComponent();
        }
        //public string a, b, c, d, e;
        void darj()
        {


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

            string sel = "select * from moshtari ";
            sel += " where hazf='" + 0 + "'";
            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 Form9_Load(object sender, EventArgs e)
        {
            darj();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            if (textBox1.Text == "" && textBox2.Text == "" && textBox3.Text == "")
            {
                darj();
            }
            else
            {
                Class1 c1 = new Class1();
                string sel = "select * from moshtari";
                Boolean flag = false;

                if (textBox1.Text != "" || textBox2.Text != "" || textBox3.Text != "")
                {
                    sel += " where ";
                    if (textBox1.Text != "")
                    {
                        sel += "codemeli='" + textBox1.Text + "'";
                        flag = true;

                    }
                    if (textBox2.Text != "")
                    {
                        if (flag)
                            sel += " and ";
                        sel += "name like '%" + textBox2.Text + "%'";
                        flag = true;

                    }
                    if (textBox3.Text != "")
                    {
                        if (flag)
                            sel += " and ";
                        sel += "lastname like '%" + textBox3.Text + "%'";
                        flag = true;

                    }

                    if (flag)
                    {
                        sel += " and ";
                        sel += "hazf='" + 0 + "'";
                        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 button1_Click(object sender, EventArgs e)
        {
            Form6 f6 = new Form6();
            f6.textBox2.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 0]);
            f6.textBox3.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 1]);
            f6.textBox1.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 3]);
            f6.textBox7.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 4]);
            f6.textBox6.Text = Convert.ToString(dataGrid1[dataGrid1.CurrentRowIndex, 5]);
            Hide();
            f6.ShowDialog();
            
        }
    }
}