FrmPurOilImportUse.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Data.OleDb;
  7. using System.Drawing;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Windows.Forms;
  13. using com.hnshituo.pur.vo;
  14. using Core.Mes.Client.Comm.Control;
  15. using Core.Mes.Client.Comm.Tool;
  16. using CoreFS.CA06;
  17. using Infragistics.Win;
  18. using Infragistics.Win.UltraWinGrid;
  19. using NPOI.HSSF.UserModel;
  20. using NPOI.SS.UserModel;
  21. using NPOI.XSSF.UserModel;
  22. using Pur.Entity;
  23. using Pur.Entity.configureEntity;
  24. using Pur.Entity.pur_orderEntiy;
  25. using Pur.Entity.require_planEntiy;
  26. namespace Pur.require_plan
  27. {
  28. public partial class FrmPurOilImportUse : FrmPmsBase
  29. {
  30. public String strTips = "0";
  31. string[] str ={"0","0","0","0","0","0","0","0","0","0","0","0","0"};
  32. string[] str1 = { "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" };
  33. public FrmPurOilImportUse()
  34. {
  35. InitializeComponent();
  36. this.IsLoadUserView = true;
  37. }
  38. public FrmPurOilImportUse(OpeBase OB)
  39. {
  40. InitializeComponent();
  41. this.ob = OB;
  42. }
  43. HSSFWorkbook hssfworkbook; //Office 2003
  44. XSSFWorkbook xssfworkbook; //Office 2007 2010
  45. ISheet sheet = null;
  46. private void FrmPurOilImportUse_Load(object sender, EventArgs e)
  47. {
  48. //绑定年份数据
  49. DataTable dt1 = new DataTable();
  50. dt1.Columns.Add("YEAR", Type.GetType("System.Int32"));
  51. for (int i = DateTime.Now.AddYears(-3).Year; i <= DateTime.Now.AddYears(3).Year; i++)
  52. dt1.Rows.Add(new object[] { i });
  53. Qyear.DataSource = dt1;
  54. Qyear.ValueMember = "YEAR";
  55. Qyear.DisplayMember = "YEAR";
  56. Qyear.Value = DateTime.Now.Year.ToString();
  57. ultraTabControl1.SelectedTab = ultraTabControl1.Tabs[0];
  58. //ultraGrid1.DisplayLayout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False;
  59. //ultraGrid2.DisplayLayout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False;
  60. GridHelper.SetExcludeColumnsActive(ultraGrid2.DisplayLayout.Bands[0],new string[]{"CHK"});
  61. ultraGrid2.DisplayLayout.Bands[0].Override.AllowUpdate = DefaultableBoolean.False;
  62. ck_ctime.Checked = true;
  63. txtCreateTimeStart.Value = DateTime.Now.AddMonths(-1);
  64. txtCreateTimeEnd.Value = DateTime.Now.AddDays(2);
  65. int mouth=DateTime.Now.Month;
  66. if (mouth == 1)
  67. {
  68. ck_yu.Checked = true;
  69. ck_1m.Checked = true;
  70. }
  71. else if (mouth == 2)
  72. {
  73. ck_2m.Checked = true;
  74. }
  75. else if (mouth == 3)
  76. {
  77. ck_3m.Checked = true;
  78. }
  79. else if (mouth == 4)
  80. {
  81. ck_4m.Checked = true;
  82. }
  83. else if (mouth == 5)
  84. {
  85. ck_5m.Checked = true;
  86. }
  87. else if (mouth == 6)
  88. {
  89. ck_6m.Checked = true;
  90. }
  91. else if (mouth == 7)
  92. {
  93. ck_7m.Checked = true;
  94. }
  95. else if (mouth == 8)
  96. {
  97. ck_8m.Checked = true;
  98. }
  99. else if (mouth == 9)
  100. {
  101. ck_9m.Checked = true;
  102. }
  103. else if (mouth == 10)
  104. {
  105. ck_10m.Checked = true;
  106. }
  107. else if (mouth == 11)
  108. {
  109. ck_10m.Checked = true;
  110. }
  111. else if (mouth == 12)
  112. {
  113. ck_12m.Checked = true;
  114. }
  115. }
  116. private void FrmImportOrder_Shown(object sender, EventArgs e)
  117. {
  118. this.ultraToolbarsManager1.Toolbars[0].Tools["doImport"].InstanceProps.Visible = DefaultableBoolean.True;
  119. this.ultraToolbarsManager1.Toolbars[0].Tools["doSure"].InstanceProps.Visible = DefaultableBoolean.True;
  120. this.ultraToolbarsManager1.Toolbars[0].Tools["doExcel"].InstanceProps.Visible = DefaultableBoolean.True;
  121. this.ultraToolbarsManager1.Toolbars[0].Tools["doClear"].InstanceProps.Visible = DefaultableBoolean.True;
  122. this.ultraToolbarsManager1.Toolbars[0].Tools["doQuery"].InstanceProps.Visible = DefaultableBoolean.False;
  123. }
  124. //查询导入的记录
  125. private void getInportData()
  126. {
  127. try
  128. {
  129. if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[1])
  130. {
  131. this.Cursor = Cursors.WaitCursor;
  132. import.Clear();
  133. OilImport ipt = new OilImport();
  134. ipt.UserName = txt_useName.Text.Trim();
  135. ipt.CardDId = txt_card_change_d.Text.Trim();
  136. if (ck_ctime.Checked)
  137. {
  138. if (!String.IsNullOrEmpty(txtCreateTimeStart.Text))
  139. {
  140. ipt.CreateTime = Convert.ToDateTime(txtCreateTimeStart.Value);
  141. }
  142. if (!String.IsNullOrEmpty(txtCreateTimeEnd.Text))
  143. {
  144. ipt.DeleteTime = Convert.ToDateTime(txtCreateTimeEnd.Value);
  145. }
  146. }
  147. DataTable dt = this.execute<DataTable>("com.hnshituo.pur.requireplan.service.OilImportService", "find_Import", new object[] { ipt });
  148. GridHelper.CopyDataToDatatable(dt, dataTable1, true);
  149. GridHelper.RefreshAndAutoSize(ultraGrid2);
  150. }
  151. }
  152. catch (Exception ex)
  153. {
  154. MessageUtil.ShowTips("查询导入历史数据数据失败:" + ex);
  155. }
  156. finally
  157. {
  158. this.Cursor = Cursors.Default;
  159. }
  160. }
  161. /// <summary>
  162. /// 使用系统软件打开模板
  163. /// </summary>
  164. /// <param name="sender"></param>
  165. /// <param name="e"></param>
  166. private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  167. {
  168. string path = "";
  169. try
  170. {
  171. path = System.Windows.Forms.Application.StartupPath + "\\OrderTemplate\\OrderTemplate.xls";
  172. System.Diagnostics.Process.Start(path);
  173. }
  174. catch (Exception ex)
  175. {
  176. MessageUtil.ShowWarning("没有可用的模板!");
  177. }
  178. }
  179. #region toolbar工具栏
  180. private void ultraToolbarsManager1_ToolClick(object sender, Infragistics.Win.UltraWinToolbars.ToolClickEventArgs e)
  181. {
  182. switch (e.Tool.Key)
  183. {
  184. case "doImport": // ButtonTool
  185. ImportExcel();
  186. break;
  187. case "doQuery": // ButtonTool
  188. getInportData();
  189. break;
  190. case "doSure": // ButtonTool
  191. ConfirmData();
  192. break;
  193. case "doClose": // ButtonTool
  194. this.Close();
  195. break;
  196. case "doExcel": // ButtonTool
  197. doExcel();
  198. break;
  199. case "doClear": // ButtonTool
  200. doClear();
  201. break;
  202. }
  203. }
  204. private void doExcel()
  205. {
  206. try
  207. {
  208. this.Cursor = Cursors.Default;
  209. if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[0])
  210. {
  211. if (ultraGrid1.Rows.Count <= 0)
  212. {
  213. MessageUtil.ShowTips("无可导出的待导入交易明细!");
  214. return;
  215. }
  216. ArrayList alUltraGrid = new ArrayList();
  217. alUltraGrid.Add(ultraGrid1);
  218. ArrayList alSheeft = new ArrayList();
  219. alSheeft.Add("待导入交易明细");
  220. GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "待导入交易明细");
  221. }
  222. else
  223. {
  224. if (ultraGrid2.Rows.Count <= 0)
  225. {
  226. MessageUtil.ShowTips("无可导出导入记录!");
  227. return;
  228. }
  229. ArrayList alUltraGrid = new ArrayList();
  230. alUltraGrid.Add(ultraGrid2);
  231. ArrayList alSheeft = new ArrayList();
  232. alSheeft.Add("导入记录");
  233. GridHelper.ulGridToExcel(alUltraGrid, alSheeft, "导入记录");
  234. }
  235. }
  236. catch (Exception e)
  237. {
  238. MessageUtil.ShowTips("导出失败" + e.Message);
  239. }
  240. finally
  241. {
  242. this.Cursor = Cursors.Default;
  243. }
  244. }
  245. //清空
  246. private void doClear()
  247. {
  248. if (MessageUtil.ShowYesNoAndQuestion("确定清空?") != DialogResult.Yes)
  249. { return; }
  250. for (int i = this.ultraGrid1.Rows.Count-1; i >=0 ; i--)
  251. {
  252. this.ultraGrid1.Rows[i].Delete();
  253. }
  254. }
  255. private void ImportExcel()
  256. {
  257. OpenFileDialog ofd = new OpenFileDialog();
  258. ofd.Filter = "所有文件|*.xls;*.xlsx|xls文件(*.xls)|*.xls|xlsx文件(*.xlsx)|*.xlsx";
  259. ofd.Multiselect = false;
  260. if (ofd.ShowDialog() == DialogResult.OK)
  261. {
  262. this.Cursor = Cursors.WaitCursor;
  263. string filePath = ofd.FileName;
  264. InitializeWorkbook(filePath);
  265. //ConvertToDataTable();
  266. Thread t = new Thread(new ThreadStart(ConvertToDataTable));
  267. t.Start();
  268. }
  269. }
  270. /// <summary>
  271. /// 确定提交
  272. /// </summary>
  273. private void ConfirmData()
  274. {
  275. try
  276. {
  277. this.Cursor = Cursors.WaitCursor;
  278. List<OilImport> listc = new List<OilImport>();
  279. ultraGrid1.UpdateData();
  280. if (Qyear.SelectedIndex == -1)
  281. {
  282. MessageUtil.ShowTips("请选择导入的年份");
  283. Qyear.Focus();
  284. return;
  285. }
  286. String strYear = Qyear.Value.ToString().Trim();
  287. foreach (UltraGridRow row in ultraGrid1.Rows)
  288. {
  289. if (row.Cells["选择"].Value.ToString().ToUpper() == "TRUE")
  290. {
  291. string cardDId = row.Cells[1].Value.ToString().Trim();
  292. string remain = row.Cells[2].Value.ToString().Trim();
  293. string use1 = row.Cells[3].Value.ToString().Trim();
  294. string use2 = row.Cells[4].Value.ToString().Trim();
  295. string use3 = row.Cells[5].Value.ToString().Trim();
  296. string use4 = row.Cells[6].Value.ToString().Trim();
  297. string use5 = row.Cells[7].Value.ToString().Trim();
  298. string use6 = row.Cells[8].Value.ToString().Trim();
  299. string use7 = row.Cells[9].Value.ToString().Trim();
  300. String use8 = row.Cells[10].Value.ToString().Trim();
  301. string use9 = row.Cells[11].Value.ToString().Trim();
  302. string use10 = row.Cells[12].Value.ToString().Trim();
  303. string use11 = row.Cells[13].Value.ToString().Trim();
  304. string use12 = row.Cells[14].Value.ToString().Trim();
  305. if (String.IsNullOrEmpty(cardDId))
  306. {
  307. MessageUtil.ShowWarning("副卡卡号不能为空!");
  308. row.Activate();
  309. return;
  310. }
  311. if (!IsNum(remain))
  312. {
  313. MessageUtil.ShowWarning("卡:" + cardDId + "年初卡余额输入数字格式不正确!");
  314. row.Activate();
  315. return;
  316. }
  317. if (!IsNum(use1))
  318. {
  319. MessageUtil.ShowWarning("卡:" + cardDId + "去年12月输入数字格式不正确!");
  320. return;
  321. }
  322. if (!IsNum(use2))
  323. {
  324. MessageUtil.ShowWarning("卡:" + cardDId + "1月输入数字格式不正确!");
  325. row.Activate();
  326. return;
  327. }
  328. if (!IsNum(use3))
  329. {
  330. MessageUtil.ShowWarning("卡:" + cardDId + "2月输入数字格式不正确!");
  331. row.Activate();
  332. return;
  333. }
  334. if (!IsNum(use4))
  335. {
  336. MessageUtil.ShowWarning("卡:" + cardDId + "3月输入数字格式不正确!");
  337. row.Activate();
  338. return;
  339. }
  340. if (!IsNum(use5))
  341. {
  342. MessageUtil.ShowWarning("卡:" + cardDId + "4月输入数字格式不正确!");
  343. row.Activate();
  344. return;
  345. }
  346. if (!IsNum(use6))
  347. {
  348. MessageUtil.ShowWarning("卡:" + cardDId + "5月输入数字格式不正确!");
  349. row.Activate();
  350. return;
  351. }
  352. if (!IsNum(use7))
  353. {
  354. MessageUtil.ShowWarning("卡:" + cardDId + "6月输入数字格式不正确!");
  355. row.Activate();
  356. return;
  357. }
  358. if (!IsNum(use8))
  359. {
  360. MessageUtil.ShowWarning("卡:" + cardDId + "7月输入数字格式不正确!");
  361. row.Activate();
  362. return;
  363. }
  364. if (!IsNum(use9))
  365. {
  366. MessageUtil.ShowWarning("卡:" + cardDId + "8月输入数字格式不正确!");
  367. row.Activate();
  368. return;
  369. }
  370. if (!IsNum(use10))
  371. {
  372. MessageUtil.ShowWarning("卡:" + cardDId + "9月输入数字格式不正确!");
  373. row.Activate();
  374. return;
  375. }
  376. if (!IsNum(use11))
  377. {
  378. MessageUtil.ShowWarning("卡:" + cardDId + "10月输入数字格式不正确!");
  379. return;
  380. }
  381. if (!IsNum(use12))
  382. {
  383. MessageUtil.ShowWarning("卡:" + cardDId + "11月输入数字格式不正确!");
  384. row.Activate();
  385. return;
  386. }
  387. OilImport ipt = new OilImport();
  388. ipt.CardDId = cardDId;
  389. if (!String.IsNullOrEmpty(use1))
  390. {
  391. ipt.M1UseNew = use1;
  392. }
  393. if (!String.IsNullOrEmpty(use2))
  394. {
  395. ipt.M2UseNew = use2;
  396. }
  397. if (!String.IsNullOrEmpty(use3))
  398. {
  399. ipt.M3UseNew = use3;
  400. }
  401. if (!String.IsNullOrEmpty(use4))
  402. {
  403. ipt.M4UseNew = use4;
  404. }
  405. if (!String.IsNullOrEmpty(use5))
  406. {
  407. ipt.M5UseNew = use5;
  408. }
  409. if (!String.IsNullOrEmpty(use6))
  410. {
  411. ipt.M6UseNew = use6;
  412. }
  413. if (!String.IsNullOrEmpty(use7))
  414. {
  415. ipt.M7UseNew = use7;
  416. }
  417. if (!String.IsNullOrEmpty(use8))
  418. {
  419. ipt.M8UseNew = use8;
  420. }
  421. if (!String.IsNullOrEmpty(use9))
  422. {
  423. ipt.M9UseNew = use9;
  424. }
  425. if (!String.IsNullOrEmpty(use10))
  426. {
  427. ipt.M10UseNew = use10;
  428. }
  429. if (!String.IsNullOrEmpty(use11))
  430. {
  431. ipt.M11UseNew =use11;
  432. }
  433. if (!String.IsNullOrEmpty(use12))
  434. {
  435. ipt.M12UseNew = use12;
  436. }
  437. if (!String.IsNullOrEmpty(remain))
  438. {
  439. ipt.RemainNew =remain;
  440. }
  441. ipt.CreateUserid = UserInfo.GetUserID();
  442. ipt.CreateName = UserInfo.GetUserName();
  443. ipt.CreateTime = DateTime.Now;
  444. ipt.Validflag = "1";
  445. listc.Add(ipt);
  446. }
  447. }
  448. if (listc.Count <= 0)
  449. {
  450. MessageUtil.ShowWarning("请勾选您要确认导入的数据行!");
  451. return;
  452. }
  453. str = str1;
  454. String strtips1 = "确定更新"+strYear+"年的";
  455. int ii = 0;
  456. if (ck_yu.Checked)
  457. {
  458. str[0] = "1";
  459. strtips1 = strtips1 + "年初余额 ";
  460. ii = ii + 1;
  461. }
  462. String strtips="";
  463. if (ck_1m.Checked)
  464. {
  465. str[1] = "1";
  466. strtips = strtips + "去年12月 ";
  467. ii = ii + 1;
  468. }
  469. if (ck_2m.Checked)
  470. {
  471. str[2] = "1";
  472. strtips = strtips + "1月 ";
  473. ii = ii + 1;
  474. }
  475. if (ck_3m.Checked)
  476. {
  477. str[3] = "1";
  478. strtips = strtips + "2月 ";
  479. ii = ii + 1;
  480. }
  481. if (ck_4m.Checked)
  482. {
  483. str[4] = "1";
  484. strtips = strtips + "3月 ";
  485. ii = ii + 1;
  486. }
  487. if (ck_5m.Checked)
  488. {
  489. str[5] = "1";
  490. strtips = strtips + "4月 ";
  491. ii = ii + 1;
  492. }
  493. if (ck_6m.Checked)
  494. {
  495. str[6] = "1";
  496. strtips = strtips + "5月 ";
  497. ii = ii + 1;
  498. }
  499. if (ck_7m.Checked)
  500. {
  501. str[7] = "1";
  502. strtips = strtips + "6月 ";
  503. ii = ii + 1;
  504. }
  505. if (ck_8m.Checked)
  506. {
  507. str[8] = "1";
  508. strtips = strtips + "7月 ";
  509. ii = ii + 1;
  510. }
  511. if (ck_9m.Checked)
  512. {
  513. str[9] = "1";
  514. strtips = strtips + "8月 ";
  515. ii = ii + 1;
  516. }
  517. if (ck_10m.Checked)
  518. {
  519. str[10] = "1";
  520. strtips = strtips + "9月 ";
  521. ii = ii + 1;
  522. }
  523. if (ck_11m.Checked)
  524. {
  525. str[11] = "1";
  526. strtips = strtips + "10月 ";
  527. ii = ii + 1;
  528. }
  529. if (ck_12m.Checked)
  530. {
  531. str[12] = "1";
  532. strtips = strtips + "11月 ";
  533. ii = ii + 1;
  534. }
  535. if (ii <= 0)
  536. {
  537. MessageUtil.ShowTips("请指定更新内容");
  538. return;
  539. }
  540. if(!String.IsNullOrEmpty(strtips))
  541. {
  542. strtips = "和"+strtips + "的消耗";
  543. strtips1 = strtips1 + strtips;
  544. }
  545. strtips1 = strtips1 + "项目,共" + listc.Count + "条数据?";
  546. if (MessageUtil.ShowYesNoAndQuestion(strtips1) != DialogResult.Yes) return;
  547. CoreResult rt = this.execute<CoreResult>("com.hnshituo.pur.requireplan.service.OilImportService", "insert_Import", new object[] { listc, strYear, str });
  548. if (rt.Resultcode == 0)
  549. {
  550. MessageUtil.ShowTips("操作成功");
  551. ultraGrid1.Refresh();
  552. strTips = "1";
  553. for (int i = this.ultraGrid1.Rows.Count - 1; i >= 0; i--)
  554. {
  555. if (ultraGrid1.Rows[i].Cells["选择"].Value.ToString().ToUpper() == "TRUE")
  556. {
  557. this.ultraGrid1.Rows[i].Delete();
  558. }
  559. }
  560. }
  561. else
  562. {
  563. MessageUtil.ShowTips("操作失败:" + rt.Resultmsg);
  564. }
  565. }
  566. finally
  567. {
  568. this.Cursor = Cursors.Default;
  569. }
  570. }
  571. #endregion
  572. /// <summary>
  573. /// 打开选择的Excel
  574. /// </summary>
  575. /// <param name="path"></param>
  576. private void InitializeWorkbook(string path)
  577. {
  578. try
  579. {
  580. using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
  581. {
  582. hssfworkbook = new HSSFWorkbook(file);
  583. sheet = hssfworkbook.GetSheetAt(0);
  584. }
  585. }
  586. catch
  587. {
  588. using (FileStream file = new FileStream(path, FileMode.Open, FileAccess.Read))
  589. {
  590. xssfworkbook = new XSSFWorkbook(file);
  591. sheet = xssfworkbook.GetSheetAt(0);
  592. }
  593. }
  594. }
  595. /// <summary>
  596. /// 将Excel内容转化为DataTable
  597. /// </summary>
  598. private void ConvertToDataTable()
  599. {
  600. //ISheet sheet = hssfworkbook.GetSheetAt(0);
  601. System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
  602. IRow iRow = sheet.GetRow(0);
  603. short count = iRow.LastCellNum;
  604. if (count <14)
  605. {
  606. MessageUtil.ShowWarning("导入的Excel列数与模板列数不符!");
  607. return;
  608. }
  609. DataTable dt = new DataTable();
  610. for (int j = 0; j < 14 + 1; j++)
  611. {
  612. if (j == 0) //加一列选择框
  613. {
  614. dt.Columns.Add("选择");
  615. }
  616. else
  617. {
  618. dt.Columns.Add(Convert.ToChar(((int)'A') + j).ToString());
  619. }
  620. }
  621. dt.Columns[0].DefaultValue = "False";
  622. dt.Columns[0].DataType = typeof(Boolean);
  623. while (rows.MoveNext())
  624. {
  625. IRow row = null;
  626. try
  627. {
  628. row = (HSSFRow)rows.Current;
  629. }
  630. catch
  631. {
  632. row = (XSSFRow)rows.Current;
  633. }
  634. DataRow dr = dt.NewRow();
  635. int k=0;
  636. for (int i = 1; i < row.LastCellNum + 1; i++)
  637. {
  638. ICell cell = row.GetCell(i - 1);
  639. if (cell == null)
  640. {
  641. dr[i] = null;
  642. }
  643. else
  644. {
  645. if (!String.IsNullOrEmpty(cell.ToString().Trim()))
  646. {
  647. if (StringUtil.IsDouble(cell.ToString().Trim()))
  648. {
  649. dr[i] = Convert.ToDecimal(Decimal.Parse(cell.ToString().Trim(), System.Globalization.NumberStyles.Float));
  650. }
  651. else
  652. {
  653. dr[i] = cell.ToString().Trim();
  654. }
  655. k = k + 1;
  656. }
  657. }
  658. }
  659. if (k >= 1)
  660. {
  661. dt.Rows.Add(dr);
  662. }
  663. }
  664. SetGrid(dt);
  665. }
  666. delegate void SetGridCallBack(DataTable dt);
  667. private void SetGrid(DataTable dt)
  668. {
  669. if (ultraGrid1.InvokeRequired)
  670. {
  671. SetGridCallBack sg = new SetGridCallBack(SetGrid);
  672. this.Invoke(sg, new object[] { dt });
  673. }
  674. else
  675. {
  676. ultraGrid1.DataSource = dt;
  677. ultraGrid1.DisplayLayout.Bands[0].Columns["选择"].Header.CheckBoxVisibility = Infragistics.Win.UltraWinGrid.HeaderCheckBoxVisibility.WhenUsingCheckEditor;
  678. ultraGrid1.DisplayLayout.Bands[0].Columns[1].Width = 135;
  679. GridHelper.RefreshAndAutoSize(ultraGrid1);
  680. this.Cursor = Cursors.Default;
  681. }
  682. }
  683. private void ultraTabControl1_SelectedTabChanged(object sender, Infragistics.Win.UltraWinTabControl.SelectedTabChangedEventArgs e)
  684. {
  685. if (ultraTabControl1.SelectedTab == ultraTabControl1.Tabs[0])
  686. {
  687. this.ultraToolbarsManager1.Toolbars[0].Tools["doImport"].InstanceProps.Visible = DefaultableBoolean.True;
  688. this.ultraToolbarsManager1.Toolbars[0].Tools["doSure"].InstanceProps.Visible = DefaultableBoolean.True;
  689. this.ultraToolbarsManager1.Toolbars[0].Tools["doExcel"].InstanceProps.Visible = DefaultableBoolean.True;
  690. this.ultraToolbarsManager1.Toolbars[0].Tools["doClear"].InstanceProps.Visible = DefaultableBoolean.True;
  691. this.ultraToolbarsManager1.Toolbars[0].Tools["doQuery"].InstanceProps.Visible = DefaultableBoolean.False;
  692. }
  693. else
  694. {
  695. this.ultraToolbarsManager1.Toolbars[0].Tools["doImport"].InstanceProps.Visible = DefaultableBoolean.False;
  696. this.ultraToolbarsManager1.Toolbars[0].Tools["doSure"].InstanceProps.Visible = DefaultableBoolean.False;
  697. this.ultraToolbarsManager1.Toolbars[0].Tools["doExcel"].InstanceProps.Visible = DefaultableBoolean.True;
  698. this.ultraToolbarsManager1.Toolbars[0].Tools["doClear"].InstanceProps.Visible = DefaultableBoolean.False;
  699. this.ultraToolbarsManager1.Toolbars[0].Tools["doQuery"].InstanceProps.Visible = DefaultableBoolean.True;
  700. }
  701. }
  702. private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
  703. {
  704. string path = "";
  705. try
  706. {
  707. path = System.Windows.Forms.Application.StartupPath + "\\OrderTemplate\\OilCardUse.xls";
  708. System.Diagnostics.Process.Start(path);
  709. }
  710. catch (Exception ex)
  711. {
  712. MessageUtil.ShowWarning("没有可用的模板!");
  713. }
  714. }
  715. private void ck_ctime_CheckedChanged(object sender, EventArgs e)
  716. {
  717. txtCreateTimeEnd.Enabled = ck_ctime.Checked;
  718. txtCreateTimeStart.Enabled = ck_ctime.Checked;
  719. }
  720. /// <summary>
  721. /// 判断是否为正数数字
  722. /// </summary>
  723. /// <param name="p"></param>
  724. /// <returns></returns>
  725. private bool IsNum(string str)
  726. {
  727. if (str != "")
  728. {
  729. return StringUtil.IsNumber(str);
  730. }
  731. return true;
  732. }
  733. }
  734. }