Browse Source

调整删除方法

章政 7 năm trước cách đây
mục cha
commit
48ba8edcfb

+ 7 - 11
UAS_DeviceMonitor/CustomerControl/Button/ButtonDeleteRow.cs

@@ -1,14 +1,9 @@
 using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Drawing;
-using System.Data;
-using System.Linq;
-using System.Text;
 using System.Windows.Forms;
 using DevExpress.XtraEditors;
 using DevExpress.XtraGrid.Views.Grid;
 using UAS_DeviceMonitor.Entity;
+using System.Collections.Generic;
 
 namespace UAS_DeviceMonitor.CustomerControl.Button
 {
@@ -40,17 +35,18 @@ namespace UAS_DeviceMonitor.CustomerControl.Button
             if (grid != null)
             {
                 GridView view = grid.MainView as GridView;
-                int[] DeleteID = view.GetSelectedRows();
-                for (int i = 0; i < DeleteID.Length; i++)
+                List<int> DeleteID = new List<int>();
+                for (int i = 0; i < view.RowCount; i++)
                 {
-                    DeleteID[i] = int.Parse(view.GetRowCellValue(i, grid.ID.ToUpper()).ToString());
+                    if (view.GetRowCellValue(i, SystemInf.CheckedColumnName).ToString() != "0")
+                        DeleteID.Add(int.Parse(view.GetRowCellValue(i, grid.ID.ToUpper()).ToString()));
                 }
-                if (DeleteID.Length > 0)
+                if (DeleteID.Count > 0)
                 {
                     DialogResult result = XtraMessageBox.Show("确认删除", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                     if (result.ToString() == "Yes")
                     {
-                        SystemInf.dh.DeleteDataByID(grid.TableName, grid.ID, DeleteID);
+                        SystemInf.dh.DeleteDataByID(grid.TableName, grid.ID, DeleteID.ToArray());
                         grid.RefreshData();
                     }
                 }

+ 3 - 4
UAS_DeviceMonitor/CustomerControl/GridViewWithSerialNum/GridViewWithSerialNum.cs

@@ -5,14 +5,13 @@ using DevExpress.XtraGrid.Views.Grid.ViewInfo;
 using System.Drawing;
 using System.Windows.Forms;
 using System.Windows.Forms.VisualStyles;
+using UAS_DeviceMonitor.Entity;
 
 namespace UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum
 {
     public partial class GridViewWithSerialNum : GridView
     {
 
-        string fieldName = "COLUMNCHECKED";
-
         private Rectangle checkBoxColumnHeaderRect = Rectangle.Empty;
 
         private GridColumn checkBoxColumn = null;
@@ -43,7 +42,7 @@ namespace UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum
         /// <param name="e"></param>
         private void GridViewWithSerialNum_CustomDrawColumnHeader(object sender, ColumnHeaderCustomDrawEventArgs e)
         {
-            if (e.Column != null && e.Column.FieldName == fieldName)
+            if (e.Column != null && e.Column.FieldName == SystemInf.CheckedColumnName)
             {
                 checkBoxColumnHeaderRect = e.Bounds;
                 checkBoxColumn = e.Column;
@@ -71,7 +70,7 @@ namespace UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum
         /// <param name="e"></param>
         private void GridViewWithSerialNum_MouseDown(object sender, MouseEventArgs e)
         {
-            SyncCheckStatus(this, fieldName, e);
+            SyncCheckStatus(this, SystemInf.CheckedColumnName, e);
         }
 
         /// <summary>

+ 2 - 0
UAS_DeviceMonitor/Entity/SystemInf.cs

@@ -41,5 +41,7 @@ namespace UAS_DeviceMonitor.Entity
         public static bool UpperCollection = true;
 
         public static DataOperate.DataHelper dh;
+
+        public static string CheckedColumnName = "CHECKEDCOLUMN";
     }
 }

+ 13 - 13
UAS_DeviceMonitor/Main.Designer.cs

@@ -83,7 +83,7 @@ namespace UAS_DeviceMonitor
             this.ButtonStartPolling = new DevExpress.XtraEditors.SimpleButton();
             this.GridPollingSetting = new UAS_DeviceMonitor.CustomerControl.AutoDataGridControl.AutoDataGridControl();
             this.GridViewPollSetting = new UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum.GridViewWithSerialNum();
-            this.COLUMNCHECKED = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.PollSettingCheckedColumn = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dpc_enableCheckEdit = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
             this.dpc_id = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dpc_decode = new DevExpress.XtraGrid.Columns.GridColumn();
@@ -640,7 +640,7 @@ namespace UAS_DeviceMonitor
             // GridViewPollSetting
             // 
             this.GridViewPollSetting.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] {
-            this.COLUMNCHECKED,
+            this.PollSettingCheckedColumn,
             this.dpc_id,
             this.dpc_decode,
             this.dpc_plcode,
@@ -658,17 +658,17 @@ namespace UAS_DeviceMonitor
             this.GridViewPollSetting.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.CheckBoxRowSelect;
             this.GridViewPollSetting.CellValueChanging += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridViewPollSetting_CellValueChanging);
             // 
-            // COLUMNCHECKED
+            // PollSettingCheckedColumn
             // 
-            this.COLUMNCHECKED.Caption = " ";
-            this.COLUMNCHECKED.ColumnEdit = this.dpc_enableCheckEdit;
-            this.COLUMNCHECKED.FieldName = "COLUMNCHECKED";
-            this.COLUMNCHECKED.Name = "COLUMNCHECKED";
-            this.COLUMNCHECKED.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
-            this.COLUMNCHECKED.OptionsFilter.AllowFilter = false;
-            this.COLUMNCHECKED.Tag = "0";
-            this.COLUMNCHECKED.Visible = true;
-            this.COLUMNCHECKED.VisibleIndex = 0;
+            this.PollSettingCheckedColumn.Caption = " ";
+            this.PollSettingCheckedColumn.ColumnEdit = this.dpc_enableCheckEdit;
+            this.PollSettingCheckedColumn.FieldName = "CHECKEDCOLUMN";
+            this.PollSettingCheckedColumn.Name = "PollSettingCheckedColumn";
+            this.PollSettingCheckedColumn.OptionsColumn.AllowSort = DevExpress.Utils.DefaultBoolean.False;
+            this.PollSettingCheckedColumn.OptionsFilter.AllowFilter = false;
+            this.PollSettingCheckedColumn.Tag = "0";
+            this.PollSettingCheckedColumn.Visible = true;
+            this.PollSettingCheckedColumn.VisibleIndex = 0;
             // 
             // dpc_enableCheckEdit
             // 
@@ -1026,6 +1026,6 @@ namespace UAS_DeviceMonitor
         private CustomerControl.Button.ButtonSaveGrid ButtonSaveCommandSet;
         private DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit PollingSetItemLookUpEdit;
         private DevExpress.XtraGrid.Columns.GridColumn POLLSETTINGSTATUSCOLUMN;
-        private DevExpress.XtraGrid.Columns.GridColumn COLUMNCHECKED;
+        private DevExpress.XtraGrid.Columns.GridColumn PollSettingCheckedColumn;
     }
 }

+ 1 - 1
UAS_DeviceMonitor/Main.cs

@@ -41,7 +41,7 @@ namespace UAS_DeviceMonitor
             ButtonSavePolling.Grid = GridPolling;
             ButtonAddPolling.Grid = GridPolling;
             //轮询配置界面
-            GridPollingSetting.GetDataSQL = "SELECT '' POLLSETTINGSTATUSCOLUMN,0 COLUMNCHECKED,DPC_ID,DPC_DECODE ,DPC_PLCODE ,DPC_PLNAME ,DPC_INTERVAL ,DPC_DCCODE ,DPC_FUNCTION , DPC_ENABLE,DPC_STATUS ,DPC_REMARK FROM DEVICEPOLLINGCONFIG";
+            GridPollingSetting.GetDataSQL = "SELECT '' POLLSETTINGSTATUSCOLUMN,0 CHECKEDCOLUMN,DPC_ID,DPC_DECODE ,DPC_PLCODE ,DPC_PLNAME ,DPC_INTERVAL ,DPC_DCCODE ,DPC_FUNCTION , DPC_ENABLE,DPC_STATUS ,DPC_REMARK FROM DEVICEPOLLINGCONFIG";
             GridPollingSetting.ID = "DPC_ID";
             GridPollingSetting.TableName = "DEVICEPOLLINGCONFIG";
             GridPollingSetting.InsertSQL = "insert into DEVICEPOLLINGCONFIG(DPC_ID,DPC_DECODE ,DPC_PLCODE ,DPC_PLNAME ,DPC_INTERVAL ,DPC_DCCODE ,DPC_FUNCTION , DPC_ENABLE,DPC_STATUS ,DPC_REMARK) values(DEVICEPOLLINGCONFIG_seq.nextval,:DPC_DECODE ,:DPC_PLCODE ,:DPC_PLNAME ,:DPC_INTERVAL ,:DPC_DCCODE ,:DPC_FUNCTION , :DPC_ENABLE,:DPC_STATUS ,:DPC_REMARK)";