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.SqlClient;

namespace DabirKhane
{
    public partial class tel: Form
    {
        public void tohi()
        {
            textBox3.Text = "";
            textBox2.Text = "";
            textBox1.Text = "";
        }
        
        public tel()
        {
            InitializeComponent();
        }

        private void tel_Load(object sender, EventArgs e)
        {

        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tel_Load_1(object sender, EventArgs e)
        {

            Payegah.ShowData(Variables.masir,Variables.StrCommandTel , 3, dataGridView1);
        }

        private void button1_Click(object sender, EventArgs e)
        {
                   
            string s3 = string.Format("insert into tel values('{0}','{1}','{2}')", textBox1.Text, textBox2.Text, textBox3.Text);
            Payegah.Insert(Variables.masir, s3);
            Payegah.ShowData(Variables.masir, Variables.StrCommandTel, 3, dataGridView1);
            tohi();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            mask.StrText(e);
        }

        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            mask.IntText(e);
        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            string s = "select * from tel where telnumber='" + textBox1.Text + "'";
            string s2 = "delete from tel where telnumber='" + textBox1.Text + "'";
            Payegah.Delet(Variables.masir, s, textBox1,textBox2 , s2);
            Payegah.ShowData(Variables.masir, Variables.StrCommandTel, 3, dataGridView1);
            tohi();
        }
        

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            textBox1.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            textBox2.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            textBox3.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
            if (textBox1.Text != "")
            {
                button1.Enabled = true;
                button2.Enabled = true;
                button4.Enabled = true;
            }
            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string s = "update tel set telnumber='" + textBox1.Text + "',name='" + textBox2.Text + "',family='"+textBox3.Text +"' where telnumber='" + textBox1.Text + "'";
            Payegah.UpDate(Variables.masir, s);
            Payegah.ShowData(Variables.masir, Variables.StrCommandTel, 3, dataGridView1 );
            tohi();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged_1(object sender, EventArgs e)
        {
            if ((textBox1.Text == "") | (textBox2.Text == ""))
            {
                button1.Enabled = false;
                button2.Enabled = false;
                button4.Enabled = false;
            }
            else
            {
                button1.Enabled = true;
                button2.Enabled = true;
                button4.Enabled = true;
            } 
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void textBox1_KeyPress_1(object sender, KeyPressEventArgs e)
        {
            mask.IntText(e);
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            mask.StrText(e);
        }
    }
}