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

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


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


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

        public void insSql()
        {

            clsAdding insTodb = new clsAdding();
            //SqlParameter param1 = new SqlParameter("@geimat", SqlDbType.Money);
            //param1.Value = textBox10.Text;
            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 == "" || textBox2.Text == "")
            {
                MessageBox.Show("مقادیر هر دوفیلد باید وارد شوند");
            }
            else
            {
                FirstClass db = new FirstClass();
                db.cmd.Parameters.Add("@SubId", SqlDbType.Int).Value = int.Parse(textBox2.Text.Trim());
                db.cmd.Parameters.Add("@Subject", SqlDbType.NVarChar).Value = textBox1.Text.Trim();
                db.exeCommand("sp_Subjects_Update");
                dbConnection();
                textBox1.Clear();
                textBox2.Clear();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "" )
            {
                MessageBox.Show("مقدار فیلد کد موضوع وارد نشده است");
            }
            else
            {
                FirstClass db = new FirstClass();
                db.cmd.Parameters.Add("@SubId", SqlDbType.Int).Value = int.Parse(textBox2.Text.Trim());
                db.exeCommand("sp_Subjects_DeleteRow");
                dbConnection();
                textBox1.Clear();
                textBox2.Clear();
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            if (textBox1.Text == "")
            {
                MessageBox.Show("موضوع یا بخشی از موضوع وارد نشده است");
            }
            else
            {
                clsGrideview dbCon1 = new clsGrideview();
                dataGridView1.DataSource = dbCon1.dbConnection(@"SELECT     TOP 100 PERCENT SubId, Subject  FROM        Subjects WHERE (Subject LIKE N'%" + textBox1.Text.Trim() + "%') ORDER BY SubId");
            }
        }
    }
}