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 MyDataAccess;
using System.Data.SqlClient;

namespace Amozeshgah
{
    public partial class SearchingDars : Form
    {
        public SearchingDars()
        {
            InitializeComponent();
        }



        cDataAccess cData = new cDataAccess(clsPath.ConnectionString());
        static SqlConnection con = new SqlConnection(clsPath.ConnectionString());
        SqlDataAdapter da = new SqlDataAdapter("", con);
        DataSet ds = new DataSet();
       

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

        private void txtSearching_TextChanged(object sender, EventArgs e)
        {
            string s;
            ds.Clear();
            if (rdbNameDars.Checked)
            {
                s = "select * from tDoros where NameDars like N'%" + txtSearching.Text + "%'";
                da.SelectCommand.CommandText = s;

            }
            if (rdbMozo.Checked)
            {
                s = "select * from tDoros where Mozo like N'%" + txtSearching.Text + "%'";
                da.SelectCommand.CommandText = s;

            }
            da.Fill(ds, "ID");
            dgDars.DataSource = ds.Tables["ID"];
        }

        private void SearchingDars_Load(object sender, EventArgs e)
        {
            
            dgDars.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(50, 228, 125);
            dgDars.DefaultCellStyle.SelectionBackColor = Color.FromArgb(99, 145, 152);
            dgDars.DefaultCellStyle.WrapMode = DataGridViewTriState.False;
            dgDars.GridColor = Color.FromArgb(214, 214, 214);
            dgDars.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
            dgDars.MultiSelect = false;
            dgDars.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            dgDars.RowHeadersVisible = false;
            dgDars.ReadOnly = true;
            dgDars.AllowUserToResizeRows = false;
            DataSet ret = cData.ExecuteQuery("SELECT [ID],[NameDars],[Mozo],[TedadVahed],[NameOstad]FROM [tDoros]");
            dgDars.DataSource = ret.Tables[0];
        }

        private void dgDars_SelectionChanged(object sender, EventArgs e)
        {
            if (dgDars.SelectedRows.Count > 0)
            {

                txtNameDars.Text = dgDars.CurrentRow.Cells["NameDars"].Value.ToString();
                txtMozo.Text = dgDars.CurrentRow.Cells["Mozo"].Value.ToString();
                txtTedadVahed.Text = dgDars.CurrentRow.Cells["TedadVahed"].Value.ToString();
                txtNameOstad.Text = dgDars.CurrentRow.Cells["NameOstad"].Value.ToString();
            }
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            SearchingDars_Load(sender, e);
            txtSearching.Text = "";
        }
    }
}
