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 Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Class1 c1 = new Class1();
            string sel = "select * from moshtari";
            Boolean flag = false;

            if (textBox1.Text != "" || textBox2.Text != "")
            {
                sel += " where ";
                if (textBox1.Text != "")
                {
                    sel += "name like '%" + textBox1.Text + "%'";
                    flag = true;

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

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


                if (ds.Tables["t1"].Rows.Count == 1)
                {
                    this.ClientSize = new System.Drawing.Size(465, 376);
                    
                    dataGrid2.DataSource = ds;
                    dataGrid2.DataMember = "t1"; 
                }
                else
                {
                    
                    this.ClientSize = new System.Drawing.Size(465, 376);
                    //f3.dataGrid1.CaptionText = "نتایج جستجو" + " : " + chek + "  مورد";
                   dataGrid2.DataSource = ds;
                    dataGrid2.DataMember = "t1";
                    
                }

            }
        }

        private void Form5_Load(object sender, EventArgs e)
        {

        }
       
    }
}