using Core.Mes.Client.Comm.Server; using CoreFS.CA06; using Infragistics.Win.UltraWinEditors; using Infragistics.Win.UltraWinGrid; using Infragistics.Win.UltraWinMaskedEdit; using System; using System.Collections; using System.Collections.Generic; using System.Data; using System.Drawing; using System.Linq; using System.Windows.Forms; namespace Core.StlMes.Client.Judge.Commons { public class BaseMethod { /// /// UltraGrid可读 /// /// UltraGrid /// 可编辑列 public static void setOtherColumnReadOnly(UltraGrid ugr, string[] keys) { keys.ToArray(); foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns) { if (!keys.Contains(ugc.Key)) { ugc.CellActivation = Activation.ActivateOnly; } } } /// /// UltraGrid激活某行 /// /// UltraGrid /// 列名 /// 对应的值 public static void UltraGridLocation(UltraGrid ug, String[] keys, String[] values) { if (ug.Rows.Count == 0) { return; } if (keys.Length == 0 || values.Length == 0 || values.Length != keys.Length) { return; } foreach (UltraGridRow ugr in ug.Rows) { Boolean flag = true; for (int i = 0; i < keys.Length; i++) { if (!ugr.Cells[keys[i]].ToString().Equals(values[i])) { flag = false; } } if (flag == true) { ugr.Activate(); return; } } } /// /// 设置列字段显示位置在右 /// /// UltraGrid /// 要设置的列 public static void InitCellPosition(UltraGrid ug, string[] columnsKeys) { columnsKeys.ToArray(); foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns) { if (columnsKeys.Contains(ugc.Key.ToString())) { ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right; } } } /// /// 列求和 /// /// UltraGrid /// 列数组 public static void GridColumnSum(UltraGrid ug, string[] columnKeys) { if (columnKeys.Length == 0) { return; } for (int i = 0; i < columnKeys.Length; i++) { ug.DisplayLayout.Bands[0].Summaries.Add(SummaryType.Sum, ug.DisplayLayout.Bands[0].Columns[columnKeys[i]], SummaryPosition.UseSummaryPositionColumn); } } /// /// 设置UltraGrid行颜色 /// /// UltraGrid /// 列 /// 值 /// 颜色 public static void SetUltraGridRowColor(UltraGrid ug, string[] columnKeys, string[] values, Color color) { if (ug.Rows.Count == 0 || columnKeys.Length == 0 || values.Length == 0 || color == null || values.Length != columnKeys.Length) { return; } foreach (UltraGridRow ugr in ug.Rows) { Boolean flag = true; for (int i = 0; i < columnKeys.Length; i++) { if (!ugr.Cells[columnKeys[i]].Value.ToString().Equals(values[i])) { flag = false; } } if (flag) { ugr.Appearance.BackColor = color; } } } /// /// 合并单元格 /// /// /// public static void MergedCell(UltraGrid ug, string[] columnKeys) { if (columnKeys.Length == 0) { return; } ug.DisplayLayout.Override.MergedCellStyle = MergedCellStyle.Never; for (int i = 0; i < columnKeys.Length; i++) { ug.DisplayLayout.Bands[0].Columns[columnKeys[i]].MergedCellStyle = MergedCellStyle.Always; } } /// /// 销售组织权限 /// /// 数据权限 /// /// 字符串数组 public static string[] InitPermissions(string[] validDataPurviewIds, OpeBase ob) { string[] arr = null; DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getSalgPermissions", new object[] { validDataPurviewIds }, ob); if (dt != null && dt.Rows.Count > 0) { arr = new string[dt.Rows.Count]; for (int i = 0; i < dt.Rows.Count; i++) { arr[i] = dt.Rows[i][0].ToString(); } return arr; } else { return new string[1] { "" }; } } /// /// 把角色集合转换成数组 /// /// /// public static string[] getRole(List list) { string str = ""; string[] roles = new string[list.Count]; for (int i = 0; i < list.Count; i++) { str += list[i] + ','; } if (str.Length > 2) { str = str.Substring(0, str.LastIndexOf(',')); roles = str.Split(','); } return roles; } /// /// 初始下拉框 /// /// /// /// /// public static void InitComboEditor(UltraComboEditor uce, DataTable dt, String showName, String hideValue) { uce.DataSource = dt; uce.DisplayMember = showName; uce.ValueMember = hideValue; } /// /// 初始下拉框 /// /// /// /// /// public static void InitComboEditor1(UltraComboEditor uce, DataTable dt, String showName, String hideValue) { uce.DataSource = dt; uce.DisplayMember = showName; uce.ValueMember = hideValue; uce.SelectedIndex = 1; } /// /// 设置列显示位数 /// /// /// public static void setUltraGridColumnMaxInput(UltraGrid ug, string[] arr) { if (ug == null || arr == null || arr.Length == 0) { return; } arr.ToArray(); foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns) { if (arr.Contains(ugc.Key.ToString())) { ugc.MaskClipMode = MaskMode.IncludeLiterals; ugc.MaskInput = "{LOC}nn,nnn,nnn.nnn"; } } } /// /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中 /// /// UltraGrid /// /// 可以进行列名称 public static void setGridCopyActColumn(UltraGrid ugrid, KeyEventArgs e, params string[] strs) { if (e.Control && e.KeyCode == Keys.D) { if (ugrid != null && ugrid.ActiveRow != null) { UltraGridRow ugr = ugrid.ActiveRow; foreach (string colName in strs) { if (ugrid.ActiveCell.Column.Key == null) { return; } if (ugrid.ActiveCell.Column.Key.Equals(colName)) { if (ugr.Cells[colName].Activation != Activation.AllowEdit) { return; } ugrid.UpdateData(); ArrayList list = new ArrayList(); IQueryable checkRows = ugrid.Rows.AsQueryable().Where("CHK = 'True' "); if (checkRows.Count() == 0) { return; } foreach (UltraGridRow uRow in checkRows) { if (uRow != ugr && uRow.Cells[colName].Activation == Activation.AllowEdit) { uRow.Cells[colName].Value = ugr.Cells[colName].Value; } } } } } } } /// /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中 /// /// UltraGrid /// /// 可以进行列名称 public static void setGridCopyActColumn1(UltraGrid ugrid, KeyEventArgs e, params string[] strs) { if (e.Control && e.KeyCode == Keys.D) { if (ugrid != null && ugrid.ActiveRow != null) { UltraGridRow ugr = ugrid.ActiveRow; foreach (string colName in strs) { if (ugrid.ActiveCell.Column.Key.Equals(colName)) { if (ugr.Cells[colName].Activation != Activation.AllowEdit) { return; } ugrid.UpdateData(); ArrayList list = new ArrayList(); IQueryable checkRows = ugrid.Rows.AsQueryable().Where("CHOOSE = 'True' "); if (checkRows.Count() == 0) { return; } foreach (UltraGridRow uRow in checkRows) { if (uRow != ugr && uRow.Cells[colName].Activation == Activation.AllowEdit) { uRow.Cells[colName].Value = ugr.Cells[colName].Value; } } } } } } } } }