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

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

        }

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

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

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

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

        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();
            Term Trm = new Term();
            Trm.ID = Int32.Parse(val);
            Trm.Delete();
            Edit_Term_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();
            //
            Term Trm = new Term();
            Trm.ID = Int32.Parse(val);
            Trm.GetOne();
            //
            Update_Term frm = new Update_Term();
            frm.txtID.Text = Trm.ID.ToString();
            frm.txtTitle.Text = Trm.Title;
            frm.txtStart.Text = Trm.Start;
            frm.txtEnd.Text = Trm.End;
            frm.txtMonth.Text = Trm.Month;
            frm.txtYear.Text = Trm.Year;
            frm.ShowDialog();
        }

        
    }
}
