| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357 |
- 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;
- }
- /// <summary>
- /// 设置grid所有列宽自动调整
- /// </summary>
- /// <param name="ugb"></param>
- public static void autoGridColumnWSize(UltraGridBand ugb)
- {
- ugb.PerformAutoResizeColumns(true, PerformAutoSizeType.AllRowsInBand);
- }
- //激活输入当前值行数据
- /// <summary>
- /// 激活输入当前值行数据
- /// </summary>
- /// <param name="ug">ultragrid</param>
- /// <param name="strColumn">列名</param>
- /// <param name="strKey">列值</param>
- 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();
- }
- }
- /// <summary>
- /// 显示在指定列中的列。
- /// </summary>
- /// <param name="gridBand">UltraGridBand</param>
- /// <param name="columnKeys">不需要显示的列</param>
- 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;
- }
- }
- }
- /// <summary>
- /// 隐藏在指定列中的列。
- /// </summary>
- /// <param name="gridBand">UltraGridBand</param>
- /// <param name="columnKeys">不需要隐藏的列</param>
- 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;
- }
- }
- }
- /// <summary>
- /// 绑定combobox
- /// </summary>
- /// <param name="cmbx">控件名</param>
- /// <param name="dset">数据源ds</param>
- /// <param name="strVal">值</param>
- /// <param name="strName">显示名</param>
- /// <param name="filCondition">筛选条件</param>
- /// <param name="tips">是否新增</param>
- /// <param name="addItem">新增itemName</param>
- 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<String> list = new List<String>();
- 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中的中文和非中文统一高度。
- /// </summary>
- /// <param name="cmb"></param>
- 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;
- }
- }
- }
- /// <summary>
- /// 判断数据创建者ID和登录者ID是否拥有相同的角色
- /// </summary>
- /// <param name="strCreatUserId"></param>
- /// <param name="LoginUserId"></param>
- 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();
- }
- /// <summary>
- /// string转化为RTF类型
- /// </summary>
- /// <param name="strs"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// Char转16进制字符
- /// </summary>
- /// <param name="ch"></param>
- /// <returns></returns>
- 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
- /// <summary>
- /// 检验字符串是否只有三位有效小位
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>true代表是,false代表否</returns>
- public static bool IsNumberWith3(string str)
- {
- Regex rx = new Regex(@"/^[1-9]\d*(\.\d{1,3})?$");
- return rx.IsMatch(str);
- }
- /// <summary>
- /// 是否为百分比
- /// </summary>
- /// <param name="str">需要检验的字符串</param>
- /// <returns>true代表是,false代表否</returns>
- 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);
- }
- /// <summary>
- /// 清空容器控件数据,设置指定控件不清空
- /// </summary>
- /// <param name="control"></param>
- 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;
- }
- }
- }
- }
|