Ejemplo n.º 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;
                    }
                }
            }
        }
Ejemplo n.º 2
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;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
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;
            }
        }