using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Nano_System
{
    public partial class frmSbj : Form
    {
        public frmSbj()
        {
            InitializeComponent();
        }

        public void dbConnection()
        {
            clsGrideview dbCon1 = new clsGrideview();
            dataGridView1.DataSource = dbCon1.dbConnection(@"SELECT  TOP 100 PERCENT Subject, SubId FROM Subjects ORDER BY Subject");
        }


        private void frmSbj_Load(object sender, EventArgs e)
        {
            dbConnection();
        }

        public void insSql()
        {
            clsAdding insTodb = new clsAdding();
            insTodb.insSql("insert into Subjects (Subject)values('" + textBox1.Text + "')");
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("فیلد موضوع خالی است");
            }
            else
            {
                insSql();
                dbConnection();
                textBox1.Clear();
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("فیلد کد موضوع خالی است");
            }
            else
            {
                FirstClass dbDel1 = new FirstClass();
                dbDel1.cmd.Parameters.Add("@SubId", SqlDbType.Int).Value = int.Parse(textBox1.Text);
                dbDel1.exeCommand("sp_Subjects_DeleteRow");
                dbConnection();
            }
        }
    }
}