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

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

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

        private void button1_Click(object sender, EventArgs e)
        {
            cmd.Connection = con;
            con.Open();
            cmd.CommandText = "insert into [Emdad] (id_team,id_Hadese,time_Emdad) values ('"+comboBox2.SelectedValue.ToString()+"','"+comboBox1.SelectedValue.ToString()+"','"+maskedTextBox1.Text+"')";
            cmd.ExecuteNonQuery();
            con.Close();
            MessageBox.Show("ثبت با موفقیت انجام شد");
            maskedTextBox1.Text = "";
        }
    }
}
