Jelajahi Sumber

添加删除Grid数据按钮

章政 7 tahun lalu
induk
melakukan
a9837b0d40

+ 42 - 0
UAS_DeviceMonitor/CustomerControl/Button/ButtonDeleteRow.Designer.cs

@@ -0,0 +1,42 @@
+namespace UAS_DeviceMonitor.CustomerControl.Button
+{
+    partial class ButtonDeleteRow
+    {
+        /// <summary> 
+        /// 必需的设计器变量。
+        /// </summary>
+        private System.ComponentModel.IContainer components = null;
+
+        /// <summary> 
+        /// 清理所有正在使用的资源。
+        /// </summary>
+        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
+        protected override void Dispose(bool disposing)
+        {
+            if (disposing && (components != null))
+            {
+                components.Dispose();
+            }
+            base.Dispose(disposing);
+        }
+
+        #region 组件设计器生成的代码
+
+        /// <summary> 
+        /// 设计器支持所需的方法 - 不要修改
+        /// 使用代码编辑器修改此方法的内容。
+        /// </summary>
+        private void InitializeComponent()
+        {
+            this.SuspendLayout();
+            // 
+            // ButtonDeleteRow
+            // 
+            this.Click += new System.EventHandler(this.ButtonDeleteRow_Click);
+            this.ResumeLayout(false);
+
+        }
+
+        #endregion
+    }
+}

+ 59 - 0
UAS_DeviceMonitor/CustomerControl/Button/ButtonDeleteRow.cs

@@ -0,0 +1,59 @@
+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;
+
+namespace UAS_DeviceMonitor.CustomerControl.Button
+{
+    public partial class ButtonDeleteRow : SimpleButton
+    {
+        private AutoDataGridControl.AutoDataGridControl grid;
+
+        public AutoDataGridControl.AutoDataGridControl Grid
+        {
+            get
+            {
+                return grid;
+            }
+
+            set
+            {
+                grid = value;
+            }
+        }
+
+
+        public ButtonDeleteRow()
+        {
+            InitializeComponent();
+        }
+
+        private void ButtonDeleteRow_Click(object sender, EventArgs e)
+        {
+            if (grid != null)
+            {
+                List<string> DeleteID = new List<string>();
+                GridView view = grid.MainView as GridView;
+                for (int i = 0; i < grid.RowCount; i++)
+                {
+                    string Checked = view.GetRowCellValue(i, "CHOOSE").ToString().ToUpper();
+                    if (Checked != "0")
+                        DeleteID.Add(view.GetRowCellValue(i, grid.ID.ToUpper()).ToString());
+                }
+                if (DeleteID.Count > 0)
+                {
+                    SystemInf.dh.DeleteDataByID(grid.TableName, grid.ID, DeleteID.ToArray());
+                    grid.RefreshData();
+                }
+                else XtraMessageBox.Show("请选择要删除的数据");
+            }
+        }
+    }
+}

+ 123 - 0
UAS_DeviceMonitor/CustomerControl/Button/ButtonDeleteRow.resx

