CtrlCgRes.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using DevExpress.XtraEditors;
  2. using DevExpress.XtraExport.Helpers;
  3. using DevExpress.XtraGrid.Views.Grid;
  4. using DxHelper;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Data.Entity;
  10. using System.Drawing;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Controls;
  15. using System.Windows.Documents;
  16. using System.Windows.Forms;
  17. using XdDw.App.EFContext;
  18. using XzXdDw.App.Model;
  19. namespace XdDw.App.UserControl
  20. {
  21. public partial class CtrlCgRes : DevExpress.XtraEditors.XtraUserControl
  22. {
  23. public CtrlCgRes()
  24. {
  25. InitializeComponent();
  26. }
  27. private async void CtrlCg_Load(object sender, EventArgs e)
  28. {
  29. gridCg.Init().UseFilter().UseMultiSelect().UseRowNumber()
  30. .AddMenu("删除", SvgHelper.CreateClose(), async () =>
  31. {
  32. try
  33. {
  34. var ids = gridView1.GetSelectedRows();
  35. using (RHDWContext db = new RHDWContext())
  36. {
  37. foreach (var id in ids)
  38. {
  39. var item = gridView1.GetRow(id) as CgRes;
  40. var delItem = await db.CgRes.Where(p => p.ID == item.ID).FirstOrDefaultAsync();
  41. if (delItem != null)
  42. {
  43. db.CgRes.Remove(delItem);
  44. }
  45. }
  46. await db.SaveChangesAsync();
  47. }
  48. gridView1.DeleteSelectedRows();
  49. }
  50. catch (Exception ex)
  51. {
  52. Serilog.Log.Error("删除结果失败", ex);
  53. XtraMessageBox.Show("删除结果失败");
  54. }
  55. });
  56. //查询已有的定位记录
  57. using (RHDWContext db = new RHDWContext())
  58. {
  59. List<CgRes> list = await db.CgRes.ToListAsync();
  60. this.gridCg.DataSource = list;
  61. }
  62. }
  63. }
  64. }