GestionDeDommerceInformatique/Gestion de commerce Informa.../GestionUtilisateurs.cs

112 lines
3.6 KiB
C#
Raw Normal View History

2018-06-05 12:59:35 +02:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
2018-06-05 17:20:36 +02:00
using GestionDeCommerceInfoClasseBDDNCouches;
using GestionDeCommerceInfoClasseBDDNCouches.DataLayer;
2018-06-05 12:59:35 +02:00
namespace Gestion_de_commerce_Informatique
{
public partial class GestionUtilisateurs : UserControl
{
public DataGridView DgvUser
{
get
{
return dgvUser;
}
set
{
this.dgvUser = value;
}
}
2018-06-05 17:20:36 +02:00
private DataTable dtPersonne;
private BindingSource bsPersonne;
2018-06-07 12:34:14 +02:00
BDDAccesUtilisateur bddUser = new BDDAccesUtilisateur(Settings1.Default.ChaineDeConnection);
2018-06-05 12:59:35 +02:00
public GestionUtilisateurs()
{
InitializeComponent();
2018-06-05 17:20:36 +02:00
bsPersonne = new BindingSource();
2018-06-05 12:59:35 +02:00
this.BackColor = Color.Transparent;
2018-06-05 17:20:36 +02:00
RemplirDVG(dgvUser);
2018-06-05 12:59:35 +02:00
}
private void dgvUser_CellContentClick(object sender, EventArgs e)
{
object sendser = sender;
Console.WriteLine();
}
2018-06-05 17:20:36 +02:00
private void lblAddUser_Click(object sender, EventArgs e)
{
ConfigurationUtilisateur ajoutUtilisateur = new ConfigurationUtilisateur(bddUser);
ajoutUtilisateur.ShowDialog();
dtPersonne.Rows.Add(ajoutUtilisateur.user.ID, $"{ajoutUtilisateur.user.Prenom} {ajoutUtilisateur.user.Nom}");
}
private void txtBoxRecherche_Click(object sender, EventArgs e)
{
if (txtBoxRecherche.text == "Recherche")
txtBoxRecherche.text = "";
}
private void RemplirDVG(DataGridView dgv)
{
dtPersonne = new DataTable();
dtPersonne.Columns.Add(new DataColumn("userId", System.Type.GetType("System.Int32")));
dtPersonne.Columns.Add("Nom");
List<Utilisateur> lusers;
lusers = bddUser.ListUtilisateurs(Utilisateur.Tri_E.NONE);
foreach (Utilisateur Tmp in lusers)
dtPersonne.Rows.Add(Tmp.ID, $"{Tmp.Prenom} {Tmp.Nom}");
bsPersonne.DataSource = dtPersonne;
dgv.DataSource = bsPersonne;
2018-06-07 12:34:14 +02:00
dgv.Columns["userId"].Visible = false;
2018-06-05 17:20:36 +02:00
}
2018-06-07 12:34:14 +02:00
public void RemplirDVG()
{
bsPersonne = new BindingSource();
RemplirDVG(dgvUser);
}
2018-06-05 17:20:36 +02:00
private void txtBoxRecherche_KeyUp(object sender, EventArgs e)
{
string rowFilter = string.Format("[{0}] LIKE '%{1}%'", "Nom", txtBoxRecherche.text);//https://10tec.com/articles/datagridview-filter.aspx
dtPersonne.DefaultView.RowFilter = rowFilter;
}
private void dgvUser_CellContentClick_1(object sender, EventArgs e)
{
2018-06-05 17:30:54 +02:00
if (dgvUser.SelectedRows.Count > 0)
{
2018-06-05 17:20:36 +02:00
2018-06-05 17:30:54 +02:00
//tbId.Text = dgvPersonne.SelectedRows[0].Cells["ID"].Value.ToString();
ConfigurationUtilisateur win = new ConfigurationUtilisateur(bddUser.LireUtilisateur(int.Parse(dgvUser.SelectedRows[0].Cells["userId"].Value.ToString())), bddUser);
win.ShowDialog();
dgvUser.SelectedRows[0].Cells["Nom"].Value = $"{win.user.Prenom} {win.user.Nom}";
}
2018-06-05 17:20:36 +02:00
}
2018-06-07 12:34:14 +02:00
private void txtBoxRecherche_OnTextChange_1(object sender, EventArgs e)
{
}
private void txtBoxRecherche_Click(object sender, MouseEventArgs e)
{
if (txtBoxRecherche.text == "Recherche")
txtBoxRecherche.text = "";
}
2018-06-05 12:59:35 +02:00
}
}