Globals.cs.svn-base 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. using System;
  2. using System.Data;
  3. using System.Collections;
  4. using System.Windows.Forms;
  5. using System.Text.RegularExpressions;
  6. using System.Reflection;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using CoreFS.CA06;
  10. namespace Core.Mes.Client.Common
  11. {
  12. public class Globals
  13. {
  14. /// <summary>
  15. /// 初始化Combox数据
  16. /// </summary>
  17. /// <param name="cmbx">ComboBox控件</param>
  18. /// <param name="dset">DataSet数据源</param>
  19. public static void FillComboxItems(ComboBox cmbx, DataSet dset)
  20. {
  21. if (dset.Tables.Count > 0 && dset.Tables[0].Columns.Count > 1)
  22. {
  23. ArrayList aryTmp = new ArrayList();
  24. for (int i = 0; i < dset.Tables[0].Rows.Count; i++)
  25. {
  26. aryTmp.Add(new ValueListItem(dset.Tables[0].Rows[i][0].ToString(), dset.Tables[0].Rows[i][1].ToString()));
  27. }
  28. cmbx.DataSource = aryTmp;
  29. cmbx.DisplayMember = "Name";
  30. cmbx.ValueMember = "ID";
  31. }
  32. }
  33. /// <summary>
  34. /// 初始化Combox数据,加入数据筛选
  35. /// </summary>
  36. /// <param name="cmbx">ComboBox控件</param>
  37. /// <param name="dset">DataSet数据源</param>
  38. /// <param name="filterCondition">RowFilter条件</param>
  39. public static void FillComboxItems(ComboBox cmbx, DataSet dset, string filterCondition)
  40. {
  41. if (dset.Tables.Count > 0 && dset.Tables[0].Columns.Count > 1)
  42. {
  43. DataView dvw = dset.Tables[0].DefaultView;
  44. dvw.RowFilter = filterCondition;
  45. ArrayList aryTmp = new ArrayList();
  46. for (int i = 0; i < dvw.Count; i++)
  47. {
  48. aryTmp.Add(new ValueListItem(dvw[i][0].ToString(), dvw[i][1].ToString()));
  49. }
  50. cmbx.DataSource = aryTmp;
  51. cmbx.DisplayMember = "Name";
  52. cmbx.ValueMember = "ID";
  53. }
  54. }
  55. /// <summary>
  56. /// 初始化UltraCombo数据
  57. /// </summary>
  58. /// <param name="ulcme">ultraComboEditor控件</param>
  59. /// <param name="dset">DataSet数据源</param>
  60. public static void FillUltraComboItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataSet dset)
  61. {
  62. if (dset.Tables.Count > 0 && dset.Tables[0].Columns.Count > 1)
  63. {
  64. for (int i = 0; i < dset.Tables[0].Rows.Count; i++)
  65. ulcme.Items.Add(dset.Tables[0].Rows[i][0].ToString(), dset.Tables[0].Rows[i][1].ToString());
  66. }
  67. }
  68. /// <summary>
  69. /// 初始化UltraComboEditor数据
  70. /// </summary>
  71. /// <param name="ulcme"></param>
  72. /// <param name="dt"></param>
  73. public static void FillUlcmeItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataTable dt)
  74. {
  75. if (dt.Columns.Count > 0)
  76. {
  77. ulcme.Items.Clear();
  78. for (int i = 0; i < dt.Rows.Count; i++)
  79. ulcme.Items.Add(dt.Rows[i][0].ToString());
  80. }
  81. }
  82. /// <summary>
  83. /// 初始化UltraCombo数据,加入数据筛选
  84. /// </summary>
  85. /// <param name="ulcme">ultraComboEditor控件</param>
  86. /// <param name="dset">DataSet数据源</param>
  87. /// <param name="filterCondition">RowFilter条件</param>
  88. public static void FillUltraComboItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataSet dset, string filterCondition)
  89. {
  90. if (dset.Tables.Count > 0 && dset.Tables[0].Columns.Count > 1)
  91. {
  92. DataView dvw = dset.Tables[0].DefaultView;
  93. dvw.RowFilter = filterCondition;
  94. for (int i = 0; i < dvw.Count; i++)
  95. ulcme.Items.Add(dvw[i][0].ToString(), dvw[i][1].ToString());
  96. }
  97. }
  98. /// <summary>
  99. /// 初始化UltraCombo数据
  100. /// </summary>
  101. /// <param name="ulcme"></param>
  102. /// <param name="dt">DataTable</param>
  103. public static void FillUltraComboItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataTable dt)
  104. {
  105. if (dt.Columns.Count > 1)
  106. {
  107. for (int i = 0; i < dt.Rows.Count; i++)
  108. ulcme.Items.Add(dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString());
  109. }
  110. }
  111. /// <summary>
  112. /// 初始化UltraCombo数据
  113. /// </summary>
  114. /// <param name="ulcme"></param>
  115. /// <param name="dv">DataView</param>
  116. public static void FillUltraComboItems(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataView dv)
  117. {
  118. if (dv.Count > 0)
  119. {
  120. for (int i = 0; i < dv.Count; i++)
  121. ulcme.Items.Add(dv[i]["BASECODE"].ToString(), dv[i]["BASENAME"].ToString());
  122. }
  123. }
  124. /// <summary>
  125. /// 初始化UltraCombo数据,并添加“空”
  126. /// </summary>
  127. /// <param name="ulcme">ultraComboEditor控件</param>
  128. /// <param name="dset">DataSet数据源</param>
  129. public static void FillUlcmItemsAddEmpty(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataSet dset)
  130. {
  131. ulcme.Items.Add("", "空");
  132. FillUltraComboItems(ulcme, dset);
  133. }
  134. /// <summary>
  135. /// 初始化UltraCombo数据,并添加“空”;加入数据筛选
  136. /// </summary>
  137. /// <param name="ulcme">ultraComboEditor控件</param>
  138. /// <param name="dset">DataSet数据源</param>
  139. /// <param name="filterCondition">RowFilter条件</param>
  140. public static void FillUlcmItemsAddEmpty(Infragistics.Win.UltraWinEditors.UltraComboEditor ulcme, DataSet dset, string filterCondition)
  141. {
  142. ulcme.Items.Add("", "空");
  143. FillUltraComboItems(ulcme, dset, filterCondition);
  144. }
  145. /// <summary>
  146. /// 字符串转是否能转换成非负数
  147. /// </summary>
  148. /// <param name="str"></param>
  149. /// <returns></returns>
  150. public static bool Is_Below_zero(string str)
  151. {
  152. try
  153. {
  154. if (IsDouble(str) && double.Parse(str) > 0)
  155. return true;
  156. else
  157. return false;
  158. }
  159. catch
  160. {
  161. return false;
  162. }
  163. }
  164. /// <summary>
  165. /// 删除记录激活指定行
  166. /// </summary>
  167. /// <param name="grid">ultraGrid</param>
  168. /// <param name="delRowIndex">删除行的索引</param>
  169. public static void GridAfterDelRow_ReSelectRow(ref Infragistics.Win.UltraWinGrid.UltraGrid grid, int delRowIndex)
  170. {
  171. if (grid.Rows.Count == 0) return;
  172. if ((delRowIndex + 1) > grid.Rows.Count)
  173. {
  174. grid.Rows[delRowIndex - 1].Activate();
  175. grid.Rows[delRowIndex - 1].Selected = true;
  176. }
  177. else
  178. {
  179. grid.Rows[delRowIndex].Activate();
  180. grid.Rows[delRowIndex].Selected = true;
  181. }
  182. }
  183. /// <summary>
  184. /// 全单位修约(GB 8170-87)
  185. /// </summary>
  186. /// <param name="sOriVal">原始值</param>
  187. /// <param name="ten_interval">10的n次方修约间隔</param>
  188. /// <returns>修约后值</returns>
  189. public static string XYFullUnit(string sOriVal, sbyte ten_interval)
  190. {
  191. try
  192. {
  193. decimal interval = Convert.ToDecimal(Math.Pow(10, ten_interval));//修约间隔
  194. decimal d = decimal.Parse(sOriVal) / interval;
  195. bool isPlus = (d > 0); //是否为正数
  196. d = Math.Abs(d);
  197. int i = (int)d;
  198. if ((d - i) < 0.5m)
  199. {
  200. d = i * interval;
  201. }
  202. else if ((d - i) > 0.5m)
  203. {
  204. d = (i + 1) * interval;
  205. }
  206. else //(d-i) == 0.5m
  207. {
  208. if ((i % 2) == 0) //双数舍去
  209. d = i * interval;
  210. else //单数进一
  211. d = (i + 1) * interval;
  212. }
  213. if (!isPlus)
  214. d = 0 - d;
  215. if (ten_interval >= 0)
  216. return d.ToString();
  217. else
  218. return ValWithDigits(d.ToString(), Math.Abs(ten_interval));
  219. }
  220. catch
  221. {
  222. return "";
  223. }
  224. }
  225. /// <summary>
  226. /// 保留指定位数小数
  227. /// </summary>
  228. /// <param name="sVal"></param>
  229. /// <param name="Digits"></param>
  230. /// <returns></returns>
  231. public static string ValWithDigits(string sVal, int Digits)
  232. {
  233. try
  234. {
  235. decimal d = decimal.Parse(sVal);
  236. string sFormat = "0";
  237. if (Digits > 0)
  238. {
  239. sFormat += ".";
  240. for (int i = 0; i < Digits; i++)
  241. sFormat += "0";
  242. }
  243. return d.ToString(sFormat);
  244. }
  245. catch
  246. {
  247. return "";
  248. }
  249. }
  250. /// <summary>
  251. /// 单元格复制内容
  252. /// </summary>
  253. /// <param name="strMessage"></param>
  254. public static void cellCopy(string strMessage)
  255. {
  256. Clipboard.SetDataObject(strMessage, false);
  257. }
  258. #region "数据验证"
  259. /// <summary>
  260. /// 验证DataTable是否为空
  261. /// </summary>
  262. /// <param name="dt">DataTable数据</param>
  263. /// <returns>true为空值</returns>
  264. public static bool IsNullTable(DataTable dt)
  265. {
  266. if (dt == null || dt.Rows.Count <= 0)
  267. {
  268. return true;
  269. }
  270. else
  271. {
  272. return false;
  273. }
  274. }
  275. /// <summary>
  276. /// 校验字符串是否只包含字母与数字
  277. /// </summary>
  278. /// <param name="toVerified">需要校验的字符串</param>
  279. /// <returns>true表示符合要求,false表示不符合要求</returns>
  280. public static bool IsOnlyLetterAndDigit(string toVerified)
  281. {
  282. Regex rx = new Regex(@"^[a-zA-Z0-9-]*$");
  283. return rx.IsMatch(toVerified.Trim(), 0);
  284. }
  285. /// <summary>
  286. /// 检验是否是整数
  287. /// </summary>
  288. /// <param name="str">需要检验的字符串</param>
  289. /// <returns>是否为整数:true是整数,false非整数</returns>
  290. public static bool IsInt(string str)
  291. {
  292. Regex rx = new Regex(@"^[0123456789]+$");
  293. return rx.IsMatch(str);
  294. }
  295. /// <summary>
  296. /// 检验是否是整数(庹建勇)
  297. /// </summary>
  298. /// <param name="sVal"></param>
  299. /// <returns></returns>
  300. public static bool IsInt32(string sVal)
  301. {
  302. try
  303. {
  304. Int32.Parse(sVal);
  305. return true;
  306. }
  307. catch
  308. {
  309. return false;
  310. }
  311. }
  312. /// <summary>
  313. /// 校验是否为正的浮点数
  314. /// </summary>
  315. /// <param name="price">需要检验的字符串</param>
  316. /// <returns>是否为正浮点,是返回true,否则返回false</returns>
  317. public static bool IsFloat(string str)
  318. {
  319. Regex rx = new Regex(@"^[0-9]*(.)?[0-9]+$", RegexOptions.IgnoreCase);
  320. return rx.IsMatch(str.Trim());
  321. }
  322. /// <summary>
  323. /// 验证浮点数
  324. /// </summary>
  325. /// <param name="sVal"></param>
  326. /// <returns></returns>
  327. public static bool IsDouble(string sVal)
  328. {
  329. try
  330. {
  331. Double.Parse(sVal);
  332. return true;
  333. }
  334. catch
  335. {
  336. return false;
  337. }
  338. }
  339. /// <summary>
  340. /// 检验是否为数字
  341. /// </summary>
  342. /// <param name="str">需要检验的字符串</param>
  343. /// <returns>是否为数字:true代表是,false代表否</returns>
  344. public static bool IsNumber(string str)
  345. {
  346. Regex rx = new Regex(@"^[+-]?[0123456789]*[.]?[0123456789]*$");
  347. return rx.IsMatch(str);
  348. }
  349. /// <summary>
  350. /// 检验字符串是否为日期时间
  351. /// </summary>
  352. /// <param name="str">需要检验的字符串</param>
  353. /// <returns>是否为日期时间:true代表是,false代表否</returns>
  354. public static bool IsNotDateTime(string str)
  355. {
  356. DateTime dt = new DateTime();
  357. return (!(DateTime.TryParse(str, out dt)));
  358. }
  359. /// <summary>
  360. /// 检验字符串是否为邮政编码
  361. /// </summary>
  362. /// <param name="str">需要检验的字符串</param>
  363. /// <returns>是否为邮政编码:true代表是,false代表否</returns>
  364. public static bool IsPostCode(string str)
  365. {
  366. Regex rx = new Regex(@"^[0123456789]{6}$");
  367. return rx.IsMatch(str);
  368. }
  369. /// <summary>
  370. /// 检验字符串是否为身份证号
  371. /// </summary>
  372. /// <param name="str">需要检验的字符串</param>
  373. /// <returns>是否为身份证号:true代表是,false代表否</returns>
  374. public static bool IsCode(string str)
  375. {
  376. Regex rx = new Regex(@"^[0123456789]{15,18}$");
  377. return rx.IsMatch(str);
  378. }
  379. /// <summary>
  380. /// 检验字符串是否为电子邮件
  381. /// </summary>
  382. /// <param name="str">需要检验的字符串</param>
  383. /// <returns>是否为电子邮件:true代表是,false代表否</returns>
  384. public static bool IsEMail(string str)
  385. {
  386. Regex rx = new Regex(@"w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*");
  387. return rx.IsMatch(str);
  388. }
  389. /// <summary>
  390. /// 检验字符串是否为中国地区的电话号码
  391. /// </summary>
  392. /// <param name="str">需要检验的字符串</param>
  393. /// <returns>是否为中国地区的电话号码:true代表是,false代表否</returns>
  394. public static bool IsPhoneNumber(string str)
  395. {
  396. Regex rx = new Regex(@"((d{3,4})|d{3,4}-)?d{7,8}(-d{3})*");
  397. return rx.IsMatch(str);
  398. }
  399. /// <summary>
  400. /// 检验字符串是否为汉字
  401. /// </summary>
  402. /// <param name="str">需要检验的字符串</param>
  403. /// <returns>是否为汉字:true代表是,false代表否</returns>
  404. public static bool IsChinese(string str)
  405. {
  406. Regex rx = new Regex(@"u4e00-u9fa5");
  407. return rx.IsMatch(str);
  408. }
  409. /// <summary>
  410. /// 检验字符串是否为双字节字符(包括汉字)
  411. /// </summary>
  412. /// <param name="str">需要检验的字符串</param>
  413. /// <returns>是否为双字节字符:true代表是,false代表否</returns>
  414. public static bool IsDoubleByteChar(string str)
  415. {
  416. Regex rx = new Regex(@"[^x00-xff]");
  417. return rx.IsMatch(str);
  418. }
  419. /// <summary>
  420. /// 检验字符串是否为URL地址
  421. /// </summary>
  422. /// <param name="str">需要检验的字符串</param>
  423. /// <returns>是否为URL地址:true代表是,false代表否</returns>
  424. public static bool IsURLAddress(string str)
  425. {
  426. Regex rx = new Regex(@"[a-zA-z]+://[^s]*");
  427. return rx.IsMatch(str);
  428. }
  429. /// <summary>
  430. /// 检验字符串是否为IP地址
  431. /// </summary>
  432. /// <param name="str">需要检验的字符串</param>
  433. /// <returns>是否为IP地址:true代表是,false代表否</returns>
  434. public static bool IsIPAddress(string str)
  435. {
  436. Regex rx = new Regex(@"d+.d+.d+.d+");
  437. return rx.IsMatch(str);
  438. }
  439. /// <summary>
  440. /// 清除字符串中的HTML标签(对于复杂的嵌套标签有时不准确)
  441. /// </summary>
  442. /// <param name="toEvaluate">指定的要被处理的字符串</param>
  443. /// <returns>清除HTML标签后的字符串</returns>
  444. public static string RemoveHtmlTags(string toEvaluate)
  445. {
  446. Regex rx = new Regex(@"s/<[a-zA-Z/][^>]*>//g", RegexOptions.IgnoreCase);
  447. return rx.Replace(toEvaluate, "");
  448. }
  449. /// <summary>
  450. /// 判断输入的字符串是否完全匹配正则
  451. /// </summary>
  452. /// <param name="RegexExpression">正则表达式</param>
  453. /// <param name="str">待判断的字符串</param>
  454. /// <returns></returns>
  455. public static bool IsValiable(string RegexExpression, string str)
  456. {
  457. bool blResult = false;
  458. Regex rep = new Regex(RegexExpression, RegexOptions.IgnoreCase);
  459. //blResult = rep.IsMatch(str);
  460. Match mc = rep.Match(str);
  461. if (mc.Success)
  462. {
  463. if (mc.Value == str) blResult = true;
  464. }
  465. return blResult;
  466. }
  467. /// <summary>
  468. /// 判断DataSet是否是空值
  469. /// </summary>
  470. /// <param name="ds">DataSet数据</param>
  471. /// <returns>true 空值</returns>
  472. public static bool IsNullData(DataSet ds)
  473. {
  474. if (ds == null || ds.Tables.Count == 0 || ds.Tables[0].Rows.Count == 0)
  475. {
  476. return true;
  477. }
  478. else
  479. {
  480. return false;
  481. }
  482. }
  483. /// <summary>
  484. /// 值比对 sSign:符号,sMin:最小值,sMax:最大值,sRealVal:实际值
  485. /// </summary>
  486. /// <param name="sSign"></param>
  487. /// <param name="sMin"></param>
  488. /// <param name="sMax"></param>
  489. /// <param name="sRealVal"></param>
  490. /// <returns></returns>
  491. public static bool ValIsEligible(string sSign, string sMin, string sMax, string sRealVal)
  492. {
  493. try
  494. {
  495. switch (sSign)
  496. {
  497. case ">":
  498. return (double.Parse(sMin) < double.Parse(sRealVal));
  499. case ">=":
  500. return (double.Parse(sMin) <= double.Parse(sRealVal));
  501. case "=":
  502. if (Globals.IsDouble(sMin))
  503. return (double.Parse(sMin) == double.Parse(sRealVal));
  504. else
  505. return (sMin == sRealVal);
  506. case "<":
  507. return (double.Parse(sMax) > double.Parse(sRealVal));
  508. case "<=":
  509. return (double.Parse(sMax) >= double.Parse(sRealVal));
  510. default:
  511. return true;
  512. }
  513. }
  514. catch
  515. {
  516. return false;
  517. }
  518. }
  519. #endregion
  520. /// <summary>
  521. /// 数字转换成中文数字
  522. /// </summary>
  523. /// <param name="strNum"></param>
  524. /// <returns></returns>
  525. public static string ConvertNumberToChinese(string strNum)
  526. {
  527. string[] Nums = { "零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖" };
  528. string[] Digits = { "", "拾", "佰", "仟" };
  529. string[] Units = { "元", "万", "亿", "万亿" };
  530. string x, y, z = "";
  531. if (strNum.Length > 2)
  532. {
  533. x = strNum.Substring(0, strNum.Length - 2);
  534. y = strNum.Substring(strNum.Length - 2, 2);
  535. }
  536. else
  537. {
  538. x = "";
  539. y = strNum;
  540. }
  541. if (y.Length == 2)
  542. {
  543. int n = Convert.ToInt32(y.Substring(0, 1));
  544. z = Nums[n] + "角";
  545. }
  546. if (y.Length > 0)
  547. {
  548. int n = Convert.ToInt32(y.Substring(y.Length - 1, 1));
  549. z += Nums[n] + "分";
  550. }
  551. if (y.Length == 0)
  552. {
  553. if (x.Length == 0)
  554. z = "零元整";
  555. else
  556. z = "整";
  557. }
  558. string S = ""; //返回值
  559. int p = 0; //字符位置指针
  560. int m = x.Length % 4; //取模
  561. // 四位一组得到组数
  562. int k = (m > 0 ? x.Length / 4 + 1 : x.Length / 4);
  563. // 外层循环在所有组中循环
  564. // 从左到右 高位到低位 四位一组 逐组处理
  565. // 每组最后加上一个单位: "[万亿]","[亿]","[万]"
  566. for (int i = k; i > 0; i--)
  567. {
  568. int L = 4;
  569. if (i == k && m != 0)
  570. {
  571. L = m;
  572. }
  573. // 得到一组四位数 最高位组有可能不足四位
  574. string s = x.Substring(p, L);
  575. int l = s.Length;
  576. // 内层循环在该组中的每一位数上循环 从左到右 高位到低位
  577. for (int j = 0; j < l; j++)
  578. {
  579. //处理改组中的每一位数加上所在位: "仟","佰","拾",""(个)
  580. int n = Convert.ToInt32(s.Substring(j, 1));
  581. if (n == 0)
  582. {
  583. if (j < l - 1
  584. && Convert.ToInt32(s.Substring(j + 1, 1)) > 0 //后一位(右低)
  585. && !S.EndsWith(Nums[n]))
  586. {
  587. S += Nums[n];
  588. }
  589. }
  590. else
  591. {
  592. //处理 1013 一千零"十三", 1113 一千一百"一十三"
  593. if (!(n == 1 && (S.EndsWith(Nums[0]) | S.Length == 0) && j == l - 2))
  594. {
  595. S += Nums[n];
  596. }
  597. S += Digits[l - j - 1];
  598. }
  599. }
  600. p += L;
  601. // 每组最后加上一个单位: [万],[亿] 等
  602. if (i < k) //不是最高位的一组
  603. {
  604. if (Convert.ToInt32(s) != 0)
  605. {
  606. //如果所有 4 位不全是 0 则加上单位 [万],[亿] 等
  607. S += Units[i - 1];
  608. }
  609. }
  610. else
  611. {
  612. //处理最高位的一组,最后必须加上单位
  613. S += Units[i - 1];
  614. }
  615. }
  616. return S + z;
  617. }
  618. /// <summary>
  619. /// 打开其他工程中的窗体
  620. /// </summary>
  621. /// <param name="vParentFrm">主窗体 (this.MdiParent)</param>
  622. /// <param name="vKey">一般为窗体的全称 + 配置信息(可无)</param>
  623. /// <param name="vAssemblyName">程序集名</param>
  624. /// <param name="vClassName">窗体的全称</param>
  625. /// <param name="vCaption">窗体的中文名</param>
  626. public static void OpenOtherAssemblyForm(Form vParentFrm, string vKey, string vAssemblyName,
  627. string vClassName, string vCaption)
  628. {
  629. //检查窗体是否已经打开
  630. foreach (Form mdiChild in vParentFrm.MdiChildren)
  631. {
  632. if ((mdiChild as FrmBase).Key == vKey)
  633. {
  634. mdiChild.Activate();
  635. return;
  636. }
  637. }
  638. //实例化窗体并打开
  639. try
  640. {
  641. Assembly baseFormAssembly = Assembly.Load(vAssemblyName);
  642. Type type = baseFormAssembly.GetType(vClassName);
  643. System.Diagnostics.Debug.Assert(type.IsSubclassOf(typeof(FrmBase)));
  644. FrmBase form = Activator.CreateInstance(type, true) as FrmBase;
  645. form.MdiParent = vParentFrm;
  646. form.Text = vCaption;
  647. form.Key = vKey;
  648. form.Show();
  649. }
  650. catch (Exception ex)
  651. {
  652. Console.WriteLine(ex.Message);
  653. }
  654. }
  655. ///// <summary>
  656. ///// 获取当前班次
  657. ///// </summary>
  658. ///// <returns></returns>
  659. //public static string GetCurrentClass(RemotingHelp RemotingHelp)
  660. //{
  661. // string szOut = "";
  662. // CallingMessage par = new CallingMessage();
  663. // par.ServerName = "lgJobMgt";
  664. // par.AssemblyName = "Core.LgMes.Server.lgJobMgt";
  665. // par.ClassName = "Core.LgMes.Server.lgJobMgt.classCommonModule";
  666. // par.MethodName = "GetCurrDuty";
  667. // par.args = null;
  668. // object obj = ClientCommon._RemotingHelp.ExecuteMethod(par, out szOut);
  669. // if (szOut == "" && obj != null)
  670. // {
  671. // return obj as string;
  672. // }
  673. // return "";
  674. //}
  675. /// <summary>
  676. /// 班次转换
  677. /// </summary>
  678. /// <returns></returns>
  679. public static string ClassConvert(string szClassID)
  680. {
  681. if (szClassID.Trim() == "")
  682. return "";
  683. if (szClassID.Length == 2)
  684. szClassID = szClassID.Substring(1);
  685. string szClassName = "";
  686. switch (szClassID)
  687. {
  688. case "1":
  689. szClassName = "甲";
  690. break;
  691. case "2":
  692. szClassName = "乙";
  693. break;
  694. case "3":
  695. szClassName = "丙";
  696. break;
  697. case "4":
  698. szClassName = "丁";
  699. break;
  700. default:
  701. break;
  702. }
  703. return szClassName;
  704. }
  705. /// <summary>
  706. /// 时间计算返回分
  707. /// </summary>
  708. /// <param name="startTime"></param>
  709. /// <param name="endTime"></param>
  710. /// <returns></returns>
  711. public static int caculateTime(DateTime startTime, DateTime endTime)
  712. {
  713. int lStayDuration = 0;
  714. TimeSpan odtSpan;
  715. if (endTime > startTime)
  716. {
  717. odtSpan = endTime - startTime;
  718. lStayDuration = Convert.ToInt32(System.Math.Round(odtSpan.TotalMinutes));
  719. }
  720. else if (startTime != endTime)
  721. {
  722. if (startTime > DateTime.Now)
  723. lStayDuration = 0;
  724. else
  725. {
  726. odtSpan = DateTime.Now - startTime;
  727. lStayDuration = Convert.ToInt32(System.Math.Round(odtSpan.TotalMinutes));
  728. }
  729. }
  730. return lStayDuration;
  731. }
  732. /// <summary>
  733. /// 时间计算返回秒
  734. /// </summary>
  735. /// <param name="startTime"></param>
  736. /// <param name="endTime"></param>
  737. /// <returns></returns>
  738. public static int caculateTimeSeconds(DateTime startTime, DateTime endTime)
  739. {
  740. int lStayDuration = 0;
  741. TimeSpan odtSpan;
  742. if (endTime > startTime)
  743. {
  744. odtSpan = endTime - startTime;
  745. lStayDuration = Convert.ToInt32(System.Math.Round(odtSpan.TotalSeconds));
  746. }
  747. else if (startTime != endTime)
  748. {
  749. if (startTime > DateTime.Now)
  750. lStayDuration = 0;
  751. else
  752. {
  753. odtSpan = DateTime.Now - startTime;
  754. lStayDuration = Convert.ToInt32(System.Math.Round(odtSpan.TotalSeconds));
  755. }
  756. }
  757. return lStayDuration;
  758. }
  759. /// <summary>
  760. /// 获取两个时间段的差值
  761. /// </summary>
  762. /// <param name="startTime"></param>
  763. /// <param name="endTime"></param>
  764. /// <returns></returns>
  765. public static int JudgeTime(DateTime startTime, DateTime endTime)
  766. {
  767. int lStayDuration = 0;
  768. TimeSpan odtSpan;
  769. if (endTime > startTime)
  770. {
  771. odtSpan = endTime - startTime;
  772. lStayDuration = Convert.ToInt32(System.Math.Round(odtSpan.TotalMinutes));
  773. }
  774. return lStayDuration;
  775. }
  776. /// <summary>
  777. /// 将ultragrid的数据导出到Excel中
  778. /// </summary>
  779. /// <param name="ulGrid">要导出数据的ulGrid名称</param>
  780. /// <param name="sFileName">Excel文件名</param>
  781. public static void ulGridToExcel(Infragistics.Win.UltraWinGrid.UltraGrid ulGrid, string sFileName)
  782. {
  783. try
  784. {
  785. Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter ulGridExt = new Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter();
  786. ulGridExt.CellExporting += new Infragistics.Win.UltraWinGrid.ExcelExport.CellExportingEventHandler(ultraGridExcelExporter1_CellExporting);
  787. System.Windows.Forms.SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  788. if (ulGrid.Rows.Count == 0)
  789. {
  790. MessageBox.Show("没有数据!", "提示");
  791. return;
  792. }
  793. saveFileDialog1.FileName = sFileName + DateTime.Now.ToString("yyMMdd");
  794. saveFileDialog1.Filter = "Excel文件(*.xls)|*.xls";
  795. if (saveFileDialog1.ShowDialog() == DialogResult.OK)
  796. {
  797. string sFullName = saveFileDialog1.FileName;
  798. ulGridExt.Export(ulGrid, sFullName);
  799. ProcessStartInfo p = new ProcessStartInfo(sFullName);
  800. p.WorkingDirectory = Path.GetDirectoryName(sFullName);
  801. Process.Start(p);
  802. }
  803. }
  804. catch (Exception ex)
  805. {
  806. MessageBox.Show("导出失败,原因:" + ex.Message);
  807. }
  808. }
  809. /// <summary>
  810. /// 当Grid导出EXCEL时,列字段中的值为编码时,将编码转换成中文
  811. /// </summary>
  812. /// <param name="sender"></param>
  813. /// <param name="e"></param>
  814. public static void ultraGridExcelExporter1_CellExporting(object sender, Infragistics.Win.UltraWinGrid.ExcelExport.CellExportingEventArgs e)
  815. {
  816. try
  817. {
  818. if (e.GridColumn.RowLayoutColumnInfo.LabelPosition == Infragistics.Win.UltraWinGrid.LabelPosition.LabelOnly)
  819. {
  820. e.Cancel = true;
  821. }
  822. if (e.GridColumn.EditorControl != null || e.GridColumn.ValueList != null)
  823. {
  824. e.Value = e.GridRow.GetCellText(e.GridColumn);
  825. }
  826. }
  827. catch
  828. {
  829. }
  830. }
  831. /// <summary>
  832. /// 清除Grid的列过滤
  833. /// </summary>
  834. /// <param name="ulGrid">Grid名称</param>
  835. public static void ClearUlGridFilter(Infragistics.Win.UltraWinGrid.UltraGrid ulGrid)
  836. {
  837. ulGrid.DisplayLayout.Bands[0].ColumnFilters.ClearAllFilters();
  838. }
  839. /// <summary>
  840. /// 增加Grid的列过滤
  841. /// </summary>
  842. /// <param name="ulGrid"></param>
  843. public static void AddUlGridFilter(Infragistics.Win.UltraWinGrid.UltraGrid ulGrid)
  844. {
  845. ulGrid.DisplayLayout.Override.AllowRowFiltering = Infragistics.Win.DefaultableBoolean.True;
  846. }
  847. //查找treeView结点的父结点
  848. public static TreeNode findParentNode(TreeNode preLvlNode, string parentKey)
  849. {
  850. if (preLvlNode.Name == parentKey) return preLvlNode;
  851. foreach (TreeNode node in preLvlNode.Nodes)
  852. {
  853. if (node.Name.Length <= parentKey.Length)
  854. {
  855. if (node.Nodes.Count > 0)
  856. {
  857. TreeNode tNode = findParentNode(node, parentKey);
  858. if (tNode != null)
  859. return tNode;
  860. }
  861. else
  862. if (node.Name == parentKey)
  863. return node;
  864. }
  865. else
  866. return null;
  867. }
  868. return null;
  869. }
  870. }
  871. public class ValueListItem
  872. {
  873. string _id = "";
  874. string _name = "";
  875. public string ID
  876. {
  877. get { return _id; }
  878. set { _id = value; }
  879. }
  880. public string Name
  881. {
  882. get { return _name; }
  883. set { _name = value; }
  884. }
  885. public ValueListItem(string sID, string sName)
  886. {
  887. _id = sID;
  888. _name = sName;
  889. }
  890. public override string ToString()
  891. {
  892. return _name;
  893. }
  894. }
  895. }