public CollectionExplorerTab(string ConnectionString, string DbName, string CollectionName) { InitializeComponent(); this.DbName = DbName; this.ConnectionString = ConnectionString; this.CollectionName = CollectionName; long bytesSize; Collection = MongoGeneralLogic.GetCollection(ConnectionString, DbName, CollectionName, out bytesSize); CmbItemPerPage.SelectedIndex = 0; BindGrid(); LblCollectionName.Text = DbName + "." + CollectionName; float bytesSizeF = bytesSize; if (bytesSizeF < 1000) { LblSize.Text = Math.Round(bytesSizeF, 2) + " Bytes"; } else if (bytesSize < 1000 * 1000) { LblSize.Text = Math.Round(bytesSizeF / 1000, 2) + " KB"; } else if (bytesSize < 1000 * 1000 * 1000) { LblSize.Text = Math.Round(bytesSizeF / 1000000, 2) + " MB"; } }
void Filter() { long bytesSize; Collection = MongoGeneralLogic.GetCollection(ConnectionString, DbName, CollectionName, out bytesSize); if (DDFilterOperator.Text == "==") { Collection = Collection.Where(x => x[TxtFilterCol.Text] != null && x.ContainsKey(TxtFilterCol.Text) && x[TxtFilterCol.Text].ToString().ToLower() == TxtFilterValue.Text.ToLower()).ToList(); } if (DDFilterOperator.Text == "!=") { Collection = Collection.Where(x => x[TxtFilterCol.Text] != null && x.ContainsKey(TxtFilterCol.Text) && x[TxtFilterCol.Text].ToString().ToLower() != TxtFilterValue.Text.ToLower()).ToList(); } if (DDFilterOperator.Text == "Contains") { Collection = Collection.Where(x => x[TxtFilterCol.Text] != null && x.ContainsKey(TxtFilterCol.Text) && x[TxtFilterCol.Text].ToString().ToLower().Contains(TxtFilterValue.Text.ToLower())).ToList(); } if (DDFilterOperator.Text == "! Contains") { Collection = Collection.Where(x => x[TxtFilterCol.Text] != null && x.ContainsKey(TxtFilterCol.Text) && !x[TxtFilterCol.Text].ToString().ToLower().Contains(TxtFilterValue.Text.ToLower())).ToList(); } BindGrid(); }
public FrmCollectionRpt(MDTServer server, string DbName) { InitializeComponent(); label1.Text = server + " - " + DbName; GrvReport.DataSource = MongoGeneralLogic.GetCollectionReport(server, DbName); }
void Migrate() { MigrationOptions.Collections.Clear(); for (int i = 0; i < CollectionChk.Items.Count; i++) { if (CollectionChk.GetItemChecked(i)) { MigrationOptions.Collections.Add(CollectionChk.Items[i].ToString()); } } if (!MigrationOptions.Collections.Any()) { MessageBox.Show("Please Select Collections To Be Migrated"); return; } string log = ""; var exportPath = MongoGeneralLogic.ExportToJson(MigrationOptions.SourceServer.ConnectionString, MigrationOptions.SourceDb, "", MigrationOptions.Collections, true, false, out log, true); MongoGeneralLogic.ImportFromJson(MigrationOptions.DestinationServer, MigrationOptions.DestinationDb, Directory.GetFiles(exportPath).ToList(), true); try { Directory.Delete(exportPath, true); MessageBox.Show("Migration DONE"); } catch { MessageBox.Show("Migration ERROR"); } }
private void Grv_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.ControlKey) { OnControlPressed = true; } if (e.KeyCode == Keys.ShiftKey) { OnShiftPressed = true; } if (e.KeyCode == Keys.Delete) { if (Grv.SelectedRows.Count > 0) { if (MessageBox.Show("Are you sure you want to delete selected row(s)?", "Delete Row(s) Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int counter = 0; int ToBeDeleted = Grv.SelectedRows.Count; foreach (DataGridViewRow item in Grv.SelectedRows) { if (item.Cells["_id"].Value != null && MongoGeneralLogic.DeleteDocument(Server.ConnectionString, DbName, CollectionName, item.Cells["_id"].Value.ToString())) { Grv.Rows.Remove(item); counter++; } } MessageBox.Show(counter + "/" + ToBeDeleted + " Rows Deleted "); } } } }
private void ConnectionTree_BeforeExpand(object sender, TreeViewCancelEventArgs e) { if (!string.IsNullOrEmpty(e.Node.Name) && e.Node.Name.StartsWith("Db_")) { var dbTreeNode = e.Node as DbTreeNode; dbTreeNode.Nodes.Clear(); var DbCollections = MongoGeneralLogic.GetDatabaseCollections(dbTreeNode.ServerConnectionString, dbTreeNode.DbName); foreach (var item in DbCollections) { var collectionTreeNode = new CollectionTreeNode() { Text = item, Name = "Collection_" + item, ImageIndex = 2, SelectedImageIndex = 1, ContextMenuStrip = CollectionContext, DbName = dbTreeNode.DbName, CollectionName = item, Server = dbTreeNode.Server }; dbTreeNode.Nodes.Add(collectionTreeNode); } ConnectionTree.SelectedNode = e.Node; } }
private void BtnReload_Click(object sender, EventArgs e) { long bytesSize; Collection = MongoGeneralLogic.GetCollection(ConnectionString, DbName, CollectionName, out bytesSize); BindGrid(); HiddenColumns.Clear(); }
private void Grv_CellValueChanged(object sender, DataGridViewCellEventArgs e) { var id = Grv.Rows[e.RowIndex].Cells[0].Value.ToString(); var item = Collection.FirstOrDefault(x => (x as Dictionary <string, object>)["_id"] == id); item[Grv.Columns[e.ColumnIndex].Name] = Grv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value; MongoGeneralLogic.UpdateCollection(id, item, ConnectionString, DbName, CollectionName); }
private void Main_Load(object sender, EventArgs e) { if (Session.Settings.StartLocalServiceWithStartUp) { MongoGeneralLogic.StartLocalHost(Session.Settings.MongoInstallationPath, Session.Settings.LocalHostDataFilesPath); } //NewConnection(); NewConnection(Session.Settings.Servers.FirstOrDefault()); }
private void BtnExport_Click(object sender, EventArgs e) { string log = ""; var Collections = new List<string>(); for (int i = 0; i < CollectionChk.Items.Count; i++) { if (CollectionChk.GetItemChecked(i)) { Collections.Add(CollectionChk.Items[i].ToString()); } } //TODO Check Save Path if (RdJson.Checked) { if (!string.IsNullOrEmpty(txtSavePath.Text)) { MongoGeneralLogic.ExportToJson(server.ConnectionString, DbName, txtSavePath.Text, Collections, ChkFormatJson.Checked, ChkArray.Checked, out log); log = string.IsNullOrEmpty(log) ? "Done" : ""; MessageBox.Show(log); Close(); } } else if (RdAnotherDb.Checked) { var exportTodbFrm = new ExportToDbFrm(server.ConnectionString, DbName, Collections); if (exportTodbFrm.ShowDialog() == DialogResult.OK) { log = string.IsNullOrEmpty(log) ? "Done" : ""; MessageBox.Show(log); Close(); } else { MessageBox.Show("Please Select Save Location"); } } else if (RdBackUpFile.Checked) { if (!string.IsNullOrEmpty(TxtMdtFilePath.Text)) { MongoGeneralLogic.ExportToDump(server, DbName, TxtMdtFilePath.Text, Collections, out log); log = string.IsNullOrEmpty(log) ? "Done" : ""; MessageBox.Show(log); Close(); } else { MessageBox.Show("Please Select Save Path"); } } }
private void BtnExport_Click(object sender, EventArgs e) { string DbName = ""; if (!ChkCreateDatabase.Checked) { if (ConnectionTree.SelectedNode == null) { MessageBox.Show("Please Select a db Or Choose To Create New"); return; } else { DbName = (ConnectionTree.SelectedNode as DbTreeNode).DbName; } } else { if (string.IsNullOrEmpty(TxtNewDbName.Text)) { MessageBox.Show("Please Enter Db Name"); return; } else { DbName = TxtNewDbName.Text; } } Main mainfrm = null; for (int i = 0; i < Application.OpenForms.Count; i++) { if (Application.OpenForms[i] is Main) { mainfrm = Application.OpenForms[i] as Main; } } string log = ""; MongoGeneralLogic.ExportToDb(Sourceconnectionstring, SourceDbName, SelectedCollection, TargetConnection, DbName, out log); mainfrm.RunAsyncTask((x, ee) => { }, (x, ee) => { MessageBox.Show("Export Done"); } ); DialogResult = DialogResult.OK; Close(); }
void BindGrid() { ItemsPerPage = int.Parse(CmbItemPerPage.Text); var dt = MongoGeneralLogic.ConvertToDataTable(Collection.Skip(CurrentPage * ItemsPerPage).Take(ItemsPerPage).ToList()); TotalPages = (int)Math.Ceiling(Collection.Count / (double)ItemsPerPage); lblPages.Text = string.Format("{0} / {1}", CurrentPage + 1, TotalPages); LblCount.Text = Collection.Count.ToString(); Grv.DataSource = dt; foreach (var col in HiddenColumns) { if (Grv.Columns[col] != null) { Grv.Columns.Remove(Grv.Columns[col]); } } }
private void BtnSave_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(TxtName.Text)) { try { MongoGeneralLogic.CreateDataBase(ServerConnectionString, TxtName.Text); DialogResult = DialogResult.OK; } catch (Exception ex) { MessageBox.Show(ex.Message); } } else { MessageBox.Show("please Enter Db Name"); } }
void GetCollectionFromSource() { if (MigrationOptions.SourceServer != null) { var collections = MongoGeneralLogic.GetDatabaseCollections(MigrationOptions.SourceServer.ConnectionString, MigrationOptions.SourceDb); foreach (var item in collections) { bool ChekItem = !MigrationOptions.Collections.Any() || MigrationOptions.Collections.Contains(item); if (MigrationOptions.Collections.Any()) { CollectionChk.Items.Add(item, ChekItem); } else { CollectionChk.Items.Add(item, true); } } } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { ConnectionsGrid.Enabled = BtnConnect.Enabled = false; int ConnectionIndex = ConnectionsGrid.Rows.IndexOf(ConnectionsGrid.SelectedRows[0]); var server = Session.Settings.Servers[ConnectionIndex]; if (MongoGeneralLogic.TryToConnectToServer(server)) { Session.CurrentConnections.Add(server); DialogResult = DialogResult.OK; Close(); } else { LoadingImg.Visible = false; ConnectionsGrid.Enabled = BtnConnect.Enabled = true; MessageBox.Show("Failed To Connect To Server"); } }
private void BtnDropDatabase_Click(object sender, EventArgs e) { var dbTreeNode = ConnectionTree.SelectedNode as DbTreeNode; if (dbTreeNode != null) { if (MessageBox.Show("Are you sure you want to delete This Database?", "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { MongoGeneralLogic.DropDataBase(dbTreeNode.ServerConnectionString, dbTreeNode.DbName); dbTreeNode.Parent.Nodes.Remove(dbTreeNode); } catch (Exception ex) { MessageBox.Show("Failed To Drop Database.\n" + ex.Message); } } } }
public ExportFrm(MDTServer server, string DbName, List<string> Collection) { InitializeComponent(); this.server = server; this.DbName = DbName; this.Text += " - " + DbName; var collections = MongoGeneralLogic.GetDatabaseCollections(server.ConnectionString, DbName); foreach (var item in collections) { bool ChekItem = !Collection.Any() || Collection.Contains(item); if (Collection.Any()) { CollectionChk.Items.Add(item, ChekItem); } else { CollectionChk.Items.Add(item, true); } } ChkAll.Checked = !Collection.Any(); }
private void BtnDeleteCollection_Click(object sender, EventArgs e) { var CollectionNode = ConnectionTree.SelectedNode as CollectionTreeNode; string Message = string.Format("Are You Sure You want to delete '{0}' Collection", CollectionNode.CollectionName); if (MessageBox.Show(this, Message, "Delete Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { MongoGeneralLogic.DropCollection(CollectionNode.Server.ConnectionString, CollectionNode.DbName, CollectionNode.CollectionName); var parent = CollectionNode.Parent; parent.Collapse(); parent.Expand(); //Close All Open Tabs OF Collection Explorer foreach (TabPage ParentTab in CollectionExplorer.TabPages) { CollectionExplorerTab tab = ParentTab.Controls[0] as CollectionExplorerTab; if (tab.Server == CollectionNode.Server && tab.CollectionName == CollectionNode.CollectionName && tab.DbName == CollectionNode.DbName) { CollectionExplorer.TabPages.Remove(tab.Parent as TabPage); } } } }
void NewConnection(MDTServer server = null) { var c = new ConnectionsFrm(); if (server != null || c.ShowDialog() == DialogResult.OK) { var CurrentConnection = server ?? Session.CurrentConnections.Last(); var ConnectionDb = MongoGeneralLogic.GetServerDataBases(CurrentConnection); string ConnectionName = !string.IsNullOrEmpty(CurrentConnection.ConnectionAlias) ? CurrentConnection.ConnectionAlias : CurrentConnection.Server; ServerTreeNode connectionNode = new ServerTreeNode() { Text = ConnectionName, ImageIndex = 0, ServerConnectionString = CurrentConnection.ConnectionString, Server = CurrentConnection, ContextMenuStrip = ServerContextMenu, }; foreach (var db in ConnectionDb) { var dbTreeNode = new DbTreeNode() { Text = db, Name = "Db_" + db, ImageIndex = 1, ContextMenuStrip = DbContextMenu, DbName = db, Server = CurrentConnection, ServerConnectionString = CurrentConnection.ConnectionString }; dbTreeNode.Nodes.Add(""); connectionNode.Nodes.Add(dbTreeNode); } ConnectionTree.Nodes.Add(connectionNode); connectionNode.Expand(); } }
private void ConnectionsGrid_SelectionChanged(object sender, EventArgs e) { ConnectionTree.Nodes.Clear(); if (ConnectionsGrid.SelectedRows.Count > 0) { int SelectedIndex = ConnectionsGrid.Rows.IndexOf(ConnectionsGrid.SelectedRows[0]); var CurrentConnection = Session.Settings.Servers[SelectedIndex]; var ConnectionDb = MongoGeneralLogic.GetServerDataBases(CurrentConnection); string ConnectionName = !string.IsNullOrEmpty(CurrentConnection.ConnectionAlias) ? CurrentConnection.ConnectionAlias : CurrentConnection.Server; TargetConnection = CurrentConnection.ConnectionString; foreach (var db in ConnectionDb) { var dbTreeNode = new DbTreeNode() { Text = db, Name = "Db_" + db, //ImageIndex = 1, DbName = db, ServerConnectionString = CurrentConnection.ConnectionString }; ConnectionTree.Nodes.Add(dbTreeNode); } } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { MongoGeneralLogic.ImportFromJson(server, TxtDbName.Text, SelectedFiles, ChkDropIfExist.Checked); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { MongoGeneralLogic.ImportFromDump(server, TxtDbName.Text, TxtPath.Text, ChkDropIfExist.Checked); }
private void BtnLocalHostRestart_Click(object sender, EventArgs e) { MongoGeneralLogic.RestatLocalHost(Session.Settings.MongoInstallationPath, Session.Settings.LocalHostDataFilesPath); }
private void BtnLocalHostStop_Click(object sender, EventArgs e) { MongoGeneralLogic.StopLocalHost(); }