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

namespace Self_Project
{
    public partial class SearchStudent : Form
    {
        Student Std = new Student();
        public string STDNUM = "";
        public SearchStudent()
        {
            InitializeComponent();
        }

        private void R1_CheckedChanged(object sender, EventArgs e)
        {
            if(R1.Checked)
            {
                txt_Student_ID.Enabled = true;
                txt_Cart_ID.Enabled = false;
                txt_Student_Name.Enabled = false;
                txt_Student_Family.Enabled = false;
                txt_Student_ID.Focus();
            }
        }

        private void R2_CheckedChanged(object sender, EventArgs e)
        {
            if (R2.Checked)
            {
                txt_Student_ID.Enabled = false;
                txt_Cart_ID.Enabled = true;
                txt_Student_Name.Enabled = false;
                txt_Student_Family.Enabled = false;
                txt_Cart_ID.Focus();
            }
        }

        private void R3_CheckedChanged(object sender, EventArgs e)
        {
            if (R3.Checked)
            {
                txt_Student_ID.Enabled = false;
                txt_Cart_ID.Enabled = false;
                txt_Student_Name.Enabled = true;
                txt_Student_Family.Enabled = true;
                txt_Student_Name.Focus();
            }
        }

        private void T1_TextChanged(object sender, EventArgs e)
        {
            if (txt_Student_ID.TEXT == "")
                DGV1.DataSource = Std.Search_Student(Student.SearchType.None);
            else
                DGV1.DataSource = Std.Search_Student(Student.SearchType.StudentID, txt_Student_ID.TEXT);
            RenameDGV();
        }

        private void T2_TextChanged(object sender, EventArgs e)
        {
            if (txt_Cart_ID.TEXT == "")
                DGV1.DataSource = Std.Search_Student(Student.SearchType.None);
            else
                DGV1.DataSource = Std.Search_Student(Student.SearchType.CartID, txt_Cart_ID.TEXT);
            RenameDGV();
        }

        private void T3_TextChanged(object sender, EventArgs e)
        {
            DGV1.DataSource = Std.Search_Student(Student.SearchType.Name_Family, txt_Student_Name.TEXT, txt_Student_Family.TEXT);
            RenameDGV();
        }

        private void RenameDGV()
        {
            DGV1.Columns[0].HeaderText = "شماره دانشجو";
            DGV1.Columns[1].HeaderText = "شماره كارت";
            DGV1.Columns[2].HeaderText = "نام";
            DGV1.Columns[3].HeaderText = "فاميل";
            DGV1.Columns[4].HeaderText = "مبلغ حساب";
            DGV1.Columns[5].HeaderText = "نوع دانشجويي";
            DGV1.Columns[6].HeaderText = "فعال";
            DGV1.Columns[0].Width = 120;
            DGV1.Columns[4].Width = 90;
            DGV1.Columns[5].Width = 120;
            DGV1.Columns[6].Width = 50;
        }
        private void DGV1_DoubleClick(object sender, EventArgs e)
        {
            STDNUM = DGV1.Rows[DGV1.CurrentCell.RowIndex].Cells[0].Value.ToString();
            this.Hide();
        }

        private void SearchStudent_Activated(object sender, EventArgs e)
        {
            R1.Checked = true;
        }
    }
}