PublicPur.cs 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063
  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 Infragistics.Win;
  16. using System.Drawing;
  17. namespace Pur.PublicTools
  18. {
  19. /// <summary>
  20. /// 自定义公共方法类
  21. /// </summary>
  22. class PublicPur
  23. {
  24. /// <summary>
  25. /// 筛选符合条件的DataTable
  26. /// </summary>
  27. /// <param name="dt"></param>源dt
  28. /// <returns></returns>
  29. public static DataTable GetSelectDt(DataTable dtSource, string sql)
  30. {
  31. if (dtSource != null)
  32. {
  33. DataTable dtReturn = dtSource.Clone();
  34. DataRow[] arrDrSelect = dtSource.Select(sql);
  35. if (arrDrSelect != null && arrDrSelect.Length > 0)
  36. {
  37. foreach (DataRow row in arrDrSelect)
  38. {
  39. dtReturn.Rows.Add(row.ItemArray);
  40. }
  41. }
  42. return dtReturn;
  43. }
  44. else
  45. {
  46. return null;
  47. }
  48. }
  49. /// <summary>
  50. /// 筛选符合条件的DataTable加入排序
  51. /// </summary>
  52. /// <param name="dt"></param>源dt
  53. /// <returns></returns>
  54. public static DataTable GetSelectDt(DataTable dtSource, string sql, string sort)
  55. {
  56. if (dtSource != null)
  57. {
  58. DataTable dtReturn = dtSource.Clone();
  59. DataRow[] arrDrSelect;
  60. if (sort != "")
  61. {
  62. arrDrSelect = dtSource.Select(sql, sort);
  63. }
  64. else
  65. {
  66. arrDrSelect = dtSource.Select(sql);
  67. }
  68. if (arrDrSelect != null && arrDrSelect.Length > 0)
  69. {
  70. foreach (DataRow row in arrDrSelect)
  71. {
  72. dtReturn.Rows.Add(row.ItemArray);
  73. }
  74. }
  75. return dtReturn;
  76. }
  77. else
  78. {
  79. return null;
  80. }
  81. }
  82. /// <summary>
  83. /// 比较字符串是否含某元素
  84. /// </summary>
  85. /// <param name="chemName"></param>元素名称
  86. /// <returns></returns>
  87. public static bool IsHaveChemItems(string chemName, string[] arrChems)
  88. {
  89. if (chemName == "" || arrChems.Length == 0)
  90. {
  91. return false;
  92. }
  93. else
  94. {
  95. foreach (string row in arrChems)
  96. {
  97. if (chemName == row)
  98. {
  99. return true;
  100. }
  101. }
  102. }
  103. return false;
  104. }
  105. /// <summary>
  106. /// 激活当前操作的列
  107. ///
  108. /// </summary>
  109. /// <param name="ultraGrid"></param>
  110. /// <param name="strPK"></param>主键
  111. public static void ActiveOperateRow(UltraGrid ultraGrid, string strPK, string strPKText)
  112. {
  113. for (int i = 0; i < ultraGrid.Rows.Count; i++)
  114. {
  115. if (ultraGrid.Rows[i].Cells[strPK].Text == strPKText)
  116. {
  117. ultraGrid.Rows[i].Activated = true;
  118. }
  119. }
  120. }
  121. /// <summary>
  122. /// 激活当前操作的列
  123. ///
  124. /// </summary>
  125. /// <param name="ultraGrid"></param>
  126. /// <param name="strPK"></param>多主键
  127. public static void ActiveOperateRow(UltraGrid ultraGrid, object[] strPK, object[] strPKText)
  128. {
  129. bool isEquals;
  130. for (int i = 0; i < ultraGrid.Rows.Count; i++)
  131. {
  132. isEquals = true;
  133. for (int j = 0; j < strPK.Length; j++)
  134. {
  135. if (ultraGrid.Rows[i].Cells[strPK[j].ToString()].Text != strPKText[j].ToString())
  136. {
  137. isEquals = false;
  138. break;
  139. }
  140. }
  141. if (isEquals == true)
  142. {
  143. ultraGrid.Rows[i].Activated = true;
  144. return;
  145. }
  146. }
  147. }
  148. //点击Grid编辑区显示基本信息
  149. public static void ShowBaseInfo(UltraGridRow ur, Panel panel)
  150. {
  151. if (ur != null)
  152. {
  153. foreach (UltraGridCell uc in ur.Cells)
  154. {
  155. if (panel.Controls.ContainsKey("txt" + uc.Column.Key) == true)//判定是否存在text
  156. {
  157. ((UltraTextEditor)panel.Controls["txt" + uc.Column.Key]).Text = uc.Text.Trim();
  158. }
  159. else if (panel.Controls.ContainsKey("ultra" + uc.Column.Key) == true)//判定是否存在text
  160. {
  161. ((UltraComboEditor)panel.Controls["ultra" + uc.Column.Key]).Text = uc.Text.Trim();
  162. }
  163. }
  164. }
  165. }
  166. //点击Grid编辑区显示基本信息
  167. public static void ShowDataTaleInfo(DataTable dt, Panel panel)
  168. {
  169. foreach (DataColumn dc in dt.Columns)
  170. {
  171. if (panel.Controls.ContainsKey("txt" + dc.ColumnName) == true)//判定是否存在text
  172. {
  173. }
  174. if (panel.Controls.ContainsKey("txt" + dc.ColumnName) == true)//判定是否存在text
  175. {
  176. ((UltraTextEditor)panel.Controls["txt" + dc.ColumnName]).Text = dt.Rows[0][dc.ColumnName].ToString();
  177. }
  178. else if (panel.Controls.ContainsKey("ultra" + dc.ColumnName) == true)//判定是否存在text
  179. {
  180. ((UltraComboEditor)panel.Controls["ultra" + dc.ColumnName]).Text = dt.Rows[0][dc.ColumnName].ToString();
  181. }
  182. }
  183. }
  184. //点击Grid编辑区显示基本信息
  185. public static void ClearBaseInfo(Panel panel, string[] cols)
  186. {
  187. if (cols != null)
  188. {
  189. foreach (string col in cols)
  190. {
  191. if (panel.Controls.ContainsKey("txt" + col) == true)//判定是否存在text && panel.Controls.ContainsKey("txt" + col).GetType(). == UltraTextEditor
  192. {
  193. ((UltraTextEditor)panel.Controls["txt" + col]).Text = "";
  194. }
  195. else if (panel.Controls.ContainsKey("ultra" + col) == true)//判定是否存在text && panel.Controls.ContainsKey("txt" + col).GetType(). == UltraTextEditor
  196. {
  197. ((UltraTextEditor)panel.Controls["ultra" + col]).Text = "";
  198. }
  199. }
  200. }
  201. }
  202. /// <summary>
  203. /// 隐藏空列
  204. /// </summary>
  205. /// <param name="strHidden"></param>本来就隐藏的列名集合
  206. /// <param name="ug"></param>需要操作的UltraGrid
  207. /// <param name="dt"></param>需要操作的dt
  208. private void HideNullColumn(string strHidden, UltraGrid ultraGrid, DataTable dataTable)
  209. {
  210. if (strHidden != "")
  211. {
  212. foreach (DataColumn dc in dataTable.Columns)
  213. {
  214. if (strHidden.IndexOf(dc.ColumnName) >= 0)
  215. {
  216. continue;
  217. }
  218. foreach (DataRow dr in dataTable.Rows)
  219. {
  220. if (dr[dc].ToString() != "")
  221. {
  222. ultraGrid.DisplayLayout.Bands[0].Columns[dc.ColumnName].Hidden = false;
  223. break;
  224. }
  225. else
  226. {
  227. ultraGrid.DisplayLayout.Bands[0].Columns[dc.ColumnName].Hidden = true;
  228. }
  229. }
  230. }
  231. }
  232. else
  233. {
  234. foreach (DataColumn dc in dataTable.Columns)
  235. {
  236. foreach (DataRow dr in dataTable.Rows)
  237. {
  238. if (dr[dc].ToString() != "")
  239. {
  240. ultraGrid.DisplayLayout.Bands[0].Columns[dc.ColumnName].Hidden = false;
  241. break;
  242. }
  243. else
  244. {
  245. ultraGrid.DisplayLayout.Bands[0].Columns[dc.ColumnName].Hidden = true;
  246. }
  247. }
  248. }
  249. }
  250. }
  251. /// <summary>
  252. /// UltraGrid可读
  253. /// </summary>
  254. /// <param name="ugr">UltraGrid</param>
  255. /// <param name="keys">可编辑列</param>
  256. public static void setOtherColumnReadOnly(UltraGrid ugr, string[] keys)
  257. {
  258. if (keys == null || keys.Length == 0)
  259. {
  260. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  261. {
  262. ugc.CellActivation = Activation.ActivateOnly;
  263. }
  264. }
  265. else
  266. {
  267. keys.ToArray();
  268. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  269. {
  270. if (!keys.Contains(ugc.Key))
  271. {
  272. ugc.CellActivation = Activation.ActivateOnly;
  273. }
  274. //else
  275. //{
  276. // ugc.CellActivation = Activation.AllowEdit;
  277. //}
  278. }
  279. }
  280. if (ugr.DisplayLayout.Bands[0].Columns.Exists("CHK"))
  281. {
  282. ugr.DisplayLayout.Bands[0].Columns["CHK"].DefaultCellValue = "False";
  283. ugr.DisplayLayout.Bands[0].Columns["CHK"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always;
  284. ugr.DisplayLayout.Bands[0].Columns["CHK"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
  285. }
  286. }
  287. /// <summary>
  288. /// UltraGrid可读
  289. /// </summary>
  290. /// <param name="ugr">UltraGrid</param>
  291. /// <param name="keys">可编辑列</param>
  292. public static void setOtherColumnReadOnly(UltraGrid ugr, string[] keys, int bandNum)
  293. {
  294. if (bandNum < 0 || ugr.DisplayLayout.Bands.Count < bandNum + 1)
  295. {
  296. return;
  297. }
  298. if (keys == null || keys.Length == 0)
  299. {
  300. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[bandNum].Columns)
  301. {
  302. ugc.CellActivation = Activation.ActivateOnly;
  303. }
  304. }
  305. else
  306. {
  307. keys.ToArray();
  308. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[bandNum].Columns)
  309. {
  310. if (!keys.Contains(ugc.Key))
  311. {
  312. ugc.CellActivation = Activation.ActivateOnly;
  313. }
  314. }
  315. }
  316. if (ugr.DisplayLayout.Bands[bandNum].Columns.Exists("CHK"))
  317. {
  318. ugr.DisplayLayout.Bands[bandNum].Columns["CHK"].DefaultCellValue = "False";
  319. ugr.DisplayLayout.Bands[bandNum].Columns["CHK"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.Always;
  320. ugr.DisplayLayout.Bands[bandNum].Columns["CHK"].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.CheckBox;
  321. }
  322. }
  323. /// <summary>
  324. /// UltraGrid列是否隐藏
  325. /// </summary>isShow 为true则显示其他隐藏,false则隐藏其他显示
  326. /// <param name="ugr">UltraGrid</param>
  327. /// <param name="keys">隐藏列</param>
  328. public static void setColumnShowOrHidden(UltraGrid ugr, string[] keys, bool isShow)
  329. {
  330. if (keys == null || keys.Length == 0)
  331. {
  332. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  333. {
  334. ugc.Hidden = false;
  335. }
  336. }
  337. else
  338. {
  339. keys.ToArray();
  340. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  341. {
  342. if (keys.Contains(ugc.Key))
  343. {
  344. if (isShow)
  345. {
  346. ugc.Hidden = false;
  347. }
  348. else
  349. {
  350. ugc.Hidden = true;
  351. }
  352. }
  353. else
  354. {
  355. if (isShow)
  356. {
  357. ugc.Hidden = true;
  358. }
  359. }
  360. }
  361. }
  362. }
  363. /// <summary>
  364. /// UltraGrid列是否隐藏
  365. /// </summary>isShow 为true则显示其他隐藏,false则隐藏其他显示
  366. /// <param name="ugr">UltraGrid</param>
  367. /// <param name="keys">隐藏列</param>
  368. public static void setColumnShowOrHidden(UltraGrid ugr, string[] keys, bool isShow, int bandNum)
  369. {
  370. if (bandNum < 0 || ugr.DisplayLayout.Bands.Count < bandNum + 1)
  371. {
  372. return;
  373. }
  374. if (keys == null || keys.Length == 0)
  375. {
  376. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[bandNum].Columns)
  377. {
  378. ugc.Hidden = false;
  379. }
  380. }
  381. else
  382. {
  383. keys.ToArray();
  384. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[bandNum].Columns)
  385. {
  386. if (keys.Contains(ugc.Key))
  387. {
  388. if (isShow)
  389. {
  390. ugc.Hidden = false;
  391. }
  392. else
  393. {
  394. ugc.Hidden = true;
  395. }
  396. }
  397. else
  398. {
  399. if (isShow)
  400. {
  401. ugc.Hidden = true;
  402. }
  403. }
  404. }
  405. }
  406. }
  407. //初始化列
  408. public static void InitColumns(string[] arrColumns, string[] arrCaption, DataTable dataTable1)
  409. {
  410. if (arrColumns == null || arrColumns.Length == 0 || arrColumns.Length != arrCaption.Length)
  411. {
  412. return;
  413. }
  414. dataTable1.Columns.Clear();//先清除
  415. DataColumn dc;
  416. for (int i = 0; i < arrColumns.Length; i++)
  417. {
  418. try
  419. {
  420. dc = new DataColumn(arrColumns[i]);
  421. dc.Caption = arrCaption[i];
  422. dataTable1.Columns.Add(dc);
  423. if (dc.ColumnName == "CHK")
  424. {
  425. dc.DataType = typeof(bool);
  426. dc.DefaultValue = "False";
  427. }
  428. }
  429. catch
  430. {
  431. continue;
  432. }
  433. }
  434. }
  435. public static void InitColumns(string[] arrColumns, string[] arrCaption, DataTable dataTable, UltraGrid ultraGrid, string[] show, bool isShow, string[] ope)
  436. {
  437. InitColumns(arrColumns, arrCaption, dataTable);
  438. setColumnShowOrHidden(ultraGrid, show, isShow);
  439. setOtherColumnReadOnly(ultraGrid, ope);
  440. }
  441. public static void InitColumns(string[] arrColumns, string[] arrCaption, DataTable dataTable, UltraGrid ultraGrid, string[] show, bool isShow, string[] ope, int bandNum)
  442. {
  443. InitColumns(arrColumns, arrCaption, dataTable);
  444. setColumnShowOrHidden(ultraGrid, show, isShow, bandNum);
  445. setOtherColumnReadOnly(ultraGrid, ope, bandNum);
  446. }
  447. //建立主从表关系
  448. public static void CreateConstraints(DataSet dataSet, DataTable dtParent, DataTable dtChild, string[] col)
  449. {
  450. Infragistics.Win.UltraWinGrid.UltraGridColumn ultraGridColumn = new Infragistics.Win.UltraWinGrid.UltraGridColumn("Relation1");
  451. dataSet.Relations.AddRange(new System.Data.DataRelation[] {
  452. new System.Data.DataRelation("Relation1", dtParent.TableName, dtChild.TableName, col, col, false)});
  453. UniqueConstraint un = new UniqueConstraint("Constraint1", col, false);
  454. dtParent.Constraints.AddRange(new System.Data.Constraint[] {
  455. new UniqueConstraint("Constraint1", col, false)});
  456. dtChild.Constraints.AddRange(new System.Data.Constraint[] {
  457. new System.Data.ForeignKeyConstraint("Relation1", dtParent.TableName, col, col, System.Data.AcceptRejectRule.None, System.Data.Rule.Cascade, System.Data.Rule.Cascade)});
  458. }
  459. //隐藏空列
  460. /// <summary>
  461. ///
  462. ///
  463. /// </summary>
  464. /// <param name="strHidden"></param>需要判断的列
  465. /// <param name="ug"></param>
  466. public static void HideNullColumn(string strHidden, UltraGrid ug)
  467. {
  468. string[] arr = strHidden.Split(',');
  469. for (int i = 0; i < arr.Length; i++)
  470. {
  471. if (!ug.DisplayLayout.Bands[0].Columns.Exists(arr[i]))
  472. {
  473. continue;
  474. }
  475. foreach (UltraGridRow ur in ug.Rows)
  476. {
  477. if (ur.Cells[arr[i]].Text != "")
  478. {
  479. ug.DisplayLayout.Bands[0].Columns[arr[i]].Hidden = false;
  480. break;
  481. }
  482. else
  483. {
  484. ug.DisplayLayout.Bands[0].Columns[arr[i]].Hidden = true;
  485. }
  486. }
  487. }
  488. }
  489. //选择事件
  490. /// <summary>
  491. ///
  492. ///
  493. /// </summary>
  494. /// <param name="strHidden"></param>
  495. /// <param name="ug"></param>
  496. public static void SelectRow(UltraGrid ultraGrid)
  497. {
  498. if (ultraGrid.DisplayLayout.Bands[0].Columns.Exists("CHK"))
  499. {
  500. foreach (UltraGridRow uRow in ultraGrid.Selected.Rows)
  501. {
  502. if (uRow.GetType() != typeof(Infragistics.Win.UltraWinGrid.UltraGridGroupByRow))
  503. {
  504. uRow.Cells["CHK"].Value = true;
  505. }
  506. }
  507. }
  508. }
  509. public static void ReMoveColumns(DataTable dataTable, int position)
  510. {
  511. //从0开始
  512. int dcNum = dataTable.Columns.Count;
  513. if (dcNum > position)
  514. {
  515. for (int i = 0; i < dcNum - position; i++)
  516. {
  517. dataTable.Columns.RemoveAt(position);
  518. }
  519. }
  520. }
  521. //自适应
  522. private void RefreshAutoSize(UltraGrid ultraGrid1)
  523. {
  524. ultraGrid1.DisplayLayout.Bands[0].Columns[0].Width = 80;
  525. for (int i = 1; i < ultraGrid1.DisplayLayout.Bands[0].Columns.Count; i++)
  526. {
  527. ultraGrid1.DisplayLayout.Bands[0].Columns[i].Width = 60;//设置列宽
  528. }
  529. }
  530. /// <summary>
  531. /// 设置列宽
  532. /// </summary>
  533. /// <param name="dt"></param>需要设置的UltraGrid
  534. /// <param name="haveNum"></param>不需要清除的列
  535. /// /// <param name="width"></param>宽度
  536. public static void ColumnsWidth(UltraGrid ultraGrid, int haveNum, int width)
  537. {
  538. int col = ultraGrid.DisplayLayout.Bands[0].Columns.Count;
  539. for (int i = haveNum; i < col; i++)
  540. {
  541. ultraGrid.DisplayLayout.Bands[0].Columns[i].Width = width;//设置列宽
  542. }
  543. }
  544. /// <summary>
  545. /// 设置列宽
  546. /// </summary>
  547. /// <param name="dt"></param>需要设置的UltraGrid
  548. /// <param name="haveNum"></param>不需要清除的列
  549. /// /// <param name="width"></param>宽度
  550. public static void ColumnsWidth(UltraGrid ultraGrid, int haveNum, int width, string[] noSet)
  551. {
  552. ArrayList al = new ArrayList();
  553. for (int i = 0; i < noSet.Length; i++)
  554. {
  555. al.Add(noSet[i]);
  556. }
  557. int col = ultraGrid.DisplayLayout.Bands[0].Columns.Count;
  558. for (int i = haveNum; i < col; i++)
  559. {
  560. if (!al.Contains(ultraGrid.DisplayLayout.Bands[0].Columns[i].ToString()))
  561. {
  562. ultraGrid.DisplayLayout.Bands[0].Columns[i].Width = width;//设置列宽
  563. }
  564. }
  565. }
  566. /// <summary>
  567. /// 刷新Grid数据并根据数据调整Grid列宽
  568. /// </summary>
  569. /// <param name="ultraGrid">需要处理的Grid</param>
  570. /// <param name="cols">需要调整的列</param>
  571. /// <param name="is调整">true则自适应,false则不自适应</param>
  572. public static void RefreshAndAutoSizeColumns(Infragistics.Win.UltraWinGrid.UltraGrid ultraGrid, object[] cols, bool isMove)
  573. {
  574. try
  575. {
  576. ultraGrid.DataBind();
  577. foreach (Infragistics.Win.UltraWinGrid.UltraGridBand band in ultraGrid.DisplayLayout.Bands)
  578. {
  579. foreach (Infragistics.Win.UltraWinGrid.UltraGridColumn column in band.Columns)
  580. {
  581. if (cols != null && cols.Contains(column.Key))
  582. {
  583. if (!isMove)
  584. {
  585. continue;
  586. }
  587. column.PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand);//AllRowsInBand
  588. }
  589. else
  590. {
  591. if (!isMove)
  592. {
  593. column.PerformAutoResize(Infragistics.Win.UltraWinGrid.PerformAutoSizeType.AllRowsInBand);
  594. }
  595. }
  596. }
  597. }
  598. ultraGrid.Refresh();
  599. }
  600. catch { }
  601. }
  602. //改变splitContainer1.Panel1
  603. public static void ChangeSplit(SplitContainer splitContainer, DataTable dtPhyMax)
  604. {
  605. if (dtPhyMax != null && dtPhyMax.Rows.Count > 0)
  606. {
  607. splitContainer.Panel1Collapsed = false;
  608. }
  609. else
  610. {
  611. splitContainer.Panel1Collapsed = true; ;
  612. }
  613. }
  614. //解析数据权限
  615. public static string ValidDataString(string[] arrId)
  616. {
  617. string strId = "";
  618. if (arrId != null)
  619. {
  620. foreach (string str in arrId)
  621. {
  622. strId += "'" + str + "',";
  623. }
  624. }
  625. strId = strId.Remove(0, 1);
  626. strId = strId.Remove(strId.Length - 2);
  627. return strId;
  628. }
  629. // 路径组成 Lims + 界面名称 + 文件名 "Lims/data/base/";
  630. public static string GetFilePath(string strPath)
  631. {
  632. return "";
  633. }
  634. /// <summary>
  635. /// 更改文件路径
  636. /// </summary>
  637. /// <param name="Department">user_depatment</param>
  638. /// <returns></returns>
  639. public static void UpdateFilePosition(string strTableName, string strPath, string strPk, string strPkValue, OpeBase ob)
  640. {
  641. try
  642. {
  643. string sql = "UPDATE " + strTableName + " SET FILE_POSITION = '" + strPath + "' WHERE " + strPk + " = '" + strPkValue + "'";
  644. //PublicServer.SetData("com.steering.BaseInfo.UpdateFilePosition", new Object[] { sql }, ob);
  645. }
  646. catch
  647. {
  648. }
  649. }
  650. /// <summary>
  651. /// 查看文件路径
  652. /// </summary>
  653. /// <param name="Department">user_depatment</param>
  654. /// <returns></returns>
  655. public static bool ViewFilePosition(OpeBase _ob, string path)
  656. {
  657. bool isSucc = true;
  658. FormFileDown down = new FormFileDown(_ob, path);
  659. down.ShowDialog();
  660. if (down.CtrlFileDown1.List.Count == 0)
  661. {
  662. isSucc = false;//删除了则更新FILE_POSITION
  663. }
  664. return isSucc;
  665. }
  666. /// <summary>
  667. /// 上传文件路径
  668. /// </summary>
  669. /// <param name="Department">user_depatment</param>
  670. /// <returns></returns>
  671. public static bool UploadFilePosition(OpeBase _ob, string path)
  672. {
  673. //var serverFileList = FileHelper.Download(path);
  674. //if (serverFileList.Count > 0)
  675. //{
  676. // MessageUtil.ShowWarning("该记录已存在一份文件,请删除后再重新上传!");
  677. // return false;
  678. //}
  679. List<FileBean> list = new List<FileBean>();
  680. FileBean bean = new FileBean();
  681. OpenFileDialog file = new OpenFileDialog();
  682. file.Multiselect = false;
  683. DialogResult drStat;
  684. drStat = file.ShowDialog();
  685. if (drStat == DialogResult.OK)
  686. {
  687. string filePath = file.FileName;
  688. string fileName = System.IO.Path.GetFileName(filePath);
  689. bean = new FileBean();
  690. bean.setFileName(fileName);
  691. bean.setPathName(path);
  692. bean.setFile(FileHelper.FileToArray(filePath));
  693. list.Add(bean);
  694. bool isSuccess = Core.Mes.Client.Comm.Server.FileHelper.Upload(list);
  695. if (isSuccess)
  696. {
  697. MessageUtil.ShowTips("上传成功!");
  698. }
  699. else
  700. {
  701. MessageUtil.ShowTips("上传失败,请重试!");
  702. }
  703. return isSuccess;//成功了则更新FILE_POSITION
  704. }
  705. return false;
  706. }
  707. //勾选激活行
  708. public static void GridEdite(UltraGridRow row)
  709. {
  710. if (row.GetValue("CHK") == "True")
  711. {
  712. foreach (UltraGridCell cell in row.Cells)
  713. {
  714. if (cell.Column.CellActivation == Activation.AllowEdit)
  715. {
  716. cell.Activation = Activation.AllowEdit;
  717. }
  718. }
  719. }
  720. else
  721. {
  722. foreach (UltraGridCell cell in row.Cells)
  723. {
  724. if (cell.Column.Key == "CHK") continue;
  725. if (cell.Column.CellActivation == Activation.AllowEdit)
  726. {
  727. cell.Activation = Activation.ActivateOnly;
  728. }
  729. }
  730. }
  731. }
  732. public static void GridEdite(UltraGridRow row, string[] arrStr)
  733. {
  734. if (row.GetValue("CHK") == "True")
  735. {
  736. foreach (UltraGridCell cell in row.Cells)
  737. {
  738. if (cell.Column.CellActivation == Activation.AllowEdit)
  739. {
  740. cell.Activation = Activation.AllowEdit;
  741. }
  742. }
  743. }
  744. else
  745. {
  746. foreach (UltraGridCell cell in row.Cells)
  747. {
  748. if (cell.Column.Key == "CHK") continue;
  749. if (cell.Column.CellActivation == Activation.AllowEdit)
  750. {
  751. cell.Activation = Activation.ActivateOnly;
  752. }
  753. }
  754. }
  755. }
  756. /// <summary>
  757. /// 设置列字段显示位置在右
  758. /// </summary>
  759. /// <param name="ug">UltraGrid</param>
  760. /// <param name="columnsKeys">要设置的列</param>
  761. public static void InitCellPositionRight(UltraGrid ug, string[] columnsKeys)
  762. {
  763. if (columnsKeys == null || columnsKeys.Length == 0)
  764. {
  765. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  766. {
  767. ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
  768. }
  769. }
  770. else
  771. {
  772. columnsKeys.ToArray();
  773. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  774. {
  775. if (columnsKeys.Contains(ugc.Key.ToString()))
  776. {
  777. ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
  778. }
  779. }
  780. }
  781. }
  782. /// <summary>
  783. /// 设置列字段显示位置在右
  784. /// </summary>
  785. /// <param name="ug">UltraGrid</param>
  786. /// <param name="columnsKeys">要设置的列</param>
  787. public static void InitCellPositionRight(UltraGrid[] arrUg, string[] columnsKeys)
  788. {
  789. if (arrUg == null || arrUg.Length < 1)
  790. {
  791. return;
  792. }
  793. foreach (UltraGrid ug in arrUg)
  794. {
  795. if (ug.DisplayLayout.Bands.Count < 1)
  796. {
  797. continue;
  798. }
  799. if (columnsKeys == null || columnsKeys.Length == 0)
  800. {
  801. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  802. {
  803. ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
  804. }
  805. }
  806. else
  807. {
  808. columnsKeys.ToArray();
  809. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  810. {
  811. if (columnsKeys.Contains(ugc.Key.ToString()))
  812. {
  813. ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
  814. }
  815. }
  816. }
  817. }
  818. }
  819. /// <summary>
  820. /// 设置列字段显示小数位后几位
  821. /// </summary>
  822. /// <param name="ug">UltraGrid</param>
  823. /// band 第几个 num显示位数不足补齐0,isShow 数字是否用逗号隔开
  824. /// <param name="columnsKeys">要设置的列</param>
  825. public static void InitColumnShowLength(UltraGrid ug, int band, string[] columnsKeys, int num, bool isShow)
  826. {
  827. if (columnsKeys == null || columnsKeys.Length == 0 || band < 0 || num < 0 || ug.DisplayLayout.Bands.Count < band + 1)
  828. {
  829. return;
  830. }
  831. else
  832. {
  833. string strShow = "";//nnnnnnnnnn {LOC}nn,nnn,nnn.nn
  834. if (isShow)
  835. {
  836. strShow += "-n,nnn,nnn,nnn,nnn,nnn";
  837. }
  838. else
  839. {
  840. strShow += "-nnnnnnnnnnnnnnnn";
  841. }
  842. if (num > 0)
  843. {
  844. strShow += ".";
  845. for (int i = 0; i < num; i++)
  846. {
  847. strShow += "n";
  848. }
  849. }
  850. columnsKeys.ToArray();
  851. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[band].Columns)
  852. {
  853. if (columnsKeys.Contains(ugc.Key.ToString()))
  854. {
  855. //ug.DisplayLayout.Bands[band].Columns[ugc.Key.ToString()].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Double;
  856. ug.DisplayLayout.Bands[band].Columns[ugc.Key.ToString()].MaskInput = strShow;
  857. }
  858. }
  859. }
  860. }
  861. /// <summary>
  862. /// 设置列字段显示小数位后几位
  863. /// </summary>
  864. /// <param name="ug">UltraGrid</param>
  865. /// band 第几个 num显示位数不足补齐0,isShow 数字是否用逗号隔开
  866. /// <param name="columnsKeys">要设置的列</param>
  867. public static void InitColumnShowLength(UltraGrid[] arrUg, int band, string[] columnsKeys, int num, bool isShow)
  868. {
  869. if (columnsKeys == null || columnsKeys.Length == 0 || band < 0 || num < 0 || arrUg == null
  870. || arrUg.Length < 1)
  871. {
  872. return;
  873. }
  874. else
  875. {
  876. string strShow = "";//nnnnnnnnnn {LOC}nn,nnn,nnn.nn
  877. if (isShow)
  878. {
  879. strShow += "-n,nnn,nnn,nnn,nnn,nnn";
  880. }
  881. else
  882. {
  883. strShow += "-nnnnnnnnnnnnnnnn";
  884. }
  885. if (num > 0)
  886. {
  887. strShow += ".";
  888. for (int i = 0; i < num; i++)
  889. {
  890. strShow += "n";
  891. }
  892. }
  893. columnsKeys.ToArray();
  894. foreach (UltraGrid ug in arrUg)
  895. {
  896. if (ug.DisplayLayout.Bands.Count < band + 1)
  897. {
  898. continue;
  899. }
  900. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[band].Columns)
  901. {
  902. if (columnsKeys.Contains(ugc.Key.ToString()))
  903. {
  904. //ug.DisplayLayout.Bands[band].Columns[ugc.Key.ToString()].Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Double;
  905. ug.DisplayLayout.Bands[band].Columns[ugc.Key.ToString()].MaskInput = strShow;
  906. }
  907. }
  908. }
  909. }
  910. }
  911. /// <summary>
  912. /// 设置Grid统计格式
  913. ///
  914. /// </summary>
  915. /// <param name="Arrsumtype"></param>统计格式集合
  916. /// <param name="HeadeVale"></param>显示格式
  917. /// <param name="ColumName"></param>列名
  918. /// <param name="band"></param>
  919. /// <param name="areas"></param>位置
  920. public static void SetupSummaryHeade(string[] Arrsumtype, string[] HeadeVale, string[] ColumName, UltraGridBand band, SummaryDisplayAreas areas)
  921. {
  922. if (HeadeVale.Length != Arrsumtype.Length && Arrsumtype.Length != ColumName.Length)
  923. {
  924. return;
  925. }
  926. SummaryType sumType; ;
  927. for (int i = 0; i < HeadeVale.Length; i++)
  928. {
  929. //SummaryType.Count 统计 Average平均值 Maximum最大值 Minimum 最小值 Sum 求和
  930. if (Arrsumtype[i] == "Count")
  931. {
  932. sumType = SummaryType.Count;
  933. }
  934. else if (Arrsumtype[i] == "Maximum")
  935. {
  936. sumType = SummaryType.Maximum;
  937. }
  938. else if (Arrsumtype[i] == "Minimum")
  939. {
  940. sumType = SummaryType.Minimum;
  941. }
  942. else
  943. {
  944. sumType = SummaryType.Sum;
  945. }
  946. if (band.Columns.Exists(ColumName[i]))
  947. {
  948. SummarySettings summary = band.Summaries.Add(sumType, band.Columns[ColumName[i]]);
  949. summary.SummaryDisplayArea = areas;
  950. summary.SummaryPosition = SummaryPosition.UseSummaryPositionColumn;
  951. summary.DisplayFormat = HeadeVale[i];
  952. summary.Appearance.TextHAlign = Infragistics.Win.HAlign.Center;
  953. summary.Appearance.TextVAlign = Infragistics.Win.VAlign.Middle;
  954. //summary.Appearance.ForeColor = Color.Black;
  955. //summary.Appearance.BackColor = Color.FromArgb(248, 253, 180);
  956. }
  957. }
  958. Infragistics.Win.Appearance appearance21 = new Infragistics.Win.Appearance();
  959. Infragistics.Win.Appearance appearance20 = new Infragistics.Win.Appearance();
  960. appearance20.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(224)))), ((int)(((byte)(192)))));
  961. band.Override.SummaryFooterAppearance = appearance20;
  962. appearance21.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(224)))), ((int)(((byte)(192)))));
  963. appearance21.TextHAlignAsString = "Right";
  964. band.Override.SummaryValueAppearance = appearance21;
  965. }
  966. /// <summary>
  967. /// 可编区域显示(黄色+可编辑)
  968. /// </summary>
  969. /// <param name="ug">UltraGrid</param>
  970. /// <param name="columnsKeys">要设置的列</param>
  971. public static void InitCellEdit(UltraGrid[] arrUg, string[] columnsKeys)
  972. {
  973. if (arrUg == null || arrUg.Length < 1)
  974. {
  975. return;
  976. }
  977. if (columnsKeys == null || columnsKeys.Length == 0)
  978. {
  979. return;
  980. }
  981. foreach (UltraGrid ug in arrUg)
  982. {
  983. if (ug.DisplayLayout.Bands.Count < 1)
  984. {
  985. continue;
  986. }
  987. columnsKeys.ToArray();
  988. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  989. {
  990. if (columnsKeys.Contains(ugc.Key.ToString()))
  991. {
  992. ugc.CellAppearance.BackColor = Color.FromArgb(255, 255, 128);
  993. ugc.CellActivation = Activation.AllowEdit;
  994. }
  995. else
  996. {
  997. ugc.CellActivation = Activation.ActivateOnly;
  998. }
  999. }
  1000. }
  1001. }
  1002. }
  1003. }