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 shop
{
    public partial class tel : Form
    {
        public tel()
        {
            InitializeComponent();
        }

        void display()
        {
            OleDbConnection con1 = new OleDbConnection();
            con1.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbDataAdapter da = new OleDbDataAdapter("select * from telefon", con1);
            DataSet ds = new DataSet();
            da.Fill(ds, "telefon");
            dataGridView1.DataSource = ds.Tables["telefon"].DefaultView;
            con1.Close();
        }

        private void cls()
        {
            textBox1.Text = textBox2.Text = textBox3.Text = 
            textBox4.Text = textBox5.Text = textBox6.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbCommand com = new OleDbCommand();
            com.CommandText = "insert into telefon(nam,famili,tel,mob,fks,toz) values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "')";
            con.Open();
            com.Connection = con;
            com.ExecuteNonQuery();
            con.Close();
            display();
            cls();
        }

        private void tel_Load(object sender, EventArgs e)
        {
            display();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection();
            con.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbCommand com = new OleDbCommand();
            com.Connection = con;
            int item;
            com.CommandText = "select count(nam) from telefon where nam='" + textBox1.Text + "'";
            con.Open();
            item = (int)com.ExecuteScalar();
            con.Close();
            if (item != 0)
            {
                if (MessageBox.Show("آيا مي خواهيد شماره مورد نظز حذف شود؟", "توجه", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    com.CommandText = "delete from telefon where nam='" + textBox1.Text + "' and famili='" + textBox2.Text + "'";
                con.Open();
                com.ExecuteNonQuery();
                con.Close();
                display();
                cls();
            }
            else
            {
                MessageBox.Show("!شماره مورد نظر موجود نيست", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button5_Click(object sender, EventArgs e)
        {
            cls();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            OleDbConnection con1 = new OleDbConnection();
            con1.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbDataAdapter da = new OleDbDataAdapter("select * from telefon where nam like'%" + textBox1.Text + "%'", con1);
            DataSet ds = new DataSet();
            da.Fill(ds, "telefon");
            dataGridView1.DataSource = ds.Tables["telefon"].DefaultView;
            con1.Close();
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            OleDbConnection con1 = new OleDbConnection();
            con1.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbDataAdapter da = new OleDbDataAdapter("select * from telefon where famili like'%" + textBox2.Text + "%'", con1);
            DataSet ds = new DataSet();
            da.Fill(ds, "telefon");
            dataGridView1.DataSource = ds.Tables["telefon"].DefaultView;
            con1.Close();
        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {
            OleDbConnection con1 = new OleDbConnection();
            con1.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbDataAdapter da = new OleDbDataAdapter("select * from telefon where tel like'%" + textBox3.Text + "%'", con1);
            DataSet ds = new DataSet();
            da.Fill(ds, "telefon");
            dataGridView1.DataSource = ds.Tables["telefon"].DefaultView;
            con1.Close();
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            OleDbConnection con1 = new OleDbConnection();
            con1.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbDataAdapter da = new OleDbDataAdapter("select * from telefon where mob like'%" + textBox4.Text + "%'", con1);
            DataSet ds = new DataSet();
            da.Fill(ds, "telefon");
            dataGridView1.DataSource = ds.Tables["telefon"].DefaultView;
            con1.Close();
        }

        private void textBox5_TextChanged(object sender, EventArgs e)
        {
            OleDbConnection con1 = new OleDbConnection();
            con1.ConnectionString = "provider=microsoft.jet.oledb.4.0; data source=shoping.mdb";
            OleDbDataAdapter da = new OleDbDataAdapter("select * from telefon where fks like'%" + textBox5.Text + "%'", con1);
            DataSet ds = new DataSet();
            da.Fill(ds, "telefon");
            dataGridView1.DataSource = ds.Tables["telefon"].DefaultView;
            con1.Close();
        }

        private void label5_Click(object sender, EventArgs e)
        {

        }

        private void label6_Click(object sender, EventArgs e)
        {

        }

        private void textBox6_TextChanged(object sender, EventArgs e)
        {

        }

        private void label3_Click(object sender, EventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
