/// <summary> /// 在不存在key的时候将缓存追加到缓存工厂中 /// </summary> /// <param name="cacheFactory">缓存工厂</param> /// <param name="type">缓存类型</param> /// <param name="adjustSize">调整大小</param> /// <param name="editMode">修改内容</param> /// <param name="gridView">DataGridView</param> private static void addCacheNotKey(Dictionary <string, List <DataViewCacheModel> > cacheFactory, DataCacheTypeEnum type , AdjustSizeMode adjustSize, EditMode editMode, DataGridView gridView) { try { List <DataViewCacheModel> listCacheM = null; List <AdjustSizeMode> listSize = null; List <EditMode> listEditM = null; List <SelectCellMode> listSeletM = null; SelectCellMode selectMode = null; DataViewCacheModel model = null; string key = gridView.Name; // 初始化缓存实体类 model = new DataViewCacheModel(); // 类型 model.Type = type; // 总行与总列 model.ColumnCount = gridView.ColumnCount; model.RowsCount = gridView.RowCount; // 选中单元格 listSeletM = new List <SelectCellMode>(); foreach (DataGridViewCell selcell in gridView.SelectedCells) { selectMode = new SelectCellMode(); selectMode.CellSize = selcell.Size; selectMode.CellValue = selcell.Value.ToString(); selectMode.ColumnIndex = selcell.ColumnIndex; selectMode.RowIndex = selcell.RowIndex; listSeletM.Add(selectMode); } model.SelectCell = listSeletM; // 调整大小 listSize = new List <AdjustSizeMode>(); listSize.Add(adjustSize); model.Size = listSize; // 修改单元格内容 listEditM = new List <EditMode>(); listEditM.Add(editMode); model.EditCells = listEditM; // 将实体类装入List listCacheM = new List <DataViewCacheModel>(); listCacheM.Add(model); cacheFactory.Add(key, listCacheM); } catch { throw new Exception(); } }
/// <summary> /// 将缓存追加到缓存工厂中 /// </summary> /// <param name="cacheFactory">缓存工厂</param> /// <param name="type">缓存类型</param> /// <param name="adjustSize">调整大小</param> /// <param name="editMode">修改内容</param> /// <param name="gridView">DataGridView</param> public static void addCacheFactory(DataCacheTypeEnum type, AdjustSizeMode adjustSize, EditMode editMode, bool isCancel, bool isRestore, DataGridView gridView) { string key = gridView.Name; if (isCancel != true && isRestore != true) { // 刷新缓存索引 refreshCacheIndex(cacheFactory, key); if (cacheFactory.ContainsKey(key)) { addCacheHaveKey(cacheFactory, type, adjustSize, editMode, gridView); } else { addCacheNotKey(cacheFactory, type, adjustSize, editMode, gridView); } // 同步缓存索引 synchronizeIndex(cacheFactory, key); } }
/// <summary> /// 在存在key的时候将缓存追加到缓存工厂中 /// </summary> /// <param name="cacheFactory">缓存工厂</param> /// <param name="type">缓存类型</param> /// <param name="adjustSize">调整大小</param> /// <param name="editMode">修改内容</param> /// <param name="gridView">DataGridView</param> private static void addCacheHaveKey(Dictionary <string, List <DataViewCacheModel> > cacheFactory, DataCacheTypeEnum type , AdjustSizeMode adjustSize, EditMode editMode, DataGridView gridView) { string key = gridView.Name; List <DataViewCacheModel> listCacheM = cacheFactory[key]; List <AdjustSizeMode> listSize = null; List <EditMode> listEditM = null; List <SelectCellMode> listSeletM = null; SelectCellMode selectMode = null; DataViewCacheModel model = null; // 初始化缓存实体类 model = new DataViewCacheModel(); // 类型 model.Type = type; // 总行与总列 model.ColumnCount = gridView.ColumnCount; model.RowsCount = gridView.RowCount; // 选中单元格 listSeletM = new List <SelectCellMode>(); foreach (DataGridViewCell selcell in gridView.SelectedCells) { selectMode = new SelectCellMode(); selectMode.CellSize = selcell.Size; selectMode.CellValue = selcell.Value.ToString(); selectMode.ColumnIndex = selcell.ColumnIndex; selectMode.RowIndex = selcell.RowIndex; listSeletM.Add(selectMode); } model.SelectCell = listSeletM; // 调整大小 if (adjustSize != null && adjustSize.IsJoin && listCacheM.Count > 0) { listSize = listCacheM[listCacheM.Count - 1].Size; } else { listSize = new List <AdjustSizeMode>(); } listSize.Add(adjustSize); model.Size = listSize; // 修改单元格内容 if (editMode != null && editMode.IsJoin && listCacheM.Count > 0) { listEditM = listCacheM[listCacheM.Count - 1].EditCells; } else { listEditM = new List <EditMode>(); } listEditM.Add(editMode); model.EditCells = listEditM; if ((DataCacheTypeEnum.调整大小.Equals(type) && adjustSize != null && adjustSize.IsJoin) || (DataCacheTypeEnum.修改内容.Equals(type) && editMode != null && editMode.IsJoin)) { listCacheM[listCacheM.Count - 1] = model; } else { listCacheM.Add(model); } cacheFactory[key] = listCacheM; }