F_P_00002.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /*******************************************************************************
  2. * Copyright(c) 2015 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:F_P_00002.cs
  5. * 2.功能描述:成型结算信息表
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2017/01/11 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Data;
  13. using System.Drawing;
  14. using System.Windows.Forms;
  15. using Dongke.IBOSS.PRD.Basics.BaseControls;
  16. using Dongke.IBOSS.PRD.Basics.BaseResources;
  17. using Dongke.IBOSS.PRD.Client.CommonModule;
  18. using Dongke.IBOSS.PRD.Client.Controls;
  19. using Dongke.IBOSS.PRD.WCF.DataModels;
  20. using Dongke.IBOSS.PRD.WCF.Proxys;
  21. namespace Dongke.IBOSS.PRD.Client.Public
  22. {
  23. /// <summary>
  24. /// 成型结算信息表
  25. /// </summary>
  26. public partial class F_P_00002 : DKFormBase
  27. {
  28. #region 功能条码
  29. //public const string PreMonthCN = "#前月#";
  30. //public const string CurMonthCN = "#当月#";
  31. //public const string QUITCN = "#退出#";
  32. //public const string NextPageCN = "#下一页#";
  33. //public const string PrePageCN = "#上一页#";
  34. //public const string NextRowCN = "#下一行#";
  35. //public const string PreRowCN = "#上一行#";
  36. //public const string CurRowCN = "#当日#";
  37. //public const string Month00CN = "#合计#";
  38. public const string PreMonth = "#PREMONTH#";
  39. public const string CurMonth = "#CURMONTH#";
  40. public const string QUIT = "#QUIT#";
  41. public const string NextPage = "#NEXTPAGE#";
  42. public const string PrePage = "#PREPAGE#";
  43. public const string NextRow = "#NEXTROW#";
  44. public const string PreRow = "#PREROW#";
  45. public const string CurRow = "#CURROW#";
  46. public const string Month00 = "#00#";
  47. public const string Month01 = "#01#";
  48. public const string Month02 = "#02#";
  49. public const string Month03 = "#03#";
  50. public const string Month04 = "#04#";
  51. public const string Month05 = "#05#";
  52. public const string Month06 = "#06#";
  53. public const string Month07 = "#07#";
  54. public const string Month08 = "#08#";
  55. public const string Month09 = "#09#";
  56. public const string Month10 = "#10#";
  57. public const string Month11 = "#11#";
  58. public const string Month12 = "#12#";
  59. public const string Month13 = "#13#";
  60. public const string Month14 = "#14#";
  61. public const string Month15 = "#15#";
  62. public const string Month16 = "#16#";
  63. public const string Month17 = "#17#";
  64. public const string Month18 = "#18#";
  65. public const string Month19 = "#19#";
  66. public const string Month20 = "#20#";
  67. public const string Month21 = "#21#";
  68. public const string Month22 = "#22#";
  69. public const string Month23 = "#23#";
  70. public const string Month24 = "#24#";
  71. public const string Month25 = "#25#";
  72. public const string Month26 = "#26#";
  73. public const string Month27 = "#27#";
  74. public const string Month28 = "#28#";
  75. public const string Month29 = "#29#";
  76. public const string Month30 = "#30#";
  77. public const string Month31 = "#31#";
  78. #endregion
  79. #region 成员变量
  80. // 窗体的单例模式
  81. private static F_P_00002 _instance;
  82. private long _showLimitTime = 0;
  83. private long _LimitTime = 120;
  84. private F_P_000021 _frmUserCode = new F_P_000021();
  85. private bool _isLoading = false;
  86. private DataSet _dataSet = null;
  87. #endregion
  88. #region 构造函数
  89. public F_P_00002()
  90. {
  91. InitializeComponent();
  92. // 窗体显示的Title
  93. this.Text = "成型结算";
  94. this.tsbtnAdaptive.Text = ButtonText.TSBTN_ADAPTIVE;
  95. this.tsbtnClose.Text = ButtonText.TSBTN_CLOSE;
  96. this.lblUserCode.Text = null;
  97. this.dgv0.AutoGenerateColumns = false;
  98. this.dgv1.AutoGenerateColumns = false;
  99. this.dgv2.AutoGenerateColumns = false;
  100. this.dgv3.AutoGenerateColumns = false;
  101. this.dgv4.AutoGenerateColumns = false;
  102. this.dgvM.AutoGenerateColumns = false;
  103. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
  104. //this.tsbtnAdaptive_Click(null, null);
  105. }
  106. #endregion
  107. #region 单例模式
  108. /// <summary>
  109. /// 单例模式,防止重复创建窗体
  110. /// </summary>
  111. public static F_P_00002 Instance
  112. {
  113. get
  114. {
  115. if (_instance == null || _instance.IsDisposed)
  116. {
  117. _instance = new F_P_00002();
  118. }
  119. return _instance;
  120. }
  121. }
  122. #endregion
  123. #region 事件处理
  124. /// <summary>
  125. /// 窗体加载事件
  126. /// </summary>
  127. /// <param name="sender"></param>
  128. /// <param name="e"></param>
  129. private void F_P_00002_Load(object sender, EventArgs e)
  130. {
  131. try
  132. {
  133. string showLimitTime = System.Configuration.ConfigurationManager.AppSettings["ShowLimitTime"];
  134. long time = 0;
  135. if (!long.TryParse(showLimitTime, out time))
  136. {
  137. _LimitTime = time;
  138. }
  139. //this.BindPage();
  140. }
  141. catch (Exception ex)
  142. {
  143. // 对异常进行共通处理
  144. ExceptionManager.HandleEventException(this.ToString(),
  145. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  146. }
  147. }
  148. private void F_P_00002_Shown(object sender, EventArgs e)
  149. {
  150. this.ResetForm();
  151. }
  152. private void F_P_00002_FormClosed(object sender, FormClosedEventArgs e)
  153. {
  154. _instance = null;
  155. }
  156. private void tsbtnClose_Click(object sender, EventArgs e)
  157. {
  158. this.Close();
  159. }
  160. private void F_P_00002_SizeChanged(object sender, EventArgs e)
  161. {
  162. this.WindowState = FormWindowState.Maximized;
  163. }
  164. private void timer1_Tick(object sender, EventArgs e)
  165. {
  166. SetShowTime(this._showLimitTime);
  167. this._showLimitTime--;
  168. }
  169. private void btnResetForm_Click(object sender, EventArgs e)
  170. {
  171. this.ResetForm();
  172. }
  173. #endregion
  174. #region 私有方法
  175. /// <summary>
  176. /// 绑定下拉列表值
  177. /// </summary>
  178. /// <returns></returns>
  179. private void BindPage()
  180. {
  181. //绑定数据来源下拉列表
  182. //ServiceResultEntity sre = (ServiceResultEntity)DoAsync(new BaseAsyncMethod(() =>
  183. //{
  184. // return PublicModuleProxy.Service.GetRptProcedureModule(F_P_00001.AccountID);
  185. //}));
  186. //this.dropRptProcedure.DataSource = sre.Data.Tables[Constant.INT_IS_ZERO];
  187. //this.dropRptProcedure.ValueMember = "Rptprocedureid";
  188. //this.dropRptProcedure.DisplayMember = "Rptprocedurename";
  189. }
  190. /// <summary>
  191. /// 根据界面查询条件获取数据集
  192. /// </summary>
  193. private ServiceResultEntity GetSearchData()
  194. {
  195. try
  196. {
  197. if (string.IsNullOrWhiteSpace(this._frmUserCode.UserCode))
  198. {
  199. return null;
  200. }
  201. //if (string.IsNullOrEmpty(this.dropRptProcedure.Text))
  202. //{
  203. // return null;
  204. //}
  205. ////se.RptProcedureID = Convert.ToInt32(this.dropRptProcedure.SelectedValue);
  206. //DataRowView drv = this.dropRptProcedure.SelectedItem as DataRowView;
  207. //int? pid = null;
  208. //if (drv != null)
  209. //{
  210. // pid = int.Parse(drv["SProcedureid"].ToString());
  211. //}
  212. //if (!pid.HasValue)
  213. //{
  214. // return null;
  215. //}
  216. string usercode = this._frmUserCode.UserCode;
  217. //DateTime selectDate = this._frmUserCode.DateStart;
  218. DateTime selectDate = this._frmUserCode.DateMonth;
  219. ServiceResultEntity sre = (ServiceResultEntity)DoAsync(() =>
  220. {
  221. return PublicModuleProxy.Service.GetFP00002Data(F_P_00001.AccountID,
  222. usercode, selectDate);
  223. });
  224. return sre;
  225. }
  226. catch (Exception ex)
  227. {
  228. throw ex;
  229. }
  230. }
  231. private void SetShowTime(long time)
  232. {
  233. if (time == 0)
  234. {
  235. this.ResetForm();
  236. return;
  237. }
  238. string t = time.ToString();
  239. int l = t.Length;
  240. if (l >= 3)
  241. {
  242. pic3.Image = GetTimePic(t[0]);
  243. pic2.Image = GetTimePic(t[1]);
  244. pic1.Image = GetTimePic(t[2]);
  245. }
  246. else if (l == 2)
  247. {
  248. pic3.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
  249. pic2.Image = GetTimePic(t[0]);
  250. pic1.Image = GetTimePic(t[1]);
  251. }
  252. else if (l == 1)
  253. {
  254. pic3.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
  255. pic2.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
  256. pic1.Image = GetTimePic(t[0]);
  257. }
  258. }
  259. private Bitmap GetTimePic(char num)
  260. {
  261. switch (num)
  262. {
  263. case '0':
  264. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
  265. case '1':
  266. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_1;
  267. case '2':
  268. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_2;
  269. case '3':
  270. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_3;
  271. case '4':
  272. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_4;
  273. case '5':
  274. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_5;
  275. case '6':
  276. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_6;
  277. case '7':
  278. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_7;
  279. case '8':
  280. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_8;
  281. case '9':
  282. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_9;
  283. default:
  284. return Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
  285. }
  286. }
  287. private void ClearGridData()
  288. {
  289. this._isLoading = true;
  290. try
  291. {
  292. this.lblUserCode.Text = null;
  293. //this.gb0.Text = "总体信息";
  294. this.gbm.Text = "月度信息【 】";
  295. this.gb1.Text = "成检缺陷明细【 】";
  296. this.gb2.Text = "后道损坯明细【 】";
  297. this.gb3.Text = "半检不合格明细【 】";
  298. this.gb4.Text = "返工(合格)明细【 】";
  299. this.dgvM.DataSource = null;
  300. this.dgv0.DataSource = null;
  301. this.dgv1.DataSource = null;
  302. this.dgv2.DataSource = null;
  303. this.dgv3.DataSource = null;
  304. this.dgv4.DataSource = null;
  305. this._dataSet = null;
  306. }
  307. finally
  308. {
  309. this._isLoading = false;
  310. }
  311. }
  312. private void AutoResizeColumns()
  313. {
  314. this.dgv0.AutoResizeColumns();
  315. this.dgv1.AutoResizeColumns();
  316. this.dgv2.AutoResizeColumns();
  317. this.dgv3.AutoResizeColumns();
  318. this.dgv4.AutoResizeColumns();
  319. this.dgvM.AutoResizeColumns();
  320. }
  321. private void ResetSearch()
  322. {
  323. timerShow.Stop();
  324. this.ClearGridData();
  325. this.AutoResizeColumns();
  326. pic3.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
  327. pic2.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
  328. pic1.Image = Dongke.IBOSS.PRD.Client.Public.Properties.Resources.num_0;
  329. }
  330. private void ResetForm()
  331. {
  332. this.ResetSearch();
  333. if (this._frmUserCode.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  334. {
  335. this.SearchData();
  336. }
  337. else
  338. {
  339. this.Close();
  340. }
  341. }
  342. private void SearchData()
  343. {
  344. try
  345. {
  346. this.ResetSearch();
  347. if (F_P_00001.AutoUp())
  348. {
  349. return;
  350. }
  351. this.gb0.Text = string.Format("总体信息【{0}】", DateTime.Now.ToString("yyyy-MM-dd"));
  352. this.lblUserCode.Text = this._frmUserCode.UserCode;
  353. ServiceResultEntity sre = this.GetSearchData();
  354. if (sre == null)
  355. {
  356. this._frmUserCode.ErrorMessges = "没有查询到任何数据";
  357. this.ResetForm();
  358. return;
  359. }
  360. if (sre.Status == Constant.ServiceResultStatus.Other)
  361. {
  362. this._frmUserCode.ErrorMessges = sre.Message + "【" + this._frmUserCode.UserCode + "】";
  363. this.ResetForm();
  364. return;
  365. }
  366. this._dataSet = sre.Data;
  367. if (this._dataSet != null)
  368. {
  369. this._isLoading = true;
  370. this.dgvM.DataSource = this._dataSet.Tables["DataM"];
  371. this.dgv0.DataSource = this._dataSet.Tables["DataD"];
  372. this._isLoading = false;
  373. _currentRowIndex = -1;
  374. this.dgvM_SelectionChanged(null, null);
  375. }
  376. else
  377. {
  378. this.ResetForm();
  379. return;
  380. }
  381. this.AutoResizeColumns();
  382. this.txtKey.Focus();
  383. //string showLimitTime = System.Configuration.ConfigurationManager.AppSettings["ShowLimitTime"];
  384. //if (!long.TryParse(showLimitTime, out _showLimitTime))
  385. //{
  386. // _showLimitTime = 120;
  387. //}
  388. _showLimitTime = _LimitTime;
  389. //SetShowTime(_showLimitTime);
  390. timerShow.Start();
  391. }
  392. catch (Exception ex)
  393. {
  394. this._isLoading = false;
  395. // 对异常进行共通处理
  396. ExceptionManager.HandleEventException(this.ToString(),
  397. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  398. this.ResetForm();
  399. }
  400. finally
  401. {
  402. this._isLoading = false;
  403. }
  404. }
  405. #endregion
  406. private int _currentRowIndex = -1;
  407. private void dgvM_SelectionChanged(object sender, EventArgs e)
  408. {
  409. if (this._isLoading || this._dataSet == null || this.dgvM.Rows.Count <= 0 || this.dgvM.CurrentRow == null)
  410. {
  411. return;
  412. }
  413. if (_currentRowIndex == this.dgvM.CurrentRow.Index)
  414. {
  415. return;
  416. }
  417. try
  418. {
  419. _currentRowIndex = this.dgvM.CurrentRow.Index;
  420. DataRowView drv = this.dgvM.CurrentRow.DataBoundItem as DataRowView;
  421. if (drv == null)
  422. {
  423. return;
  424. }
  425. string cddate = drv["cdate"] + "";
  426. string rowFilter = null;
  427. this.gbm.Text = string.Format("月度信息【{0} {1}】", cddate, drv["goodscode"]);
  428. //this.gb1.Text = string.Format("成检缺陷明细【{0} {1}】", cddate, drv["goodscode"]);
  429. //this.gb2.Text = string.Format("后道损坯明细【{0} {1}】", cddate, drv["goodscode"]);
  430. //this.gb3.Text = string.Format("半检不合格明细【{0} {1}】", cddate, drv["goodscode"]);
  431. //this.gb4.Text = string.Format("返工(合格)明细【{0} {1}】", cddate, drv["goodscode"]);
  432. if (cddate == "合计")
  433. {
  434. rowFilter = string.Format("goodscode = '{0}'", drv["goodscode"]);
  435. }
  436. else
  437. {
  438. rowFilter = string.Format("goodscode = '{0}' and cdate = '{1}'", drv["goodscode"], cddate);
  439. }
  440. this.dgv1.DataSource = null;
  441. this.dgv2.DataSource = null;
  442. this.dgv3.DataSource = null;
  443. this.dgv4.DataSource = null;
  444. // 成检明细
  445. this._dataSet.Tables["DataCC"].DefaultView.RowFilter = rowFilter;
  446. // 后道损明细
  447. this._dataSet.Tables["DataNS"].DefaultView.RowFilter = rowFilter;
  448. // 半检不合格明细
  449. this._dataSet.Tables["DataSC"].DefaultView.RowFilter = rowFilter;
  450. // 返工合格明细
  451. this._dataSet.Tables["DataRC"].DefaultView.RowFilter = rowFilter;
  452. this.dgv1.DataSource = this._dataSet.Tables["DataCC"];
  453. this.dgv2.DataSource = this._dataSet.Tables["DataNS"];
  454. this.dgv3.DataSource = this._dataSet.Tables["DataSC"];
  455. this.dgv4.DataSource = this._dataSet.Tables["DataRC"];
  456. this.gb1.Text = string.Format("成检缺陷明细【{0} {1}】({2})", cddate, drv["goodscode"], this.dgv1.RowCount);
  457. this.gb2.Text = string.Format("后道损坯明细【{0} {1}】({2})", cddate, drv["goodscode"], this.dgv2.RowCount);
  458. this.gb3.Text = string.Format("半检不合格明细【{0} {1}】({2})", cddate, drv["goodscode"], this.dgv3.RowCount);
  459. this.gb4.Text = string.Format("返工(合格)明细【{0} {1}】({2})", cddate, drv["goodscode"], this.dgv4.RowCount);
  460. this.AutoResizeColumns();
  461. }
  462. catch (Exception ex)
  463. {
  464. // 对异常进行共通处理
  465. ExceptionManager.HandleEventException(this.ToString(),
  466. System.Reflection.MethodBase.GetCurrentMethod().Name, this.Text, ex);
  467. }
  468. }
  469. private void F_P_00002_KeyDown(object sender, KeyEventArgs e)
  470. {
  471. if (e.KeyCode == Keys.Enter)
  472. {
  473. this.txtKey.Focus();
  474. }
  475. }
  476. private void txtKey_KeyDown(object sender, KeyEventArgs e)
  477. {
  478. if (e.KeyCode == Keys.Enter)
  479. {
  480. string text = this.txtKey.Text.Trim().ToUpper();
  481. this.txtKey.Clear();
  482. if (text.Length < 3 || !text.StartsWith("#") || !text.EndsWith("#"))
  483. {
  484. return;
  485. }
  486. if (QUIT == text)
  487. {
  488. this.btnResetForm_Click(null, null);
  489. return;
  490. }
  491. if (NextPage == text)
  492. {
  493. // 下一页
  494. int last = -1;
  495. if (this.dgv0.VerticalScrollBarVisible)
  496. {
  497. last = this.dgv0.FirstDisplayedScrollingRowIndex + this.dgv0.DisplayedRowCount(false);
  498. if (last < this.dgv0.RowCount)
  499. {
  500. this.dgv0.FirstDisplayedScrollingRowIndex = last;
  501. }
  502. }
  503. if (this.dgv1.VerticalScrollBarVisible)
  504. {
  505. last = this.dgv1.FirstDisplayedScrollingRowIndex + this.dgv1.DisplayedRowCount(false);
  506. if (last < this.dgv1.RowCount)
  507. {
  508. this.dgv1.FirstDisplayedScrollingRowIndex = last;
  509. }
  510. }
  511. if (this.dgv2.VerticalScrollBarVisible)
  512. {
  513. last = this.dgv2.FirstDisplayedScrollingRowIndex + this.dgv2.DisplayedRowCount(false);
  514. if (last < this.dgv2.RowCount)
  515. {
  516. this.dgv2.FirstDisplayedScrollingRowIndex = last;
  517. }
  518. }
  519. if (this.dgv3.VerticalScrollBarVisible)
  520. {
  521. last = this.dgv3.FirstDisplayedScrollingRowIndex + this.dgv3.DisplayedRowCount(false);
  522. if (last < this.dgv3.RowCount)
  523. {
  524. this.dgv3.FirstDisplayedScrollingRowIndex = last;
  525. }
  526. }
  527. if (this.dgv4.VerticalScrollBarVisible)
  528. {
  529. last = this.dgv4.FirstDisplayedScrollingRowIndex + this.dgv4.DisplayedRowCount(false);
  530. if (last < this.dgv4.RowCount)
  531. {
  532. this.dgv4.FirstDisplayedScrollingRowIndex = last;
  533. }
  534. }
  535. if (this.dgvM.VerticalScrollBarVisible)
  536. {
  537. last = this.dgvM.FirstDisplayedScrollingRowIndex + this.dgvM.DisplayedRowCount(false);
  538. if (last < this.dgvM.RowCount)
  539. {
  540. this.dgvM.FirstDisplayedScrollingRowIndex = last;
  541. }
  542. }
  543. }
  544. else if (PrePage == text)
  545. {
  546. // 上一页
  547. int last = this.dgv0.FirstDisplayedScrollingRowIndex;
  548. if (last > 0)
  549. {
  550. last = last - this.dgv0.DisplayedRowCount(false);
  551. if (last < 0)
  552. {
  553. last = 0;
  554. }
  555. this.dgv0.FirstDisplayedScrollingRowIndex = last;
  556. }
  557. last = this.dgv1.FirstDisplayedScrollingRowIndex;
  558. if (last > 0)
  559. {
  560. last = last - this.dgv1.DisplayedRowCount(false);
  561. if (last < 0)
  562. {
  563. last = 0;
  564. }
  565. this.dgv1.FirstDisplayedScrollingRowIndex = last;
  566. }
  567. last = this.dgv2.FirstDisplayedScrollingRowIndex;
  568. if (last > 0)
  569. {
  570. last = last - this.dgv2.DisplayedRowCount(false);
  571. if (last < 0)
  572. {
  573. last = 0;
  574. }
  575. this.dgv2.FirstDisplayedScrollingRowIndex = last;
  576. }
  577. last = this.dgv3.FirstDisplayedScrollingRowIndex;
  578. if (last > 0)
  579. {
  580. last = last - this.dgv3.DisplayedRowCount(false);
  581. if (last < 0)
  582. {
  583. last = 0;
  584. }
  585. this.dgv3.FirstDisplayedScrollingRowIndex = last;
  586. }
  587. last = this.dgv4.FirstDisplayedScrollingRowIndex;
  588. if (last > 0)
  589. {
  590. last = last - this.dgv4.DisplayedRowCount(false);
  591. if (last < 0)
  592. {
  593. last = 0;
  594. }
  595. this.dgv4.FirstDisplayedScrollingRowIndex = last;
  596. }
  597. last = this.dgvM.FirstDisplayedScrollingRowIndex;
  598. if (last > 0)
  599. {
  600. last = last - this.dgvM.DisplayedRowCount(false);
  601. if (last < 0)
  602. {
  603. last = 0;
  604. }
  605. this.dgvM.FirstDisplayedScrollingRowIndex = last;
  606. }
  607. }
  608. else if (this.dgvM.RowCount > 0)
  609. {
  610. if (PreRow == text)
  611. {
  612. // 上一条
  613. int index = this._currentRowIndex - 1;
  614. if (index < 0)
  615. {
  616. index = this.dgvM.RowCount - 1;
  617. }
  618. this.dgvM.CurrentCell = this.dgvM.Rows[index].Cells["gmcdate"];
  619. this.dgvM_SelectionChanged(null, null);
  620. }
  621. else if (NextRow == text)
  622. {
  623. // 下一条
  624. int index = this._currentRowIndex + 1;
  625. if (index >= this.dgvM.RowCount)
  626. {
  627. index = 0;
  628. }
  629. this.dgvM.CurrentCell = this.dgvM.Rows[index].Cells["gmcdate"];
  630. this.dgvM_SelectionChanged(null, null);
  631. }
  632. else
  633. {
  634. string monthFlag = null;
  635. if (CurRow == text)
  636. {
  637. // 当前日期
  638. foreach (DataGridViewRow item in this.dgvM.Rows)
  639. {
  640. if ((item.Cells["gmcdate"].Value + "") != "合计")
  641. {
  642. monthFlag = (item.Cells["gmcdate"].Value + "");
  643. //this.dgvM.CurrentCell = item.Cells["gmcdate"];
  644. //this.dgvM_SelectionChanged(null, null);
  645. //this._currentRowIndex = item.Index;
  646. break;
  647. }
  648. }
  649. }
  650. else
  651. {
  652. monthFlag = text.Replace("#", "");
  653. }
  654. if (monthFlag == "00")
  655. {
  656. monthFlag = "合计";
  657. }
  658. int firstIndex = -1;
  659. foreach (DataGridViewRow item in this.dgvM.Rows)
  660. {
  661. if ((item.Cells["gmcdate"].Value + "").EndsWith(monthFlag))
  662. {
  663. if (firstIndex == -1)
  664. {
  665. firstIndex = item.Index;
  666. }
  667. if (this._currentRowIndex < item.Index)
  668. {
  669. this.dgvM.CurrentCell = item.Cells["gmcdate"];
  670. this.dgvM_SelectionChanged(null, null);
  671. //this._currentRowIndex = item.Index;
  672. break;
  673. }
  674. }
  675. else
  676. {
  677. if (firstIndex > -1)
  678. {
  679. this.dgvM.CurrentCell = this.dgvM.Rows[firstIndex].Cells["gmcdate"];
  680. this.dgvM_SelectionChanged(null, null);
  681. //this._currentRowIndex = firstIndex;
  682. break;
  683. }
  684. }
  685. }
  686. if (firstIndex == -1)
  687. {
  688. //this.dgvM.CurrentCell = this.dgvM.Rows[this.dgvM.RowCount - 1].Cells["gmcdate"];
  689. this.dgvM.CurrentCell = this.dgvM.Rows[0].Cells["gmcdate"];
  690. this.dgvM_SelectionChanged(null, null);
  691. }
  692. }
  693. }
  694. }
  695. }
  696. }
  697. }