EntranceForm.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. using DevExpress.XtraEditors;
  2. using GCAS.Code;
  3. using GCAS.Dto;
  4. using GCAS.Localization;
  5. using GCAS.Model;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Threading;
  11. using System.Windows.Forms;
  12. namespace GCAS
  13. {
  14. public partial class EntranceForm : DevExpress.XtraEditors.XtraForm
  15. {
  16. private List<NameValue> L;
  17. private EntranceRepository entranceRepository;
  18. public OperatorModel currentUser;
  19. private ActionsRepository actionsRepository;
  20. public EntranceForm()
  21. {
  22. InitializeComponent();
  23. L = LocalizationHelper.GetSource(Thread.CurrentThread.CurrentUICulture);
  24. }
  25. private void DeviceForm_Load(object sender, System.EventArgs e)
  26. {
  27. actionsRepository = new ActionsRepository();
  28. entranceRepository = new EntranceRepository();
  29. InitDataView();
  30. }
  31. private void InitDataView(bool isPageLoad = true)
  32. {
  33. gridView1.LoadingPanelVisible = true;
  34. var list = entranceRepository.GetList();
  35. gridControl1.DataSource = list;
  36. gridView1.LoadingPanelVisible = false;
  37. if (!isPageLoad)
  38. {
  39. var realForm = MdiParent.MdiChildren.FirstOrDefault(c => c.Name == "RealTimeForm") as RealTimeForm;
  40. realForm.ChangeEntranceInfo();
  41. }
  42. if (currentUser.Role == 1)
  43. {
  44. contextMenuStrip1.Enabled = false;
  45. }
  46. }
  47. private async void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
  48. {
  49. DeviceModel rowData;
  50. switch (e.ClickedItem.Name)
  51. {
  52. case "menu_new":
  53. using (NewDeviceForm form = new NewDeviceForm())
  54. {
  55. form.Text = L.GetString("new");
  56. form.currentUser = currentUser;
  57. if (form.ShowDialog() == DialogResult.OK)
  58. InitDataView(false);
  59. }
  60. break;
  61. case "menu_edit":
  62. rowData = gridView1.GetFocusedRow() as DeviceModel;
  63. if (rowData != null)
  64. {
  65. using (NewDeviceForm form = new NewDeviceForm())
  66. {
  67. form.Text = L.GetString("edit");
  68. form.deviceModel = rowData;
  69. form.currentUser = currentUser;
  70. if (form.ShowDialog() == DialogResult.OK)
  71. InitDataView(false);
  72. }
  73. }
  74. break;
  75. case "menu_delete":
  76. rowData = gridView1.GetFocusedRow() as DeviceModel;
  77. if (rowData != null)
  78. {
  79. if (XtraMessageBox.Show(string.Format(L.GetString("DeleteDeviceMessage"), rowData.Name), L.GetString("notification"), MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
  80. {
  81. if (await entranceRepository.Delete(rowData.Id) > 0)
  82. {
  83. await actionsRepository.Insert(new ActionsModel { Info = string.Format(L.GetString("deleteEntranceLog"), rowData.Name), Operator = currentUser.Name, RoleName = currentUser.RoleName, Time = DateTime.Now });
  84. InitDataView(false);
  85. }
  86. }
  87. }
  88. break;
  89. }
  90. }
  91. private void gridView1_PopupMenuShowing(object sender, DevExpress.XtraGrid.Views.Grid.PopupMenuShowingEventArgs e)
  92. {
  93. if (e.HitInfo.InRow)
  94. {
  95. int index = gridView1.FocusedRowHandle;
  96. if (index >= 0)
  97. {
  98. menu_edit.Enabled = true;
  99. }
  100. else
  101. {
  102. menu_edit.Enabled = false;
  103. }
  104. }
  105. else
  106. {
  107. menu_edit.Enabled = false;
  108. }
  109. }
  110. private void gridView1_MouseDown(object sender, MouseEventArgs e)
  111. {
  112. if (currentUser.Role == 1)
  113. {
  114. return;
  115. }
  116. if (e.Clicks != 2 || e.Button != MouseButtons.Left) return;
  117. var rowData = gridView1.GetRow(gridView1.CalcHitInfo(new Point(e.X, e.Y)).RowHandle) as EntranceModel;
  118. if (rowData != null)
  119. {
  120. using (NewEntranceForm form = new NewEntranceForm())
  121. {
  122. form.Text = L.GetString("Edit");
  123. form.entranceModel = rowData;
  124. form.currentUser = currentUser;
  125. if (form.ShowDialog() == DialogResult.OK)
  126. InitDataView(false);
  127. }
  128. }
  129. }
  130. private void menu_edit_Click(object sender, EventArgs e)
  131. {
  132. var rowData = gridView1.GetFocusedRow() as EntranceModel;
  133. if (rowData != null)
  134. {
  135. using (NewEntranceForm form = new NewEntranceForm())
  136. {
  137. form.Text = L.GetString("Edit");
  138. form.entranceModel = rowData;
  139. form.currentUser = currentUser;
  140. if (form.ShowDialog() == DialogResult.OK)
  141. InitDataView(false);
  142. }
  143. }
  144. }
  145. }
  146. }