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 Amozeshgah
{
    public partial class Edit_Teacher : DevComponents.DotNetBar.Office2007Form
    {
        public Edit_Teacher()
        {
            InitializeComponent();
        }

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

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

        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();
            //
            Teacher std = new Teacher();
            std.ID = Int32.Parse(val);
            std.GetOne();
            //
            Update_Tea up = new Update_Tea();
            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;
            up.madrak.Text = std.madrak;
            if (std.genus == "مرد")
                up.rdoMale.Checked = true;
            else
                up.rdoFemale.Checked = true;
            up.txtID.Text = std.ID.ToString();
            up.ShowDialog();
        }

        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_Teacher_Load(null, null);
        }

        private void btnCode_Click(object sender, EventArgs e)
        {
           teacherTableAdapter.SearchById(amozeshgahDataSet1.Teacher,Int32.Parse(txtCode.Text));
        }

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

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

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

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

        private void btnView_Click(object sender, EventArgs e)
        {
            this.teacherTableAdapter.Fill(this.amozeshgahDataSet1.Teacher);
        }
    }
}
