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

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

        }

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

        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();
            Lesson lss = new Lesson();
            lss.ID = Int32.Parse(val);
            lss.Delete();
            Edit_Lesson_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();
            //
            Lesson lss = new Lesson();
            lss.ID = Int32.Parse(val);
            lss.GetOne();
            //
            Update_Lesson frm = new Update_Lesson();
            frm.txtID.Text = lss.ID.ToString();
            frm.txtTitle.Text = lss.Title;
            frm.Kind.Text = lss.kind;
            frm.txtVahed.Text = lss.Vahed;
            frm.txtDuration.Text = lss.Duration;
            frm.txtSharyeh.Text= lss.Sharyeh;
            frm.ShowDialog();
        }
        }
   
}
