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; using GestionDeCommerceInfoClasseBDDNCouches; using GestionDeCommerceInfoClasseBDDNCouches.DataLayer; namespace Gestion_de_commerce_Informatique { public partial class GestionUtilisateurs : UserControl { public DataGridView DgvUser { get { return dgvUser; } set { this.dgvUser = value; } } private DataTable dtPersonne; private BindingSource bsPersonne; BDDAccesUtilisateur bddUser = new BDDAccesUtilisateur(Settings1.Default.ChaineDeConnection); public GestionUtilisateurs() { InitializeComponent(); bsPersonne = new BindingSource(); this.BackColor = Color.Transparent; RemplirDVG(dgvUser); } private void dgvUser_CellContentClick(object sender, EventArgs e) { object sendser = sender; Console.WriteLine(); } 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 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; dgv.Columns["userId"].Visible = false; } public void RemplirDVG() { bsPersonne = new BindingSource(); RemplirDVG(dgvUser); } 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) { if (dgvUser.SelectedRows.Count > 0) { //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}"; } } private void txtBoxRecherche_OnTextChange_1(object sender, EventArgs e) { } private void txtBoxRecherche_Click(object sender, MouseEventArgs e) { if (txtBoxRecherche.text == "Recherche") txtBoxRecherche.text = ""; } } }