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;

namespace hukpiWinApp.Forms.Admin
{
    public partial class UserListForm : BaseForm
    {
        public UserListForm()
        {
            InitializeComponent();
            fillComboUserGroups(true);
        }

        private void fillComboUserGroups(bool justActives)
        {
            comboBoxGroup.DataSource = Utils.getUserGroupsForCombo(Properties.Settings.Default.ComboBoxAll ,justActives);
            comboBoxGroup.DisplayMember = "Description";
            comboBoxGroup.ValueMember = "Id";
        }

        public override void refreshData()
        {
            buttonSearchStart_Click(null, null);
        }

        private void UserListForm_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'hukpiDatabaseDataSet.UsersView' table. You can move, or remove it, as needed.
            this.usersViewTableAdapter.Fill(this.hukpiDatabaseDataSet.UsersView);

        }

        private void buttonSearchStart_Click(object sender, EventArgs e)
        {
            string userNameCriteria = "%" + textBoxSearchUserName.Text + "%";
            string fullNameCriteria = "%" + textBoxSearchFullName.Text + "%";
            
            if (radioButtonJustActive.Checked)
            {
                this.usersViewTableAdapter.FillBySearchActives(this.hukpiDatabaseDataSet.UsersView, Convert.ToDecimal(comboBoxGroup.SelectedValue), userNameCriteria, fullNameCriteria);
            }
            else if (radioButtonAll.Checked)
            {
                this.usersViewTableAdapter.FillBySearchAll(this.hukpiDatabaseDataSet.UsersView, Convert.ToDecimal(comboBoxGroup.SelectedValue), userNameCriteria, fullNameCriteria);
            }
            else
            {
                MessageBox.Show("Legalább egy rádió gombot válasszon ki!");
            }
        }

        private void dataGridViewSearchResult_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            Forms.Admin.EditUserForm editUserForm = new Forms.Admin.EditUserForm(Convert.ToDecimal(dataGridViewSearchResult.SelectedRows[0].Cells[0].Value));
            ((MainForm)this.MdiParent).openNewMDIChildForm(editUserForm);
        }
    }
}
