/// <summary> /// Reverts the changes done to Excel cell values after the last commit. /// </summary> /// <param name="refreshFromDb">Flag indicating if instead of reverting the data back to the way it was when the editing session started, it is pulled to have the most recent version of it.</param> private void RevertDataChanges(bool refreshFromDb) { try { if (!refreshFromDb) { _mySqlTable.RejectChanges(); } else { _mySqlTable.RefreshData(); } } catch (Exception ex) { MiscUtilities.ShowCustomizedErrorDialog(Resources.EditDataRefreshErrorText, ex.Message); } Globals.ThisAddIn.SkipSelectedDataContentsDetection = true; EditingWorksheet.UnprotectEditingWorksheet(EditingWorksheet_Change, WorksheetProtectionKey); _editDataRange.Clear(); ExcelInterop.Range topLeftCell = _editDataRange.Cells[1, 1]; topLeftCell.Select(); _editDataRange = _mySqlTable.ImportDataIntoExcelRange(topLeftCell); CommitChangesButton.Enabled = false; AddNewRowToEditingRange(false); }
/// <summary> /// Creates the <see cref="EditConnectionInfo"/> or restores the saved one. /// </summary> /// <param name="mySqlTable">The <see cref="MySqlDataTable"/> used for the Edit Data session.</param> /// <param name="currentWorksheet">The current worksheet.</param> /// <returns>A new or restored <see cref="EditConnectionInfo"/> object.</returns> private EditConnectionInfo GetEditConnectionInfo(MySqlDataTable mySqlTable, ExcelInterop.Worksheet currentWorksheet) { if (mySqlTable == null || currentWorksheet == null) { return(null); } var atCell = currentWorksheet.Range["A1", Type.Missing]; var editingRange = mySqlTable.ImportDataIntoExcelRange(atCell); EditConnectionInfo connectionInfo = null; var workbookEditConnectionInfos = WorkbookConnectionInfos.GetWorkbookEditConnectionInfos(Globals.ThisAddIn.ActiveWorkbook); if (workbookEditConnectionInfos.Count > 0) { connectionInfo = workbookEditConnectionInfos.GetActiveEditConnectionInfo(mySqlTable.TableName); } // The EditConnectionInfo is new and has to be created from scratch. if (connectionInfo == null) { var activeWorkbook = Globals.ThisAddIn.ActiveWorkbook; connectionInfo = new EditConnectionInfo(activeWorkbook.GetOrCreateId(), activeWorkbook.FullName, WbConnection.Id, WbConnection.Schema, mySqlTable.TableName); } if (connectionInfo.EditDialog != null) { return(connectionInfo); } // The EditConnectionInfo is being either restored from the settings file or created for the newborn object. connectionInfo.EditDialog = new EditDataDialog(this, new NativeWindowWrapper(Globals.ThisAddIn.Application.Hwnd), WbConnection, editingRange, mySqlTable, currentWorksheet); currentWorksheet.StoreProtectionKey(connectionInfo.EditDialog.WorksheetProtectionKey); return(connectionInfo); }