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

        private void Form4_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'havapeymaDataSet2.Mosafer' table. You can move, or remove it, as needed.
            this.mosaferTableAdapter.Fill(this.havapeymaDataSet2.Mosafer);

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if ((textBox1.Text!="") && (textBox2.Text!=""))
            {
                
           

            SqlConnection myConn;
            SqlCommand myComm;

            StrConn = "SERVER=.;DATABASE=Havapeyma;Integrated Security=True";
            StrQury = "Delete Mosafer Where Name=@N And Family=@F";

            myConn = new SqlConnection(StrConn);

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

            myComm.Parameters.Add("N", SqlDbType.NVarChar, 50).Value = this.textBox1.Text;
            myComm.Parameters.Add("F", SqlDbType.NVarChar, 50).Value = this.textBox2.Text;
            myConn.Open();
            myComm.ExecuteNonQuery();
            myConn.Close();
            MessageBox.Show("حذف اطلاعات مسافر با موفقیت انجام شد ","حذف اطلاعات مسافران");
            Show1();
            textBox1.Text = "";
            textBox2.Text = "";
            textBox1.Focus();
        }
             }

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

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

            myDS = new DataSet();

            myDA.Fill(myDS, "Mosafer");

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

        private void button1_Click(object sender, EventArgs e)
        {
            if (CodeMosafer.Text != "")
            {
                
            

            SqlConnection myConn;
            SqlCommand myComm;

            StrConn = "SERVER=.;DATABASE=Havapeyma;Integrated Security=True";
            StrQury = "Delete Mosafer Where CodeMosafer=@Code";

            myConn = new SqlConnection(StrConn);

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

            myComm.Parameters.Add("Code", SqlDbType.NVarChar, 50).Value = this.CodeMosafer.Text ;
            myConn.Open();
            myComm.ExecuteNonQuery();
            myConn.Close();
            MessageBox.Show("حذف اطلاعات مسافر با موفقیت انجام شد ", "حذف اطلاعات مسافران");
            Show1();
            CodeMosafer.Text = "";
            CodeMosafer.Focus();
                }
        }
    }
}
