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_Class : 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_Class()
        {
            InitializeComponent();
        }

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

        private void btnShow_Click(object sender, EventArgs e)
        {
            string sql;
            sql = "select * from Class ";
            ds.Clear();
            da.SelectCommand.CommandText = sql;
            da.Fill(ds, "Class");
            dataGridViewX1.DataSource = ds;
            dataGridViewX1.DataMember = "Class";
        }

        private void btnFamily_Click(object sender, EventArgs e)
        {
            string sql;
            sql = "select * from Class where C_title ='" + txtTitle.Text +  "'";
            ds.Clear();
            da.SelectCommand.CommandText = sql;
            da.Fill(ds, "Class");
            dataGridViewX1.DataSource = ds;
            dataGridViewX1.DataMember = "Class";
        }

        private void btnCode_Click(object sender, EventArgs e)
        {
            string sql;
            sql = "select * from Class where C_id =" + Int32.Parse(txtCode.Text);
            ds.Clear();
            da.SelectCommand.CommandText = sql;
            da.Fill(ds, "Class");
            dataGridViewX1.DataSource = ds;
            dataGridViewX1.DataMember = "Class";
        }

        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();
            Class1 std = new Class1();
            std.ID = Int32.Parse(val);
            std.Delete();
            Edit_Class_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();
            Class1 cls = new Class1();
            cls.ID = Int32.Parse(val);
            cls.GetOne();
        }

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

        private void btnDelete_Click_1(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();
            Class1 cls = new Class1();
            cls.ID = Int32.Parse(val);
            cls.Delete();
            Edit_Class_Load(null, null);
        }

        private void buttonX1_Click(object sender, EventArgs e)
        {
            if (dataGridViewX1.CurrentRow == null)
                return;
            int row = dataGridViewX1.CurrentRow.Index;
            string val = dataGridViewX1[0, row].Value.ToString();
            //
            Class1 cls = new Class1();
            cls.ID = Int32.Parse(val);
            cls.GetOne();
            //
            Update_Class frm = new Update_Class();
            frm.txtID.Text = cls.ID.ToString();
            frm.txtTitle.Text = cls.title;
            frm.txtcap.Text = cls.des;
            frm.txtdes.Text = cls.des;
            frm.genus.Text = cls.genus;
            frm.ShowDialog();
        }
    }
}
