CallBoxUI.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using ProjectManagementSystem.Device.CasunBox;
  2. using ProjectManagementSystem.Common.Core;
  3. using ProjectManagementSystem.Common.Device;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.ComponentModel;
  7. using System.Data;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Forms;
  13. namespace ProjectManagementSystem.UI
  14. {
  15. public partial class CallBoxUI : UserControl, IDisplayUI
  16. {
  17. private int selectRowIndexOfordersDataGridView; // 记录选中的行号
  18. private int selectColumnIndexOfordersDataGridView; // 记录选中的列号
  19. private int scrollingRowIndexOfordersDataGridView; // 记录垂直滚动条位置
  20. private int scrollingColumnIndexOfordersDataGridView; // 记录水平滚动条的位置
  21. public CallBoxUI()
  22. {
  23. InitializeComponent();
  24. dataGridView1.AutoGenerateColumns = false;
  25. }
  26. public bool Init()
  27. {
  28. return true;
  29. }
  30. public void UpdateDisplay()
  31. {
  32. if (!this.Visible)
  33. {
  34. return;
  35. }
  36. this.Invoke(new MethodInvoker(() =>
  37. {
  38. this.SuspendLayout();
  39. if (dataGridView1.CurrentCell != null && dataGridView1.RowCount != 0 && dataGridView1.ColumnCount != 0)
  40. {
  41. selectRowIndexOfordersDataGridView = dataGridView1.CurrentCell.RowIndex;
  42. selectColumnIndexOfordersDataGridView = dataGridView1.CurrentCell.ColumnIndex;
  43. scrollingRowIndexOfordersDataGridView = dataGridView1.FirstDisplayedScrollingRowIndex;
  44. scrollingColumnIndexOfordersDataGridView = dataGridView1.FirstDisplayedScrollingColumnIndex;
  45. }
  46. var allInfoBox = BoxFactory.GetInfoBox();
  47. this.dataGridView1.DataSource = allInfoBox?.OrderBy(d => d.Name).ThenBy(d => d.Route).ToList();
  48. int n = dataGridView1.RowCount;
  49. int m = dataGridView1.ColumnCount;
  50. if (n != 0 && m != 0)
  51. {
  52. if (selectRowIndexOfordersDataGridView < n && selectColumnIndexOfordersDataGridView < m &&
  53. scrollingRowIndexOfordersDataGridView < n && scrollingColumnIndexOfordersDataGridView < m)
  54. {
  55. dataGridView1.CurrentCell = dataGridView1.Rows[selectRowIndexOfordersDataGridView].Cells[selectColumnIndexOfordersDataGridView];
  56. dataGridView1.FirstDisplayedScrollingRowIndex = scrollingRowIndexOfordersDataGridView;
  57. dataGridView1.FirstDisplayedScrollingColumnIndex = scrollingColumnIndexOfordersDataGridView;
  58. }
  59. }
  60. this.ResumeLayout(false);
  61. }));
  62. }
  63. }
  64. }