@@ -0,0 +1,123 @@
+<?xml version="1.0" encoding="utf-8"?>
+<root>
+  <!-- 
+    Microsoft ResX Schema 
+    
+    Version 2.0
+    
+    The primary goals of this format is to allow a simple XML format 
+    that is mostly human readable. The generation and parsing of the 
+    various data types are done through the TypeConverter classes 
+    associated with the data types.
+    
+    Example:
+    
+    ... ado.net/XML headers & schema ...
+    <resheader name="resmimetype">text/microsoft-resx</resheader>
+    <resheader name="version">2.0</resheader>
+    <resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
+    <resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
+    <data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
+    <data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
+    <data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
+        <value>[base64 mime encoded serialized .NET Framework object]</value>
+    </data>
+    <data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
+        <value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
+        <comment>This is a comment</comment>
+    </data>
+                
+    There are any number of "resheader" rows that contain simple 
+    name/value pairs.
+    
+    Each data row contains a name, and value. The row also contains a 
+    type or mimetype. Type corresponds to a .NET class that support 
+    text/value conversion through the TypeConverter architecture. 
+    Classes that don't support this are serialized and stored with the 
+    mimetype set.
+    
+    The mimetype is used for serialized objects, and tells the 
+    ResXResourceReader how to depersist the object. This is currently not 
+    extensible. For a given mimetype the value must be set accordingly:
+    
+    Note - application/x-microsoft.net.object.binary.base64 is the format 
+    that the ResXResourceWriter will generate, however the reader can 
+    read any of the formats listed below.
+    
+    mimetype: application/x-microsoft.net.object.binary.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
+            : and then encoded with base64 encoding.
+    
+    mimetype: application/x-microsoft.net.object.soap.base64
+    value   : The object must be serialized with 
+            : System.Runtime.Serialization.Formatters.Soap.SoapFormatter
+            : and then encoded with base64 encoding.
+
+    mimetype: application/x-microsoft.net.object.bytearray.base64
+    value   : The object must be serialized into a byte array 
+            : using a System.ComponentModel.TypeConverter
+            : and then encoded with base64 encoding.
+    -->
+  <xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
+    <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
+    <xsd:element name="root" msdata:IsDataSet="true">
+      <xsd:complexType>
+        <xsd:choice maxOccurs="unbounded">
+          <xsd:element name="metadata">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" />
+              </xsd:sequence>
+              <xsd:attribute name="name" use="required" type="xsd:string" />
+              <xsd:attribute name="type" type="xsd:string" />
+              <xsd:attribute name="mimetype" type="xsd:string" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="assembly">
+            <xsd:complexType>
+              <xsd:attribute name="alias" type="xsd:string" />
+              <xsd:attribute name="name" type="xsd:string" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="data">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+                <xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
+              <xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
+              <xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
+              <xsd:attribute ref="xml:space" />
+            </xsd:complexType>
+          </xsd:element>
+          <xsd:element name="resheader">
+            <xsd:complexType>
+              <xsd:sequence>
+                <xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
+              </xsd:sequence>
+              <xsd:attribute name="name" type="xsd:string" use="required" />
+            </xsd:complexType>
+          </xsd:element>
+        </xsd:choice>
+      </xsd:complexType>
+    </xsd:element>
+  </xsd:schema>
+  <resheader name="resmimetype">
+    <value>text/microsoft-resx</value>
+  </resheader>
+  <resheader name="version">
+    <value>2.0</value>
+  </resheader>
+  <resheader name="reader">
+    <value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <resheader name="writer">
+    <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
+  </resheader>
+  <metadata name="$this.TrayLargeIcon" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+    <value>False</value>
+  </metadata>
+</root>

+ 40 - 3
UAS_DeviceMonitor/Main.Designer.cs

@@ -67,6 +67,8 @@ namespace UAS_DeviceMonitor
             this.ButtonSaveCommand = new UAS_DeviceMonitor.CustomerControl.Button.ButtonSaveGrid();
             this.GridCommandSetting = new UAS_DeviceMonitor.CustomerControl.AutoDataGridControl.AutoDataGridControl();
             this.GridViewCommandSet = new UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum.GridViewWithSerialNum();
+            this.Choose = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.CheckEditCommandSet = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
             this.dc_id = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_code = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dc_name = new DevExpress.XtraGrid.Columns.GridColumn();
@@ -96,6 +98,7 @@ namespace UAS_DeviceMonitor
             this.pl_type = new DevExpress.XtraGrid.Columns.GridColumn();
             this.pl_dccode = new DevExpress.XtraGrid.Columns.GridColumn();
             this.pl_remark = new DevExpress.XtraGrid.Columns.GridColumn();
+            this.ButtonDeleteCommand = new UAS_DeviceMonitor.CustomerControl.Button.ButtonDeleteRow();
             ((System.ComponentModel.ISupportInitialize)(this.RibbonNav)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.MainTabControl)).BeginInit();
             this.MainTabControl.SuspendLayout();
@@ -106,6 +109,7 @@ namespace UAS_DeviceMonitor
             ((System.ComponentModel.ISupportInitialize)(this.Brand.Properties)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridCommandSetting)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewCommandSet)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.CheckEditCommandSet)).BeginInit();
             this.PagePollingSetting.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.GridPollingSetting)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPollSetting)).BeginInit();
@@ -380,6 +384,7 @@ namespace UAS_DeviceMonitor
             // 
             // PageCommandSet
             // 
+            this.PageCommandSet.Controls.Add(this.ButtonDeleteCommand);
             this.PageCommandSet.Controls.Add(this.Brand_label);
             this.PageCommandSet.Controls.Add(this.Brand);
             this.PageCommandSet.Controls.Add(this.ButtonNewCommand);
@@ -447,6 +452,8 @@ namespace UAS_DeviceMonitor
             this.GridCommandSetting.MainView = this.GridViewCommandSet;
             this.GridCommandSetting.MenuManager = this.RibbonNav;
             this.GridCommandSetting.Name = "GridCommandSetting";
