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

namespace personal_info
{
    public partial class personal : Form
    {
        public personal()
        {
            InitializeComponent();
        
        }
        DataTable dt = new DataTable();
        BindingSource bs = new BindingSource();
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=DBTest;Integrated Security=True");
         private void commandBarButton1_Click(object sender, EventArgs e)
        {
            addinfo info = new addinfo(dt,-1,"جدید");
            info.Show();
        }

        private void btn_edit_Click(object sender, EventArgs e)
        {
            addinfo info = new addinfo(dt, bs.Position, "ویرایش");
            info.Show();

        }


        private void personal_Load(object sender, EventArgs e)
        {
            SqlDataAdapter da = new SqlDataAdapter("select * from tblPerson", con);
            da.Fill(dt);
            bs.DataSource = dt;
            radGridView1.DataSource = bs;
        }

        private void btn_delete_Click(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "delete from tblPerson where CodeMelli=@CodeMelli";
            cmd.Connection = con;
            cmd.Parameters.Add("@CodeMelli", SqlDbType.NVarChar).Value = radGridView1.CurrentRow.Cells[0].Value.ToString();
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            bs.RemoveCurrent();
        }

        private void btn_search_Click(object sender, EventArgs e)
        {
 bs.Filter="CodeMelli='"+txtSearch.Text+"'";
        }
    }
}
