CtrlCxRes.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using DevExpress.XtraEditors;
  2. using DevExpress.XtraGrid.Views.Grid;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Data;
  7. using System.Data.Entity;
  8. using System.Drawing;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows.Documents;
  13. using System.Windows.Forms;
  14. using XdCxRhDW.Repostory.EFContext;
  15. using XdCxRhDW.Repostory.Model;
  16. namespace XdCxRhDW.App.UserControl
  17. {
  18. public partial class CtrlCxRes : DevExpress.XtraEditors.XtraUserControl
  19. {
  20. public CtrlCxRes()
  21. {
  22. InitializeComponent();
  23. }
  24. private async void CtrlCxRes_Load(object sender, EventArgs e)
  25. {
  26. try
  27. {
  28. gridCx.Init<CxRes>().UseSort().UseFilter().UseMultiSelect().UseRowNumber();
  29. using (RHDWContext db = new RHDWContext())
  30. {
  31. gridCx.DataSource = await db.CxRes.OrderByDescending(p => p.SigTime).ToListAsync();
  32. }
  33. }
  34. catch (Exception ex)
  35. {
  36. Serilog.Log.Error(ex, "查询测向结果异常");
  37. DxHelper.MsgBoxHelper.ShowError("查询测向结果异常");
  38. }
  39. }
  40. private async void btnDel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
  41. {
  42. try
  43. {
  44. var ids = gridView1.GetSelectedRows();
  45. using (RHDWContext db = new RHDWContext())
  46. {
  47. foreach (var id in ids)
  48. {
  49. var item = gridView1.GetRow(id) as CxRes;
  50. var delItem = await db.CxRes.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
  51. if (delItem != null)
  52. {
  53. db.CxRes.Remove(delItem);
  54. }
  55. }
  56. await db.SaveChangesAsync();
  57. }
  58. gridView1.DeleteSelectedRows();
  59. }
  60. catch (Exception ex)
  61. {
  62. Serilog.Log.Error(ex, "删除测向结果异常");
  63. DxHelper.MsgBoxHelper.ShowError("删除测向结果异常");
  64. }
  65. }
  66. private void gridView1_PopupMenuShowing(object sender, PopupMenuShowingEventArgs e)
  67. {
  68. if (gridView1.FocusedRowHandle < 0) return;
  69. if (!gridView1.GetSelectedRows().Any())
  70. {
  71. btnDel.Visibility = DevExpress.XtraBars.BarItemVisibility.Never;
  72. }
  73. else
  74. {
  75. btnDel.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
  76. }
  77. popupMenu2.ShowPopup(MousePosition);
  78. }
  79. }
  80. }