+            this.GridCommandSetting.RepositoryItems.AddRange(new DevExpress.XtraEditors.Repository.RepositoryItem[] {
+            this.CheckEditCommandSet});
             this.GridCommandSetting.RowCount = 0;
             this.GridCommandSetting.Size = new System.Drawing.Size(1027, 517);
             this.GridCommandSetting.TabIndex = 1;
@@ -457,6 +464,7 @@ namespace UAS_DeviceMonitor
             // GridViewCommandSet
             // 
             this.GridViewCommandSet.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] {
+            this.Choose,
             this.dc_id,
             this.dc_code,
             this.dc_name,
@@ -464,6 +472,22 @@ namespace UAS_DeviceMonitor
             this.GridViewCommandSet.GridControl = this.GridCommandSetting;
             this.GridViewCommandSet.IndicatorWidth = 30;
             this.GridViewCommandSet.Name = "GridViewCommandSet";
+            this.GridViewCommandSet.OptionsSelection.MultiSelect = true;
+            // 
+            // Choose
+            // 
+            this.Choose.Caption = "勾选";
+            this.Choose.ColumnEdit = this.CheckEditCommandSet;
+            this.Choose.FieldName = "CHOOSE";
+            this.Choose.Name = "Choose";
+            this.Choose.Visible = true;
+            this.Choose.VisibleIndex = 0;
+            // 
+            // CheckEditCommandSet
+            // 
+            this.CheckEditCommandSet.AutoHeight = false;
+            this.CheckEditCommandSet.Name = "CheckEditCommandSet";
+            this.CheckEditCommandSet.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;
             // 
             // dc_id
             // 
@@ -476,7 +500,7 @@ namespace UAS_DeviceMonitor
             this.dc_code.FieldName = "DC_CODE";
             this.dc_code.Name = "dc_code";
             this.dc_code.Visible = true;
-            this.dc_code.VisibleIndex = 0;
+            this.dc_code.VisibleIndex = 1;
             this.dc_code.Width = 118;
             // 
             // dc_name
@@ -485,7 +509,7 @@ namespace UAS_DeviceMonitor
             this.dc_name.FieldName = "DC_NAME";
             this.dc_name.Name = "dc_name";
             this.dc_name.Visible = true;
-            this.dc_name.VisibleIndex = 1;
+            this.dc_name.VisibleIndex = 2;
             this.dc_name.Width = 123;
             // 
             // dc_command
@@ -494,7 +518,7 @@ namespace UAS_DeviceMonitor
             this.dc_command.FieldName = "DC_COMMAND";
             this.dc_command.Name = "dc_command";
             this.dc_command.Visible = true;
-            this.dc_command.VisibleIndex = 2;
+            this.dc_command.VisibleIndex = 3;
             this.dc_command.Width = 768;
             // 
             // PageDeviceKind
@@ -733,6 +757,15 @@ namespace UAS_DeviceMonitor
             this.pl_remark.Visible = true;
             this.pl_remark.VisibleIndex = 4;
             // 
+            // ButtonDeleteCommand
+            // 
+            this.ButtonDeleteCommand.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+            this.ButtonDeleteCommand.Location = new System.Drawing.Point(816, 551);
+            this.ButtonDeleteCommand.Name = "ButtonDeleteCommand";
+            this.ButtonDeleteCommand.Size = new System.Drawing.Size(64, 23);
+            this.ButtonDeleteCommand.TabIndex = 6;
+            this.ButtonDeleteCommand.Text = "删除";
+            // 
             // Main
             // 
             this.AllowFormGlass = DevExpress.Utils.DefaultBoolean.False;
@@ -759,6 +792,7 @@ namespace UAS_DeviceMonitor
             ((System.ComponentModel.ISupportInitialize)(this.Brand.Properties)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridCommandSetting)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewCommandSet)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.CheckEditCommandSet)).EndInit();
             this.PagePollingSetting.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.GridPollingSetting)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPollSetting)).EndInit();
@@ -835,5 +869,8 @@ namespace UAS_DeviceMonitor
         private GridViewWithSerialNum GridViewPollSetting;
         private LabelControl Brand_label;
         private ComboBoxEdit Brand;
+        private DevExpress.XtraGrid.Columns.GridColumn Choose;
+        private DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit CheckEditCommandSet;
+        private CustomerControl.Button.ButtonDeleteRow ButtonDeleteCommand;
     }
 }

+ 14 - 10
UAS_DeviceMonitor/Main.cs

