瀏覽代碼

完善基础控件和公共方法

章政 7 年之前
父節點
當前提交
a07da6d705

+ 26 - 7
UAS_DeviceMonitor/CustomerControl/AutoDataGridControl/AutoDataGridControl.cs

@@ -1,14 +1,7 @@
 using System;
 using System;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Drawing;
 using System.Data;
 using System.Data;
-using System.Linq;
-using System.Text;
-using System.Windows.Forms;
 using DevExpress.XtraGrid;
 using DevExpress.XtraGrid;
 using UAS_DeviceMonitor.DataOperate;
 using UAS_DeviceMonitor.DataOperate;
-using UAS_DeviceMonitor.Entity;
 
 
 namespace UAS_DeviceMonitor.CustomerControl.AutoDataGridControl
 namespace UAS_DeviceMonitor.CustomerControl.AutoDataGridControl
 {
 {
@@ -16,6 +9,11 @@ namespace UAS_DeviceMonitor.CustomerControl.AutoDataGridControl
     {
     {
         string getDataSQL;
         string getDataSQL;
 
 
+        string condition;
+
+        //记录初始化的SQL,防止条件重复拼接
+        string firstsql;
+
         DataHelper dh = new DataHelper();
         DataHelper dh = new DataHelper();
         //获取数据的SQL
         //获取数据的SQL
         public string GetDataSQL
         public string GetDataSQL
@@ -28,8 +26,11 @@ namespace UAS_DeviceMonitor.CustomerControl.AutoDataGridControl
             set
             set
             {
             {
                 getDataSQL = value;
                 getDataSQL = value;
+                firstsql = value;
             }
             }
         }
         }
+
+
         //获取数据的总行数
         //获取数据的总行数
         public int RowCount
         public int RowCount
         {
         {
@@ -83,6 +84,19 @@ namespace UAS_DeviceMonitor.CustomerControl.AutoDataGridControl
             }
             }
         }
         }
 
 
+        public string Condition
+        {
+            get
+            {
+                return condition;
+            }
+
+            set
+            {
+                condition = value;
+            }
+        }
+
         private string insertSQL;
         private string insertSQL;
 
 
         //用于保存数据的主表的名称
         //用于保存数据的主表的名称
@@ -106,9 +120,14 @@ namespace UAS_DeviceMonitor.CustomerControl.AutoDataGridControl
         {
         {
             if (getDataSQL != null)
             if (getDataSQL != null)
             {
             {
+                if (condition != null)
+                {
+                    getDataSQL = getDataSQL + " " + condition;
+                }
                 DataTable dt = (DataTable)dh.ExecuteSql(getDataSQL, "select");
                 DataTable dt = (DataTable)dh.ExecuteSql(getDataSQL, "select");
                 rowCount = dt.Rows.Count;
                 rowCount = dt.Rows.Count;
                 DataSource = dt;
                 DataSource = dt;
+                getDataSQL = firstsql;
             }
             }
         }
         }
     }
     }

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

@@ -12,7 +12,10 @@ namespace UAS_DeviceMonitor.CustomerControl.GridViewWithSerialNum
 
 
         private void GridViewWithSerialNum_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
         private void GridViewWithSerialNum_CustomDrawRowIndicator(object sender, RowIndicatorCustomDrawEventArgs e)
         {
         {
-            e.Info.DisplayText = e.RowHandle.ToString();
+            if (e.Info.IsRowIndicator && e.RowHandle >= 0)
+            {
+                e.Info.DisplayText = (e.RowHandle + 1).ToString();
+            }
         }
         }
     }
     }
 }
 }

+ 0 - 5
UAS_DeviceMonitor/DataOperate/ComboBoxData.cs

@@ -17,11 +17,6 @@ namespace UAS_DeviceMonitor.DataOperate
         /// </summary>
         /// </summary>
         public string Value { set; get; }
         public string Value { set; get; }
 
 
-        /// <summary>
-        /// 重写ToString()方法
-        /// </summary>
-        /// <author>PengZhen</author>
-        /// <time>2013-10-31 15:51:37</time>
         /// <returns>返回ComboBox的值</returns>
         /// <returns>返回ComboBox的值</returns>
         public override string ToString()
         public override string ToString()
         {
         {

+ 12 - 2
UAS_DeviceMonitor/Device/Command/FormNewCommand.cs

@@ -24,6 +24,11 @@ namespace UAS_DeviceMonitor.Device.Command
             Text = "新增指令(" + BrandName + ")";
             Text = "新增指令(" + BrandName + ")";
         }
         }
 
 
