Exemple #1
0
        /// <summary>
        /// 撤销时类型为修改内容时的执行方法
        /// </summary>
        private static void 修改内容(DataCacheOperationType type, DataGridView dataGrid, DataViewCacheModel keyMode, int index)
        {
            // 初始化参数
            string          key      = dataGrid != null?dataGrid.Name:"";
            List <EditMode> editList = null;
            string          text     = "";

            if (index >= 0 && keyMode != null)
            {
                editList = keyMode.EditCells;
                foreach (EditMode model in editList)
                {
                    if (model != null)
                    {
                        if (DataCacheOperationType.撤销.Equals(type))
                        {
                            text = model.BeforeText;
                        }
                        else if (DataCacheOperationType.恢复.Equals(type))
                        {
                            text = model.EndText;
                        }
                        dataGrid.Rows[model.RowIndex].Cells[model.ColumnIndex].Value       = text;
                        dataGrid.Rows[model.RowIndex].Cells[model.ColumnIndex].ToolTipText = text;
                    }
                }
            }
        }
Exemple #2
0
        /// <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();
            }
        }
Exemple #3
0
        /// <summary>
        /// 撤销时类型为调整大小时的执行方法
        /// </summary>
        private static void 调整大小(DataCacheOperationType type, DataGridView dataGrid, DataViewCacheModel keyMode, int index)
        {
            // 初始化参数
            string key = dataGrid != null?dataGrid.Name:"";
            List <AdjustSizeMode> sizeList = null;
            // 索引
            int dataIndex = -1;

            if (index >= 0 && cacheFactory.ContainsKey(key) && index < cacheFactory[key].Count && keyMode != null)
            {
                sizeList = keyMode.Size;
                foreach (AdjustSizeMode model in sizeList)
                {
                    dataIndex = model.Index;
                    // 为行
                    if (0.Equals(model.SizeType))
                    {
                        if (DataCacheOperationType.撤销.Equals(type))
                        {
                            dataGrid.Rows[dataIndex].Height = model.BeforeSize.Height;
                        }
                        else if (DataCacheOperationType.恢复.Equals(type))
                        {
                            dataGrid.Rows[dataIndex].Height = model.EndSize.Height;
                        }
                    }
                    else if (1.Equals(model.SizeType))   // 为列
                    {
                        if (DataCacheOperationType.撤销.Equals(type))
                        {
                            dataGrid.Columns[dataIndex].Width = model.BeforeSize.Width;
                        }
                        else if (DataCacheOperationType.恢复.Equals(type))
                        {
                            dataGrid.Columns[dataIndex].Width = model.EndSize.Width;
                        }
                    }
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// 操作缓存区域
        /// </summary>
        /// <param name="dataGrid">要撤销的表格</param>
        public static void operationCache(DataGridView dataGrid, DataCacheOperationType type)
        {
            string key   = dataGrid != null?dataGrid.Name:"";
            int    index = -1;
            List <DataViewCacheModel> keyList = null;
            DataViewCacheModel        keyMode = null;

            if (cacheIndexs.Count > 0 && cacheFactory.Count > 0 && cacheFactory.ContainsKey(key))
            {
                keyList = cacheFactory[key];
                index   = cacheIndexs[key];
                if (cacheOperationType.ContainsKey(key) &&
                    DataCacheOperationType.恢复.Equals(cacheOperationType[key]) && DataCacheOperationType.撤销.Equals(type))
                {
                    int i = index - 1;
                    if (i >= 0)
                    {
                        index--;
                    }
                }
                else if (cacheOperationType.ContainsKey(key) &&
                         DataCacheOperationType.撤销.Equals(cacheOperationType[key]) && DataCacheOperationType.恢复.Equals(type))
                {
                    int i = index + 1;
                    if (i < keyList.Count)
                    {
                        index++;
                    }
                }
                if (index >= 0 && index < keyList.Count)
                {
                    keyMode = keyList[index];
                    // 执行对应方法
                    if (DataCacheTypeEnum.修改内容.Equals(keyMode.Type))
                    {
                        修改内容(type, dataGrid, keyMode, index);
                    }
                    if (DataCacheTypeEnum.调整大小.Equals(keyMode.Type))
                    {
                        调整大小(type, dataGrid, keyMode, index);
                    }
                    // 调整索引
                    if (DataCacheOperationType.撤销.Equals(type))
                    {
                        if (index >= 0)
                        {
                            index--;
                        }
                    }
                    else if (DataCacheOperationType.恢复.Equals(type))
                    {
                        if (index < keyList.Count)
                        {
                            index++;
                        }
                    }
                }
                cacheOperationType[key] = type;
                cacheIndexs[key]        = index;
            }
        }
Exemple #5
0
        /// <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;
        }