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

namespace BongahCS
{
    public partial class frmAsnadStatuses : Form
    {
        public frmAsnadStatuses()
        {
            InitializeComponent();
        }

        protected void grdFill()
        {
            FirstClass db = new FirstClass();
            DataTable dt = new DataTable();
            dt = db.dbOut("SELECT     TOP 100 PERCENT sanadStatuseID, sanadStatusDescript FROM  tblSanadsStatuse ORDER BY sanadStatuseID DESC");
            dataGridView1.DataSource = dt;
        }

        protected void dbIns()
        {
            FirstClass db = new FirstClass();
            db.exeCommand1("insert into  tblSanadsStatuse (sanadStatusDescript)values('" + textBox1.Text.Trim() + "')");
            grdFill();
            textBox1.Text = "";
            MessageBox.Show("رکورد جدید اضافه شد");
        }

        protected void dbDel()
        {
            FirstClass db = new FirstClass();
            db.cmd.Parameters.Add("@sanadStatuseID", SqlDbType.Int).Value = int.Parse(textBox2.Text.Trim());
            db.exeCommand("sp_tblSanadsStatuse_DeleteRow");
            grdFill();
            textBox2.Text = "";
            MessageBox.Show("رکورد مورد نظر حذف شد");
        }

        private void frmAsnadStatuses_Load(object sender, EventArgs e)
        {
            grdFill();
        }

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

        private void button2_Click(object sender, EventArgs e)
        {
            if (textBox2.Text == "")
            {
                MessageBox.Show("فیلد کد وضعیت سند خالی است");
            }
            else
            {
                dbDel();
            }
        }
    }
}