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;
using System.Data.SqlClient;

namespace Amozeshgah
{
    public partial class Edit_Student : DevComponents.DotNetBar.Office2007Form
    {
        static SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Amozeshgah.mdf;integrated security=true;User Instance=True");
        SqlDataAdapter da = new SqlDataAdapter("", con);
        DataSet ds = new DataSet();
        public Edit_Student()
        {
            InitializeComponent();
        }

        private void Edit_Student_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'amozeshgahDataSet1.Student' table. You can move, or remove it, as needed.
            this.studentTableAdapter.Fill(this.amozeshgahDataSet1.Student);

        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (dataGridViewX1.CurrentRow == null)
                return;
            DialogResult dr;
            dr = MessageBox.Show("آیا می خواهید سطر انتخاب شده را حذف کنید", "مدیریت آموزشگاه", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            if (dr == DialogResult.No)
                return;
            int row = dataGridViewX1.CurrentRow.Index;
            string val = dataGridViewX1[0, row].Value.ToString();
            Student std = new Student();
            std.ID = Int32.Parse(val);
            std.Delete();
            Edit_Student_Load(null, null);
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dataGridViewX1.CurrentRow == null)
                return;
            int row = dataGridViewX1.CurrentRow.Index;
            string val = dataGridViewX1[0, row].Value.ToString();
            //
            Student std = new Student();
            std.ID = Int32.Parse(val);
            std.GetOne();
            //
            Update_Stu up = new Update_Stu();
            up.txtName.Text = std.name;
            up.txtFamily.Text = std.family;
            up.txtFather.Text = std.father;
            up.txtCode.Text = std.code;
            up.txtEmail.Text = std.email;
            up.txtMobile.Text = std.mobile;
            up.txtShomare.Text = std.shomareh;
            up.txtTel.Text = std.tel;
            up.txtAddress.Text = std.address;
            up.txtBirth.Text = std.birth;
            up.txtDate.Text = std.date;
            if (std.genus == "مرد")
                up.rdoMale.Checked = true;
            else
                up.rdoFemale.Checked = true;
            up.txtID.Text = std.ID.ToString();
            up.ShowDialog();
        }

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

        private void btnCode_Click(object sender, EventArgs e)
        {
            studentTableAdapter.SearchByID(amozeshgahDataSet1.Student,Int32.Parse(txtCode.Text));
            
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            studentTableAdapter.Fill(amozeshgahDataSet1.Student);
        }

        private void btnName_Click(object sender, EventArgs e)
        {
            studentTableAdapter.SearchByName(amozeshgahDataSet1.Student, txtName.Text);
        }

        private void btnFamily_Click(object sender, EventArgs e)
        {
            studentTableAdapter.SearchByFamily(amozeshgahDataSet1.Student, txtFamily.Text);
        }

        private void txtName_TextChanged(object sender, EventArgs e)
        {
            studentTableAdapter.SearchByName(amozeshgahDataSet1.Student, '%' + txtName.Text + '%');
        }

        private void txtFamily_TextChanged(object sender, EventArgs e)
        {
            studentTableAdapter.SearchByFamily(amozeshgahDataSet1.Student, '%' + txtFamily.Text + '%');
        }

        
       
    }
}
