public List <string> FindDocs(ExcelWorksheet newWorksheet) { var database = MongoDBData.GetDatabase(client); var collection = database.GetCollection <BsonDocument>(ColNameUnload); //var filter = Builders<BsonDocument>.Filter.Eq("Имя файла", ""); var projection = Builders <BsonDocument> .Projection.Exclude("_id"); List <string> DocsList = new List <string>(); var docs = collection.Find(new BsonDocument()).Project(projection).ToList(); int row = 2; foreach (BsonDocument doc in docs) { int FieldOffset = 1; for (int col = 0; col < doc.Count(); col++) { newWorksheet.Cells[row, col + FieldOffset].Value = doc[col]; newWorksheet.Cells[row, col + FieldOffset].Style.HorizontalAlignment = ExcelHorizontalAlignment.Left; newWorksheet.Cells[row, col + FieldOffset].Style.Border.BorderAround(ExcelBorderStyle.Thin); } row += 1; } return(DocsList); }
public BsonDocument InsertOneDoc(List <string> list) { //Get collection IMongoCollection <BsonDocument> collection = MongoDBData.GetDatabase(client).GetCollection <BsonDocument>(ColName); var document = new BsonDocument { { "Дата изменения", list[0] }, { "Время изменения", list[1] }, { "Шифр объекта", list[5] }, { "Номер объекта на ситуационном плане", list[6] }, { "Исполнитель", list[7] }, { "Проект", list[8] }, { "Объект", list[9] }, { "Стадия", list[10] }, { "Раздел", list[11] }, { "Имя файла", list[4] }, { "Размер файла", list[2] }, { "Ссылка на файл", list[3] } }; collection.InsertOne(document); return(document); }
public void SortPeople(MongoClient client) { if (ColName != null) { //Get collection IMongoCollection <BsonDocument> collection = MongoDBData.GetDatabase(client).GetCollection <BsonDocument>(ColName); collection.Find(new BsonDocument()).Sort("{Объект:1}").ToListAsync(); } else { MessageBox.Show("Sorry:( \nNo files have been found by your request."); } }
public void CheckCollectionsNames() //Get all collections names from all DBs { using var collCursor = MongoDBData.GetDatabase(client).ListCollectionNames(); List <string> colls = collCursor.ToList(); foreach (string col in colls) { if (col == ColName) { string Mestext = "Default collection name '" + col + "' alredy exists. Do you like to replace it ?"; DialogResult dialogResult = MessageBox.Show(Mestext, "Warning message", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { MongoDBData.GetDatabase(client).DropCollection(ColName); } else if (dialogResult == DialogResult.No) { Form_NewColName form_NewColName = new Form_NewColName { TopLevel = true }; form_NewColName.ShowDialog(); ColName = form_NewColName.textBox_NewColName.Text; if (ColName == "") { Environment.Exit(1); } } } } }