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 Ajans
{
    public partial class Form9 : Form
    {
        String StrConn;
        String StrQury;
        public Form9()
        {
            InitializeComponent();
        }

        private void Form9_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'havapeymaDataSet.Havapeyma' table. You can move, or remove it, as needed.
            this.havapeymaTableAdapter1.Fill(this.havapeymaDataSet.Havapeyma);
            // TODO: This line of code loads data into the 'havapeymaDataSet1.Havapeyma' table. You can move, or remove it, as needed.
            this.havapeymaTableAdapter.Fill(this.havapeymaDataSet1.Havapeyma);

        }

        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection myConn;
            SqlCommand myComm;
            StrConn = "SERVER=.;DATABASE=Havapeyma;Integrated Security=True";
            StrQury = "Insert Into Havapeyma (CodeH,NameH,NoaH,Zarfyat) Values (@CodeH,@NameH,@NoaH,@Zarfyat)";
            myConn = new SqlConnection(StrConn);
            myComm = new SqlCommand();
            myComm.Connection = myConn;
            myComm.CommandType = CommandType.Text;
            myComm.CommandText = StrQury;

            myComm.Parameters.Add("CodeH", SqlDbType.NVarChar, 50).Value = this.CodeH.Text;
            myComm.Parameters.Add("NameH", SqlDbType.NVarChar, 50).Value = this.textBox1.Text;
            myComm.Parameters.Add("NoaH", SqlDbType.NVarChar, 50).Value = this.textBox2.Text;
            myComm.Parameters.Add("Zarfyat", SqlDbType.NVarChar, 50).Value = this.textBox3.Text;


            myConn.Open();
            myComm.ExecuteNonQuery();
            myConn.Close();
            Show1();

            MessageBox.Show(" اطلاعات هواپیما با موفقیت ثبت شد");
        }

        private void Show1()
        {
            SqlDataAdapter myDA;
            DataSet myDS;

            StrConn = "SERVER=.;DATABASE=Havapeyma;Integrated Security=True";
            StrQury = "Select * From Havapeyma";
            myDA = new SqlDataAdapter(StrQury, StrConn);

            myDS = new DataSet();

            myDA.Fill(myDS, "Havapeyma");

            this.dataGridView1.DataSource = myDS;
            this.dataGridView1.DataMember = "Havapeyma";
            this.dataGridView1.AutoGenerateColumns = true;
            this.dataGridView1.RightToLeft = RightToLeft.Yes;
            this.dataGridView1.Refresh();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            SqlConnection myConn;
            SqlCommand myComm;

            StrConn = "SERVER=.;DATABASE=Havapeyma;Integrated Security=True";
            StrQury = "Delete Havapeyma Where CodeH=@CodeH";

            myConn = new SqlConnection(StrConn);

            myComm = new SqlCommand();
            myComm.Connection = myConn;
            myComm.CommandType = CommandType.Text;
            myComm.CommandText = StrQury;

            myComm.Parameters.Add("CodeH", SqlDbType.NVarChar, 50).Value = this.Code.Text;


            myConn.Open();
            myComm.ExecuteNonQuery();
            myConn.Close();
            MessageBox.Show("حذف اطلاعات هواپیما  با موفقیت انجام شد ");
            Show1();
        }

        private void groupBox2_Enter(object sender, EventArgs e)
        {

        }
    }
}
