PublicMat.cs 31 KB

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