+        /// <summary>
+        /// 设置下拉框的值
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void FormNewCommand_Load(object sender, EventArgs e)
         private void FormNewCommand_Load(object sender, EventArgs e)
         {
         {
             DataTable dt = (DataTable)SystemInf.dh.ExecuteSql("select * from CommandFunctionSetting where cfs_debrand='" + brand + "' order by cfs_id ", "select");
             DataTable dt = (DataTable)SystemInf.dh.ExecuteSql("select * from CommandFunctionSetting where cfs_debrand='" + brand + "' order by cfs_id ", "select");
@@ -33,12 +38,17 @@ namespace UAS_DeviceMonitor.Device.Command
             BaseUtil.FillComBoxEditWidthDataTable(CodeEnd, "cfs_name", "cfs_value", BaseUtil.ToDataTable(dt.Select("cfs_type='CE'")));
             BaseUtil.FillComBoxEditWidthDataTable(CodeEnd, "cfs_name", "cfs_value", BaseUtil.ToDataTable(dt.Select("cfs_type='CE'")));
         }
         }
 
 
+        /// <summary>
+        /// 插入生成的指令,根据选择的功能码+地址位+长度+补码+结束码
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void AddCommand_Click(object sender, EventArgs e)
         private void AddCommand_Click(object sender, EventArgs e)
         {
         {
-            string code = BaseUtil.GetComboxEditValue(CodeClientAddress.SelectedItem) + BaseUtil.GetComboxEditValue(CodeFunction.SelectedItem) + CodeAddress.Text + CodeLength.Text;
+            string code = BaseUtil.GetComboxEditValue(CodeClientAddress) + BaseUtil.GetComboxEditValue(CodeFunction) + CodeAddress.Text + CodeLength.Text;
             //添加指令的补码
             //添加指令的补码
             code = code + BaseUtil.getLRC(code);
             code = code + BaseUtil.getLRC(code);
-            code = code + BaseUtil.GetComboxEditValue(CodeEnd.SelectedItem);
+            code = code + BaseUtil.GetComboxEditValue(CodeEnd);
             SystemInf.dh.ExecuteSql("insert into devicecommand(dc_id,dc_name,dc_code,dc_command,dc_brand) values (devicecommand_seq.nextval,'" + dc_name.Text + "','" + dc_code.Text + "','" + code + "','" + brand + "')", "insert");
             SystemInf.dh.ExecuteSql("insert into devicecommand(dc_id,dc_name,dc_code,dc_command,dc_brand) values (devicecommand_seq.nextval,'" + dc_name.Text + "','" + dc_code.Text + "','" + code + "','" + brand + "')", "insert");
             XtraMessageBox.Show("指令保存成功");
             XtraMessageBox.Show("指令保存成功");
             Close();
             Close();

+ 10 - 2
UAS_DeviceMonitor/Main.Designer.cs

@@ -264,6 +264,7 @@ namespace UAS_DeviceMonitor
             // 
             // 
             // GridDeviceList
             // GridDeviceList
             // 
             // 
+            this.GridDeviceList.Condition = null;
             this.GridDeviceList.Dock = System.Windows.Forms.DockStyle.Fill;
             this.GridDeviceList.Dock = System.Windows.Forms.DockStyle.Fill;
             this.GridDeviceList.GetDataSQL = null;
             this.GridDeviceList.GetDataSQL = null;
             this.GridDeviceList.ID = null;
             this.GridDeviceList.ID = null;
@@ -401,13 +402,17 @@ namespace UAS_DeviceMonitor
             // 
             // 
             // Brand
             // Brand
             // 
             // 
-            this.Brand.Location = new System.Drawing.Point(47, 6);
+            this.Brand.Location = new System.Drawing.Point(47, 4);
             this.Brand.MenuManager = this.RibbonNav;
             this.Brand.MenuManager = this.RibbonNav;
             this.Brand.Name = "Brand";
             this.Brand.Name = "Brand";
+            this.Brand.Properties.Appearance.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+            this.Brand.Properties.Appearance.Options.UseFont = true;
             this.Brand.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
             this.Brand.Properties.Buttons.AddRange(new DevExpress.XtraEditors.Controls.EditorButton[] {
             new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
             new DevExpress.XtraEditors.Controls.EditorButton(DevExpress.XtraEditors.Controls.ButtonPredefines.Combo)});
-            this.Brand.Size = new System.Drawing.Size(100, 20);
+            this.Brand.Properties.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor;
+            this.Brand.Size = new System.Drawing.Size(100, 24);
             this.Brand.TabIndex = 4;
             this.Brand.TabIndex = 4;
+            this.Brand.SelectedIndexChanged += new System.EventHandler(this.Brand_SelectedIndexChanged);
             // 
             // 
             // ButtonNewCommand
             // ButtonNewCommand
             // 
             // 
@@ -434,6 +439,7 @@ namespace UAS_DeviceMonitor
             this.GridCommandSetting.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
             this.GridCommandSetting.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
             | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
             | System.Windows.Forms.AnchorStyles.Right)));
