using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace telif
{
    public partial class frmupdate : Form
    {
        long i;
        public frmupdate()
        {
            InitializeComponent();
        }

        private void frmupdate_Load(object sender, EventArgs e)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            var q = db.Storedselectall();
            dataGridView1.DataSource = q;
        }

        private void dataGridView1_RowStateChanged(object sender, DataGridViewRowStateChangedEventArgs e)
        {
            try
            {
                if (dataGridView1.RowCount > 1)
                {
                    txtname.Text = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
                    txtlast.Text = dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
                    txttel.Text = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
                    i =long.Parse(dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                }
            }
            catch (Exception)
            {
            }
        }

        private void btnupdate_Click(object sender, EventArgs e)
        {
            DataClasses1DataContext db = new DataClasses1DataContext();
            db.Storedupdate(i, txtname.Text, txtlast.Text, txttel.Text);
            var q = db.Storedselectall();
            dataGridView1.DataSource = q;
        }
    }
}
