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

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

                SqlConnection myConn;
                SqlCommand myComm;
                SqlDataReader myDR;

                StrConn = "SERVER=.;DATABASE=Havapeyma;Integrated Security=True";
                StrQury = "Select * From 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.textBox1.Text;

                myConn.Open();
                myDR = myComm.ExecuteReader();

                if (myDR.Read())
                {

                    this.textBox10.Text = myDR["Name"].ToString();
                    this.textBox2.Text = myDR["Family"].ToString();
                    this.textBox3.Text = myDR["TelNumber"].ToString();
                    this.textBox4.Text = myDR["Age"].ToString();
                    this.LBsex.Text = myDR["Sex"].ToString();
                    if (LBsex.Text == "زن") radioButton1.Checked = true;
                    if (LBsex.Text == "مرد") radioButton2.Checked = true;
                    this.textBox5.Text = myDR["SHarekat"].ToString();
                    this.textBox11.Text = myDR["Tharekat"].ToString();
                    this.textBox6.Text = myDR["MablaghD"].ToString();
                    this.textBox7.Text = myDR["Mabda"].ToString();
                    this.textBox8.Text = myDR["Maghsad"].ToString();
                    this.textBox12.Text = myDR["CodeHavapeyma"].ToString();
                    this.textBox9.Text = myDR["NSandali"].ToString();
                    groupBox2.Enabled = true;
                   


                }
                else
                {
                    this.textBox10.Text = "";
                    this.textBox2.Text = "";
                    this.textBox3.Text = "";
                    this.textBox4.Text = "";
                    this.LBsex.Text = "";
                    this.textBox5.Text = "";
                    this.textBox11.Text = "";
                    this.textBox6.Text = "";
                    this.textBox7.Text = "";
                    this.textBox11.Text = "";
                    this.textBox8.Text = "";
                    this.textBox12.Text = "";
                    this.textBox9.Text = "";
                }




                myConn.Close();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            StrQury = "Select * From VIEW1 Where CodeMosafer='" + textBox1.Text + "'";
            StrQury += "And CodeH='" + textBox12.Text + "'";
            Form11 obj = new Form11(StrQury);
            obj.ShowDialog();
            
          

        }

        
    }
}
