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

namespace WindowsFormsApplication5
{
    public partial class frmmember : Form
    {
        
        public frmmember()
        {
            InitializeComponent();
        }

        private void memberBindingNavigatorSaveItem_Click(object sender, EventArgs e)
        {
            this.Validate();
            this.memberBindingSource.EndEdit();
            this.tableAdapterManager.UpdateAll(this.libraryDataSet);
         
           
        }

        private void frmmember_Load(object sender, EventArgs e)
        {
            if (WindowsFormsApplication5.Properties.Settings.Default.stringeditmember == false)
            {
                memberBindingNavigator.Visible  = false;
                txbsearch.Visible = true ;
                cbxsearch.Visible = true;
                btnsearch.Visible = true;
                lklhelp.Visible = true;

            }
            else {

                memberBindingNavigator.Visible = true ;
                txbsearch.Visible = false ;
                cbxsearch.Visible = false ;
                btnsearch.Visible = false;
                lklhelp.Visible = false;
            
            }
          
            // TODO: This line of code loads data into the 'libraryDataSet.member' table. You can move, or remove it, as needed.
            this.memberTableAdapter.Fill(this.libraryDataSet.member);

        }

        private void toolStripComboBox1_Click(object sender, EventArgs e)
        {
            

            
        }

        private void lklhelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
           
           
            
        }

        private void toolStripCbx_TextChanged(object sender, EventArgs e)
        {
          #region sort
           try
            {
                switch (toolStripCbx.Text)
                {
                    case "code":
                        memberDataGridView.Sort(codedataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "lname":
                        memberDataGridView.Sort(lnamedataGridViewTextBoxColumn , ListSortDirection.Ascending);

                        break;
                    case "barrownumber":
                        memberDataGridView.Sort(barrownumberdataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "fname":
                        memberDataGridView.Sort(fnamedataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "membershipdate":
                        memberDataGridView.Sort(membershipdatedataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "membershipexpire":
                        memberDataGridView.Sort(membershipexpiredataGridViewTextBoxColumn, ListSortDirection.Ascending);
                        break;
                    case "roll":
                        memberDataGridView.Sort(rolldataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "tel":
                        memberDataGridView.Sort(teldataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "address":
                        memberDataGridView.Sort(addressdataGridViewTextBoxColumn, ListSortDirection.Ascending);
                        break;
                    default: memberDataGridView.Refresh();
                        break;

                }




            }
            catch (Exception exep)
            {
                MessageBox.Show(exep.ToString());



            }

            #endregion
   
        }

        private void btnsearch_Click(object sender, EventArgs e)
        {
            #region custom search
            try
            {
                StringBuilder pb = new StringBuilder();
                pb.Append("@");
                pb.Append(cbxsearch.Text);
                String strcom = cbxsearch.Text;
                StringBuilder strb = new StringBuilder();
                strb.Append("SELECT * FROM [member] WHERE ([");
                strb.Append(strcom);
                strb.Append("] like '%'+ @");
                strb.Append(strcom);
                strb.Append("+'%')");
                SqlConnection con = new SqlConnection();
                con.ConnectionString = WindowsFormsApplication5.Properties.Settings.Default.libraryConnectionString.ToString();
                SqlCommand com = new SqlCommand();
                com.Connection =con ;
                com.CommandType = CommandType.Text;
                com.CommandText = strb.ToString();
                String par = txbsearch.Text;
                com.Parameters.AddWithValue(pb.ToString(), par);
                SqlDataAdapter da = new SqlDataAdapter(com);
                DataTable dt = new DataTable();
                da.Fill(dt);

                memberDataGridView.DataSource = dt;
                this.tableAdapterManager.UpdateAll(this.libraryDataSet);

            }
            catch { }

            #endregion

            #region sort
          
            try
            {
                   switch (cbxsearch.Text)
                {
                    case "code":
                        memberDataGridView.Sort(codedataGridViewTextBoxColumn, ListSortDirection.Ascending);
                        break;
                    case "lname":
                        memberDataGridView.Sort(lnamedataGridViewTextBoxColumn , ListSortDirection.Ascending);

                        break;
                    case "barrownumber":
                        memberDataGridView.Sort(barrownumberdataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "fname":
                        memberDataGridView.Sort(fnamedataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "membershipdate":
                        memberDataGridView.Sort(membershipdatedataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "membershipexpire":
                        memberDataGridView.Sort(membershipexpiredataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "roll":
                        memberDataGridView.Sort(rolldataGridViewTextBoxColumn, ListSortDirection.Ascending);
                        break;
                    case "tel":
                        memberDataGridView.Sort(teldataGridViewTextBoxColumn , ListSortDirection.Ascending);
                        break;
                    case "address":
                        memberDataGridView.Sort(addressdataGridViewTextBoxColumn, ListSortDirection.Ascending);
                        break;
                    default: memberDataGridView.Refresh();
                        break;

                }




            }
            catch (Exception exep)
            {
                MessageBox.Show(exep.ToString());



            }
         
            #endregion
        }

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

        private void toolStripguibtn_Click(object sender, EventArgs e)
        {
          

        }

        private void lkldate_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            frmdate fd = new frmdate();
            fd.Show();
        }
    }
}
