public static List <LecteurResult> TrouverLecteursParGroupe(InfoLecteur ilParent) { List <LecteurResult> result = new List <LecteurResult>(); var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); foreach (InfoLecteur il in db.GetCollection <InfoLecteur>("InfoLecteur").Find(a => a.lecteurId == ilParent.lecteurId).ToList()) { if (!il.deleted) { LecteurResult lr = new LecteurResult() { infoLecteur = il, lecteur = db.GetCollection <Lecteur>("Lecteur").Find(a => a._id == il.lecteurId).FirstOrDefault() }; result.Add(lr); } } result.Sort((a, b) => { if (a.infoLecteur.nom.ToLower() != b.infoLecteur.nom.ToLower()) { return(a.infoLecteur.nom.ToLower().CompareTo(b.infoLecteur.nom.ToLower())); } else { return(a.infoLecteur.prénom.ToLower().CompareTo(b.infoLecteur.prénom.ToLower())); } }); return(result); }
private void supprimerToolStripMenuItem_Click(object sender, EventArgs e) { int total = 0; int users = 0; BsonArray ids = new BsonArray(); foreach (DataGridViewCell cell in infoLecteurDataGridView.SelectedCells) { InfoLecteur il = infoLecteurDataGridView.Rows[cell.RowIndex].DataBoundItem as InfoLecteur; if (il != null) { total += il.nombreDemprunts; ids.Add(il._id); } users++; } if (total > 0) { MessageBox.Show(toolTip1.GetToolTip(label1)); } else { if (MessageBox.Show(($"Confirmez-vous la suppression de {users} membre") + (users > 1 ? "s." : "." + "\r\nC'est irréverssible."), "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); db.GetCollection <InfoLecteur>("InfoLecteur").UpdateMany( Builders <InfoLecteur> .Filter.In("_id", ids), Builders <InfoLecteur> .Update.Set(a => a.lecteurId, ObjectId.Empty).CurrentDate(a => a.dateSuppression).Set(a => a.deleted, true) ); RefreshLecteursList(); } } }
private void btnDelete_Click(object sender, EventArgs e) { int total = 0; int users = 0; BsonArray ids = new BsonArray(); foreach (DataGridViewRow row in infoLecteurDataGridView.Rows) { InfoLecteur il = row.DataBoundItem as InfoLecteur; if (il != null) { total += il.nombreDemprunts; ids.Add(il._id); } users++; } if (total > 0) { MessageBox.Show(toolTip1.GetToolTip(label1)); } else { if (MessageBox.Show("Confirmez-vous la suppression du groupe?\r\nC'est action est irréverssible.", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); db.GetCollection <InfoLecteur>("InfoLecteur").UpdateMany( Builders <InfoLecteur> .Filter.In("_id", ids), Builders <InfoLecteur> .Update.Set(a => a.lecteurId, ObjectId.Empty).CurrentDate(a => a.dateSuppression).Set(a => a.deleted, true) ); db.GetCollection <Lecteur>("Lecteur").UpdateOne( a => a._id == m_lr.lecteur._id, Builders <Lecteur> .Update.CurrentDate(a => a.dateSuppression).Set(a => a.deleted, true) ); Close(); } } }
public static void Importer() { var lines = Csv.CsvReader.ReadFromStream(new System.IO.StreamReader(@"I:\Dropbox\Public\Mediathèque2000\Cocteau\biblio.csv", Encoding.UTF8).BaseStream); var collNotice = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio").GetCollection <Notice>("Notice"); foreach (var line in lines) { string isbn = ""; try { isbn = line["ISBN"]; } catch { try { isbn = line["ISSN"]; } catch { } } Notice notice = new Notice() { titre = line["Titre"], auteur = line["Auteur"], éditeur = line["Editeur"], année = line["Annee d'edition"], dateAchat = line["Date d'achat"], collection = line["Collection"], isbn = isbn, @public = line["Public"], exemplaires = new List <Exemplaire>() { new Exemplaire() { _id = MongoDB.Bson.ObjectId.GenerateNewId(), localisation = Properties.Settings.Default.Localisation, codeBarre = isbn } } }; collNotice.InsertOne(notice); } lines = Csv.CsvReader.ReadFromStream(new System.IO.StreamReader(@"I:\Dropbox\Public\Mediathèque2000\Cocteau\adhérents.csv", Encoding.UTF8).BaseStream); var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); Dictionary <string, List <InfoLecteur> > tmp = new Dictionary <string, List <InfoLecteur> >(); Dictionary <string, Lecteur> lecteurs = new Dictionary <string, Lecteur>(); foreach (var line in lines) { string Codefamille = line["Codefamille"]; if (Codefamille.StartsWith("Calmette")) { if (!lecteurs.ContainsKey(Codefamille)) { lecteurs[Codefamille] = new Lecteur() { titre = line["Codefamille"], adresse = line["No"] + " " + line["Rue"], codePostal = line["Code"], ville = line["Ville"], téléphone = line["Tel Pers"], mail = line["Email"], débutAdhésion = DateTime.Now, finAdhésion = DateTime.Now.AddYears(1), localisation = Properties.Settings.Default.Localisation } } ; if (!tmp.ContainsKey(Codefamille)) { tmp[Codefamille] = new List <InfoLecteur>(); } tmp[Codefamille].Add( new InfoLecteur() { nom = line["Nom"], prénom = line["Prenom"], localisation = Properties.Settings.Default.Localisation } ); } else { Lecteur lecteur = new Lecteur() { titre = line["Codefamille"], adresse = line["No"] + " " + line["Rue"], codePostal = line["Code"], ville = line["Ville"], téléphone = line["Tel Pers"], mail = line["Email"], débutAdhésion = DateTime.Now, finAdhésion = DateTime.Now.AddYears(1), localisation = Properties.Settings.Default.Localisation }; db.GetCollection <Lecteur>("Lecteur").InsertOne(lecteur); InfoLecteur infoLecteur = new InfoLecteur() { lecteurId = lecteur._id, nom = line["Nom"], prénom = line["Prenom"], localisation = Properties.Settings.Default.Localisation }; db.GetCollection <InfoLecteur>("InfoLecteur").InsertOne(infoLecteur); } } foreach (var key in lecteurs) { db.GetCollection <Lecteur>("Lecteur").InsertOne(key.Value); foreach (InfoLecteur il in tmp[key.Key]) { il.lecteurId = key.Value._id; db.GetCollection <InfoLecteur>("InfoLecteur").InsertOne(il); } } } }
private void btnImport_Click(object sender, EventArgs e) { using (frmImport import = new frmImport()) { var tmp = import.ShowDialog(); switch (tmp) { case DialogResult.OK: if (import.m_append != null) { foreach (var item in import.m_append) { infoLecteurBindingSource.Add(new InfoLecteur() { _id = ObjectId.GenerateNewId(), nom = item.Item1, prénom = item.Item2 }); } } break; case DialogResult.Yes: if (import.m_replace != null) { int total = 0; int users = 0; BsonArray ids = new BsonArray(); foreach (DataGridViewRow row in infoLecteurDataGridView.Rows) { InfoLecteur il = row.DataBoundItem as InfoLecteur; if (il != null) { total += il.nombreDemprunts; ids.Add(il._id); } users++; } if (total > 0) { MessageBox.Show(toolTip1.GetToolTip(label1)); } else { var db = new MongoDB.Driver.MongoClient(Properties.Settings.Default.MongoDB).GetDatabase("wfBiblio"); db.GetCollection <InfoLecteur>("InfoLecteur").UpdateMany( Builders <InfoLecteur> .Filter.In("_id", ids), Builders <InfoLecteur> .Update.Set(a => a.lecteurId, ObjectId.Empty).CurrentDate(a => a.dateSuppression).Set(a => a.deleted, true) ); infoLecteurBindingSource.Clear(); foreach (var item in import.m_replace) { infoLecteurBindingSource.Add(new InfoLecteur() { _id = ObjectId.GenerateNewId(), nom = item.Item1, prénom = item.Item2 }); } } } break; } } }