| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108 |
- using Core.Mes.Client.Comm.Server;
- using CoreFS.CA06;
- using Infragistics.Win;
- using Infragistics.Win.UltraWinEditors;
- using Infragistics.Win.UltraWinGrid;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Reflection;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using System.Xml.Linq;
- namespace Core.Mes.Client.Comm
- {
- public static class ComHelper
- {
- /// <summary>
- /// 不能为空
- /// </summary>
- public static string ERROR_EMPTY = "不能为空";
- /// <summary>
- /// 未选择
- /// </summary>
- public static string ERROR_CHOOSE = "未选择";
- /// <summary>
- /// 日期错误
- /// </summary>
- public static string ERROR_DATE = "日期错误";
- /// <summary>
- /// 应该输入整数
- /// </summary>
- public static string ERROR_INT = "应该输入整数";
- /// <summary>
- /// 应该输入非整数或小数
- /// </summary>
- public static string ERROR_DOUBLE = "应该输入整数或小数";
- /// <summary>
- /// 读取xml文件返回连接地址
- /// </summary>
- /// <param name="name">Config节点的name属性值</param>
- /// <returns></returns>
- public static string GetServiceUrl(string name)
- {
- string url = "";
- var xml = XDocument.Load(Application.StartupPath + "/data/comm.core");
- var items = xml.Element("CommunicationConfig").Elements("Config");
- for (int i = 0; i < items.Count(); i++)
- {
- try
- {
- if (items.ElementAt(i).Attribute("name").Value == name)
- {
- url = items.ElementAt(i).Element("url").Value.Replace("remoting/HessianRemoting", "service/");
- break;
- }
- }
- catch { }
- }
- return url;
- }
- /// <summary>
- /// 禁用 grid 列头排序
- /// </summary>
- /// <param name="grid"></param>
- public static void GridDisableSortIndicator(UltraGrid grid)
- {
- foreach (var band in grid.DisplayLayout.Bands)
- {
- foreach (var col in band.Columns)
- {
- col.SortIndicator = SortIndicator.Disabled;
- }
- }
- }
- /// <summary>
- /// 获取List数据
- /// </summary>
- /// <param name="url">接口反问地址</param>
- /// <typeparam name="TEntity">实体类</typeparam>
- /// <param name="className">服务端接口全名称</param>
- /// <param name="methodName">方法名</param>
- /// <param name="param">参数</param>
- /// <returns></returns>
- public static List<TEntity> GetListEntity<TEntity>(string url, string className, string methodName, object[] param) where TEntity : class, new()
- {
- CoreJsonService service = new CoreJsonService(url);
- List<TEntity> list = service.execute<List<TEntity>>(className, methodName, param);
- return list;
- }
- /// <summary>
- /// 获取List数据
- /// </summary>
- /// <param name="url">接口反问地址</param>
- /// <typeparam name="TEntity">实体类</typeparam>
- /// <param name="className">服务端接口全名称</param>
- /// <param name="methodName">方法名</param>
- /// <param name="param">参数</param>
- /// <returns></returns>
- public static TEntity GetEntity<TEntity>(string url, string className, string methodName, object[] param)
- {
- CoreJsonService service = new CoreJsonService(url);
- TEntity entity = service.execute<TEntity>(className, methodName, param);
- return entity;
- }
- /// <summary>
- /// 无返回数据
- /// </summary>
- /// <param name="url">接口访问地址</param>
- /// <param name="className">服务端接口全名称</param>
- /// <param name="methodName">方法名</param>
- /// <param name="param">参数</param>
- /// <returns></returns>
- public static void RequestServer(string url, string className, string methodName, object[] param)
- {
- CoreJsonService service = new CoreJsonService(url);
- service.execute(className, methodName, param);
- }
- /// <summary>
- /// 获取Text值
- /// </summary>
- /// <param name="textBox"></param>
- /// <returns></returns>
- public static string GetText(this TextBox textBox)
- {
- return string.IsNullOrWhiteSpace(textBox.Text) ? null : textBox.Text.Trim();
- }
- /// <summary>
- /// 判定是否为空
- /// </summary>
- /// <param name="textBox"></param>
- /// <returns></returns>
- public static bool IsEmpty(this UltraTextEditor textBox)
- {
- return string.IsNullOrWhiteSpace(textBox.Text);
- }
- /// <summary>
- /// 获取value
- /// </summary>
- /// <param name="editor"></param>
- /// <returns></returns>
- public static DateTime? GetValue(this UltraDateTimeEditor editor)
- {
- if (editor.Value == null)
- return null;
- else
- return Convert.ToDateTime(editor.Value);
- }
- /// <summary>
- /// 获取 DateTime 值
- /// </summary>
- /// <param name="editor"></param>
- /// <param name="date"></param>
- /// <returns></returns>
- public static DateTime GetDate(this UltraDateTimeEditor editor)
- {
- return Convert.ToDateTime(editor.Value);
- }
- /// <summary>
- /// 获取短日期
- /// </summary>
- /// <param name="date"></param>
- /// <returns></returns>
- public static DateTime GetDate(this DateTime date)
- {
- DateTime dateTime = Convert.ToDateTime(date.ToShortDateString());
- return dateTime;
- }
- /// <summary>
- /// string 转为int?
- /// </summary>
- /// <param name="text"></param>
- /// <returns></returns>
- public static int? ParseInt(this string text)
- {
- if (string.IsNullOrWhiteSpace(text))
- return null;
- return Convert.ToInt32(text);
- }
- /// <summary>
- /// int? 转 string
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static string ParseStr(this int? value)
- {
- if (value == null)
- return null;
- return value.ToString();
- }
- public static double? ParseDouble(this object value)
- {
- if (value == null || value is DBNull)
- {
- return null;
- }
- try
- {
- return Convert.ToDouble(value);
- }
- catch
- {
- return null;
- }
- }
- public static int? ParseInt(this object value)
- {
- if (value == null)
- {
- return null;
- }
- return Convert.ToInt32(value);
- }
- /// <summary>
- /// double? 转 string
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static string ParseStr(this double? value)
- {
- if (value == null)
- return null;
- return value.ToString();
- }
- /// <summary>
- /// string 转 double?
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static double? ParseDouble(this string value)
- {
- if (value == null)
- return null;
- return Convert.ToDouble(value);
- }
- /// <summary>
- /// string 转 float
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static float ParseFloat(this string value)
- {
- return Convert.ToSingle(value);
- }
- /// <summary>
- /// string 转 double
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static double ConvertDouble(this string value)
- {
- if (value == null)
- return 0;
- return Convert.ToDouble(value);
- }
- /// <summary>
- /// DateTime? 转为 DateTime
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static DateTime ParseDate(this DateTime? value)
- {
- if (value == null)
- return DateTime.Now;
- return Convert.ToDateTime(value);
- }
- /// <summary>
- /// 尝试转换为日期
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static bool TryDate(this string value)
- {
- if (string.IsNullOrWhiteSpace(value))
- return false;
- try
- {
- Convert.ToDateTime(value);
- return true;
- }
- catch { return false; }
- }
- /// <summary>
- /// 尝试转换为小数形式
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static bool TryDouble(this string value)
- {
- if (string.IsNullOrWhiteSpace(value))
- return false;
- try
- {
- Convert.ToDouble(value);
- return true;
- }
- catch { return false; }
- }
- /// <summary>
- /// 尝试转换为小数形式
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static bool TryDouble(this object value)
- {
- if (value == null)
- return false;
- try
- {
- Convert.ToDouble(value);
- return true;
- }
- catch { return false; }
- }
- /// <summary>
- /// 尝试转换为整数
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static bool TryInt(this string value)
- {
- if (string.IsNullOrWhiteSpace(value))
- return false;
- try
- {
- Convert.ToInt32(value);
- return true;
- }
- catch { return false; }
- }
- /// <summary>
- /// 给数字补小数位
- /// </summary>
- /// <param name="value"></param>
- /// <param name="digits"></param>
- /// <returns></returns>
- public static string AddTail(string value, int digits)
- {
- if (string.IsNullOrWhiteSpace(value))
- {
- return value;
- }
- value = value.Trim(' ');
- string[] items = value.Split('.');
- string format = ".";
- if (items.Length > 2)
- {
- return value;
- }
- if (items.Length < 2)
- { //刚好为整数
- for (int i = 0; i < digits; i++)
- {
- format += "0";
- }
- return items[0] + format;
- }
- if (items[1].Length == digits)
- { //刚好够位数
- return value;
- }
- int count = items[1].Length - digits;
- if (count < 0)
- { //位数不够
- format += items[1];
- for (int i = 0; i < Math.Abs(count); i++)
- {
- format += "0";
- }
- }
- else if (count > 0)
- { //位数大于需要的位数
- format += items[1].Substring(0, digits);
- }
- return items[0] + format;
- }
- /// <summary>
- /// 获取Text值
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public static string GetText(this object obj)
- {
- return obj == null ? null : obj.ToString().Trim();
- }
- /// <summary>
- /// 获取Text值
- /// </summary>
- /// <param name="textBox"></param>
- /// <returns></returns>
- public static string GetText(this UltraTextEditor textBox)
- {
- return string.IsNullOrWhiteSpace(textBox.Text) ? null : textBox.Text.Trim();
- }
- /// <summary>
- /// 获取value值
- /// </summary>
- /// <param name="combEditor"></param>
- /// <returns></returns>
- public static string GetSelectValue(this UltraComboEditor comb)
- {
- return comb.SelectedIndex < 0 ? null : comb.Value.ToString();
- }
- /// <summary>
- /// 设置选中项
- /// </summary>
- /// <param name="combEditor"></param>
- /// <param name="Value"></param>
- /// <returns></returns>
- public static void SetSelectValue(this UltraComboEditor comb, object value)
- {
- if (value == null)
- {
- comb.SelectedIndex = -1;
- return;
- }
- int index = 0;
- foreach (var item in comb.Items)
- {
- if (item.DataValue.ToString() == value.ToString())
- {
- comb.SelectedIndex = index;
- break;
- }
- index++;
- }
- }
- /// <summary>
- ///为空的时候返回null 不为空返回 toString
- /// </summary>
- /// <param name="value"></param>
- /// <returns></returns>
- public static string GetString(this object value)
- {
- if (value == null || value is DBNull || string.IsNullOrWhiteSpace(value.ToString()))
- {
- return null;
- }
- return value.ToString();
- }
- #region 获取 相关 ValueList 数据
- /// <summary>
- ///班次
- /// </summary>
- /// <returns></returns>
- public static ValueList List_GetWorkGroup()
- {
- ValueListItem[] items = new ValueListItem[] {
- new ValueListItem("1", "夜班"),
- new ValueListItem("2", "白班"),
- new ValueListItem("3", "中班")
- };
- ValueList valueList = new ValueList();
- valueList.ValueListItems.AddRange(items);
- return valueList;
- }
- /// <summary>
- /// DataTable 转换为valueList数据
- /// </summary>
- /// <param name="dt">数据表</param>
- /// <param name="Value">隐藏值</param>
- /// <param name="Text"> 显示值</param>
- /// <param name="ob">OB对象</param>
- public static ValueList GetValueList(DataTable dt, string value, string text)
- {
- ValueListItem[] items = new ValueListItem[dt.Rows.Count];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- items[i] = new ValueListItem(dt.Rows[i][value].ToString(), dt.Rows[i][text].ToString());
- }
- ValueList list = new ValueList();
- list.ValueListItems.AddRange(items);
- return list;
- }
- /// <summary>
- /// 获取valueList数据
- /// </summary>
- /// <param name="methodID">方法名</param>
- /// <param name="ob">OB对象</param>
- public static DataTable GetDataTable(string methodID, OpeBase ob)
- {
- DataTable dt = ServerHelper.GetData(methodID, new Object[] { }, ob);
- return dt;
- }
- /// <summary>
- /// 获取valueList数据
- /// </summary>
- /// <param name="methodID">方法名</param>
- /// <param name="Text">显示值</param>
- /// <param name="Value">隐藏值</param>
- /// <param name="ob">OB对象</param>
- public static ValueList GetValueList(string methodID, string text, string value, OpeBase ob)
- {
- DataTable dt = ServerHelper.GetData(methodID, new Object[] { }, ob);
- ValueListItem[] items = new ValueListItem[dt.Rows.Count];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- items[i] = new ValueListItem(dt.Rows[i][value].ToString(), dt.Rows[i][text].ToString());
- }
- ValueList list = new ValueList();
- list.ValueListItems.AddRange(items);
- return list;
- }
- /// <summary>
- /// 检验补充项目类型
- /// </summary>
- /// <returns></returns>
- public static DataTable List_MaterialOther()
- {
- DataTable dt = new DataTable();
- dt.Columns.AddRange(new DataColumn[] { new DataColumn("NAME"), new DataColumn("CODE") });
- dt.Rows.Add(new object[] { "试验方向", "A" });
- dt.Rows.Add(new object[] { "试验温度", "B" });
- dt.Rows.Add(new object[] { "试样尺寸", "C" });
- dt.Rows.Add(new object[] { "试验位置", "D" });
- return dt;
- }
- #endregion 获取 相关 ValueList 数据
- /// <summary>
- /// 获取grid 所有勾选的行
- /// </summary>
- /// <param name="grid"></param>
- /// <param name="columnName">复选框所在列名</param>
- /// <returns></returns>
- public static List<UltraGridRow> UltraGridGetChooseRows(UltraGrid grid, string columnName = "Choose")
- {
- grid.UpdateData();
- List<UltraGridRow> list = new List<UltraGridRow>();
- RowsCollection rows = grid.Rows;
- foreach (var item in rows)
- {
- try
- {
- if (Convert.ToBoolean(item.Cells[columnName].Value) == true && item.Hidden == false && item.IsFilteredOut == false)
- {
- list.Add(item);
- }
- }
- catch { }
- }
- return list;
- }
- /// <summary>
- /// 获取grid 所有勾选的行
- /// </summary>
- /// <param name="grid"></param>
- /// <param name="columnName">复选框所在列名</param>
- /// <returns></returns>
- public static List<UltraGridRow> UltraGridGetCHCRows(UltraGrid grid, string columnName = "CHC")
- {
- grid.UpdateData();
- List<UltraGridRow> list = new List<UltraGridRow>();
- RowsCollection rows = grid.Rows;
- foreach (var item in rows)
- {
- try
- {
- if (Convert.ToBoolean(item.Cells[columnName].Value) == true && item.Hidden == false && item.IsFilteredOut == false)
- {
- list.Add(item);
- }
- }
- catch { }
- }
- return list;
- }
- /// <summary>
- /// 获取grid 所有勾选的行
- /// </summary>
- /// <param name="grid"></param>
- /// <param name="columnName">复选框所在列名</param>
- /// <returns></returns>
- public static List<UltraGridRow> UltraGridGetOtherRows(UltraGrid grid, string columnName)
- {
- grid.UpdateData();
- List<UltraGridRow> list = new List<UltraGridRow>();
- RowsCollection rows = grid.Rows;
- foreach (var item in rows)
- {
- try
- {
- if (Convert.ToBoolean(item.Cells[columnName].Value) == true)
- {
- list.Add(item);
- }
- }
- catch { }
- }
- return list;
- }
- /// <summary>
- /// 获取grid 所有勾选的行
- /// </summary>
- /// <param name="grid"></param>
- /// <param name="columnName">复选框所在列名</param>
- /// <returns></returns>
- public static List<UltraGridRow> UltraGridGetOtherRowsNoHidden(UltraGrid grid, string columnName)
- {
- grid.UpdateData();
- List<UltraGridRow> list = new List<UltraGridRow>();
- RowsCollection rows = grid.Rows;
- foreach (var item in rows)
- {
- try
- {
- if (Convert.ToBoolean(item.Cells[columnName].Value) == true && item.Hidden == false && item.IsFilteredOut == false)
- {
- list.Add(item);
- }
- }
- catch { }
- }
- return list;
- }
- /// <summary>
- /// 设置列隐藏(全部)
- /// </summary>
- /// <param name="grid"></param>
- public static void UltraGridColunmsHidden(UltraGrid grid)
- {
- ColumnsCollection band = grid.DisplayLayout.Bands[0].Columns;
- foreach (var bandColunm in band)
- {
- bandColunm.Hidden = true;
- }
- }
- /// <summary>
- /// 清空grid 行
- /// </summary>
- /// <param name="grid"></param>
- public static void UltraGridRowsClear(UltraGrid grid)
- {
- int count = grid.Rows.Count - 1;
- while (count != -1)
- {
- grid.Rows[count].Delete();
- count--;
- }
- }
- /// <summary>
- /// 设置Grid 全部列 CheckBox 状态
- /// </summary>
- /// <param name="grid"></param>
- /// <param name="colName">checkBox 列名</param>
- /// <param name="isChecked">是否选中</param>
- public static void UltraGridSetChecked(UltraGrid grid, string colName, bool isChecked)
- {
- int count = grid.Rows.Count - 1;
- while (count != -1)
- {
- grid.Rows[count].Cells[colName].Value = isChecked;
- count--;
- }
- }
- /// <summary>
- /// 设置Grid 单选 适用于单表
- /// </summary>
- /// <param name="grid"></param>
- /// <param name="colName">checkBox 列名</param>
- public static void UltraGridSingleChecked(UltraGrid grid, string colName = "Choose")
- {
- int count = grid.Rows.Count - 1;
- while (count != -1)
- {
- try
- {
- if (!grid.ActiveRow.Equals(grid.Rows[count]))
- {
- grid.Rows[count].Cells[colName].Value = false;
- }
- else
- {
- grid.Rows[count].Cells[colName].Value = true;
- }
- }
- catch { }
- count--;
- }
- }
- /// <summary>
- /// 设置Grid 单选
- /// </summary>
- /// <param name="grid"></param>
- /// <param name="row">选中的行</param>
- /// <param name="colName">checkBox 列名</param>
- public static void UltraGridSingleChecked(UltraGrid grid, UltraGridRow row, string colName = "Choose")
- {
- int count = grid.Rows.Count - 1;
- while (count != -1)
- {
- try
- {
- if (!row.Equals(grid.Rows[count]))
- {
- grid.Rows[count].Cells[colName].Value = false;
- }
- else
- {
- grid.Rows[count].Cells[colName].Value = true;
- }
- }
- catch { }
- count--;
- }
- }
- /// <summary>
- /// 设置单元格内容水平对齐方式
- /// </summary>
- /// <param name="band"></param>
- /// <param name="align"></param>
- public static void UltraGirdCellTextHAgin(UltraGridBand band, HAlign align)
- {
- ColumnsCollection columns = band.Columns;
- foreach (var item in columns)
- {
- item.CellAppearance.TextHAlign = align;
- }
- }
- /// <summary>
- ///设置水平对齐方式
- /// </summary>
- /// <param name="col"></param>
- /// <param name="align"></param>
- public static void UltraGridColunmHAgin(UltraGridColumn[] col, HAlign align)
- {
- foreach (var item in col)
- {
- item.CellAppearance.TextHAlign = align;
- }
- }
- /// <summary>
- /// 设置焦点行 背景色、字体颜色
- /// </summary>
- /// <param name="list"></param>
- /// <param name="backColor"></param>
- /// <param name="fontColor"></param>
- public static void UltraGridSetActiveRowColor(List<UltraGrid> list, Color? backColor, Color? fontColor)
- {
- foreach (UltraGrid grid in list)
- {
- if (backColor == null)
- grid.DisplayLayout.Override.ActiveRowCellAppearance.BackColor = Color.DeepSkyBlue;
- else
- grid.DisplayLayout.Override.ActiveRowCellAppearance.BackColor = backColor.Value;
- if (fontColor == null)
- grid.DisplayLayout.Override.ActiveRowCellAppearance.ForeColor = Color.White;
- else
- grid.DisplayLayout.Override.ActiveRowCellAppearance.ForeColor = fontColor.Value;
- }
- }
- public static bool getUserRight(String userId, OpeBase ob, String deptId, params string[] remark)
- {
- DataTable userRemaek = ServerHelper.GetData(
- "com.steering.pss.sale.order.CoreUpdateInfo.GetUserRight", new Object[] { userId }, ob);
- for (int i = 0; i < remark.Length; i++)
- {
- if (userRemaek.Rows[0]["remark"].ToString().Contains(remark[i]))
- return true;
- }
- if (deptId == "001")
- return true;
- else
- return false;
- }
- /// <summary>
- /// 反射调用模拟平台打开界面方法
- /// </summary>
- /// <param name="ParentForm">平台窗体对象</param>
- /// <param name="formkey">"命名空间+窗体类名 如:[iCore.Omp.Ai.C_Mes.frmAnneal]"</param>
- /// <param name="formName">"界面名称 如:[1#退火炉作业]"</param>
- /// <param name="formPath">界面菜单路径 如:[\\板带Mes\\板带二车间\\1#退火炉作业] 可不传,但是如果打开了错误的界面,可用此参数</param>
- public static void OpenFromWithToolInfo(Form ParentForm, string formkey, string formName, string formPath = null)
- {
- Infragistics.Win.UltraWinToolbars.UltraToolbarsManager toolManager = ParentForm.GetType().GetField("uMainMenu", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(ParentForm) as Infragistics.Win.UltraWinToolbars.UltraToolbarsManager;
- if (toolManager == null) return;
- MethodInfo mi = ParentForm.GetType().GetMethod("MainMenu_ToolClick", BindingFlags.NonPublic | BindingFlags.Instance);
- if (mi == null) return;
- Infragistics.Win.UltraWinToolbars.ToolBase bar = null;
- foreach (var item in toolManager.Tools)
- {
- CoreMenuTag mTag = item.Tag as CoreMenuTag;
- if (mTag != null)
- {
- if (mTag.Key == formkey && mTag.WinCaption == formName && (string.IsNullOrEmpty(formPath) || !string.IsNullOrEmpty(formPath) && mTag.WinPath == formPath))
- {
- bar = item;
- }
- }
- }
- if (bar == null) return;
- mi.Invoke(ParentForm, new object[] { toolManager, new Infragistics.Win.UltraWinToolbars.ToolClickEventArgs(bar, null) });
- }
- /// <summary>
- /// 设置过滤框是否显示
- /// </summary>
- /// <param name="grid"></param>
- /// <param name="flag"></param>
- public static void setAllowRowFolter(UltraGrid grid, bool flag)
- {
- if (flag)
- {
- grid.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
- }
- else
- {
- int bNum = grid.DisplayLayout.Bands.Count;
- if (bNum > 0)
- {
- for (int j = 0; j < bNum; j++)
- {
- grid.DisplayLayout.Bands[j].ColumnFilters.ClearAllFilters();
- }
- }
- grid.DisplayLayout.Override.AllowRowFiltering = DefaultableBoolean.False;
- }
- }
- public static void ToolBarItemAdd(Form ParentForm, List<structButton> Toolbar, List<structButton> newButtonList, int[] index)
- {
- bool isRun = false;
- if (Toolbar == null) return;
- for (int i = 0; i < newButtonList.Count; i++)
- {
- if (Toolbar.FindIndex(t => t.Key.ToLower() == newButtonList[i].Key.ToLower()) < 0)
- {
- int insertIndex = index[i] >= 0 ? index[i] : Toolbar.Count;
- Toolbar.Insert(insertIndex, newButtonList[i]);
- isRun = true;
- }
- else
- continue;
- }
- if (isRun)
- {
- //Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea
- FrmBase frmBase = ParentForm.GetType().GetField("thisform", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(ParentForm) as FrmBase;
- if (frmBase != null)
- {
- foreach (System.Windows.Forms.Control item in frmBase.Controls)
- {
- if (item.Name == "_FrmBase_Toolbars_Dock_Area_Top")
- {
- item.Tag = "Remove";
- }
- }
- MethodInfo mi = ParentForm.GetType().GetMethod("GenerateUltraToolBar", BindingFlags.Public | BindingFlags.Instance);
- if (mi == null) return;
- mi.Invoke(ParentForm, new object[] { frmBase, Toolbar });
- //frmBase.Controls["_FrmBase_Toolbars_Dock_Area_Top"].Hide();
- foreach (System.Windows.Forms.Control item in frmBase.Controls)
- {
- if (item.Tag != null && item.Tag.ToString() == "Remove")
- {
- frmBase.Controls.Remove(item);
- }
- }
- }
- }
- }
- #region UltraComboEditor 下拉框绑定数据
- /// <summary>
- /// 用于通过服务端方法获取绑定下拉框的数据源
- /// </summary>
- /// <typeparam name="T">实体类名</typeparam>
- /// <param name="bs">所属界面 defaultValue(this)</param>
- /// <param name="service">调用服务端方法的路径</param>
- /// <param name="method">调用服务端方法的方法名称</param>
- /// <param name="obj">调用服务端方法的参数</param>
- /// <param name="valueMeber">下拉框value绑定对象的属性名</param>
- /// <param name="displayMeber">下拉框text绑定对象的属性名</param>
- /// <param name="bandEmpty">是否绑定一个空值</param>
- /// <returns></returns>
- public static DataTable getDTForAll<T>(FrmBase bs, String service, String method, object[] obj, String valueMeber, String displayMeber, Boolean bandEmpty = true)
- {
- List<T> info = bs.GetJsonService().execute<List<T>>(service, method, obj);
- DataTable dt = new DataTable();
- dt.Columns.Add("BASECODE");
- dt.Columns.Add("BASENAME");
- if (bandEmpty) //如果为TRUE,绑定空值
- dt.Rows.Add(null, "");
- foreach (T t in info)
- dt.Rows.Add(t.GetType().GetProperty(valueMeber).GetValue(t, null), t.GetType().GetProperty(displayMeber).GetValue(t, null));
- return dt;
- }
- /// <summary>
- /// 第三方控件UltraComboEditor绑定数据源,实现自动补全
- /// </summary>
- /// <param name="source"></param>
- /// <param name="cbb"></param>
- public static void valueToUltraComboEditor(DataTable source, UltraComboEditor cbb)
- {
- cbb.DataSource = source;
- cbb.DisplayMember = "BASENAME";
- cbb.ValueMember = "BASECODE";
- cbb.SelectedIndex = -1;
- //cbb.AutoCompleteMode = Infragistics.Win.AutoCompleteMode.SuggestAppend;
- SetComboItemHeight(cbb);
- }
- /// <summary>
- /// 设置UltraComboEditor中的中文和非中文统一高度。
- /// </summary>
- /// <param name="cmb"></param>
- public static void SetComboItemHeight(UltraComboEditor cmb)
- {
- cmb.Update();
- foreach (ValueListItem item in cmb.Items)
- {
- if (Regex.IsMatch(item.DisplayText.ToString(), @"[\u4e00-\u9fa5]+"))
- {
- item.Appearance.FontData.SizeInPoints = 9.0F;
- }
- else
- {
- item.Appearance.FontData.SizeInPoints = 10.5F;
- }
- }
- }
- #endregion
- #region 打开其他模块界面
- public static void MethodInvoke(FrmBase frmBase, string methodName, object[] obj = null)
- {
- try
- {
- MethodInfo mi = frmBase.GetType().GetMethod(methodName);
- if (mi != null)
- {
- mi.Invoke(frmBase, obj);
- }
- }
- catch { }
- }
- /// <summary>
- /// 反射调用模拟平台打开界面方法
- /// </summary>
- /// <param name="ParentForm">平台窗体对象</param>
- /// <param name="formkey">"命名空间+窗体类名 如:[iCore.Omp.Ai.C_Mes.frmAnneal]"</param>
- /// <param name="formName">"界面名称 如:[1#退火炉作业]"</param>
- /// <param name="formPath">界面菜单路径 如:[\\板带Mes\\板带二车间\\1#退火炉作业] 可不传,但是如果打开了错误的界面,可用此参数</param>
- public static FrmBase OpenFromWithToolInfo(Form ParentForm, string formkey, string formName, string formPath = null, string customInfo = "")
- {
- Infragistics.Win.UltraWinToolbars.UltraToolbarsManager toolManager = ParentForm.GetType().GetField("uMainMenu", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(ParentForm) as Infragistics.Win.UltraWinToolbars.UltraToolbarsManager;
- if (toolManager == null) return null;
- MethodInfo mi = ParentForm.GetType().GetMethod("MainMenu_ToolClick", BindingFlags.NonPublic | BindingFlags.Instance);
- if (mi == null) return null;
- Infragistics.Win.UltraWinToolbars.ToolBase bar = null;
- foreach (var item in toolManager.Tools)
- {
- CoreMenuTag mTag = item.Tag as CoreMenuTag;
- if (mTag != null)
- {
- if (mTag.Key == formkey && mTag.WinCaption == formName && (string.IsNullOrEmpty(formPath) || !string.IsNullOrEmpty(formPath) && mTag.WinPath == formPath))
- {
- mTag.CustomInfo = customInfo;
- bar = item;
- }
- }
- }
- if (bar == null) return null;
- mi.Invoke(ParentForm, new object[] { toolManager, new Infragistics.Win.UltraWinToolbars.ToolClickEventArgs(bar, null) });
- return ParentForm.ActiveMdiChild as FrmBase;
- }
- #endregion
- /// <summary>
- /// 增加按钮
- /// </summary>
- /// <param name="frmBaseThis"></param>
- /// <param name="ParentForm"></param>
- /// <param name="Toolbar"></param>
- /// <param name="newButtonList"></param>
- /// <param name="index"></param>
- public static void ToolBarItemAdd(FrmBase frmBaseThis, Form ParentForm, List<structButton> Toolbar, List<structButton> newButtonList, int[] index)
- {
- bool isRun = false;
- if (Toolbar == null) return;
- for (int i = 0; i < newButtonList.Count; i++)
- {
- if (Toolbar.FindIndex(t => t.Key.ToLower() == newButtonList[i].Key.ToLower()) < 0)
- {
- int insertIndex = index[i] >= 0 ? index[i] : Toolbar.Count;
- Toolbar.Insert(insertIndex, newButtonList[i]);
- isRun = true;
- }
- else
- continue;
- }
- if (isRun)
- {
- //Infragistics.Win.UltraWinToolbars.UltraToolbarsDockArea
- FrmBase frmBase = ParentForm.GetType().GetField("thisform", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(ParentForm) as FrmBase;
- if (frmBase != null && frmBase.winPath == frmBaseThis.winPath)
- {
- foreach (System.Windows.Forms.Control item in frmBase.Controls)
- {
- if (item.Name == "_FrmBase_Toolbars_Dock_Area_Top")
- {
- item.Tag = "Remove";
- }
- }
- MethodInfo mi = ParentForm.GetType().GetMethod("GenerateUltraToolBar", BindingFlags.Public | BindingFlags.Instance);
- if (mi == null) return;
- mi.Invoke(ParentForm, new object[] { frmBase, Toolbar });
- //frmBase.Controls["_FrmBase_Toolbars_Dock_Area_Top"].Hide();
- foreach (System.Windows.Forms.Control item in frmBase.Controls)
- {
- if (item.Tag != null && item.Tag.ToString() == "Remove")
- {
- frmBase.Controls.Remove(item);
- }
- }
- }
- }
- }
- /// <summary>
- /// 获取 BaseInfo ValueList
- /// </summary>
- /// <param name="list">BaseInfo集</param>
- /// <returns></returns>
- public static ValueList List_GetBaseInfo(DataTable dt)
- {
- ValueListItem[] items = new ValueListItem[dt.Rows.Count];
- for (int i = 0; i < dt.Rows.Count; i++)
- {
- ValueListItem item = new ValueListItem();
- item.DataValue = dt.Rows[i]["BASECODE"].ToString();
- item.DisplayText = dt.Rows[i]["BASENAME"].ToString();
- items[i] = item;
- }
- ValueList valueList = new ValueList();
- valueList.ValueListItems.AddRange(items);
- return valueList;
- }
- }
- }
|