+            this.GridCommandSetting.Condition = null;
             this.GridCommandSetting.GetDataSQL = null;
             this.GridCommandSetting.GetDataSQL = null;
             this.GridCommandSetting.ID = null;
             this.GridCommandSetting.ID = null;
             this.GridCommandSetting.InsertSQL = null;
             this.GridCommandSetting.InsertSQL = null;
@@ -518,6 +524,7 @@ namespace UAS_DeviceMonitor
             this.GridPollingSetting.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
             this.GridPollingSetting.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
             | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
             | System.Windows.Forms.AnchorStyles.Right)));
+            this.GridPollingSetting.Condition = null;
             this.GridPollingSetting.GetDataSQL = null;
             this.GridPollingSetting.GetDataSQL = null;
             this.GridPollingSetting.ID = null;
             this.GridPollingSetting.ID = null;
             this.GridPollingSetting.InsertSQL = null;
             this.GridPollingSetting.InsertSQL = null;
@@ -651,6 +658,7 @@ namespace UAS_DeviceMonitor
             // 
             // 
             // GridPolling
             // GridPolling
             // 
             // 
+            this.GridPolling.Condition = null;
             this.GridPolling.Dock = System.Windows.Forms.DockStyle.Fill;
             this.GridPolling.Dock = System.Windows.Forms.DockStyle.Fill;
             this.GridPolling.GetDataSQL = null;
             this.GridPolling.GetDataSQL = null;
             this.GridPolling.ID = null;
             this.GridPolling.ID = null;

+ 25 - 2
UAS_DeviceMonitor/Main.cs

@@ -35,6 +35,7 @@ namespace UAS_DeviceMonitor
             ButtonSaveCommand.Grid = GridCommandSetting;
             ButtonSaveCommand.Grid = GridCommandSetting;
         }
         }
 
 
+        #region 界面通用事件
         /// <summary>
         /// <summary>
         /// 选项卡切换不同XPage
         /// 选项卡切换不同XPage
         /// </summary>
         /// </summary>
@@ -60,6 +61,11 @@ namespace UAS_DeviceMonitor
             }
             }
         }
         }
 
 
+        /// <summary>
+        /// 勾选Grid的CheckBox
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void CheckedEdit_QueryCheckStateByValue(object sender, DevExpress.XtraEditors.Controls.QueryCheckStateByValueEventArgs e)
         private void CheckedEdit_QueryCheckStateByValue(object sender, DevExpress.XtraEditors.Controls.QueryCheckStateByValueEventArgs e)
         {
         {
             string val = "";
             string val = "";
@@ -89,24 +95,41 @@ namespace UAS_DeviceMonitor
             }
             }
             e.Handled = true;
             e.Handled = true;
         }
         }
+        #endregion
 
 
         #region PageCommandSet业务代码
         #region PageCommandSet业务代码
