/// <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> /// Adds a new row at the bottom of the Excel editing range. /// </summary> /// <param name="clearColoringOfOldNewRow">Flag indicating whether the previous row that was placeholder for new rows is cleared of its formatting.</param> /// <returns>An Excel range containing just the newly added row.</returns> private ExcelInterop.Range AddNewRowToEditingRange(bool clearColoringOfOldNewRow) { EditingWorksheet.UnprotectEditingWorksheet(EditingWorksheet_Change, WorksheetProtectionKey); _editDataRange = _editDataRange.AddNewRow(clearColoringOfOldNewRow, out var newRowRange); EditingWorksheet.ProtectEditingWorksheet(EditingWorksheet_Change, WorksheetProtectionKey, _editDataRange); _editingRowsQuantity = _editDataRange.Rows.Count; return(newRowRange); }
/// <summary> /// Raises the Closing event. /// </summary> /// <param name="e">A <see cref="CancelEventArgs"/> that contains the event data.</param> protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); _parentTaskPane.RefreshDbObjectPanelActionLabelsEnabledStatus(EditingTableName, false); if (EditingWorksheetExists) { UnprotectWorksheet(); EditingWorksheet.UsedRange.Interior.ColorIndex = ExcelInterop.XlColorIndex.xlColorIndexNone; if (!string.IsNullOrEmpty(EditingWorksheet.GetProtectionKey())) { EditingWorksheet.RemoveProtectionKey(); } } WorkbookConnectionInfos.RemoveEditConnectionInfoWithEditDialog(this); Dispose(); }
/// <summary> /// Raises the Closing event. /// </summary> /// <param name="e">A <see cref="CancelEventArgs"/> that contains the event data.</param> protected override void OnClosing(CancelEventArgs e) { base.OnClosing(e); _parentTaskPane.RefreshDbObjectPanelActionLabelsEnabledStatus(EditingTableName, false); if (EditingWorksheetExists) { UnprotectWorksheet(); EditingWorksheet.UsedRange.Interior.ColorIndex = ExcelInterop.XlColorIndex.xlColorIndexNone; if (!string.IsNullOrEmpty(EditingWorksheet.GetProtectionKey())) { EditingWorksheet.RemoveProtectionKey(); } } var connectionInfo = Globals.ThisAddIn.ActiveWorkbookEditConnectionInfos.FirstOrDefault(ac => ac.EditDialog.Equals(this)); if (connectionInfo != null) { Globals.ThisAddIn.ActiveWorkbookEditConnectionInfos.Remove(connectionInfo); } Dispose(); }
/// <summary> /// Unprotects the edit dialog's worksheet. /// </summary> public void UnprotectWorksheet() { EditingWorksheet.UnprotectEditingWorksheet(EditingWorksheet_Change, WorksheetProtectionKey); }
/// <summary> /// Protects the edit dialog's worksheet. /// </summary> public void ProtectWorksheet() { EditingWorksheet.ProtectEditingWorksheet(EditingWorksheet_Change, WorksheetProtectionKey, _editDataRange); }