PublicPipeAndOutdec.cs 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using CoreFS.CA06;
  6. using System.Data;
  7. using Infragistics.Win.UltraWinGrid;
  8. using Core.Mes.Client.Comm;
  9. using System.Windows.Forms;
  10. using Infragistics.Win.UltraWinEditors;
  11. using System.Collections;
  12. using Core.Mes.Client.Comm.Control;
  13. using Core.Mes.Client.Comm.Server;
  14. using Core.Mes.Client.Comm.Tool;
  15. using System.IO;
  16. using Infragistics.Win;
  17. using System.Text.RegularExpressions;
  18. namespace Core.StlMes.Client.Lims.Data.PipeAndOutdec
  19. {
  20. /// <summary>
  21. /// 自定义公共方法类
  22. /// </summary>
  23. class PublicPipeAndOutdec
  24. {
  25. //状态位
  26. //CHECKCONSIGN_BASEINFO 0委托单位未取样,1委托单位正在送样,2加工已确认
  27. //CHECKCONSIGN_DETAIL '0', '未下发', '1', '加工已下发', '2', '试验室已确认', '3', '试验室已录入', '4', '试验室已审核'
  28. public const string chemMax = "ANA_C ANA_SI ANA_MN ANA_P ANA_S ANA_NI ANA_CR ANA_MO ANA_CU ANA_AL ANA_ALS ANA_CA ANA_V ANA_NB ANA_TI ANA_O ANA_N ANA_H ANA_ZN ANA_B ANA_ZR ANA_W ANA_CO ANA_FE ANA_PB ANA_SN ANA_AS ANA_SB ANA_BI";
  29. public const string chemMin = "C Si Mn P S Ni Cr Mo Cu Al Als Ca V Nb Ti O N H Zn B Zr W Co Fe Pb Sn As Sb Bi";
  30. /// <summary>
  31. /// 筛选符合条件的DataTable
  32. /// </summary>
  33. /// <param name="dt"></param>源dt
  34. /// <returns></returns>
  35. public static DataTable GetSelectDt(DataTable dtSource, string sql)
  36. {
  37. if (dtSource != null)
  38. {
  39. DataTable dtReturn = dtSource.Clone();
  40. DataRow[] arrDrSelect = dtSource.Select(sql);
  41. if (arrDrSelect != null && arrDrSelect.Length > 0)
  42. {
  43. foreach (DataRow row in arrDrSelect)
  44. {
  45. dtReturn.Rows.Add(row.ItemArray);
  46. }
  47. }
  48. return dtReturn;
  49. }
  50. else
  51. {
  52. return null;
  53. }
  54. }
  55. /// <summary>
  56. /// 筛选符合条件的DataTable加入排序
  57. /// </summary>
  58. /// <param name="dt"></param>源dt
  59. /// <returns></returns>
  60. public static DataTable GetSelectDt(DataTable dtSource, string sql, string sort)
  61. {
  62. if (dtSource != null)
  63. {
  64. DataTable dtReturn = dtSource.Clone();
  65. DataRow[] arrDrSelect;
  66. if (sort != "")
  67. {
  68. arrDrSelect = dtSource.Select(sql, sort);
  69. }
  70. else
  71. {
  72. arrDrSelect = dtSource.Select(sql);
  73. }
  74. if (arrDrSelect != null && arrDrSelect.Length > 0)
  75. {
  76. foreach (DataRow row in arrDrSelect)
  77. {
  78. dtReturn.Rows.Add(row.ItemArray);
  79. }
  80. }
  81. return dtReturn;
  82. }
  83. else
  84. {
  85. return null;
  86. }
  87. }
  88. /// <summary>
  89. /// 比较字符串是否含某元素
  90. /// </summary>
  91. /// <param name="chemName"></param>元素名称
  92. /// <returns></returns>
  93. public static bool IsHaveChemItems(string chemName, string[] arrChems)
  94. {
  95. if (chemName == "" || arrChems.Length == 0)
  96. {
  97. return false;
  98. }
  99. else
  100. {
  101. foreach (string row in arrChems)
  102. {
  103. if (chemName == row)
  104. {
  105. return true;
  106. }
  107. }
  108. }
  109. return false;
  110. }
  111. /// <summary>
  112. /// 激活当前操作的列
  113. ///
  114. /// </summary>
  115. /// <param name="ultraGrid"></param>
  116. /// <param name="strPK"></param>主键
  117. public static void ActiveOperateRow(UltraGrid ultraGrid, string strPK, string strPKText)
  118. {
  119. for (int i = 0; i < ultraGrid.Rows.Count; i++)
  120. {
  121. if (ultraGrid.Rows[i].Cells[strPK].Text == strPKText)
  122. {
  123. ultraGrid.Rows[i].Activated = true;
  124. }
  125. }
  126. }
  127. /// <summary>
  128. /// 激活当前操作的列
  129. ///
  130. /// </summary>
  131. /// <param name="ultraGrid"></param>
  132. /// <param name="strPK"></param>多主键
  133. public static void ActiveOperateRow(UltraGrid ultraGrid, object[] strPK, object[] strPKText)
  134. {
  135. bool isEquals;
  136. for (int i = 0; i < ultraGrid.Rows.Count; i++)
  137. {
  138. isEquals = true;
  139. for (int j = 0; j < strPK.Length; j++)
  140. {
  141. if (ultraGrid.Rows[i].Cells[strPK[j].ToString()].Text != strPKText[j].ToString())
  142. {
  143. isEquals = false;
  144. break;
  145. }
  146. }
  147. if (isEquals == true)
  148. {
  149. ultraGrid.Rows[i].Activated = true;
  150. return;
  151. }
  152. }
  153. }
  154. //点击Grid编辑区显示基本信息
  155. /// <summary>
  156. /// 点击Grid编辑区显示基本信息
  157. /// </summary>
  158. /// <param name="ur"></param>
  159. /// <param name="panel"></param>
  160. public static void ShowBaseInfo(UltraGridRow ur, Panel panel)
  161. {
  162. if (ur != null)
  163. {
  164. foreach (UltraGridCell uc in ur.Cells)
  165. {
  166. if (panel.Controls["txt" + uc.Column.Key] is UltraTextEditor )
  167. {
  168. if (uc.Text.Trim() != "")
  169. {
  170. ((UltraTextEditor)panel.Controls["txt" + uc.Column.Key]).Text = uc.Text.Trim();
  171. }
  172. }
  173. else if (panel.Controls["ultra" + uc.Column.Key] is UltraTextEditor)
  174. {
  175. if (uc.Text.Trim() != "")
  176. {
  177. ((UltraTextEditor)panel.Controls["ultra" + uc.Column.Key]).Text = uc.Text.Trim();
  178. }
  179. }
  180. else if (panel.Controls["txt" + uc.Column.Key] is UltraComboEditor)
  181. {
  182. if (uc.Text.Trim() != "")
  183. {
  184. ((UltraComboEditor)panel.Controls["txt" + uc.Column.Key]).Text = uc.Text.Trim();
  185. }
  186. }
  187. else if (panel.Controls["ultra" + uc.Column.Key] is UltraComboEditor)
  188. {
  189. if (uc.Text.Trim() != "")
  190. {
  191. ((UltraComboEditor)panel.Controls["ultra" + uc.Column.Key]).Text = uc.Text.Trim();
  192. }
  193. }
  194. else if (panel.Controls["P" + uc.Column.Key] is UltraComboEditor)
  195. {
  196. if (uc.Text.Trim() != "")
  197. {
  198. ((UltraComboEditor)panel.Controls["P" + uc.Column.Key]).Value = uc.Text.Trim();
  199. }
  200. }
  201. //if (panel.Controls.ContainsKey("txt" + uc.Column.Key) == true)//判定是否存在text
  202. //{
  203. // ((UltraTextEditor)panel.Controls["txt" + uc.Column.Key]).Text = uc.Text.Trim();
  204. //}
  205. //else if (panel.Controls.ContainsKey("ultra" + uc.Column.Key) == true)//判定是否存在text
  206. //{
  207. // ((UltraComboEditor)panel.Controls["ultra" + uc.Column.Key]).Text = uc.Text.Trim();
  208. //}
  209. }
  210. }
  211. }
  212. //点击Grid编辑区显示基本信息
  213. /// <summary>
  214. /// 点击Grid编辑区显示基本信息
  215. /// </summary>
  216. /// <param name="dt"></param>
  217. /// <param name="panel"></param>
  218. public static void ShowDataTaleInfo(DataTable dt, Panel panel)
  219. {
  220. foreach (DataColumn dc in dt.Columns)
  221. {
  222. if (panel.Controls.ContainsKey("txt" + dc.ColumnName) == true)//判定是否存在text
  223. {
  224. ((UltraTextEditor)panel.Controls["txt" + dc.ColumnName]).Text = dt.Rows[0][dc.ColumnName].ToString();
  225. }
  226. else if (panel.Controls.ContainsKey("ultra" + dc.ColumnName) == true)//判定是否存在text
  227. {
  228. ((UltraComboEditor)panel.Controls["ultra" + dc.ColumnName]).Text = dt.Rows[0][dc.ColumnName].ToString();
  229. }
  230. }
  231. }
  232. /// <summary>
  233. /// 隐藏空列
  234. /// </summary>
  235. /// <param name="strHidden"></param>本来就隐藏的列名集合
  236. /// <param name="ug"></param>需要操作的UltraGrid
  237. /// <param name="dt"></param>需要操作的dt
  238. private void HideNullColumn(string strHidden, UltraGrid ultraGrid, DataTable dataTable)
  239. {
  240. if (strHidden != "")
  241. {
  242. foreach (DataColumn dc in dataTable.Columns)
  243. {
  244. if (strHidden.IndexOf(dc.ColumnName) >= 0)
  245. {
  246. continue;
  247. }
  248. foreach (DataRow dr in dataTable.Rows)
  249. {
  250. if (dr[dc].ToString() != "")
  251. {
  252. ultraGrid.DisplayLayout.Bands[0].Columns[dc.ColumnName].Hidden = false;
  253. break;
  254. }
  255. else
  256. {
  257. ultraGrid.DisplayLayout.Bands[0].Columns[dc.ColumnName].Hidden = true;
  258. }
  259. }
  260. }
  261. }
  262. else
  263. {
  264. foreach (DataColumn dc in dataTable.Columns)
  265. {
  266. foreach (DataRow dr in dataTable.Rows)
  267. {
  268. if (dr[dc].ToString() != "")
  269. {
  270. ultraGrid.DisplayLayout.Bands[0].Columns[dc.ColumnName].Hidden = false;
  271. break;
  272. }
  273. else
  274. {
  275. ultraGrid.DisplayLayout.Bands[0].Columns[dc.ColumnName].Hidden = true;
  276. }
  277. }
  278. }
  279. }
  280. }
  281. /// <summary>
  282. /// UltraGrid可读
  283. /// </summary>
  284. /// <param name="ugr">UltraGrid</param>
  285. /// <param name="keys">可编辑列</param>
  286. public static void setOtherColumnReadOnly(UltraGrid ugr, string[] keys)
  287. {
  288. if (keys == null || keys.Length == 0)
  289. {
  290. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  291. {
  292. ugc.CellActivation = Activation.ActivateOnly;
  293. }
  294. }
  295. else
  296. {
  297. keys.ToArray();
  298. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  299. {
  300. if (!keys.Contains(ugc.Key))
  301. {
  302. ugc.CellActivation = Activation.ActivateOnly;
  303. }
  304. else
  305. {
  306. ugc.CellAppearance.BackColor = System.Drawing.Color.FromArgb(255, 255, 192);//可编辑列设置颜色为浅黄色
  307. ugc.CellActivation = Activation.AllowEdit;
  308. }
  309. }
  310. }
  311. if (ugr.DisplayLayout.Bands[0].Columns.Exists("CHK"))
  312. {
  313. ugr.DisplayLayout.Bands[0].Columns["CHK"].DefaultCellValue = "False";
  314. ugr.DisplayLayout.Bands[0].Columns["CHK"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always;
  315. ugr.DisplayLayout.Bands[0].Columns["CHK"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
  316. }
  317. }
  318. /// <summary>
  319. /// UltraGrid可读
  320. /// </summary>
  321. /// <param name="ugr">UltraGrid</param>
  322. /// <param name="keys">可编辑列</param>
  323. public static void setOtherColumnReadOnly(UltraGrid ugr, string[] keys, int bandNum)
  324. {
  325. if (bandNum < 0 || ugr.DisplayLayout.Bands.Count < bandNum + 1)
  326. {
  327. return;
  328. }
  329. if (keys == null || keys.Length == 0)
  330. {
  331. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[bandNum].Columns)
  332. {
  333. ugc.CellActivation = Activation.ActivateOnly;
  334. }
  335. }
  336. else
  337. {
  338. keys.ToArray();
  339. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[bandNum].Columns)
  340. {
  341. if (!keys.Contains(ugc.Key))
  342. {
  343. ugc.CellActivation = Activation.ActivateOnly;
  344. }
  345. else
  346. {
  347. ugc.CellAppearance.BackColor = System.Drawing.Color.FromArgb(255, 255, 192);//可编辑列设置颜色为浅黄色
  348. //ugc.CellActivation = Activation.AllowEdit;
  349. }
  350. }
  351. }
  352. if (ugr.DisplayLayout.Bands[bandNum].Columns.Exists("CHK"))
  353. {
  354. ugr.DisplayLayout.Bands[bandNum].Columns["CHK"].DefaultCellValue = "False";
  355. ugr.DisplayLayout.Bands[bandNum].Columns["CHK"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always;
  356. ugr.DisplayLayout.Bands[bandNum].Columns["CHK"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
  357. }
  358. }
  359. /// <summary>
  360. /// UltraGrid列是否隐藏
  361. /// </summary>isShow 为true则显示其他隐藏,false则隐藏其他显示
  362. /// <param name="ugr">UltraGrid</param>
  363. /// <param name="keys">隐藏列</param>
  364. public static void setColumnShowOrHidden(UltraGrid ugr, string[] keys, bool isShow)
  365. {
  366. if (keys == null || keys.Length == 0)
  367. {
  368. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  369. {
  370. ugc.Hidden = false;
  371. }
  372. }
  373. else
  374. {
  375. keys.ToArray();
  376. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  377. {
  378. if (keys.Contains(ugc.Key))
  379. {
  380. if (isShow)
  381. {
  382. ugc.Hidden = false;
  383. }
  384. else
  385. {
  386. ugc.Hidden = true;
  387. }
  388. }
  389. else
  390. {
  391. if (isShow)
  392. {
  393. ugc.Hidden = true;
  394. }
  395. }
  396. }
  397. }
  398. }
  399. /// <summary>
  400. /// UltraGrid列是否隐藏
  401. /// </summary>isShow 为true则显示其他隐藏,false则隐藏其他显示
  402. /// <param name="ugr">UltraGrid</param>
  403. /// <param name="keys">隐藏列</param>
  404. public static void setColumnShowOrHidden(UltraGrid ugr, string[] keys, bool isShow, int bandNum)
  405. {
  406. if (bandNum < 0 || ugr.DisplayLayout.Bands.Count < bandNum + 1)
  407. {
  408. return;
  409. }
  410. if (keys == null || keys.Length == 0)
  411. {
  412. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[bandNum].Columns)
  413. {
  414. ugc.Hidden = false;
  415. }
  416. }
  417. else
  418. {
  419. keys.ToArray();
  420. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[bandNum].Columns)
  421. {
  422. if (keys.Contains(ugc.Key))
  423. {
  424. if (isShow)
  425. {
  426. ugc.Hidden = false;
  427. }
  428. else
  429. {
  430. ugc.Hidden = true;
  431. }
  432. }
  433. else
  434. {
  435. if (isShow)
  436. {
  437. ugc.Hidden = true;
  438. }
  439. }
  440. }
  441. }
  442. }
  443. //初始化列
  444. /// <summary>
  445. /// 初始化列
  446. /// </summary>
  447. /// <param name="arrColumns"></param>
  448. /// <param name="arrCaption"></param>
  449. /// <param name="dataTable1"></param>
  450. public static void InitColumns(string[] arrColumns, string[] arrCaption, DataTable dataTable1)
  451. {
  452. if (arrColumns.Length == 0 || arrColumns.Length != arrCaption.Length)
  453. {
  454. return;
  455. }
  456. dataTable1.Columns.Clear();//先清除
  457. DataColumn dc;
  458. for (int i = 0; i < arrColumns.Length; i++)
  459. {
  460. try
  461. {
  462. dc = new DataColumn(arrColumns[i]);
  463. dc.Caption = arrCaption[i];
  464. dataTable1.Columns.Add(dc);
  465. if (dc.ColumnName == "CHK")
  466. {
  467. dc.DataType = typeof(bool);
  468. dc.DefaultValue = "False";
  469. }
  470. }
  471. catch
  472. {
  473. continue;
  474. }
  475. }
  476. }
  477. //初始化列
  478. /// <summary>
  479. /// 初始化列
  480. /// </summary>
  481. /// <param name="arrColumns"></param>
  482. /// <param name="chemMax"></param>
  483. /// <param name="arrCaption"></param>
  484. /// <param name="chemMin"></param>
  485. /// <param name="dataTable1"></param>
  486. public static void InitColumns(string[] arrColumns, string[] chemMax, object[] arrCaption, string[] chemMin, DataTable dataTable1)
  487. {
  488. if (arrColumns.Length == 0 || arrColumns.Length != arrCaption.Length || chemMax.Length != chemMin.Length)
  489. {
  490. return;
  491. }
  492. dataTable1.Columns.Clear();//先清除
  493. DataColumn dc;
  494. for (int i = 0; i < arrColumns.Length; i++)
  495. {
  496. try
  497. {
  498. dc = new DataColumn(arrColumns[i].ToString());
  499. dc.Caption = arrCaption[i].ToString();
  500. dataTable1.Columns.Add(dc);
  501. if (dc.ColumnName == "CHK")
  502. {
  503. dc.DataType = typeof(bool);
  504. dc.DefaultValue = "False";
  505. }
  506. }
  507. catch
  508. {
  509. continue;
  510. }
  511. }
  512. for (int i = 0; i < chemMax.Length; i++)
  513. {
  514. try
  515. {
  516. dc = new DataColumn(chemMax[i]);
  517. dc.Caption = chemMin[i];
  518. dataTable1.Columns.Add(dc);
  519. }
  520. catch
  521. {
  522. continue;
  523. }
  524. }
  525. }
  526. public static void InitColumns(string[] arrColumns, string[] arrCaption, DataTable dataTable, UltraGrid ultraGrid, string[] show, bool isShow, string[] ope)
  527. {
  528. InitColumns(arrColumns, arrCaption, dataTable);
  529. setColumnShowOrHidden(ultraGrid, show, isShow);
  530. setOtherColumnReadOnly(ultraGrid, ope);
  531. }
  532. //隐藏空列
  533. /// <summary>
  534. ///
  535. ///
  536. /// </summary>
  537. /// <param name="strHidden"></param>需要判断的列
  538. /// <param name="ug"></param>
  539. public static void HideNullColumn(string strHidden, UltraGrid ug)
  540. {
  541. string[] arr = strHidden.Split(',');
  542. for (int i = 0; i < arr.Length; i++)
  543. {
  544. if (!ug.DisplayLayout.Bands[0].Columns.Exists(arr[i]))
  545. {
  546. continue;
  547. }
  548. foreach (UltraGridRow ur in ug.Rows)
  549. {
  550. if (ur.Cells[arr[i]].Text != "")
  551. {
  552. ug.DisplayLayout.Bands[0].Columns[arr[i]].Hidden = false;
  553. break;
  554. }
  555. else
  556. {
  557. ug.DisplayLayout.Bands[0].Columns[arr[i]].Hidden = true;
  558. }
  559. }
  560. }
  561. }
  562. //选择事件
  563. /// <summary>
  564. ///
  565. ///
  566. /// </summary>
  567. /// <param name="strHidden"></param>
  568. /// <param name="ug"></param>
  569. public static void SelectRow(UltraGrid ultraGrid)
  570. {
  571. if (ultraGrid.DisplayLayout.Bands[0].Columns.Exists("CHK"))
  572. {
  573. foreach (UltraGridRow uRow in ultraGrid.Selected.Rows)
  574. {
  575. if (uRow.GetType() != typeof(Infragistics.Win.UltraWinGrid.UltraGridGroupByRow))
  576. {
  577. uRow.Cells["CHK"].Value = true;
  578. }
  579. }
  580. }
  581. }
  582. public static void ReMoveColumns(DataTable dataTable, int position)
  583. {
  584. //从0开始
  585. int dcNum = dataTable.Columns.Count;
  586. if (dcNum > position)
  587. {
  588. for (int i = 0; i < dcNum - position; i++)
  589. {
  590. dataTable.Columns.RemoveAt(position);
  591. }
  592. }
  593. }
  594. //自适应
  595. private void RefreshAutoSize(UltraGrid ultraGrid1)
  596. {
  597. ultraGrid1.DisplayLayout.Bands[0].Columns[0].Width = 80;
  598. for (int i = 1; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
  599. {
  600. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Width = 60;//设置列宽
  601. }
  602. }
  603. /// <summary>
  604. /// 设置列宽
  605. /// </summary>
  606. /// <param name="dt"></param>需要设置的UltraGrid
  607. /// <param name="haveNum"></param>不需要清除的列
  608. /// /// <param name="width"></param>宽度
  609. public static void ColumnsWidth(UltraGrid ultraGrid, int haveNum, int width)
  610. {
  611. int col = ultraGrid.DisplayLayout.Bands[0].Columns.Count;
  612. for (int i = haveNum; i < col; i++)
  613. {
  614. ultraGrid.DisplayLayout.Bands[0].Columns[i].Width = width;//设置列宽
  615. }
  616. }
  617. /// <summary>
  618. /// 设置列宽
  619. /// </summary>
  620. /// <param name="dt"></param>需要设置的UltraGrid
  621. /// <param name="haveNum"></param>不需要清除的列
  622. /// /// <param name="width"></param>宽度
  623. public static void ColumnsWidth(UltraGrid ultraGrid, int haveNum, int width, string[] noSet)
  624. {
  625. ArrayList al = new ArrayList();
  626. for (int i = 0; i < noSet.Length; i++)
  627. {
  628. al.Add(noSet[i]);
  629. }
  630. int col = ultraGrid.DisplayLayout.Bands[0].Columns.Count;
  631. for (int i = haveNum; i < col; i++)
  632. {
  633. if (!al.Contains(ultraGrid.DisplayLayout.Bands[0].Columns[i].ToString()))
  634. {
  635. ultraGrid.DisplayLayout.Bands[0].Columns[i].Width = width;//设置列宽
  636. }
  637. }
  638. }
  639. /// <summary>
  640. /// 刷新Grid数据并根据数据调整Grid列宽
  641. /// </summary>
  642. /// <param name="ultraGrid">需要处理的Grid</param>
  643. /// <param name="cols">需要调整的列</param>
  644. /// <param name="is调整">true则自适应,false则不自适应</param>
  645. public static void RefreshAndAutoSizeColumns(Infragistics.Win.UltraWinGrid.UltraGrid ultraGrid, object[] cols, bool isMove)
  646. {
  647. try
  648. {
  649. ultraGrid.DataBind();
  650. foreach (Infragistics.Win.UltraWinGrid.UltraGridBand band in ultraGrid.DisplayLayout.Bands)
  651. {
  652. foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn column in band.Columns)
  653. {
  654. if (cols != null && cols.Contains(column.Key))
  655. {
  656. if (!isMove)
  657. {
  658. continue;
  659. }
  660. column.PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand);//AllRowsInBand
  661. }
  662. else
  663. {
  664. if (!isMove)
  665. {
  666. column.PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand);
  667. }
  668. }
  669. }
  670. }
  671. ultraGrid.Refresh();
  672. }
  673. catch { }
  674. }
  675. //改变splitContainer1.Panel1
  676. /// <summary>
  677. /// 改变splitContainer1.Panel1
  678. /// </summary>
  679. /// <param name="splitContainer"></param>
  680. /// <param name="dtPhyMax"></param>
  681. public static void ChangeSplit(SplitContainer splitContainer, DataTable dtPhyMax)
  682. {
  683. if (dtPhyMax != null && dtPhyMax.Rows.Count > 0)
  684. {
  685. splitContainer.Panel1Collapsed = false;
  686. }
  687. else
  688. {
  689. splitContainer.Panel1Collapsed = true; ;
  690. }
  691. }
  692. //如果用户为admin默认试验室数据权限
  693. /// <summary>
  694. /// 如果用户为admin默认试验室数据权限
  695. /// </summary>
  696. /// <returns></returns>
  697. public static string[] ValidData()
  698. {
  699. string[] arrId = new string[7] { "002001007009", "002001007015", "002001007013", "002001007014", "002001007010", "002001020001", "002001020002" };
  700. //DECODE(T.DEPT_ID,
  701. // '002001007009',
  702. // '力学',
  703. // '002001007015',
  704. // '金相',
  705. // '002001007013',
  706. // '腐蚀',
  707. // '002001007014',
  708. // '工程',
  709. // '002001007010',
  710. // '化学',
  711. // '002001020001',
  712. // '一快分',
  713. // '002001020002',
  714. // '二快分')
  715. return arrId;
  716. }
  717. /// <summary>
  718. /// 绑定下拉框
  719. /// </summary>
  720. /// <param name="uce"></param>
  721. /// <param name="methodId"></param>
  722. /// <param name="valueMember"></param>
  723. /// <param name="ob"></param>
  724. /// <param name="isEmpty"></param>
  725. public static void InitComboEditor(UltraComboEditor uce, string methodId, string valueMember, OpeBase ob, bool isEmpty)
  726. {
  727. DataTable dt = ServerHelper.GetData(methodId, null, ob);
  728. if (dt != null && dt.Rows.Count > 0)
  729. {
  730. if (isEmpty)
  731. {
  732. Object[] obj = new Object[] { "", "" };
  733. DataRow dr = dt.NewRow();
  734. dr.ItemArray = obj;
  735. dt.Rows.InsertAt(dr, 0);
  736. }
  737. uce.DataSource = dt;
  738. uce.ValueMember = valueMember;
  739. SetComboItemHeight(uce);
  740. }
  741. }
  742. /// <summary>
  743. /// 设置UltraComboEditor中的中文和非中文统一高度。
  744. /// </summary>
  745. /// <param name="cmb"></param>
  746. public static void SetComboItemHeight(UltraComboEditor cmb)
  747. {
  748. cmb.Update();
  749. foreach (ValueListItem item in cmb.Items)
  750. {
  751. if (Regex.IsMatch(item.DisplayText, @"[\u4e00-\u9fa5]+"))
  752. {
  753. item.Appearance.FontData.SizeInPoints = 9.0F;
  754. }
  755. else
  756. {
  757. item.Appearance.FontData.SizeInPoints = 10.5F;
  758. }
  759. }
  760. }
  761. //解析数据权限
  762. /// <summary>
  763. /// 解析数据权限
  764. /// </summary>
  765. /// <param name="arrId"></param>
  766. /// <returns></returns>
  767. public static string ValidDataString(string[] arrId)
  768. {
  769. string strId = "";
  770. if (arrId != null)
  771. {
  772. foreach (string str in arrId)
  773. {
  774. strId += "'" + str + "',";
  775. }
  776. }
  777. strId = strId.Remove(0, 1);
  778. strId = strId.Remove(strId.Length - 2);
  779. return strId;
  780. }
  781. // 路径组成 Lims + 界面名称 + 文件名 "Lims/data/base/";
  782. /// <summary>
  783. /// 路径组成 Lims + 界面名称 + 文件名 "Lims/data/base/";
  784. /// </summary>
  785. /// <param name="strPath"></param>
  786. /// <returns></returns>
  787. public static string GetFilePath(string strPath)
  788. {
  789. return "";
  790. }
  791. /// <summary>
  792. /// 更改文件路径
  793. /// </summary>
  794. /// <param name="Department">user_depatment</param>
  795. /// <returns></returns>
  796. public static void UpdateFilePosition(string strTableName, string strPath, string strPk, string strPkValue, OpeBase ob)
  797. {
  798. try
  799. {
  800. string sql = "UPDATE " + strTableName + " SET FILE_POSITION = '" + strPath + "' WHERE " + strPk + " = '" + strPkValue + "'";
  801. PublicServer.SetData("com.steering.BaseInfo.UpdateFilePosition", new Object[] { sql }, ob);
  802. }
  803. catch
  804. {
  805. }
  806. }
  807. /// <summary>
  808. /// 查看文件路径
  809. /// </summary>
  810. /// <param name="Department">user_depatment</param>
  811. /// <returns></returns>
  812. public static bool ViewFilePosition(OpeBase _ob, string path)
  813. {
  814. bool isSucc = true;
  815. FormFileDown down = new FormFileDown(_ob, path);
  816. down.ShowDialog();
  817. if (down.CtrlFileDown1.List.Count == 0)
  818. {
  819. isSucc = false;//删除了则更新FILE_POSITION
  820. }
  821. return isSucc;
  822. }
  823. /// <summary>
  824. /// 上传文件路径
  825. /// </summary>
  826. /// <param name="Department">user_depatment</param>
  827. /// <returns></returns>
  828. public static bool UploadFilePosition(OpeBase _ob, string path)
  829. {
  830. //var serverFileList = FileHelper.Download(path);
  831. //if (serverFileList.Count > 0)
  832. //{
  833. // MessageUtil.ShowWarning("该记录已存在一份文件,请删除后再重新上传!");
  834. // return false;
  835. //}
  836. List<FileBean> list = new List<FileBean>();
  837. FileBean bean = new FileBean();
  838. OpenFileDialog file = new OpenFileDialog();
  839. file.Multiselect = false;
  840. DialogResult drStat;
  841. drStat = file.ShowDialog();
  842. if (drStat == DialogResult.OK)
  843. {
  844. string filePath = file.FileName;
  845. string fileName = System.IO.Path.GetFileName(filePath);
  846. bean = new FileBean();
  847. bean.setFileName(fileName);
  848. bean.setPathName(path);
  849. bean.setFile(FileHelper.FileToArray(filePath));
  850. list.Add(bean);
  851. bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  852. if (isSuccess)
  853. {
  854. MessageUtil.ShowTips("上传成功!");
  855. }
  856. else
  857. {
  858. MessageUtil.ShowTips("上传失败,请重试!");
  859. }
  860. return isSuccess;//成功了则更新FILE_POSITION
  861. }
  862. return false;
  863. }
  864. //调用本地程序打开查看服务器文件
  865. /// <summary>
  866. /// 调用本地程序打开查看服务器文件
  867. /// </summary>
  868. /// <param name="pathName"></param>
  869. public static void ViewCarft_No(string pathName)
  870. {
  871. try
  872. {
  873. //删除本地文件
  874. string tmpPath = Environment.CurrentDirectory + "\\Tmp\\";
  875. DirectoryInfo di = new DirectoryInfo(tmpPath);
  876. if (di.Exists == false)
  877. {
  878. di.Create();
  879. return;
  880. }
  881. foreach (FileInfo fi in di.GetFiles())
  882. {
  883. try
  884. {
  885. fi.Delete();
  886. }
  887. catch { continue; }
  888. }
  889. //下载写入本地Tmp目录
  890. if (pathName == "" || pathName == null) return;
  891. List<FileBean> list = Core.Mes.Client.Comm.Server.FileHelper.Download(pathName);
  892. foreach (FileBean bean in list)
  893. {
  894. FileStream fs = new FileStream(tmpPath + bean.getFileName(), FileMode.Create);
  895. fs.Write(bean.getFile(), 0, bean.getFile().Length);
  896. fs.Flush();
  897. fs.Close();
  898. System.Diagnostics.Process MyProcess = new System.Diagnostics.Process();
  899. MyProcess.StartInfo.FileName = tmpPath + bean.getFileName();
  900. MyProcess.StartInfo.Verb = "Open";
  901. MyProcess.StartInfo.CreateNoWindow = true;
  902. MyProcess.Start();
  903. return;
  904. }
  905. }
  906. catch { }
  907. }
  908. }
  909. }