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

namespace Dictionery_proj
{
    public partial class frmSearch : Form
    {
       
        public frmSearch()
        {
            InitializeComponent();
        }

        private void UDF_Refresh()
        {
            LSC_DictioneryDataContext db = new LSC_DictioneryDataContext();
            var Query = from Row in db.tblDictioneries
                        orderby Row.DicId descending
                        select new
                        {
                            Row.DicId,
                            Row.DicLoghatEnglish,
                            Row.DicLoghatFarci,
                            Row.DicSynonym
                        };
            Dgv_Search.DataSource = Query;
      }

        private void UDF_SearchETof()
        {
            LSC_DictioneryDataContext db = new LSC_DictioneryDataContext();
            var Query = from Row in db.tblDictioneries
                        where SqlMethods.Like(Row.DicLoghatEnglish, "%" + Txt_Search.Text.Trim() + "%")
                        orderby Row.DicId descending
                        select new
                        {
                            Row.DicId,
                            Row.DicLoghatEnglish,
                            Row.DicLoghatFarci,
                            Row.DicSynonym
                        };
            Dgv_Search.DataSource = Query;
        }

        private void UDF_SearchFToE()
        {
            LSC_DictioneryDataContext db = new LSC_DictioneryDataContext();
            var Query = from Row in db.tblDictioneries
                        where SqlMethods.Like(Row.DicLoghatFarci, "%" + Txt_Search.Text.Trim() + "%")
                        orderby Row.DicId descending
                        select new
                        {
                            Row.DicId,
                            Row.DicLoghatEnglish,
                            Row.DicLoghatFarci,
                            Row.DicSynonym
                        };
            Dgv_Search.DataSource = Query;
        }

        private void UDF_SearchSynonym()
        {
            LSC_DictioneryDataContext db = new LSC_DictioneryDataContext();
            var Query = from Row in db.tblDictioneries
                        where SqlMethods.Like(Row.DicSynonym, "%" + Txt_Search.Text.Trim() + "%")
                        orderby Row.DicId descending
                        select new
                        {
                            Row.DicId,
                            Row.DicLoghatEnglish,
                            Row.DicLoghatFarci,
                            Row.DicSynonym
                        };
            Dgv_Search.DataSource = Query;
        }
        private void frmSearch_Load(object sender, EventArgs e)
        {
           UDF_Refresh();
        }

        private void Btn_Search2_Click(object sender, EventArgs e)
        {
            if (Rdo_EnglishToFarci.Checked == true)
            {
                UDF_SearchETof();
            }
            else if (Rdo_FarciToEnglish.Checked == true)
            {
                UDF_SearchFToE();
            }
            else if (Rdo_Synonym.Checked == true)
            {
                UDF_SearchSynonym();
            }
        }                 
   }
 }
   
