using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class frmSearchName : Form
    {
        public frmSearchName()
        {
            InitializeComponent();
        }

        private void cmb2Fill()
        {
            FirstClass aa = new FirstClass();
            comboBox2.DataSource = aa.dbOut("SELECT     CustomerID, Name + N'  ' + Sname AS Expr1 FROM CustumerCode");
            comboBox2.DisplayMember = "Expr1";
            comboBox2.ValueMember = "CustomerID";
        }

        private void dbSearch()
        {
            FirstClass db = new FirstClass();
            DataTable dt = new DataTable();

            dt = db.dbOut(@"SELECT     PhoneNumbers.PhoneNumberID AS [کد شماره], PhoneNumberTypes.PhoneNumberType AS [نوع شماره تلفن], 
                      CustumerCode.Name + N'  ' + CustumerCode.Sname AS [نام و نام خانوادگی], PhoneNumbers.PhoneNumber AS [شماره تلفن]
                        FROM         CustumerCode INNER JOIN  PhoneNumbers ON CustumerCode.CustomerID = PhoneNumbers.CostumerID INNER JOIN
                      PhoneNumberTypes ON PhoneNumbers.PhoneNumberTypeID = PhoneNumberTypes.PhonesTypeID WHERE     (CustumerCode.CustomerID = '"+ comboBox2.SelectedValue +"')");
            if (dt.Rows.Count <= 0)
            {
                MessageBox.Show("موردی پیدا نشد");
            }
            else
            {
                dataGridView1.DataSource = dt;
            }

        }

        private void frmSearchName_Load(object sender, EventArgs e)
        {
            cmb2Fill();
        }

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


    }
}