BaseMethod.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Infragistics.Win.UltraWinGrid;
  6. using System.Drawing;
  7. using CoreFS.CA06;
  8. using Infragistics.Win.UltraWinEditors;
  9. using System.Data;
  10. using System.Windows.Forms;
  11. using Core.Mes.Client.Comm.Server;
  12. using Infragistics.Win.UltraWinMaskedEdit;
  13. using System.Collections;
  14. using System.Text.RegularExpressions;
  15. using System.IO;
  16. namespace Core.StlMes.Client.ZGMil.Common
  17. {
  18. class BaseMethod
  19. {
  20. /// <summary>
  21. /// UltraGrid可读
  22. /// </summary>
  23. /// <param name="ugr">UltraGrid</param>
  24. /// <param name="keys">可编辑列</param>
  25. public static void setOtherColumnReadOnly(UltraGrid ugr, string[] keys)
  26. {
  27. keys.ToArray();
  28. foreach (UltraGridColumn ugc in ugr.DisplayLayout.Bands[0].Columns)
  29. {
  30. if (!keys.Contains(ugc.Key))
  31. {
  32. ugc.CellActivation = Activation.ActivateOnly;
  33. }
  34. }
  35. }
  36. /// <summary>
  37. /// UltraGrid激活某行
  38. /// </summary>
  39. /// <param name="ug">UltraGrid</param>
  40. /// <param name="keys">列名</param>
  41. /// <param name="values">对应的值</param>
  42. public static void UltraGridLocation(UltraGrid ug, String[] keys, String[] values)
  43. {
  44. if (ug.Rows.Count == 0)
  45. {
  46. return;
  47. }
  48. if (keys.Length == 0 || values.Length == 0 || values.Length != keys.Length)
  49. {
  50. return;
  51. }
  52. foreach (UltraGridRow ugr in ug.Rows)
  53. {
  54. Boolean flag = true;
  55. for (int i = 0; i < keys.Length; i++)
  56. {
  57. if (!ugr.Cells[keys[i]].ToString().Equals(values[i]))
  58. {
  59. flag = false;
  60. }
  61. }
  62. if (flag == true)
  63. {
  64. ugr.Activate();
  65. return;
  66. }
  67. }
  68. }
  69. /// <summary>
  70. /// 设置列字段显示位置在右
  71. /// </summary>
  72. /// <param name="ug">UltraGrid</param>
  73. /// <param name="columnsKeys">要设置的列</param>
  74. public static void InitCellPosition(UltraGrid ug, string[] columnsKeys)
  75. {
  76. columnsKeys.ToArray();
  77. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  78. {
  79. if (columnsKeys.Contains(ugc.Key.ToString()))
  80. {
  81. ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
  82. }
  83. }
  84. }
  85. /// <summary>
  86. /// 设置列字段显示位置在右
  87. /// </summary>
  88. /// <param name="ug">UltraGrid</param>
  89. /// <param name="columnsKeys">要设置的列</param>
  90. public static void InitCellPosition(UltraGrid ug, string[] columnsKeys,int dex)
  91. {
  92. columnsKeys.ToArray();
  93. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[dex].Columns)
  94. {
  95. if (columnsKeys.Contains(ugc.Key.ToString()))
  96. {
  97. ugc.CellAppearance.TextHAlign = Infragistics.Win.HAlign.Right;
  98. }
  99. }
  100. }
  101. /// <summary>
  102. /// 列求和
  103. /// </summary>
  104. /// <param name="ug">UltraGrid</param>
  105. /// <param name="columnKeys">列数组</param>
  106. public static void GridColumnSum(UltraGrid ug, string[] columnKeys)
  107. {
  108. if (columnKeys.Length == 0)
  109. {
  110. return;
  111. }
  112. for (int i = 0; i < columnKeys.Length; i++)
  113. {
  114. ug.DisplayLayout.Bands[0].Summaries.Add(SummaryType.Sum, ug.DisplayLayout.Bands[0].Columns[columnKeys[i]], SummaryPosition.UseSummaryPositionColumn);
  115. }
  116. }
  117. /// <summary>
  118. /// 设置UltraGrid行颜色
  119. /// </summary>
  120. /// <param name="ug">UltraGrid</param>
  121. /// <param name="columnKeys">列</param>
  122. /// <param name="values">值</param>
  123. /// <param name="color">颜色</param>
  124. public static void SetUltraGridRowColor(UltraGrid ug, string[] columnKeys, string[] values, Color color)
  125. {
  126. if (ug.Rows.Count == 0 || columnKeys.Length == 0 || values.Length == 0 || color == null || values.Length != columnKeys.Length)
  127. {
  128. return;
  129. }
  130. foreach (UltraGridRow ugr in ug.Rows)
  131. {
  132. Boolean flag = true;
  133. for (int i = 0; i < columnKeys.Length; i++)
  134. {
  135. if (!ugr.Cells[columnKeys[i]].Value.ToString().Equals(values[i]))
  136. {
  137. flag = false;
  138. }
  139. }
  140. if (flag)
  141. {
  142. ugr.Appearance.BackColor = color;
  143. }
  144. }
  145. }
  146. /// <summary>
  147. /// 合并单元格
  148. /// </summary>
  149. /// <param name="ug"></param>
  150. /// <param name="columnKeys"></param>
  151. public static void MergedCell(UltraGrid ug, string[] columnKeys)
  152. {
  153. if (columnKeys.Length == 0)
  154. {
  155. return;
  156. }
  157. ug.DisplayLayout.Override.MergedCellStyle = MergedCellStyle.Never;
  158. for (int i = 0; i < columnKeys.Length; i++)
  159. {
  160. ug.DisplayLayout.Bands[0].Columns[columnKeys[i]].MergedCellStyle = MergedCellStyle.Always;
  161. }
  162. }
  163. /// <summary>
  164. /// 仓库数据权限
  165. /// </summary>
  166. /// <param name="customInfo">页面配制信息(自定义参数)</param>
  167. /// <param name="validDataPurviewIds">用户数据权限</param>
  168. /// <returns>可查看仓库组成的字符串</returns>
  169. public static string[] WarehousePermissions(String customInfo, String[] validDataPurviewIds, OpeBase ob)
  170. {
  171. string storageType = "";//仓库类别
  172. string storageAttr = "";//仓库类型
  173. if (customInfo.Length >= 0 && customInfo.Contains(","))
  174. {
  175. string[] strflg = customInfo.ToString().Split(new char[] { ',' });
  176. storageType = strflg[0];
  177. storageAttr = strflg[1];
  178. }
  179. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getWarehousePermissions", new object[] { storageType, storageAttr, validDataPurviewIds }, ob);
  180. if (dt != null && dt.Rows.Count > 0)
  181. {
  182. string[] storages = new string[dt.Rows.Count];
  183. for (int i = 0; i < dt.Rows.Count; i++)
  184. {
  185. storages[i] = dt.Rows[i]["STORAGE_NO"].ToString();
  186. }
  187. return storages;
  188. }
  189. else
  190. {
  191. return new string[1] { "" };
  192. }
  193. }
  194. /// <summary>
  195. /// 仓库数据权限(用于报表)
  196. /// </summary>
  197. /// <param name="customInfo">页面配制信息(自定义参数)</param>
  198. /// <param name="validDataPurviewIds">用户数据权限</param>
  199. /// <returns>可查看仓库组成的字符串</returns>
  200. public static string[] WarehousePermissionsStore(String[] validDataPurviewIds, OpeBase ob)
  201. {
  202. DataTable dt = ServerHelper.GetData("com.steering.mes.signature.WarehousePermissions.getWarehousePermissionsStore", new object[] { validDataPurviewIds }, ob);
  203. if (dt != null && dt.Rows.Count > 0)
  204. {
  205. string[] storages = new string[dt.Rows.Count];
  206. for (int i = 0; i < dt.Rows.Count; i++)
  207. {
  208. storages[i] = dt.Rows[i]["STORAGE_NO"].ToString();
  209. }
  210. return storages;
  211. }
  212. else
  213. {
  214. return new string[1] { "" };
  215. }
  216. }
  217. /// <summary>
  218. /// 获取产线
  219. /// </summary>
  220. /// <param name="arr1"></param>
  221. /// <returns></returns>
  222. public static string[] GetPlineCode(string[] arr1, OpeBase ob)
  223. {
  224. string[] arr = null;
  225. DataTable dt = ServerHelper.GetData("com.steering.mes.signature.WarehousePermissions.getPlineCode", new Object[] { arr1 }, ob);
  226. if (dt != null && dt.Rows.Count > 0)
  227. {
  228. arr = new string[dt.Rows.Count];
  229. for (int i = 0; i < dt.Rows.Count; i++)
  230. {
  231. arr[i] = dt.Rows[i][0].ToString();
  232. }
  233. return arr;
  234. }
  235. else
  236. {
  237. return new string[1] { "" };
  238. }
  239. }
  240. /// <summary>
  241. /// 初始化仓库号下拉框
  242. /// </summary>
  243. /// <param name="uce"></param>
  244. /// <param name="customInfo"></param>
  245. /// <param name="validDataPurviewIds"></param>
  246. /// <param name="ob"></param>
  247. public static void InitStorage(UltraComboEditor uce, String customInfo, String[] validDataPurviewIds, OpeBase ob)
  248. {
  249. string storageType = "";//仓库类别
  250. string storageAttr = "";//仓库类型
  251. if (customInfo.Length >= 0 && customInfo.Contains(","))
  252. {
  253. string[] strflg = customInfo.ToString().Split(new char[] { ',' });
  254. storageType = strflg[0];
  255. storageAttr = strflg[1];
  256. }
  257. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.WarehousePermissions.getWarehousePermissions", new object[] { storageType, storageAttr, validDataPurviewIds }, ob);
  258. if (dt != null && dt.Rows.Count > 0)
  259. {
  260. uce.DataSource = dt;
  261. uce.DisplayMember = "STORAGE_NAME";
  262. uce.ValueMember = "STORAGE_NO";
  263. uce.SelectedIndex = 0;
  264. }
  265. else
  266. {
  267. uce.DataSource = null;
  268. }
  269. }
  270. /// <summary>
  271. /// 初始化下拉框材料类别
  272. /// </summary>
  273. /// <param name="uce"></param>
  274. /// <param name="ob"></param>
  275. public static void InitProducFlagCom(UltraComboEditor uce, OpeBase ob)
  276. {
  277. DataTable dtProducFlag = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeMagement.queryMaterialSTyle", new object[] { }, ob);
  278. BaseMethod.InitComboEditor(uce, dtProducFlag, "BASENAME", "BASECODE");
  279. }
  280. /// <summary>
  281. /// 初始化下拉框材料状态
  282. /// </summary>
  283. /// <param name="uce"></param>
  284. /// <param name="ob"></param>
  285. public static void InitMapStatusCom(UltraComboEditor uce, OpeBase ob)
  286. {
  287. DataTable dtMapStatus = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeMagement.queryMaterialStatus", new object[] { }, ob);
  288. BaseMethod.InitComboEditor(uce, dtMapStatus, "BASENAME", "BASECODE");
  289. }
  290. /// <summary>
  291. /// 初始化下拉框材料状态
  292. /// </summary>
  293. /// <param name="uce"></param>
  294. /// <param name="ob"></param>
  295. public static void InitMapStatusCom(UltraComboEditor uce, OpeBase ob, string flag)
  296. {
  297. DataTable dtMapStatus = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeMagement.queryMaterialStatus", new object[] { flag }, ob);
  298. BaseMethod.InitComboEditor(uce, dtMapStatus, "BASENAME", "BASECODE");
  299. }
  300. /// <summary>
  301. /// 初始下拉框
  302. /// </summary>
  303. /// <param name="uce"></param>
  304. /// <param name="dt"></param>
  305. /// <param name="showName"></param>
  306. /// <param name="hideValue"></param>
  307. public static void InitComboEditor(UltraComboEditor uce, DataTable dt, String showName, String hideValue)
  308. {
  309. uce.DataSource = dt;
  310. uce.DisplayMember = showName;
  311. uce.ValueMember = hideValue;
  312. }
  313. /// <summary>
  314. /// 初始下拉框
  315. /// </summary>
  316. /// <param name="uce"></param>
  317. /// <param name="dt"></param>
  318. /// <param name="showName"></param>
  319. /// <param name="hideValue"></param>
  320. public static void InitComboEditor1(UltraComboEditor uce, DataTable dt, String showName, String hideValue)
  321. {
  322. uce.DataSource = dt;
  323. uce.DisplayMember = showName;
  324. uce.ValueMember = hideValue;
  325. uce.SelectedIndex = 1;
  326. }
  327. /// <summary>
  328. /// 初始化下拉框产线
  329. /// </summary>
  330. /// <param name="uce"></param>
  331. /// <param name="ob"></param>
  332. public static void InitPline(UltraComboEditor uce, OpeBase ob)
  333. {
  334. DataTable dtPline = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getPline", new object[] { }, ob);
  335. BaseMethod.InitComboEditor(uce, dtPline, "PLINE_NAME", "PLINE_CODE");
  336. }
  337. /// <summary>
  338. /// 初始化下拉框材料来源
  339. /// </summary>
  340. /// <param name="uce"></param>
  341. /// <param name="ob"></param>
  342. public static void InitSourse(UltraComboEditor uce, OpeBase ob)
  343. {
  344. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getSourse", new object[] { "8013" }, ob);
  345. BaseMethod.InitComboEditor1(uce, dt, "BASENAME", "BASECODE");
  346. }
  347. /// <summary>
  348. /// 初始化下拉框钢种
  349. /// </summary>
  350. /// <param name="uce"></param>
  351. /// <param name="ob"></param>
  352. public static void InitGrade(UltraComboEditor uce, OpeBase ob)
  353. {
  354. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeEnter.getGrade", new object[] { }, ob);
  355. BaseMethod.InitComboEditor(uce, dt, "GRADENAME", "GRADECODE");
  356. }
  357. /// <summary>
  358. /// 获取规格
  359. /// </summary>
  360. /// <param name="uce"></param>
  361. /// <param name="ob"></param>
  362. public static void InitSpec(UltraComboEditor uce, OpeBase ob)
  363. {
  364. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeEnter.getSpec", new object[] { }, ob);
  365. BaseMethod.InitComboEditor(uce, dt, "SPEC_NAME", "SPEC_CODE");
  366. }
  367. /// <summary>
  368. /// 获取扣型
  369. /// </summary>
  370. /// <param name="uce"></param>
  371. /// <param name="ob"></param>
  372. public static void InitModel(UltraComboEditor uce, OpeBase ob)
  373. {
  374. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeEnter.getModel", new object[] { }, ob);
  375. BaseMethod.InitComboEditor(uce, dt, "MODEL_DESC", "MODEL_CODE");
  376. }
  377. /// <summary>
  378. /// 获取品名
  379. /// </summary>
  380. /// <param name="uce"></param>
  381. /// <param name="ob"></param>
  382. public static void InitProcduce(UltraComboEditor uce, OpeBase ob)
  383. {
  384. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.BaseOperations.getProcduce", new object[] { }, ob);
  385. BaseMethod.InitComboEditor(uce, dt, "PRODUC_JX", "PRODUCCODE");
  386. }
  387. /// <summary>
  388. /// 获取钢级
  389. /// </summary>
  390. /// <param name="uce"></param>
  391. /// <param name="ob"></param>
  392. public static void InitSteel(UltraComboEditor uce, OpeBase ob)
  393. {
  394. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.BaseOperations.getSteel", new object[] { }, ob);
  395. BaseMethod.InitComboEditor(uce, dt, "STEELNAME", "STEELCODE");
  396. }
  397. /// <summary>
  398. /// 获取标准类别
  399. /// </summary>
  400. /// <param name="uce"></param>
  401. /// <param name="ob"></param>
  402. public static void InitStdStyle(UltraComboEditor uce, OpeBase ob)
  403. {
  404. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.base.BaseOperations.getStdStyle", new object[] { }, ob);
  405. BaseMethod.InitComboEditor(uce, dt, "STD_STYLE_DESC", "STD_STYLE");
  406. }
  407. /// <summary>
  408. /// 初始化下拉框原因
  409. /// </summary>
  410. /// <param name="uce"></param>
  411. /// <param name="ob"></param>
  412. public static void InitReason(UltraComboEditor uce, OpeBase ob)
  413. {
  414. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getSourse", new object[] { "8012" }, ob);
  415. BaseMethod.InitComboEditor(uce, dt, "BASENAME", "BASECODE");
  416. }
  417. /// <summary>
  418. /// 初始化下拉框综合判断结果
  419. /// </summary>
  420. /// <param name="uce"></param>
  421. /// <param name="ob"></param>
  422. public static void InitJustResult(UltraComboEditor uce, OpeBase ob)
  423. {
  424. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getSourse", new object[] { "407407" }, ob);
  425. BaseMethod.InitComboEditor(uce, dt, "BASENAME", "BASECODE");
  426. }
  427. /// <summary>
  428. /// 初始化下拉框所属权单位
  429. /// </summary>
  430. /// <param name="uce"></param>
  431. /// <param name="ob"></param>
  432. public static void InitBelongCode(UltraComboEditor uce, OpeBase ob)
  433. {
  434. DataTable dt = ServerHelper.GetData("com.steering.pss.ydm.pipemanage.FrmPipeInventoryIn.getBelongCode", new object[] { }, ob);
  435. BaseMethod.InitComboEditor(uce, dt, "DEPARTNAME", "DEPARTID");
  436. }
  437. /// <summary>
  438. /// 销售组织权限
  439. /// </summary>
  440. /// <param name="validDataPurviewIds">数据权限</param>
  441. /// <param name="ob"></param>
  442. /// <returns>字符串数组</returns>
  443. public static string[] InitPermissions(string[] validDataPurviewIds, OpeBase ob)
  444. {
  445. string[] arr = null;
  446. DataTable dt = ServerHelper.GetData("com.steering.common.WarehousePermissions.getSalgPermissions", new object[] { validDataPurviewIds }, ob);
  447. if (dt != null && dt.Rows.Count > 0)
  448. {
  449. arr = new string[dt.Rows.Count];
  450. for (int i = 0; i < dt.Rows.Count; i++)
  451. {
  452. arr[i] = dt.Rows[i][0].ToString();
  453. }
  454. }
  455. return arr;
  456. }
  457. /// <summary>
  458. /// 炼钢权限
  459. /// </summary>
  460. /// <param name="validDataPurviewIds">数据权限</param>
  461. /// <param name="ob"></param>
  462. /// <returns>字符串数组</returns>
  463. public static string[] InitLgPermissions(string[] validDataPurviewIds, OpeBase ob)
  464. {
  465. string[] arr = null;
  466. DataTable dt = ServerHelper.GetData("Core.LgMes.Server.Common.ComLgValidDataPurviewIds.getLgPermissions", new object[] { validDataPurviewIds }, ob);
  467. if (dt != null && dt.Rows.Count > 0)
  468. {
  469. arr = new string[dt.Rows.Count];
  470. for (int i = 0; i < dt.Rows.Count; i++)
  471. {
  472. arr[i] = dt.Rows[i][0].ToString();
  473. }
  474. }
  475. return arr;
  476. }
  477. /// <summary>
  478. /// 获取PCode
  479. /// </summary>
  480. /// <param name="Department">user_depatment</param>
  481. /// <returns></returns>
  482. public static string GetPCode(string Department, OpeBase ob)
  483. {
  484. string Pcode = "";
  485. DataTable dt = ServerHelper.GetData("Core.LgMes.Server.Common.ComLgValidDataPurviewIds.getPCode", new Object[] { Department }, ob);
  486. if (dt.Rows.Count > 0)
  487. {
  488. Pcode = dt.Rows[0]["pline_code"].ToString();
  489. }
  490. return Pcode;
  491. }
  492. /// <summary>
  493. /// 设置列显示位数
  494. /// </summary>
  495. /// <param name="ug"></param>
  496. /// <param name="arr"></param>
  497. public static void setUltraGridColumnMaxInput(UltraGrid ug, string[] arr)
  498. {
  499. if (ug == null || arr == null || arr.Length == 0)
  500. {
  501. return;
  502. }
  503. arr.ToArray();
  504. foreach (UltraGridColumn ugc in ug.DisplayLayout.Bands[0].Columns)
  505. {
  506. if (arr.Contains(ugc.Key.ToString()))
  507. {
  508. ugc.MaskClipMode = MaskMode.IncludeLiterals;
  509. ugc.MaskInput = "{LOC}nn,nnn,nnn.nnn";
  510. }
  511. }
  512. }
  513. /// <summary>
  514. /// 炉号去-后的字符
  515. /// </summary>
  516. /// <param name="JudgeStoveNo"></param>
  517. /// <returns></returns>
  518. public static string getJudgeStoveNo(string JudgeStoveNo)
  519. {
  520. Regex regex = new Regex("-[0-9]*");
  521. return regex.Replace(JudgeStoveNo, "");
  522. }
  523. /// <summary>
  524. /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中
  525. /// </summary>
  526. /// <param name="ugrid">UltraGrid</param>
  527. /// <param name="e"></param>
  528. /// <param name="strs">可以进行列名称</param>
  529. public static void setGridCopyActColumn(UltraGrid ugrid, KeyEventArgs e, params string[] strs)
  530. {
  531. if (e.Control && e.KeyCode == Keys.D)
  532. {
  533. if (ugrid != null && ugrid.ActiveRow != null)
  534. {
  535. UltraGridRow ugr = ugrid.ActiveRow;
  536. foreach (string colName in strs)
  537. {
  538. if (ugrid.ActiveCell.Column.Key.Equals(colName))
  539. {
  540. if (ugr.Cells[colName].Activation != Activation.AllowEdit)
  541. {
  542. return;
  543. }
  544. ugrid.UpdateData();
  545. ArrayList list = new ArrayList();
  546. IQueryable<UltraGridRow> checkRows = ugrid.Rows.AsQueryable().Where("CHK = 'True' ");
  547. if (checkRows.Count() == 0)
  548. {
  549. return;
  550. }
  551. foreach (UltraGridRow uRow in checkRows)
  552. {
  553. if (uRow != ugr && uRow.Cells[colName].Activation == Activation.AllowEdit)
  554. {
  555. uRow.Cells[colName].Value = ugr.Cells[colName].Value;
  556. }
  557. }
  558. }
  559. }
  560. }
  561. }
  562. }/// <summary>
  563. /// 初始年份
  564. /// </summary>
  565. /// <param name="uce"></param>
  566. public static void InitYear(UltraComboEditor uce)
  567. {
  568. DataTable dtYear = new DataTable();
  569. dtYear.Columns.Add("YEAR");
  570. for (int i = 2000; i < 2200; i++)
  571. {
  572. DataRow dr = dtYear.NewRow();
  573. dr["YEAR"] = i.ToString();
  574. dtYear.Rows.Add(dr);
  575. }
  576. uce.DataSource = dtYear;
  577. uce.DisplayMember = "YEAR";
  578. uce.ValueMember = "YEAR";
  579. }
  580. /// <summary>
  581. /// 初始月份
  582. /// </summary>
  583. /// <param name="uce"></param>
  584. public static void InitMonth(UltraComboEditor uce)
  585. {
  586. DataTable dtMonth = new DataTable();
  587. dtMonth.Columns.Add("MONTH");
  588. for (int i = 1; i < 13; i++)
  589. {
  590. DataRow dr = dtMonth.NewRow();
  591. dr["MONTH"] = string.Format("{0:00}", i);
  592. dtMonth.Rows.Add(dr);
  593. }
  594. uce.DataSource = dtMonth;
  595. uce.DisplayMember = "MONTH";
  596. uce.ValueMember = "MONTH";
  597. }
  598. /// <summary>
  599. /// 键盘按下Ctrl+D,拷贝活动单元格的数据到所有已勾选的此列的单元格中
  600. /// </summary>
  601. /// <param name="ugrid">UltraGrid</param>
  602. /// <param name="e"></param>
  603. /// <param name="strs">可以进行列名称</param>
  604. public static void setGridCopyActColumn1(UltraGrid ugrid, KeyEventArgs e, params string[] strs)
  605. {
  606. if (e.Control && e.KeyCode == Keys.D)
  607. {
  608. if (ugrid != null && ugrid.ActiveRow != null)
  609. {
  610. UltraGridRow ugr = ugrid.ActiveRow;
  611. foreach (string colName in strs)
  612. {
  613. if (ugrid.ActiveCell.Column.Key.Equals(colName))
  614. {
  615. if (ugr.Cells[colName].Activation != Activation.AllowEdit)
  616. {
  617. return;
  618. }
  619. ugrid.UpdateData();
  620. ArrayList list = new ArrayList();
  621. IQueryable<UltraGridRow> checkRows = ugrid.Rows.AsQueryable().Where("CHOOSE = 'True' ");
  622. if (checkRows.Count() == 0)
  623. {
  624. return;
  625. }
  626. foreach (UltraGridRow uRow in checkRows)
  627. {
  628. if (uRow != ugr && uRow.Cells[colName].Activation == Activation.AllowEdit)
  629. {
  630. uRow.Cells[colName].Value = ugr.Cells[colName].Value;
  631. }
  632. }
  633. }
  634. }
  635. }
  636. }
  637. }
  638. /// <summary>
  639. /// 获取表格中
  640. /// </summary>
  641. /// <typeparam name="T">返回类</typeparam>
  642. /// <param name="dt">数据表</param>
  643. /// <param name="t">输入类</param>
  644. /// <returns></returns>
  645. public static T GetTableToEntity<T>(DataTable dt, T t)
  646. {
  647. String[] strColumns = null;
  648. DataRow dr = dt.Rows[0];
  649. try
  650. {
  651. if (dt.Columns.Count > 0)
  652. {
  653. int columnNum = 0;
  654. columnNum = dt.Columns.Count;
  655. strColumns = new string[columnNum];
  656. for (int i = 0; i < dt.Columns.Count; i++)
  657. {
  658. strColumns[i] = dt.Columns[i].ColumnName.Replace("_", "");
  659. }
  660. System.Reflection.PropertyInfo[] pro = t.GetType().GetProperties();
  661. foreach (System.Reflection.PropertyInfo item in pro)
  662. {
  663. for (int i = 0; i < strColumns.Length; i++)
  664. {
  665. if (string.Compare(item.Name.ToString(), strColumns[i].ToString(), true) == 0)
  666. {
  667. if (item.PropertyType == typeof(int?))
  668. {
  669. item.SetValue(t, Convert.ToInt32(dr[i].ToString3()), null);
  670. }
  671. else if (item.PropertyType == typeof(decimal?))
  672. {
  673. item.SetValue(t, Convert.ToDecimal(dr[i].ToString3()), null);
  674. }
  675. else
  676. {
  677. item.SetValue(t, dr[i].ToString(), null);
  678. }
  679. }
  680. }
  681. }
  682. }
  683. else
  684. {
  685. }
  686. }
  687. catch (Exception e)
  688. {
  689. System.Windows.Forms.MessageBox.Show("出错:", e.ToString());
  690. }
  691. return t;
  692. }
  693. /// <summary>
  694. /// 获取数据源中第一行数据赋到类中(grid 带下划线)
  695. /// </summary>
  696. /// <typeparam name="T">返回类</typeparam>
  697. /// <param name="ds">输入带数据的数据源</param>
  698. /// <param name="t">输入类</param>
  699. /// <returns></returns>
  700. public static T GetUltraGridToEntityNEW<T>(UltraGrid _grid, T t)
  701. {
  702. String[] strColumns = null;
  703. String[] strColumnsNew = null;
  704. UltraGridRow dr = _grid.Rows[0];
  705. int columnNum = dr.Cells.Count;
  706. strColumns = new String[columnNum];
  707. strColumnsNew = new String[columnNum];
  708. for (int i = 0; i < columnNum; i++)
  709. {
  710. strColumns[i] = _grid.DisplayLayout.Bands[0].Columns[i].Key.ToString().Replace("_", "");
  711. strColumnsNew[i] = _grid.DisplayLayout.Bands[0].Columns[i].Key.ToString();
  712. }
  713. System.Reflection.PropertyInfo[] pro = t.GetType().GetProperties();
  714. foreach (System.Reflection.PropertyInfo item in pro)
  715. {
  716. for (int i = 0; i < strColumns.Length; i++)
  717. {
  718. if (string.Compare(item.Name.ToString(), strColumns[i].ToString(), true) == 0)
  719. {
  720. if (item.PropertyType == typeof(int?))
  721. {
  722. item.SetValue(t, Convert.ToInt32(dr.Cells[strColumnsNew[i]].Value.ToString3()), null);
  723. }
  724. else if (item.PropertyType == typeof(decimal?))
  725. {
  726. item.SetValue(t, Convert.ToDecimal(dr.Cells[strColumnsNew[i]].Value.ToString3()), null);
  727. }
  728. else
  729. {
  730. item.SetValue(t, Convert.ToString(dr.Cells[strColumnsNew[i]].Value.ToString()), null);
  731. }
  732. }
  733. }
  734. }
  735. return t;
  736. }
  737. //调用本地程序打开查看服务器文件
  738. /// <summary>
  739. /// 调用本地程序打开查看服务器文件
  740. /// </summary>
  741. /// <param name="pathName"></param>
  742. public static void ViewCarft_No(string pathName)
  743. {
  744. try
  745. {
  746. //删除本地文件
  747. string tmpPath = Environment.CurrentDirectory + "\\Tmp\\";
  748. DirectoryInfo di = new DirectoryInfo(tmpPath);
  749. if (di.Exists == false)
  750. {
  751. di.Create();
  752. return;
  753. }
  754. foreach (FileInfo fi in di.GetFiles())
  755. {
  756. try
  757. {
  758. fi.Delete();
  759. }
  760. catch { continue; }
  761. }
  762. //下载写入本地Tmp目录
  763. if (pathName == "" || pathName == null) return;
  764. List<FileBean> list = Core.Mes.Client.Comm.Server.FileHelper.Download(pathName);
  765. foreach (FileBean bean in list)
  766. {
  767. FileStream fs = new FileStream(tmpPath + bean.getFileName(), FileMode.Create);
  768. fs.Write(bean.getFile(), 0, bean.getFile().Length);
  769. fs.Flush();
  770. fs.Close();
  771. System.Diagnostics.Process MyProcess = new System.Diagnostics.Process();
  772. MyProcess.StartInfo.FileName = tmpPath + bean.getFileName();
  773. MyProcess.StartInfo.Verb = "Open";
  774. MyProcess.StartInfo.CreateNoWindow = true;
  775. MyProcess.Start();
  776. return;
  777. }
  778. }
  779. catch { }
  780. }
  781. }
  782. }