using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;


namespace AzmoonGir
{
    public partial class FrmGroup : Form
    {
        public FrmGroup()
        {
            InitializeComponent();
        }

        private void FrmGroup_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            

            if (string.IsNullOrWhiteSpace(TxtGroupName.Text))
            {
                errorProvider1.SetError(TxtGroupName, "نام گروه وارد نشده است");
            }
            else
            {
                Frm_Message Fm = new Frm_Message();
                errorProvider1.SetError(TxtGroupName, "");
                try
                {
                    SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\DbAzmoon.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True");
                    SqlCommand cmd = new SqlCommand("AddGroup", con);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.AddWithValue("@groupname", TxtGroupName.Text);
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();

                  
                    TxtGroupName.Text = "";
                    TxtGroupName.Focus();

                  
                    Fm.lbltext.Text = "گروه با موفقیت ثبت شد";
                    Fm.ImgClose.Visible = true;
                    Fm.ImgYes.Visible = false;
                    Fm.ImgNo.Visible = false;
                    Fm.ShowDialog();
                }

                catch
                {
                    Fm.lbltext.Text = "ثبت گروه با مشکل مواجه شد";
                    Fm.ImgClose.Visible = true;
                    Fm.ImgYes.Visible = false;
                    Fm.ImgNo.Visible = false;
                    Fm.ShowDialog();

                }



            }


        }

        private void TxtGroupName_TextChanged(object sender, EventArgs e)
        {

        }

        private void TxtGroupName_Enter(object sender, EventArgs e)
        {
           

        }
    }
}
