private void SetColIndex(UcDataGridView grid, string colName, int?displayIdx, int?width) { #region 变量设置 SYS_UserGridColIndex findGridIdx = null; SYS_UserGridColWidth findGridWdth = null; Guid?companyID = MySession.CompanyID; Guid?userGuid = MySession.UserGUID; #endregion #region 表格所在表单、容器、表格名称,获取表格对象 SYS_DataGridResult gridSet = new SYS_DataGridResult(); string formName = grid.FindForm().Name; string gridName = grid.Name; string parentName = ""; Control parentCon = grid.Parent; while (parentCon != null && parentCon.GetType().BaseType != typeof(ucBaseUserControl)) { parentCon = parentCon.Parent; } if (parentCon != null) { parentName = (parentCon as ucBaseUserControl).Name; } gridSet = GetGridSet(gridName, parentName, formName); #endregion #region 设置列显示索引值 if (displayIdx != null) { findGridIdx = gridSet.ColIndexList.Find(a => a.ColName == colName && a.CompanyID == companyID && a.UserGUID == userGuid); if (findGridIdx == null) { findGridIdx = new SYS_UserGridColIndex(); gridSet.ColIndexList.Add(findGridIdx); } findGridIdx.ColName = colName; findGridIdx.DisplayIndex = displayIdx; findGridIdx.CompanyID = companyID; findGridIdx.UserGUID = userGuid; findGridIdx.DGGUID = gridSet.DGGUID; } #endregion #region 设置列显示宽值 if (width != null) { findGridWdth = gridSet.ColWidthList.Find(a => a.ColName == colName && a.CompanyID == companyID && a.UserGUID == userGuid); if (findGridWdth == null) { findGridWdth = new SYS_UserGridColWidth(); gridSet.ColWidthList.Add(findGridWdth); } findGridWdth.ColName = colName; findGridWdth.ColWidth = width; findGridWdth.CompanyID = companyID; findGridWdth.UserGUID = userGuid; findGridWdth.DGGUID = gridSet.DGGUID; } #endregion }
public static void SetColName(UcDataGridView grid, string colNameCode, string colName, string customColName, bool isShow) { #region 变量设置 SYS_UserGridColName finGridName = null; Guid?companyID = MySession.CompanyID; Guid?userGuid = MySession.UserGUID; #endregion #region 表格所在表单、容器、表格名称,获取表格对象 SYS_DataGridResult gridSet = new SYS_DataGridResult(); string formName = grid.FindForm().Name; string gridName = grid.Name; string parentName = ""; Control parentCon = grid.Parent; while (parentCon != null && parentCon.GetType().BaseType != typeof(ucBaseUserControl)) { parentCon = parentCon.Parent; } if (parentCon != null) { parentName = (parentCon as ucBaseUserControl).Name; } gridSet = GetGridSet(gridName, parentName, formName); #endregion #region 设置列自定义列名 if (!string.IsNullOrEmpty(customColName)) { finGridName = gridSet.ColNameList.Find(a => a.ColNameCN_Default == colName && a.CompanyID == companyID); if (finGridName == null) { finGridName = new SYS_UserGridColName(); gridSet.ColNameList.Add(finGridName); } finGridName.ColNameCode = colNameCode; finGridName.ColNameCN_Default = colName; finGridName.ColNameCN_Custom = customColName; finGridName.ColIsShow = isShow; finGridName.CompanyID = companyID; finGridName.UserGUID = userGuid; finGridName.DGGUID = gridSet.DGGUID; } #endregion }
public void BindApplyGridEvent(UcDataGridView grid, bool isDefaultCellMouseEvent = true) { if (grid == null) { return; } #region 统一设置表头高度及列头宽度 grid.RowHeadersWidth = 30; grid.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing; grid.ColumnHeadersHeight = 32; grid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing; #endregion grid.ColumnWidthChanged += new DataGridViewColumnEventHandler(grid_ColumnWidthChanged); grid.ColumnDisplayIndexChanged += new DataGridViewColumnEventHandler(grid_ColumnDisplayIndexChanged); grid.DataBindingComplete += new DataGridViewBindingCompleteEventHandler(grid_DataBindingComplete); if (isDefaultCellMouseEvent) { if (grid.FindForm() != null && grid.FindForm().Name != "frmStockSearch") { grid.CellMouseEnter += new DataGridViewCellEventHandler(grid_CellMouseEnter); grid.CellMouseLeave += new DataGridViewCellEventHandler(grid_CellMouseLeave); } else { if (grid.Name != "grdStock") //库存查询表格需单独处理 { grid.CellMouseEnter += new DataGridViewCellEventHandler(grid_CellMouseEnter); grid.CellMouseLeave += new DataGridViewCellEventHandler(grid_CellMouseLeave); } } } ApplyGridSet(grid); #region 统一控制客户和供应商权限 if (!MySession.IsMainAccount && MySession.EnabledSubAccountRole) { if (MySession.OwnerRoles != null && MySession.OwnerRoles.Count > 0) { string extSupplierInfo = ",供应商,供应商名称,供应商信息,"; string extCustomerInfo = ",客户,客户名称,客户信息,"; foreach (DataGridViewColumn dgvc in grid.Columns) { if (((extSupplierInfo.IndexOf("," + dgvc.HeaderText + ",") != -1 || dgvc.DataPropertyName.IndexOf("SupplierName") != -1) && !MySession.OwnerRoles.Contains("Mod.供应商管理")) || (extCustomerInfo.IndexOf("," + dgvc.HeaderText + ",") != -1 || dgvc.DataPropertyName.IndexOf("CustomerName") != -1) && !MySession.OwnerRoles.Contains("Mod.客户管理")) { ZNLCRM.UI.Logic.Sys.GridUserSetting.HideGridColumn(grid, dgvc.Name); } } } } #endregion #region 汇总行处理 if (grid is UcDataGridViewSummary) { UcDataGridViewSummary ucDgvSummary = grid as UcDataGridViewSummary; if (ucDgvSummary.SummaryRowVisible == true && ucDgvSummary.DisplaySumRowHeader == true && ucDgvSummary.SummaryColumns.Length > 0) { ucDgvSummary.CreateSummaryRow(); //创建汇总行 } } #endregion }
public void ApplyGridSet(UcDataGridView grid) { #region 得到表格设置 _isSettingCol = true; if (grid == null || grid.FindForm() == null) { return; } string formName = grid.FindForm().Name; string gridName = grid.Name; string parentName = ""; Control parentCon = grid.Parent; while (parentCon != null && parentCon.GetType().BaseType != typeof(ucBaseUserControl)) { parentCon = parentCon.Parent; } if (parentCon != null) { parentName = (parentCon as ucBaseUserControl).Name; } SYS_DataGridResult gridSet = GetGridSet(gridName, parentName, formName); #endregion #region 设置表列显示索引值 if (gridSet.ColIndexList != null && gridSet.ColIndexList.Count > 0) { foreach (SYS_UserGridColIndex info in gridSet.ColIndexList) { if (grid.Columns[info.ColName] == null || grid.Columns[info.ColName].Frozen) { continue; //冻结列不处理 } if (grid.Columns.Count > info.DisplayIndex && grid.Columns[info.ColName] != null) { try { grid.Columns[info.ColName].DisplayIndex = info.DisplayIndex.GetValueOrDefault(0); } catch { } } } } #endregion #region 设置表列显示宽度值 if (gridSet.ColWidthList != null && gridSet.ColWidthList.Count > 0) { foreach (SYS_UserGridColWidth info in gridSet.ColWidthList) { if (grid.Columns[info.ColName] == null) { continue; } if (grid.Columns[info.ColName] != null) { grid.Columns[info.ColName].Width = info.ColWidth.GetValueOrDefault(5); } } } #endregion #region 设置自定义列名及是否显示 if (gridSet.ColNameList != null && gridSet.ColNameList.Count > 0) { foreach (SYS_UserGridColName info in gridSet.ColNameList) { if (grid.Columns[info.ColNameCode] == null) { continue; } if (grid.Columns[info.ColNameCode] != null) { if (!string.IsNullOrEmpty(info.ColNameCN_Custom)) { grid.Columns[info.ColNameCode].HeaderText = info.ColNameCN_Custom; } if (info.ColIsShow.HasValue) { grid.Columns[info.ColNameCode].Visible = info.ColIsShow.Value; } } } } #endregion _isSettingCol = false; }