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

namespace DabirKhane
{
    public partial class search : Form
    {
        public static  Int32 ComboSelect ;
        public string s1;
        public search()
        {
            InitializeComponent();
        }

        private void search_Load(object sender, EventArgs e)
        {
           
           switch (Variables.tab)
           {
               case "j1":
                   {
                       comboBox1.Text = "ارسالي";
                       Payegah.ShowData(Variables.masir, Variables.StrCommandErsali, 7, GridViwe);
                       break;
                   }
               case "j2":
                   {
                       comboBox1.Text = "دريافتي";
                       Payegah.ShowData(Variables.masir, Variables.StrCommandDaryafti , 7, GridViwe);
                       break;
                   }
           }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            string fild = "shandikatori";
           
            
            switch (comboBox2.Text)
            {
                case "شماره انديكاتوري":
                    {
                        fild = "shandikatori";
                        break;
                    }
                case "شماره نامه":
                    {
                        fild = "shvarede";
                        break;
                    }
                case "تاریخ نامه":
                    {
                        fild = "tarikh";
                        break;
                    }
                case "شهرت و نام":
                    {
                        fild = "shohrat";
                        break;
                    }
                case "گروه موضوعی":
                    {
                        fild = "gmozohi";
                        break;
                    }

            }
           
                if (ComboSelect == 0)
                    {
                if (Option1.Checked == true)
                {
                    s1 = "select * from ersali where " + fild + " like'" + textBox1.Text + "%'";
                }
                else 
                {
                    s1 = "select * from ersali where (" + fild + " like'%" + textBox1.Text + "%')";
                    
                }
                    }
                if (ComboSelect== 1)
                    {
               if (Option1.Checked == true)
                {
                    s1 = "select * from daryafti where " + fild + " like'" + textBox1.Text + "%'";
                }
                else 
                {
                    s1 = "select * from daryafti where (" + fild + " like'%" + textBox1.Text + "%')";
                    
                }
                    }
                if (ComboSelect == 2)
                    {
                        if (Option1.Checked == true)
                        {
                            s1 = "select * from bazyabiersali where " + fild + " like'" + textBox1.Text + "%'";
                        }
                        else
                        {
                            s1 = "select * from bazyabiersali where (" + fild + " like'%" + textBox1.Text + "%')";
                        }
                    }
                if(ComboSelect== 3)
                    {
                        if (Option1.Checked == true)
                        {
                            s1 = "select * from bazyabidaryafti where " + fild + " like'" + textBox1.Text + "%'";
                        }
                        else
                        {
                            s1 = "select * from bazyabidaryafti where (" + fild + " like'%" + textBox1.Text + "%')";
                        }
                    }
        

            
            Payegah.Jostejo(Variables.masir , s1, 7, GridViwe);
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch  (comboBox1.Text)
            {
                case "ارسالی":
                    {
                        Payegah.ShowData(Variables.masir, Variables.StrCommandErsali, 7, GridViwe);
                        ComboSelect = 0;
                        this.Text = "جستجوي نامه هاي ارسالي";
                        break;
                    }
                case "دریافتی":
                    {
                        Payegah.ShowData(Variables.masir, Variables.StrCommandDaryafti, 7, GridViwe);
                        ComboSelect = 1;
                        this.Text = "جستجوي نامه هاي دريافتي";
                        break;
                    }
                case "اصلاح شده ارسالي":
                    {
                        Payegah.ShowData(Variables.masir, Variables.StrCommandBazyabiErsali, 7, GridViwe);
                        ComboSelect = 2;
                        this.Text = "جستجوي نامه هاي اصلاحي ارسالي";
                        break;
                    }
                case "اصلاح شده دريافتي":
                    {
                        Payegah.ShowData(Variables.masir, Variables.StrCommandBazyabiDaryafti , 7, GridViwe);
                        ComboSelect = 3;
                        this.Text = "جستجوي نامه هاي اصلاحي دريافتي";
                        break;
                    }
            }
            
           
        }

        private void comboBox1_Click(object sender, EventArgs e)
        {
            
        }

        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}