| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- using Infragistics.Win.UltraWinEditors;
- using Infragistics.Win.UltraWinGrid;
- using Infragistics.Win.UltraWinMaskedEdit;
- using Microsoft.Office.Interop.Excel;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- namespace Core.StlMes.Client.Lims.Port.封装类.方法
- {
- class BaseMethod
- {
- /// <summary>
- /// 设置列显示位数
- /// </summary>
- /// <param name="ug"></param>
- /// <param name="arr"></param>
- 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";
- }
- }
- }
- /// <summary>
- /// 炉号去-后的字符
- /// </summary>
- /// <param name="JudgeStoveNo"></param>
- /// <returns></returns>
- public static string getJudgeStoveNo(string JudgeStoveNo)
- {
- Regex regex = new Regex("-[0-9]*");
- return regex.Replace(JudgeStoveNo, "");
- }
- /// <summary>
- /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中
- /// </summary>
- /// <param name="ugrid">UltraGrid</param>
- /// <param name="e"></param>
- /// <param name="strs">可以进行列名称</param>
- 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.Equals(colName))
- {
- if (ugr.Cells[colName].Activation != Activation.AllowEdit)
- {
- return;
- }
- ugrid.UpdateData();
- ArrayList list = new ArrayList();
- IQueryable<UltraGridRow> 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;
- }
- }
- }
- }
- }
- }
- }
-
- /// <summary>
- /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中
- /// </summary>
- /// <param name="ugrid">UltraGrid</param>
- /// <param name="e"></param>
- /// <param name="strs">可以进行列名称</param>
- 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<UltraGridRow> 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;
- }
- }
- }
- }
- }
- }
- }
-
- /// <summary>
- /// 获取数据源中第一行数据赋到类中(grid 带下划线)
- /// </summary>
- /// <typeparam name="T">返回类</typeparam>
- /// <param name="ds">输入带数据的数据源</param>
- /// <param name="t">输入类</param>
- /// <returns></returns>
- public static T GetUltraGridToEntityNEW<T>(UltraGrid _grid, T t)
- {
- String[] strColumns = null;
- String[] strColumnsNew = null;
- UltraGridRow dr = _grid.Rows[0];
- int columnNum = dr.Cells.Count;
- strColumns = new String[columnNum];
- strColumnsNew = new String[columnNum];
- for (int i = 0; i < columnNum; i++)
- {
- strColumns[i] = _grid.DisplayLayout.Bands[0].Columns[i].Key.ToString().Replace("_", "");
- strColumnsNew[i] = _grid.DisplayLayout.Bands[0].Columns[i].Key.ToString();
- }
- System.Reflection.PropertyInfo[] pro = t.GetType().GetProperties();
- foreach (System.Reflection.PropertyInfo item in pro)
- {
- for (int i = 0; i < strColumns.Length; i++)
- {
- if (string.Compare(item.Name.ToString(), strColumns[i].ToString(), true) == 0)
- {
- if (item.PropertyType == typeof(int?))
- {
- item.SetValue(t, Convert.ToInt32(dr.Cells[strColumnsNew[i]].Value.ToString3()), null);
- }
- else if (item.PropertyType == typeof(decimal?))
- {
- item.SetValue(t, Convert.ToDecimal(dr.Cells[strColumnsNew[i]].Value.ToString3()), null);
- }
- else
- {
- item.SetValue(t, Convert.ToString(dr.Cells[strColumnsNew[i]].Value.ToString()), null);
- }
- }
- }
- }
- return t;
- }
- }
- }
|