@@ -18,21 +18,25 @@ namespace UAS_DeviceMonitor
         {
             SystemInf.dh = new DataHelper();
             InitializeComponent();
-            dpc_enableCheckEdit.QueryCheckStateByValue += CheckedEdit_QueryCheckStateByValue; ;
+            dpc_enableCheckEdit.QueryCheckStateByValue += CheckedEdit_QueryCheckStateByValue;
+            CheckEditCommandSet.QueryCheckStateByValue += CheckedEdit_QueryCheckStateByValue;
         }
 
         private void Main_Load(object sender, EventArgs e)
         {
+            //设备列表
             GridDeviceList.GetDataSQL = "select de_id,de_code,de_name,de_spec,de_indate,de_runstatus,de_address,de_wccode,de_vendcode,de_vendname from device".ToUpper();
-
-            GridPollingSetting.GetDataSQL = "SELECT DPC_ID,DPC_DECODE ,DPC_PLCODE ,DPC_PLNAME ,DPC_INTERVAL ,DPC_DCCODE ,DPC_FUNCTION , DPC_ENABLE,DPC_STATUS ,DPC_REMARK FROM DEVICEPOLLINGCONFIG";
             PageControlDeviceList.Gridcontrol = GridDeviceList;
 
-            GridCommandSetting.GetDataSQL = "select dc_id,dc_code,dc_name,dc_command from devicecommand".ToUpper();
+            //轮询界面
+            GridPollingSetting.GetDataSQL = "SELECT DPC_ID,DPC_DECODE ,DPC_PLCODE ,DPC_PLNAME ,DPC_INTERVAL ,DPC_DCCODE ,DPC_FUNCTION , DPC_ENABLE,DPC_STATUS ,DPC_REMARK FROM DEVICEPOLLINGCONFIG";
+            //指令设置界面
+            GridCommandSetting.GetDataSQL = "select 0 CHOOSE,dc_id,dc_code,dc_name,dc_command from devicecommand".ToUpper();
             GridCommandSetting.TableName = "devicecommand";
             GridCommandSetting.ID = "dc_id";
             GridCommandSetting.InsertSQL = "insert into devicecommand(dc_id,dc_code,dc_name,dc_command) values(devicecommand_seq.nextval,:dc_code,:dc_name,:dc_command)";
             ButtonSaveCommand.Grid = GridCommandSetting;
+            ButtonDeleteCommand.Grid = GridCommandSetting;
         }
 
         #region 界面通用事件
@@ -75,17 +79,17 @@ namespace UAS_DeviceMonitor
             }
             else
             {
-                val = "False";//默认为不选   
+                val = "FALSE";//默认为不选   
             }
-            switch (val)
+            switch (val.ToUpper())
             {
-                case "True":
-                case "Yes":
+                case "TRUE":
+                case "YES":
                 case "1":
                     e.CheckState = System.Windows.Forms.CheckState.Checked;
                     break;
-                case "False":
-                case "No":
+                case "FALSE":
+                case "NO":
                 case "0":
                     e.CheckState = System.Windows.Forms.CheckState.Unchecked;
                     break;

+ 9 - 0
UAS_DeviceMonitor/UAS_DeviceMonitor.csproj

@@ -72,6 +72,12 @@
     <Compile Include="CustomerControl\Button\ButtonAddRow.Designer.cs">
       <DependentUpon>ButtonAddRow.cs</DependentUpon>
     </Compile>
+    <Compile Include="CustomerControl\Button\ButtonDeleteRow.cs">
+      <SubType>Component</SubType>
+    </Compile>
+    <Compile Include="CustomerControl\Button\ButtonDeleteRow.Designer.cs">
+      <DependentUpon>ButtonDeleteRow.cs</DependentUpon>
+    </Compile>
     <Compile Include="CustomerControl\Button\ButtonSaveGrid.cs">
       <SubType>Component</SubType>
     </Compile>
@@ -117,6 +123,9 @@
     <EmbeddedResource Include="CustomerControl\Button\ButtonAddRow.resx">
       <DependentUpon>ButtonAddRow.cs</DependentUpon>
     </EmbeddedResource>
+    <EmbeddedResource Include="CustomerControl\Button\ButtonDeleteRow.resx">
+      <DependentUpon>ButtonDeleteRow.cs</DependentUpon>
+    </EmbeddedResource>
     <EmbeddedResource Include="CustomerControl\Button\ButtonSaveGrid.resx">
       <DependentUpon>ButtonSaveGrid.cs</DependentUpon>
     </EmbeddedResource>