ButtonDeleteRow.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. using System;
  2. using System.Windows.Forms;
  3. using DevExpress.XtraEditors;
  4. using DevExpress.XtraGrid.Views.Grid;
  5. using UAS_PLCDataReader.Entity;
  6. using System.Collections.Generic;
  7. namespace UAS_PLCDataReader.CustomerControl.Button
  8. {
  9. public partial class ButtonDeleteRow : SimpleButton
  10. {
  11. private AutoDataGridControl.AutoDataGridControl grid;
  12. public AutoDataGridControl.AutoDataGridControl Grid
  13. {
  14. get
  15. {
  16. return grid;
  17. }
  18. set
  19. {
  20. grid = value;
  21. }
  22. }
  23. public ButtonDeleteRow()
  24. {
  25. InitializeComponent();
  26. }
  27. private void ButtonDeleteRow_Click(object sender, EventArgs e)
  28. {
  29. if (grid != null)
  30. {
  31. GridView view = grid.MainView as GridView;
  32. List<int> DeleteID = new List<int>();
  33. for (int i = 0; i < view.RowCount; i++)
  34. {
  35. if (view.GetRowCellValue(i, SystemInf.CheckedColumnName).ToString() != "0")
  36. DeleteID.Add(int.Parse(view.GetRowCellValue(i, grid.ID.ToUpper()).ToString()));
  37. }
  38. if (DeleteID.Count > 0)
  39. {
  40. DialogResult result = XtraMessageBox.Show("确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
  41. if (result.ToString() == "Yes")
  42. {
  43. SystemInf.dh.DeleteDataByID(grid.TableName, grid.ID, DeleteID.ToArray());
  44. grid.RefreshData();
  45. }
  46. }
  47. else XtraMessageBox.Show("请选择要删除的数据", "提示");
  48. }
  49. }
  50. }
  51. }