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 FrmPerson : Form
    {
        SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=emdad;Integrated Security=True");
        SqlCommand cmd = new SqlCommand();
        DataTable dt = new DataTable();
        public FrmPerson()
        {
            InitializeComponent();
        }

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

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

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtname.Text == "" || txtfamily.Text == "" || txtage.Text == "")
                MessageBox.Show("لطفا فیلدهای ستاره دار را پر کنید");
            else
            {
                cmd.Connection = con;
                con.Open();
                cmd.CommandText = "insert into [Person] (team,name,Famili,age,FatherName,IId) values ('"+comboBox1.SelectedValue.ToString()+"','"+txtname.Text.Trim()+"','"+txtfamily.Text.Trim()+"','"+txtage.Text.Trim()+"','"+txtfather.Text.Trim()+"','"+txtiid.Text.Trim()+"')";
                cmd.ExecuteNonQuery();
                con.Close();
                MessageBox.Show("ثبت با موفقیت انجام شد");
                txtage.Text = txtfamily.Text = txtfather.Text = txtiid.Text = txtname.Text = "";
            }
        }
    }
}
