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

namespace Emdad
{
    public partial class FrmTeam : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=emdad;Integrated Security=True");
        SqlCommand cmd = new SqlCommand();
        DataTable dt = new DataTable();
        public FrmTeam()
        {
            InitializeComponent();
        }

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

        private void button4_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txttakhasos.Text == "")
                MessageBox.Show("لطفا فیلد تخصص را پر کنید");
            else
            {
                cmd.Connection = con;
                con.Open();
                cmd.CommandText = "insert into [Takhasos] ([takhasosName]) values ('" + txttakhasos.Text.Trim() + "')";
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("ثبت با موفقیت انجام شد");
                txttakhasos.Text = "";
                //******************************************
                dt.Clear();
                DataTable dt2 = new DataTable();
                cmd.Connection = con;
                con.Open();
                cmd.CommandText = "select takhasosName from Takhasos";
                SqlDataReader dr = cmd.ExecuteReader();
                dt2.Columns.Add("takhasosName");
                dt2.Load(dr);
                cmbtakhasos.ValueMember = "takhasosName";
                cmbtakhasos.DisplayMember = "takhasosName";
                cmbtakhasos.DataSource = dt2;
                con.Close();
            }
        }

        private void FrmTeam_Load(object sender, EventArgs e)
        {
            cmd.Connection = con;
            con.Open();
            cmd.CommandText = "select takhasosName from Takhasos";
            SqlDataReader dr = cmd.ExecuteReader();
            dt.Columns.Add("takhasosName");
            dt.Load(dr);
            cmbtakhasos.ValueMember = "takhasosName";
            cmbtakhasos.DisplayMember = "takhasosName";
            cmbtakhasos.DataSource = dt;
            con.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (nameteam.Text == "" || namesargoroh.Text == "" || familysargoroh.Text == "")
                MessageBox.Show("اخطار! فیلدهای نام تیم،نام سرگروه و نام خانوادگی سرگروه نمیتوانند خالی باشند");
            else
            {
                cmd.Connection = con;
                con.Open();
                cmd.CommandText = "insert into [Team] (Name,takhasosName,nameS,familiS,iids) values ('"+nameteam.Text.Trim()+"','"+cmbtakhasos.SelectedValue.ToString()+"','"+namesargoroh.Text.Trim()+"','"+familysargoroh.Text.Trim()+"','"+iidsargoroh.Text.Trim()+"')";
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("ثبت با موفقیت انجام شد");
                nameteam.Text = namesargoroh.Text = familysargoroh.Text = iidsargoroh.Text = "";
            }
        }
    }
}
