using Infragistics.Win.UltraWinGrid; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using Infragistics.Win.UltraWinEditors; using System.Data; using Infragistics.Win; using System.Text.RegularExpressions; using System.Drawing; using System.Windows.Forms; using System.IO; using Infragistics.Win.Misc; using Infragistics.Win.UltraWinSchedule; namespace Pur.PublicTools { class publicPms { //ArrayList转化为字符串 public static string ArrayListToString(ArrayList list) { String[] ls = (String[])list.ToArray(typeof(string)); String str1 = String.Join(";", ls); return str1; } /// /// 设置grid所有列宽自动调整 /// /// public static void autoGridColumnWSize(UltraGridBand ugb) { ugb.PerformAutoResizeColumns(true, PerformAutoSizeType.AllRowsInBand); } //激活输入当前值行数据 /// /// 激活输入当前值行数据 /// /// ultragrid /// 列名 /// 列值 public static string doActiveSelRow(UltraGrid ug, string strColumn, string strKey) { try { if (strKey != "") { foreach (UltraGridRow row in ug.Rows) { if (row.Cells[strColumn].Text.ToString() == strKey) { row.Activated = true; if (row.ChildBands != null) row.Expanded = true; } } } return ""; } catch (Exception ex) { return ex.ToString(); } } /// /// 显示在指定列中的列。 /// /// UltraGridBand /// 不需要显示的列 public static void ShowExcludeColumns(UltraGridBand gridBand, params string[] columnKeys) { foreach (UltraGridColumn gridColumn in gridBand.Columns) { if (columnKeys.Contains(gridColumn.Key) == true) { gridColumn.Hidden = true; } else { gridColumn.Hidden = false; } } } /// /// 隐藏在指定列中的列。 /// /// UltraGridBand /// 不需要隐藏的列 public static void HideExcludeColumns(UltraGridBand gridBand, params string[] columnKeys) { foreach (UltraGridColumn gridColumn in gridBand.Columns) { if (columnKeys.Contains(gridColumn.Key) == true) { gridColumn.Hidden = false; } else { gridColumn.Hidden = true; } } } /// /// 绑定combobox /// /// 控件名 /// 数据源ds /// 值 /// 显示名 /// 筛选条件 /// 是否新增 /// 新增itemName public static void FilComboboxAdd(UltraComboEditor cmbx, DataTable dt, string strVal, string strName, string filCondition, Boolean tips, String addItemName, String addItemValue) { SetComboItemHeight(cmbx); ArrayList aryTmp = new ArrayList(); if (tips == true) { aryTmp.Add(new ValueListItem(addItemValue, addItemName)); } if (dt.Columns.Count > 1) { DataView dvw = dt.DefaultView; dvw.RowFilter = filCondition; List list = new List(); for (int i = 0; i < dvw.Count; i++) { if (!list.Contains(dvw[i][strVal].ToString())) { list.Add(dvw[i][strVal].ToString()); aryTmp.Add(new ValueListItem(dvw[i][strVal].ToString(), dvw[i][strName].ToString())); } } } cmbx.DataSource = aryTmp; cmbx.DisplayMember = "DisplayText"; cmbx.ValueMember = "DataValue"; } /// 设置UltraComboEditor中的中文和非中文统一高度。 /// /// public static void SetComboItemHeight(UltraComboEditor cmb) { foreach (ValueListItem item in cmb.Items) { if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+")) { item.Appearance.FontData.SizeInPoints = 9.0F; } else { item.Appearance.FontData.SizeInPoints = 10.5F; } } } /// /// 判断数据创建者ID和登录者ID是否拥有相同的角色 /// /// /// public static void hasSameRole(string strCreatUserId,string LoginUserId) { } //获取弹出框显示位置 public static Point getShowLocation(Form form) { Point PointNew=System.Windows.Forms.Form.MousePosition; int y = PointNew.Y; int x = PointNew.X; if (form.Size.Width + x > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width) { //PointNew = new Point(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - form.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - form.Height); //PointNew = new Point(PointNew.X - form.Width, PointNew.Y - form.Height); x = x - form.Size.Width; } if (y +form.Size.Height > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height) { //PointNew = new Point(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - form.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - form.Height); y = y + form.Size.Height; } return new Point(x,y); } #region richtextBox公用处理方法 //获取richtextBox流文件 public static byte[] getBytesFromRichTextBox(RichTextBox richTextBox) { //建立内存流   System.IO.MemoryStream mstream = new System.IO.MemoryStream(); richTextBox.SaveFile(mstream, RichTextBoxStreamType.RichText); //将流转换成数组 byte[] bWrite = mstream.ToArray(); mstream.Close(); return bWrite; } public static void showRichTextBoxByByte(RichTextBox richTextBox, byte[] buffer) { //将数组转换成stream System.IO.MemoryStream mstream = new System.IO.MemoryStream(buffer, false); //将stream填充到RichTextBox richTextBox.LoadFile(mstream, RichTextBoxStreamType.RichText); richTextBox.Rtf = "1111111"; mstream.Close(); } /// /// string转化为RTF类型 /// /// /// public static string Str2RTF(string strs) { if (String.IsNullOrEmpty(strs)) { return ""; } string tmpStr = "", tmpStr2 = "", strToRTF = ""; int lstrLen = strs.Length; if (lstrLen == 0) return ""; foreach (Char c in strs) { tmpStr = c.ToString(); int tmpAsc = (int)c; if (tmpAsc > 126)//转换非ASCII范围的文本为RTF格式 { tmpStr = CharTo16(c); if (tmpStr.Length == 1) tmpStr = @"\'0" + tmpStr;//转换hex值小于2位的特殊控制符号 else if (tmpStr.Length == 2) tmpStr = @"\'" + tmpStr;//转换hex值等于2位的特殊符号 else { tmpStr2 = tmpStr.Substring(tmpStr.Length - 2, 2); //Right(tmpStr, 2); tmpStr = tmpStr.Substring(0, 2); //Left(tmpStr, 2); tmpStr = @"\'" + tmpStr + @"\'" + tmpStr2;// '转换hex值等于4位的非英文字符内码 } } //if (tmpStr == "\'0D" || tmpStr == "\'0A")//Then '对换行符号进行特殊控制:0D 0A // tmpStr = @"}{\insrsid198535 \par }{\insrsid198535 \loch\af0\hich\af0\dbch\f13 "; strToRTF += tmpStr; } return strToRTF; } /// /// Char转16进制字符 /// /// /// public static string CharTo16(char ch) { System.Text.Encoding chs = System.Text.Encoding.GetEncoding("gb2312"); byte[] bytes = chs.GetBytes(ch.ToString()); string str = ""; for (int i = 0; i < bytes.Length; i++) { str += string.Format("{0:X2}", bytes[i]); } return str.ToLower(); } #endregion /// /// 检验字符串是否只有三位有效小位 /// /// 需要检验的字符串 /// true代表是,false代表否 public static bool IsNumberWith3(string str) { Regex rx = new Regex(@"/^[1-9]\d*(\.\d{1,3})?$"); return rx.IsMatch(str); } /// /// 是否为百分比 /// /// 需要检验的字符串 /// true代表是,false代表否 public static bool IsPercentage(string str) { Regex rx = new Regex(@"^(100(\.0{1,2})|(([1-9]\d|\d)(\.\d{1,2})?))%$"); return rx.IsMatch(str); } /// /// 清空容器控件数据,设置指定控件不清空 /// /// public static void clearOldData(Control control, params string[] columnKeys) { foreach (Control ctr in control.Controls) { if (columnKeys.Contains(ctr.Name)) { continue; } if (ctr is Button) { continue; } if (ctr is UltraButton) { continue; } if (ctr is Label) { continue; } if (ctr is UltraLabel) { continue; } if (ctr is UltraCheckEditor)//清空复选框1 { UltraCheckEditor ultcmb = (UltraCheckEditor)ctr; ultcmb.Checked = false; } if (ctr is CheckBox)//清空复选框2 { CheckBox cmb = (CheckBox)ctr; cmb.Checked = false; } //if (ctr is UltraComboEditor)//清空下拉列表1 //{ // UltraComboEditor ultcb = (UltraComboEditor)ctr; // ultcb.SelectedIndex = -1; //} //if (ctr is ComboBox)//清空下拉列表2 //{ // ComboBox ultcb = (ComboBox)ctr; // ultcb.SelectedIndex = -1; //} //if (ctr is UltraTextEditor)//清空编辑框 //{ // UltraTextEditor ultxt = (UltraTextEditor)ctr; // ultxt.Text = ""; //} //if (ctr is TextBox)//清空编辑框 //{ // TextBox tb = (TextBox)ctr; // tb.Text = ""; //} if (ctr is UltraCalendarCombo)//清空日期选择 { UltraCalendarCombo tb = (UltraCalendarCombo)ctr; tb.Value = DateTime.Now; } if (ctr is UltraNumericEditor)//清空数字编辑框 { UltraNumericEditor tb = (UltraNumericEditor)ctr; tb.Value = null; } ctr.Text = null; } } } }