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

namespace RezerveBeliteHavaPeimaCS
{
    public partial class frmServiceTypes : Form
    {
        public frmServiceTypes()
        {
            InitializeComponent();
        }

        private void dbIns()
        {
            if (textBox1.Text == "" )
            {
                MessageBox.Show("فیلد شرح خدمات نمی تواند خالی باشند");
            }
            else
            {
                FirstClass db = new FirstClass();
                db.cmd.Parameters.Add("@ServiceDesCript", SqlDbType.NVarChar).Value = textBox1.Text.Trim();
                db.exeCommand("sp_ServiceTypes_Insert");
                grdFill();
                txtClear();
                MessageBox.Show("رکورد جدید درج شد.");
            }
        }

        private void grdFill()
        {
            FirstClass db = new FirstClass();
            DataTable dt = new DataTable();

            dt = db.dbOut("SELECT     TOP 100 PERCENT ServiceTypeID AS [کد نوع سرویس], ServiceDesCript AS [نوع سرویس]  FROM      ServiceTypes ORDER BY ServiceTypeID DESC");
            dataGridView1.DataSource = dt;
        }

        protected void dbDel()
        {
            if (textBox2.Text == "")
            {
                MessageBox.Show("کد شرح سرویس وارد نشده");
            }
            else
            {
                FirstClass db = new FirstClass();
                db.cmd.Parameters.Add("@ServiceTypeID", SqlDbType.Int).Value = int.Parse(textBox2.Text.Trim());
                db.exeCommand("sp_ServiceTypes_DeleteRow");
                txtClear();
                grdFill();
                MessageBox.Show("رکورد مورد نظر حذف شد");
            }
        }

        protected void txtClear()
        {
            foreach (Control ctrl in this.Controls)
            {
                if (ctrl is TextBox)
                {
                    ctrl.Text = "";
                }
            } 
        }

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

        private void button1_Click(object sender, EventArgs e)
        {
            dbIns();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dbDel();
        }
    }
}