Ejemplo n.º 1
0
 private void cbox_table_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         BindingSource bs = new BindingSource();
         ObjectThread  data_data_table = new ObjectThread(dgv_data_table);
         if (connect == null)
         {
             Utils.WriteLog("Veillez reselectionner la liaison");
         }
         if (connect.State == System.Data.ConnectionState.Closed)
         {
             connect.Open();
         }
         data_data_table.ClearDataGridView(true);
         if (cbox_table.SelectedItem.Equals("users"))
         {
             //Chargement des utilisateurs de liaison
             bs.DataSource      = employes;
             externe.DataSource = bs;
             new Thread(delegate()
             {
                 Npgsql.NpgsqlCommand cmd     = null;
                 Npgsql.NpgsqlDataReader lect = null;
                 try
                 {
                     string query = "SELECT coderep, CONCAT(nom, ' ', prenom), externe FROM users ORDER BY coderep";
                     cmd          = new Npgsql.NpgsqlCommand(query, connect);
                     lect         = cmd.ExecuteReader();
                     if (lect.HasRows)
                     {
                         int i = 0;
                         while (lect.Read())
                         {
                             var _externe = lect[2];
                             int index    = _externe != null ? employes.FindIndex(x => x.Split(',')[0].Equals(_externe.ToString())) : -1;
                             data_data_table.WriteDataGridView(new object[] { lect[0].ToString(), lect[1].ToString(), null });
                             if (index > -1 ? employes.Count > index ? dgv_data_table.Rows.Count > i : false : false)
                             {
                                 ObjectThread cell = new ObjectThread(dgv_data_table.Rows[i].Cells[2] as DataGridViewComboBoxCell);
                                 cell.ValueComboBoxCell(employes[index]);
                             }
                             i++;
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     Messages.Exception(ex);
                 }
                 finally
                 {
                     if (cmd != null)
                     {
                         cmd.Dispose();
                     }
                     if (lect != null)
                     {
                         lect.Dispose();
                     }
                 }
             }).Start();
         }
         else if (cbox_table.SelectedItem.Equals("tranchehoraire"))
         {
             bs.DataSource = tranches;
             //Chargement des utilisateurs de liaison
             externe.DataSource = bs;
             new Thread(delegate()
             {
                 Npgsql.NpgsqlCommand cmd     = null;
                 Npgsql.NpgsqlDataReader lect = null;
                 try
                 {
                     string query = "SELECT id, CONCAT(typedejrnee, ' ', CONCAT(heure_debut, '-', heure_fin)), externe FROM tranchehoraire ORDER BY typedejrnee, heure_debut";
                     cmd          = new Npgsql.NpgsqlCommand(query, connect);
                     lect         = cmd.ExecuteReader();
                     if (lect.HasRows)
                     {
                         int i = 0;
                         while (lect.Read())
                         {
                             var _externe = lect[2];
                             int index    = _externe != null ? tranches.FindIndex(x => x.Split(',')[0].Equals(_externe.ToString())) : -1;
                             data_data_table.WriteDataGridView(new object[] { lect[0].ToString(), lect[1].ToString(), null });
                             if (index > -1 ? tranches.Count > index ? dgv_data_table.Rows.Count > i : false : false)
                             {
                                 var var = dgv_data_table.Rows[i].Cells[2];
                                 if (var is DataGridViewComboBoxCell)
                                 {
                                     ObjectThread cell = new ObjectThread(var as DataGridViewComboBoxCell);
                                     cell.ValueComboBoxCell(tranches[index]);
                                 }
                             }
                             i++;
                         }
                     }
                 }
                 catch (Exception ex)
                 {
                     Messages.Exception(ex);
                 }
                 finally
                 {
                     if (cmd != null)
                     {
                         cmd.Dispose();
                     }
                     if (lect != null)
                     {
                         lect.Dispose();
                     }
                 }
             }).Start();
         }
     }
     catch (Exception ex)
     {
         Messages.Exception(ex);
     }
 }