-
+        /// <summary>
+        /// 新增指令弹窗
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void ButtonNewCommand_Click(object sender, EventArgs e)
         private void ButtonNewCommand_Click(object sender, EventArgs e)
         {
         {
-            FormNewCommand fncmd = new FormNewCommand(BaseUtil.GetComboxEditValue(Brand.SelectedItem), Brand.Text);
+            FormNewCommand fncmd = new FormNewCommand(BaseUtil.GetComboxEditValue(Brand), Brand.Text);
             fncmd.ShowDialog();
             fncmd.ShowDialog();
             GridCommandSetting.RefreshData();
             GridCommandSetting.RefreshData();
         }
         }
 
 
+        /// <summary>
+        /// 加载ComBox品牌数据
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
         private void PageCommandSet_VisibleChanged(object sender, EventArgs e)
         private void PageCommandSet_VisibleChanged(object sender, EventArgs e)
         {
         {
             if (PageCommandSet.PageVisible)
             if (PageCommandSet.PageVisible)
             {
             {
                 DataTable dt = (DataTable)SystemInf.dh.ExecuteSql("select * from devicebrand", "select");
                 DataTable dt = (DataTable)SystemInf.dh.ExecuteSql("select * from devicebrand", "select");
                 BaseUtil.FillComBoxEditWidthDataTable(Brand, "db_name", "db_code", dt);
                 BaseUtil.FillComBoxEditWidthDataTable(Brand, "db_name", "db_code", dt);
+                GridCommandSetting.Condition = " where dc_brand='" + BaseUtil.GetComboxEditValue(Brand) + "'";
             }
             }
         }
         }
+
+        private void Brand_SelectedIndexChanged(object sender, EventArgs e)
+        {
+            GridCommandSetting.Condition = " where dc_brand='" + BaseUtil.GetComboxEditValue(Brand) + "'";
+            GridCommandSetting.RefreshData();
+        }
         #endregion
         #endregion
     }
     }
 }
 }

+ 6 - 21
UAS_DeviceMonitor/PublicMethod/BaseUtil.cs

@@ -1,24 +1,6 @@
 using DevExpress.XtraEditors;
 using DevExpress.XtraEditors;
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.ComponentModel;
 using System.Data;
 using System.Data;
-using System.Diagnostics;
-using System.Drawing;
-using System.IO;
-using System.Linq;
-using System.Net;
-using System.Net.Sockets;
-using System.Reflection;
-using System.Text;
-using System.Threading;
-using System.Windows.Forms;
-using System.Xml;
 using UAS_DeviceMonitor.DataOperate;
 using UAS_DeviceMonitor.DataOperate;
-using UAS_DeviceMonitor.Entity;
-using UAS_DeviceMonitor.PublicMethod;
-using static System.Windows.Forms.Control;
 
 
 namespace UAS_DeviceMonitor.PublicMethod
 namespace UAS_DeviceMonitor.PublicMethod
 {
 {
@@ -27,9 +9,9 @@ namespace UAS_DeviceMonitor.PublicMethod
         public static void FillComBoxEditWidthDataTable(ComboBoxEdit combo, string TextField, string ValueField, DataTable dt)
         public static void FillComBoxEditWidthDataTable(ComboBoxEdit combo, string TextField, string ValueField, DataTable dt)
         {
         {
             combo.Properties.Items.Clear();
             combo.Properties.Items.Clear();
-            ComboBoxData item = new ComboBoxData();
             for (int i = 0; i < dt.Rows.Count; i++)
             for (int i = 0; i < dt.Rows.Count; i++)
             {
             {
+                ComboBoxData item = new ComboBoxData();
                 item.Value = dt.Rows[i][ValueField].ToString();
                 item.Value = dt.Rows[i][ValueField].ToString();
                 item.Text = dt.Rows[i][TextField].ToString();
                 item.Text = dt.Rows[i][TextField].ToString();
                 combo.Properties.Items.Add(item);
                 combo.Properties.Items.Add(item);
@@ -46,9 +28,12 @@ namespace UAS_DeviceMonitor.PublicMethod
             return tmp;
             return tmp;
         }
         }
 
 
-        public static string GetComboxEditValue(object comboxitem)
+        public static string GetComboxEditValue(ComboBoxEdit ComBox)
         {
         {
-            return (comboxitem as ComboBoxData).Value;
+            if (ComBox.SelectedItem == null)
+                return ComBox.Text;
+            else
+                return (ComBox.SelectedItem as ComboBoxData).Value;
         }
         }
 
 
         /// <summary>
         /// <summary>