publicPms.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. using Infragistics.Win.UltraWinGrid;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using Infragistics.Win.UltraWinEditors;
  8. using System.Data;
  9. using Infragistics.Win;
  10. using System.Text.RegularExpressions;
  11. using System.Drawing;
  12. using System.Windows.Forms;
  13. using System.IO;
  14. using Infragistics.Win.Misc;
  15. using Infragistics.Win.UltraWinSchedule;
  16. namespace Pur.PublicTools
  17. {
  18. class publicPms
  19. {
  20. //ArrayList转化为字符串
  21. public static string ArrayListToString(ArrayList list)
  22. {
  23. String[] ls = (String[])list.ToArray(typeof(string));
  24. String str1 = String.Join(";", ls);
  25. return str1;
  26. }
  27. /// <summary>
  28. /// 设置grid所有列宽自动调整
  29. /// </summary>
  30. /// <param name="ugb"></param>
  31. public static void autoGridColumnWSize(UltraGridBand ugb)
  32. {
  33. ugb.PerformAutoResizeColumns(true, PerformAutoSizeType.AllRowsInBand);
  34. }
  35. //激活输入当前值行数据
  36. /// <summary>
  37. /// 激活输入当前值行数据
  38. /// </summary>
  39. /// <param name="ug">ultragrid</param>
  40. /// <param name="strColumn">列名</param>
  41. /// <param name="strKey">列值</param>
  42. public static string doActiveSelRow(UltraGrid ug, string strColumn, string strKey)
  43. {
  44. try
  45. {
  46. if (strKey != "")
  47. {
  48. foreach (UltraGridRow row in ug.Rows)
  49. {
  50. if (row.Cells[strColumn].Text.ToString() == strKey)
  51. {
  52. row.Activated = true;
  53. if (row.ChildBands != null)
  54. row.Expanded = true;
  55. }
  56. }
  57. }
  58. return "";
  59. }
  60. catch (Exception ex)
  61. {
  62. return ex.ToString();
  63. }
  64. }
  65. /// <summary>
  66. /// 显示在指定列中的列。
  67. /// </summary>
  68. /// <param name="gridBand">UltraGridBand</param>
  69. /// <param name="columnKeys">不需要显示的列</param>
  70. public static void ShowExcludeColumns(UltraGridBand gridBand, params string[] columnKeys)
  71. {
  72. foreach (UltraGridColumn gridColumn in gridBand.Columns)
  73. {
  74. if (columnKeys.Contains(gridColumn.Key) == true)
  75. {
  76. gridColumn.Hidden = true;
  77. }
  78. else
  79. {
  80. gridColumn.Hidden = false;
  81. }
  82. }
  83. }
  84. /// <summary>
  85. /// 隐藏在指定列中的列。
  86. /// </summary>
  87. /// <param name="gridBand">UltraGridBand</param>
  88. /// <param name="columnKeys">不需要隐藏的列</param>
  89. public static void HideExcludeColumns(UltraGridBand gridBand, params string[] columnKeys)
  90. {
  91. foreach (UltraGridColumn gridColumn in gridBand.Columns)
  92. {
  93. if (columnKeys.Contains(gridColumn.Key) == true)
  94. {
  95. gridColumn.Hidden = false;
  96. }
  97. else
  98. {
  99. gridColumn.Hidden = true;
  100. }
  101. }
  102. }
  103. /// <summary>
  104. /// 绑定combobox
  105. /// </summary>
  106. /// <param name="cmbx">控件名</param>
  107. /// <param name="dset">数据源ds</param>
  108. /// <param name="strVal">值</param>
  109. /// <param name="strName">显示名</param>
  110. /// <param name="filCondition">筛选条件</param>
  111. /// <param name="tips">是否新增</param>
  112. /// <param name="addItem">新增itemName</param>
  113. public static void FilComboboxAdd(UltraComboEditor cmbx, DataTable dt, string strVal, string strName, string filCondition, Boolean tips, String addItemName, String addItemValue)
  114. {
  115. SetComboItemHeight(cmbx);
  116. ArrayList aryTmp = new ArrayList();
  117. if (tips == true)
  118. {
  119. aryTmp.Add(new ValueListItem(addItemValue, addItemName));
  120. }
  121. if (dt.Columns.Count > 1)
  122. {
  123. DataView dvw = dt.DefaultView;
  124. dvw.RowFilter = filCondition;
  125. List<String> list = new List<String>();
  126. for (int i = 0; i < dvw.Count; i++)
  127. {
  128. if (!list.Contains(dvw[i][strVal].ToString()))
  129. {
  130. list.Add(dvw[i][strVal].ToString());
  131. aryTmp.Add(new ValueListItem(dvw[i][strVal].ToString(), dvw[i][strName].ToString()));
  132. }
  133. }
  134. }
  135. cmbx.DataSource = aryTmp;
  136. cmbx.DisplayMember = "DisplayText";
  137. cmbx.ValueMember = "DataValue";
  138. }
  139. /// 设置UltraComboEditor中的中文和非中文统一高度。
  140. /// </summary>
  141. /// <param name="cmb"></param>
  142. public static void SetComboItemHeight(UltraComboEditor cmb)
  143. {
  144. foreach (ValueListItem item in cmb.Items)
  145. {
  146. if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
  147. {
  148. item.Appearance.FontData.SizeInPoints = 9.0F;
  149. }
  150. else
  151. {
  152. item.Appearance.FontData.SizeInPoints = 10.5F;
  153. }
  154. }
  155. }
  156. /// <summary>
  157. /// 判断数据创建者ID和登录者ID是否拥有相同的角色
  158. /// </summary>
  159. /// <param name="strCreatUserId"></param>
  160. /// <param name="LoginUserId"></param>
  161. public static void hasSameRole(string strCreatUserId,string LoginUserId)
  162. {
  163. }
  164. //获取弹出框显示位置
  165. public static Point getShowLocation(Form form)
  166. {
  167. Point PointNew=System.Windows.Forms.Form.MousePosition;
  168. int y = PointNew.Y;
  169. int x = PointNew.X;
  170. if (form.Size.Width + x > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width)
  171. {
  172. //PointNew = new Point(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - form.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - form.Height);
  173. //PointNew = new Point(PointNew.X - form.Width, PointNew.Y - form.Height);
  174. x = x - form.Size.Width;
  175. }
  176. if (y +form.Size.Height > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height)
  177. {
  178. //PointNew = new Point(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - form.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - form.Height);
  179. y = y + form.Size.Height;
  180. }
  181. return new Point(x,y);
  182. }
  183. #region richtextBox公用处理方法
  184. //获取richtextBox流文件
  185. public static byte[] getBytesFromRichTextBox(RichTextBox richTextBox)
  186. {
  187. //建立内存流  
  188. System.IO.MemoryStream mstream = new System.IO.MemoryStream();
  189. richTextBox.SaveFile(mstream, RichTextBoxStreamType.RichText);
  190. //将流转换成数组
  191. byte[] bWrite = mstream.ToArray();
  192. mstream.Close();
  193. return bWrite;
  194. }
  195. public static void showRichTextBoxByByte(RichTextBox richTextBox, byte[] buffer)
  196. {
  197. //将数组转换成stream
  198. System.IO.MemoryStream mstream = new System.IO.MemoryStream(buffer, false);
  199. //将stream填充到RichTextBox
  200. richTextBox.LoadFile(mstream, RichTextBoxStreamType.RichText);
  201. richTextBox.Rtf = "1111111";
  202. mstream.Close();
  203. }
  204. /// <summary>
  205. /// string转化为RTF类型
  206. /// </summary>
  207. /// <param name="strs"></param>
  208. /// <returns></returns>
  209. public static string Str2RTF(string strs)
  210. {
  211. if (String.IsNullOrEmpty(strs))
  212. {
  213. return "";
  214. }
  215. string tmpStr = "", tmpStr2 = "", strToRTF = "";
  216. int lstrLen = strs.Length;
  217. if (lstrLen == 0)
  218. return "";
  219. foreach (Char c in strs)
  220. {
  221. tmpStr = c.ToString();
  222. int tmpAsc = (int)c;
  223. if (tmpAsc > 126)//转换非ASCII范围的文本为RTF格式
  224. {
  225. tmpStr = CharTo16(c);
  226. if (tmpStr.Length == 1)
  227. tmpStr = @"\'0" + tmpStr;//转换hex值小于2位的特殊控制符号
  228. else if (tmpStr.Length == 2)
  229. tmpStr = @"\'" + tmpStr;//转换hex值等于2位的特殊符号
  230. else
  231. {
  232. tmpStr2 = tmpStr.Substring(tmpStr.Length - 2, 2); //Right(tmpStr, 2);
  233. tmpStr = tmpStr.Substring(0, 2); //Left(tmpStr, 2);
  234. tmpStr = @"\'" + tmpStr + @"\'" + tmpStr2;// '转换hex值等于4位的非英文字符内码
  235. }
  236. }
  237. //if (tmpStr == "\'0D" || tmpStr == "\'0A")//Then '对换行符号进行特殊控制:0D 0A
  238. // tmpStr = @"}{\insrsid198535 \par }{\insrsid198535 \loch\af0\hich\af0\dbch\f13 ";
  239. strToRTF += tmpStr;
  240. }
  241. return strToRTF;
  242. }
  243. /// <summary>
  244. /// Char转16进制字符
  245. /// </summary>
  246. /// <param name="ch"></param>
  247. /// <returns></returns>
  248. public static string CharTo16(char ch)
  249. {
  250. System.Text.Encoding chs = System.Text.Encoding.GetEncoding("gb2312");
  251. byte[] bytes = chs.GetBytes(ch.ToString());
  252. string str = "";
  253. for (int i = 0; i < bytes.Length; i++)
  254. {
  255. str += string.Format("{0:X2}", bytes[i]);
  256. }
  257. return str.ToLower();
  258. }
  259. #endregion
  260. /// <summary>
  261. /// 检验字符串是否只有三位有效小位
  262. /// </summary>
  263. /// <param name="str">需要检验的字符串</param>
  264. /// <returns>true代表是,false代表否</returns>
  265. public static bool IsNumberWith3(string str)
  266. {
  267. Regex rx = new Regex(@"/^[1-9]\d*(\.\d{1,3})?$");
  268. return rx.IsMatch(str);
  269. }
  270. /// <summary>
  271. /// 是否为百分比
  272. /// </summary>
  273. /// <param name="str">需要检验的字符串</param>
  274. /// <returns>true代表是,false代表否</returns>
  275. public static bool IsPercentage(string str)
  276. {
  277. Regex rx = new Regex(@"^(100(\.0{1,2})|(([1-9]\d|\d)(\.\d{1,2})?))%$");
  278. return rx.IsMatch(str);
  279. }
  280. /// <summary>
  281. /// 清空容器控件数据,设置指定控件不清空
  282. /// </summary>
  283. /// <param name="control"></param>
  284. public static void clearOldData(Control control, params string[] columnKeys)
  285. {
  286. foreach (Control ctr in control.Controls)
  287. {
  288. if (columnKeys.Contains(ctr.Name))
  289. {
  290. continue;
  291. }
  292. if (ctr is Button)
  293. { continue; }
  294. if (ctr is UltraButton)
  295. { continue; }
  296. if (ctr is Label)
  297. { continue; }
  298. if (ctr is UltraLabel)
  299. { continue; }
  300. if (ctr is UltraCheckEditor)//清空复选框1
  301. {
  302. UltraCheckEditor ultcmb = (UltraCheckEditor)ctr;
  303. ultcmb.Checked = false;
  304. }
  305. if (ctr is CheckBox)//清空复选框2
  306. {
  307. CheckBox cmb = (CheckBox)ctr;
  308. cmb.Checked = false;
  309. }
  310. //if (ctr is UltraComboEditor)//清空下拉列表1
  311. //{
  312. // UltraComboEditor ultcb = (UltraComboEditor)ctr;
  313. // ultcb.SelectedIndex = -1;
  314. //}
  315. //if (ctr is ComboBox)//清空下拉列表2
  316. //{
  317. // ComboBox ultcb = (ComboBox)ctr;
  318. // ultcb.SelectedIndex = -1;
  319. //}
  320. //if (ctr is UltraTextEditor)//清空编辑框
  321. //{
  322. // UltraTextEditor ultxt = (UltraTextEditor)ctr;
  323. // ultxt.Text = "";
  324. //}
  325. //if (ctr is TextBox)//清空编辑框
  326. //{
  327. // TextBox tb = (TextBox)ctr;
  328. // tb.Text = "";
  329. //}
  330. if (ctr is UltraCalendarCombo)//清空日期选择
  331. {
  332. UltraCalendarCombo tb = (UltraCalendarCombo)ctr;
  333. tb.Value = DateTime.Now;
  334. }
  335. if (ctr is UltraNumericEditor)//清空数字编辑框
  336. {
  337. UltraNumericEditor tb = (UltraNumericEditor)ctr;
  338. tb.Value = null;
  339. }
  340. ctr.Text = null;
  341. }
  342. }
  343. }
  344. }