using DevExpress.XtraEditors; using DevExpress.XtraExport.Helpers; using DevExpress.XtraGrid.Views.Grid; using DxHelper; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.Entity; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Forms; using XzXdDw.App.EFContext; using XzXdDw.App.Model; namespace XzXdDw.App.UserControl { public partial class CtrlCgRes : DevExpress.XtraEditors.XtraUserControl { public CtrlCgRes() { InitializeComponent(); } private async void CtrlCg_Load(object sender, EventArgs e) { gridCg.Init().UseFilter().UseMultiSelect().UseRowNumber() .AddMenu("删除", SvgHelper.CreateClose(), async () => { try { var ids = gridView1.GetSelectedRows(); using (RHDWContext db = new RHDWContext()) { foreach (var id in ids) { var item = gridView1.GetRow(id) as CgRes; var delItem = await db.CgRes.Where(p => p.ID == item.ID).FirstOrDefaultAsync(); if (delItem != null) { db.CgRes.Remove(delItem); } } await db.SaveChangesAsync(); } gridView1.DeleteSelectedRows(); } catch (Exception ex) { Serilog.Log.Error("删除结果失败", ex); XtraMessageBox.Show("删除结果失败"); } }); //查询已有的定位记录 using (RHDWContext db = new RHDWContext()) { List list = await db.CgRes.ToListAsync(); this.gridCg.DataSource = list; } } } }