Browse Source

Merge branch 'master' of ssh://10.10.100.21/source/mes-client

Hcsy 7 years ago
parent
commit
388771e550

+ 221 - 23
UAS-出货标签管理/CustomControl/SearchTextBox.cs

@@ -1,31 +1,67 @@
 using System;
+using System.Data;
 using System.Windows.Forms;
+using UAS_LabelMachine.PublicMethod;
 
 namespace UAS_LabelMachine.CustomControl
 {
     public partial class SearchTextBox : UserControl
     {
+
+        DataHelper dh = new DataHelper();
+
+        #region 构造函数
         public SearchTextBox()
         {
             InitializeComponent();
         }
+        #endregion
+
+        #region 变量
+        /// <summary>
+        /// 是否通过Leave事件找到数据
+        /// </summary>
+        public bool LeaveFindData;
+        /// <summary>
+        /// DBFind窗体弹出的标题
+        /// </summary>
+        private string DBTitle1;
+        /// <summary>
+        /// 输入框是否可编辑
+        /// </summary>
+        private bool TextBoxEnable1;
+        /// <summary>
+        /// 业务逻辑的标识符
+        /// </summary>
         private string caller;
+        /// <summary>
+        /// 发起DbFind的窗体
+        /// </summary>
         private string formName;
+        /// <summary>
+        /// 需要赋值的字段
+        /// </summary>
+        private string[] setValueField;
+        /// <summary>
+        /// 初始的筛选条件
+        /// </summary>
+        private string condition;
+        /// <summary>
+        /// 权限标识
+        /// </summary>
+        private string Power1;
+        /// <summary>
+        /// 查询的表名
+        /// </summary>
+        private string tableName;
+        /// <summary>
+        /// 查询的字段
+        /// </summary>
+        private string selectField;
+        DataTable dt = new DataTable();
+        DbFind db;
 
-        //定义委托
-        public delegate void OnTextChange(object sender, EventArgs e);
-        //定义事件
-        public event OnTextChange UserControlTextChanged;
-
-        //定义委托
-        public delegate void Icon_Click(object sender, EventArgs e);
-
-        public event Icon_Click SearchIconClick;
-
-        private void TextBox_TextChanged(object sender, EventArgs e)
-        {
-            UserControlTextChanged?.Invoke(sender, new EventArgs());
-        }
+        private DataTable returnData;
 
         public override string Text
         {
@@ -39,6 +75,22 @@ namespace UAS_LabelMachine.CustomControl
             }
         }
 
+        string AllPower1;
+
+        public string AllPower
+        {
+            get
+            {
+                return AllPower1;
+            }
+
+            set
+            {
+                AllPower1 = value;
+            }
+        }
+
+
         public string Caller
         {
             get
@@ -52,8 +104,6 @@ namespace UAS_LabelMachine.CustomControl
             }
         }
 
-        private string[] setValueField;
-
         public string FormName
         {
             get
@@ -67,8 +117,6 @@ namespace UAS_LabelMachine.CustomControl
             }
         }
 
-        private string condition;
-
         public string[] SetValueField
         {
             get
@@ -121,18 +169,105 @@ namespace UAS_LabelMachine.CustomControl
             }
         }
 
-        private string tableName;
+        public string Power
+        {
+            get
+            {
+                return Power1;
+            }
 
-        private string selectField;
+            set
+            {
+                Power1 = value;
+            }
+        }
+
+        public string DBTitle
+        {
+            get
+            {
+                return DBTitle1;
+            }
+
+            set
+            {
+                DBTitle1 = value;
+            }
+        }
+
+        public bool TextBoxEnable
+        {
+            get
+            {
+                return TextBoxEnable1;
+            }
+
+            set
+            {
+                TextBoxEnable1 = value;
+            }
+        }
+
+        public DataTable ReturnData
+        {
+            get
+            {
+                return returnData;
+            }
+
+            set
+            {
+                returnData = value;
+            }
+        }
+        #endregion
+
+        #region 自定义事件
+        public delegate void OnTextChange(object sender, EventArgs e);
+        //定义事件
+        public event OnTextChange UserControlTextChanged;
+        //定义委托
+        public delegate void Icon_Click(object sender, EventArgs e);
+        /// <summary>
+        /// 图标点击事件
+        /// </summary>
+        public event Icon_Click SearchIconClick;
+
+        public delegate void DBSourceChange(object sender, EventArgs e);
+
+        public event DBSourceChange DbChange;
+
+        public delegate void OnTextKeyDown(object sender, KeyEventArgs e);
+
+        public event OnTextKeyDown TextKeyDown;
+        #endregion
+        //定义委托
+
+        private void TextBox_TextChanged(object sender, EventArgs e)
+        {
+            UserControlTextChanged?.Invoke(sender, new EventArgs());
+        }
+
+        //Key先发起失去焦点事件,在执行用户自定义的事件
+        private void TextBox_KeyDown(object sender, KeyEventArgs e)
+        {
+            if (e.KeyCode == Keys.Enter)
+            {
+                TextBox_Leave(sender, e);
+                TextKeyDown?.Invoke(sender, new KeyEventArgs(e.KeyCode));
+            }
+        }
 
         private void Search_Icon_Click(object sender, EventArgs e)
         {
             SearchIconClick?.Invoke(sender, new EventArgs());
-            
-            DbFind db = new DbFind(Name, tableName, selectField, setValueField, caller, formName, condition);
+            db = new DbFind(Name, tableName, selectField, setValueField, caller, formName, condition);
+            db.Text = DBTitle1;
+            LogManager.DoLog("DbFind查询,发起窗口【" + formName + "】,查询表【" + tableName + "】,字段" + selectField + ",条件" + condition);
             if (db.IsAbleDbFind1)
             {
                 db.ShowDialog();
+                GetData();
             }
             else
             {
@@ -140,14 +275,77 @@ namespace UAS_LabelMachine.CustomControl
             }
         }
 
+        /// <summary>
+        /// 触发给界面的
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        public void ReturnDataToForm()
+        {
+            returnData = dt;
+            DbChange?.Invoke(new object(), new EventArgs());
+        }
+
         private void TextBox_Enter(object sender, EventArgs e)
         {
             TextBox.BackColor = System.Drawing.Color.GreenYellow;
         }
 
-        private void TextBox_Leave(object sender, EventArgs e)
+        /// <summary>
+        /// 重新刷新数据
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        public void RefreshDB(object sender, EventArgs e)
+        {
+            TextBox_Leave(sender, e);
+            GetData();
+        }
+
+        public void TextBox_Leave(object sender, EventArgs e)
         {
             TextBox.BackColor = System.Drawing.Color.White;
+            GetData();
+        }
+
+        private void SearchTextBox_Load(object sender, EventArgs e)
+        {
+            if (!TextBoxEnable1)
+                TextBox.BackColor = System.Drawing.Color.White;
+            TextBox.Enabled = TextBoxEnable1;
+        }
+
+        private void SearchTextBox_SizeChanged(object sender, EventArgs e)
+        {
+            TextBox.Width = this.Width - Search_Icon.Width - 3;
+        }
+
+        public void GetData()
+        {
+            string sql = "";
+            //将查询到的结果返回界面
+            if (TextBox.Text != "")
+            {
+                sql = "select " + BaseUtil.AddField(setValueField) + " from " + tableName + " where " + Name + "='" + TextBox.Text + "'";
+            }
+            else if (db != null)
+            {
+                sql = "select " + BaseUtil.AddField(setValueField) + " from " + tableName + " where " + Name + "='" + db.TextBoxValue1 + "'";
+            }
+            if (condition != null)
+            {
+                sql += " and " + condition;
+            }
+            try
+            {
+                dt = (DataTable)dh.ExecuteSql(sql, "select");
+                if (dt.Rows.Count > 0)
+                    ReturnDataToForm();
+            }
+            catch (Exception e)
+            {
+                LogManager.DoLog(e.Message);
+            }
         }
     }
 }

+ 15 - 0
UAS-出货标签管理/DbFind.cs

@@ -15,6 +15,8 @@ namespace UAS_LabelMachine
         DataTable dt = new DataTable();
         AutoSizeFormClass asc = new AutoSizeFormClass();
 
+
+        string TextBoxValue = "";
         Control[] ctl;
         //DBFind查询的字段
         string Field;
@@ -42,6 +44,19 @@ namespace UAS_LabelMachine
             }
         }
 
+        public string TextBoxValue1
+        {
+            get
+            {
+                return TextBoxValue;
+            }
+
+            set
+            {
+                TextBoxValue = value;
+            }
+        }
+
         /// <summary>
         /// 
         /// </summary>

+ 7 - 1
UAS-出货标签管理/UAS_出货标签管理.cs

@@ -172,7 +172,7 @@ namespace UAS_LabelMachine
             sg_code.SetValueField = new string[] { "sg_code" };
             sg_code.SelectField = "sg_code # 策略编号 ,sg_name # 策略名称,sg_brand # 品牌,sg_separator # 分隔符";
             sg_code.TableName = "scangroup";
-
+            sg_code.DbChange += Sg_code_DbChange;
             pr_code.FormName = Name;
             pr_code.SetValueField = new string[] { "pr_code", "pib_id" };
             pr_code.TableName = "prodiodetail";
@@ -221,6 +221,12 @@ namespace UAS_LabelMachine
             }
         }
 
+        private void Sg_code_DbChange(object sender, EventArgs e)
+        {
+            DataTable dt = sg_code.ReturnData;
+            BaseUtil.SetFormValue(this.Controls, dt);
+        }
+
         private void 贴标机条码打印_SizeChanged(object sender, EventArgs e)
         {
             asc.controlAutoSize(this);

+ 4 - 0
UAS-出货标签管理/生成条码.cs

@@ -499,6 +499,10 @@ namespace UAS_LabelMachine
                             NrData[m] = Temp.Rows[0][0].ToString();
                             NrDic.Add(m, NrData[m]);
                         }
+                        else
+                        {
+                            NrDic.Add(m, "");
+                        }
                         break;
                     //流水需要通过MaxNumber去取
                     case "流水":

+ 1 - 1
UAS_DeviceMonitor/CustomerControl/Button/ButtonDeleteRow.cs

@@ -43,7 +43,7 @@ namespace UAS_DeviceMonitor.CustomerControl.Button
                 GridView view = grid.MainView as GridView;
                 for (int i = 0; i < grid.RowCount; i++)
                 {
-                    string Checked = view.GetRowCellValue(i, "CHOOSE").ToString().ToUpper();
+                    string Checked = view.GetRowCellValue(i, view.Name.ToUpper() + "CHOOSE").ToString().ToUpper();
                     if (Checked != "0")
                         DeleteID.Add(view.GetRowCellValue(i, grid.ID.ToUpper()).ToString());
                 }

+ 30 - 0
UAS_DeviceMonitor/Entity/Polling.cs

@@ -7,6 +7,8 @@ namespace UAS_DeviceMonitor.Entity
 {
     class Polling
     {
+        private string code;
+
         private string deviceCode;
 
         private string iP;
@@ -15,6 +17,8 @@ namespace UAS_DeviceMonitor.Entity
 
         private int interval;
 
+        private int id;
+
         private bool enable;
 
         public string DeviceCode
@@ -81,5 +85,31 @@ namespace UAS_DeviceMonitor.Entity
                 enable = value;
             }
         }
+
+        public string Code
+        {
+            get
+            {
+                return code;
+            }
+
+            set
+            {
+                code = value;
+            }
+        }
+
+        public int Id
+        {
+            get
+            {
+                return id;
+            }
+
+            set
+            {
+                id = value;
+            }
+        }
     }
 }

+ 45 - 32
UAS_DeviceMonitor/Main.Designer.cs

@@ -69,7 +69,7 @@ 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.GRIDVIEWCOMMANDSETCHOOSE = 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();
@@ -85,6 +85,8 @@ 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.GRIDVIEWPOLLSETTINGCHOOSE = 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();
             this.dpc_plcode = new DevExpress.XtraGrid.Columns.GridColumn();
@@ -94,7 +96,6 @@ namespace UAS_DeviceMonitor
             this.PollingSetItemLookUpEdit = new DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit();
             this.dpc_function = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dpc_enable = new DevExpress.XtraGrid.Columns.GridColumn();
-            this.dpc_enableCheckEdit = new DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit();
             this.dpc_status = new DevExpress.XtraGrid.Columns.GridColumn();
             this.dpc_remark = new DevExpress.XtraGrid.Columns.GridColumn();
             this.PagePolling = new DevExpress.XtraTab.XtraTabPage();
@@ -124,8 +125,8 @@ namespace UAS_DeviceMonitor
             this.PagePollingSetting.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.GridPollingSetting)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPollSetting)).BeginInit();
-            ((System.ComponentModel.ISupportInitialize)(this.PollingSetItemLookUpEdit)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.dpc_enableCheckEdit)).BeginInit();
+            ((System.ComponentModel.ISupportInitialize)(this.PollingSetItemLookUpEdit)).BeginInit();
             this.PagePolling.SuspendLayout();
             ((System.ComponentModel.ISupportInitialize)(this.GridPolling)).BeginInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPolling)).BeginInit();
@@ -488,7 +489,7 @@ namespace UAS_DeviceMonitor
             // GridViewCommandSet
             // 
             this.GridViewCommandSet.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] {
-            this.Choose,
+            this.GRIDVIEWCOMMANDSETCHOOSE,
             this.dc_id,
             this.dc_code,
             this.dc_name,
@@ -498,14 +499,14 @@ namespace UAS_DeviceMonitor
             this.GridViewCommandSet.Name = "GridViewCommandSet";
             this.GridViewCommandSet.OptionsSelection.MultiSelect = true;
             // 
-            // Choose
+            // GRIDVIEWCOMMANDSETCHOOSE
             // 
-            this.Choose.Caption = "勾选";
-            this.Choose.ColumnEdit = this.CheckEditCommandSet;
-            this.Choose.FieldName = "CHOOSE";
-            this.Choose.Name = "Choose";
-            this.Choose.Visible = true;
-            this.Choose.VisibleIndex = 0;
+            this.GRIDVIEWCOMMANDSETCHOOSE.Caption = "勾选";
+            this.GRIDVIEWCOMMANDSETCHOOSE.ColumnEdit = this.CheckEditCommandSet;
+            this.GRIDVIEWCOMMANDSETCHOOSE.FieldName = "GRIDVIEWCOMMANDSETCHOOSE";
+            this.GRIDVIEWCOMMANDSETCHOOSE.Name = "GRIDVIEWCOMMANDSETCHOOSE";
+            this.GRIDVIEWCOMMANDSETCHOOSE.Visible = true;
+            this.GRIDVIEWCOMMANDSETCHOOSE.VisibleIndex = 0;
             // 
             // CheckEditCommandSet
             // 
@@ -648,6 +649,7 @@ namespace UAS_DeviceMonitor
             // GridViewPollSetting
             // 
             this.GridViewPollSetting.Columns.AddRange(new DevExpress.XtraGrid.Columns.GridColumn[] {
+            this.GRIDVIEWPOLLSETTINGCHOOSE,
             this.dpc_id,
             this.dpc_decode,
             this.dpc_plcode,
@@ -662,6 +664,26 @@ namespace UAS_DeviceMonitor
             this.GridViewPollSetting.IndicatorWidth = 30;
             this.GridViewPollSetting.Name = "GridViewPollSetting";
             this.GridViewPollSetting.OptionsSelection.MultiSelect = true;
+            this.GridViewPollSetting.CellValueChanging += new DevExpress.XtraGrid.Views.Base.CellValueChangedEventHandler(this.GridViewPollSetting_CellValueChanging);
+            // 
+            // GRIDVIEWPOLLSETTINGCHOOSE
+            // 
+            this.GRIDVIEWPOLLSETTINGCHOOSE.Caption = "选择";
+            this.GRIDVIEWPOLLSETTINGCHOOSE.ColumnEdit = this.dpc_enableCheckEdit;
+            this.GRIDVIEWPOLLSETTINGCHOOSE.FieldName = "GRIDVIEWPOLLSETTINGCHOOSE";
+            this.GRIDVIEWPOLLSETTINGCHOOSE.Name = "GRIDVIEWPOLLSETTINGCHOOSE";
+            this.GRIDVIEWPOLLSETTINGCHOOSE.Visible = true;
+            this.GRIDVIEWPOLLSETTINGCHOOSE.VisibleIndex = 0;
+            // 
+            // dpc_enableCheckEdit
+            // 
+            this.dpc_enableCheckEdit.AutoHeight = false;
+            this.dpc_enableCheckEdit.Name = "dpc_enableCheckEdit";
+            this.dpc_enableCheckEdit.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;
+            this.dpc_enableCheckEdit.PictureChecked = ((System.Drawing.Image)(resources.GetObject("dpc_enableCheckEdit.PictureChecked")));
+            this.dpc_enableCheckEdit.PictureUnchecked = ((System.Drawing.Image)(resources.GetObject("dpc_enableCheckEdit.PictureUnchecked")));
+            this.dpc_enableCheckEdit.ValueChecked = "-1";
+            this.dpc_enableCheckEdit.ValueUnchecked = "0";
             // 
             // dpc_id
             // 
@@ -675,7 +697,7 @@ namespace UAS_DeviceMonitor
             this.dpc_decode.FieldName = "DPC_DECODE";
             this.dpc_decode.Name = "dpc_decode";
             this.dpc_decode.Visible = true;
-            this.dpc_decode.VisibleIndex = 0;
+            this.dpc_decode.VisibleIndex = 1;
             // 
             // dpc_plcode
             // 
@@ -683,7 +705,7 @@ namespace UAS_DeviceMonitor
             this.dpc_plcode.FieldName = "DPC_PLCODE";
             this.dpc_plcode.Name = "dpc_plcode";
             this.dpc_plcode.Visible = true;
-            this.dpc_plcode.VisibleIndex = 1;
+            this.dpc_plcode.VisibleIndex = 2;
             // 
             // dpc_plname
             // 
@@ -691,7 +713,7 @@ namespace UAS_DeviceMonitor
             this.dpc_plname.FieldName = "DPC_PLNAME";
             this.dpc_plname.Name = "dpc_plname";
             this.dpc_plname.Visible = true;
-            this.dpc_plname.VisibleIndex = 2;
+            this.dpc_plname.VisibleIndex = 3;
             // 
             // dpc_interval
             // 
@@ -699,7 +721,7 @@ namespace UAS_DeviceMonitor
             this.dpc_interval.FieldName = "DPC_INTERVAL";
             this.dpc_interval.Name = "dpc_interval";
             this.dpc_interval.Visible = true;
-            this.dpc_interval.VisibleIndex = 3;
+            this.dpc_interval.VisibleIndex = 4;
             // 
             // dpc_dccode
             // 
@@ -708,7 +730,7 @@ namespace UAS_DeviceMonitor
             this.dpc_dccode.FieldName = "DPC_DCCODE";
             this.dpc_dccode.Name = "dpc_dccode";
             this.dpc_dccode.Visible = true;
-            this.dpc_dccode.VisibleIndex = 4;
+            this.dpc_dccode.VisibleIndex = 5;
             // 
             // PollingSetItemLookUpEdit
             // 
@@ -726,7 +748,7 @@ namespace UAS_DeviceMonitor
             this.dpc_function.FieldName = "DPC_FUNCTION";
             this.dpc_function.Name = "dpc_function";
             this.dpc_function.Visible = true;
-            this.dpc_function.VisibleIndex = 5;
+            this.dpc_function.VisibleIndex = 6;
             // 
             // dpc_enable
             // 
@@ -735,17 +757,7 @@ namespace UAS_DeviceMonitor
             this.dpc_enable.FieldName = "DPC_ENABLE";
             this.dpc_enable.Name = "dpc_enable";
             this.dpc_enable.Visible = true;
-            this.dpc_enable.VisibleIndex = 6;
-            // 
-            // dpc_enableCheckEdit
-            // 
-            this.dpc_enableCheckEdit.AutoHeight = false;
-            this.dpc_enableCheckEdit.Name = "dpc_enableCheckEdit";
-            this.dpc_enableCheckEdit.NullStyle = DevExpress.XtraEditors.Controls.StyleIndeterminate.Unchecked;
-            this.dpc_enableCheckEdit.PictureChecked = ((System.Drawing.Image)(resources.GetObject("dpc_enableCheckEdit.PictureChecked")));
-            this.dpc_enableCheckEdit.PictureUnchecked = ((System.Drawing.Image)(resources.GetObject("dpc_enableCheckEdit.PictureUnchecked")));
-            this.dpc_enableCheckEdit.ValueChecked = "-1";
-            this.dpc_enableCheckEdit.ValueUnchecked = "0";
+            this.dpc_enable.VisibleIndex = 7;
             // 
             // dpc_status
             // 
@@ -753,7 +765,7 @@ namespace UAS_DeviceMonitor
             this.dpc_status.FieldName = "DPC_STATUS";
             this.dpc_status.Name = "dpc_status";
             this.dpc_status.Visible = true;
-            this.dpc_status.VisibleIndex = 7;
+            this.dpc_status.VisibleIndex = 8;
             // 
             // dpc_remark
             // 
@@ -761,7 +773,7 @@ namespace UAS_DeviceMonitor
             this.dpc_remark.FieldName = "DPC_REMARK";
             this.dpc_remark.Name = "dpc_remark";
             this.dpc_remark.Visible = true;
-            this.dpc_remark.VisibleIndex = 8;
+            this.dpc_remark.VisibleIndex = 9;
             // 
             // PagePolling
             // 
@@ -914,8 +926,8 @@ namespace UAS_DeviceMonitor
             this.PagePollingSetting.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.GridPollingSetting)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPollSetting)).EndInit();
-            ((System.ComponentModel.ISupportInitialize)(this.PollingSetItemLookUpEdit)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.dpc_enableCheckEdit)).EndInit();
+            ((System.ComponentModel.ISupportInitialize)(this.PollingSetItemLookUpEdit)).EndInit();
             this.PagePolling.ResumeLayout(false);
             ((System.ComponentModel.ISupportInitialize)(this.GridPolling)).EndInit();
             ((System.ComponentModel.ISupportInitialize)(this.GridViewPolling)).EndInit();
@@ -988,7 +1000,7 @@ namespace UAS_DeviceMonitor
         private GridViewWithSerialNum GridViewPollSetting;
         private LabelControl Brand_label;
         private ComboBoxEdit Brand;
-        private DevExpress.XtraGrid.Columns.GridColumn Choose;
+        private DevExpress.XtraGrid.Columns.GridColumn GRIDVIEWCOMMANDSETCHOOSE;
         private DevExpress.XtraEditors.Repository.RepositoryItemCheckEdit CheckEditCommandSet;
         private CustomerControl.Button.ButtonDeleteRow ButtonDeleteCommand;
         private CustomerControl.Button.ButtonDeleteRow ButtonDeletePolling;
@@ -1001,5 +1013,6 @@ namespace UAS_DeviceMonitor
         private CustomerControl.Button.ButtonSaveGrid ButtonSaveCommandSet;
         private DevExpress.XtraEditors.Repository.RepositoryItemLookUpEdit PollingSetItemLookUpEdit;
         private System.Windows.Forms.Timer PollingTimer;
+        private DevExpress.XtraGrid.Columns.GridColumn GRIDVIEWPOLLSETTINGCHOOSE;
     }
 }

+ 55 - 15
UAS_DeviceMonitor/Main.cs

@@ -12,6 +12,7 @@ using DevExpress.XtraGrid.Views.Grid;
 using System.Timers;
 using System.Threading;
 using System.Threading.Tasks;
+using System.Collections.Generic;
 
 namespace UAS_DeviceMonitor
 {
@@ -42,7 +43,7 @@ namespace UAS_DeviceMonitor
             ButtonSavePolling.Grid = GridPolling;
             ButtonAddPolling.Grid = GridPolling;
             //轮询配置界面
-            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";
+            GridPollingSetting.GetDataSQL = "SELECT 0 GRIDVIEWPOLLSETTINGCHOOSE,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)";
@@ -51,7 +52,7 @@ namespace UAS_DeviceMonitor
             ButtonDeleteCommandSet.Grid = GridPollingSetting;
 
             //指令设置界面
-            GridCommandSetting.GetDataSQL = "select 0 CHOOSE,dc_id,dc_code,dc_name,dc_command from devicecommand".ToUpper();
+            GridCommandSetting.GetDataSQL = "select 0 GRIDVIEWCOMMANDSETCHOOSE,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)";
@@ -169,40 +170,79 @@ namespace UAS_DeviceMonitor
 
         #region PagePollingSetting业务代码
 
-        bool PollingSign = false;
-
+        PollingTask pt = new PollingTask();
         private void ButtonStartPolling_Click(object sender, EventArgs e)
         {
-            PollingTask pt = new PollingTask();
             GridView grid = GridViewPollSetting;
             for (int i = 0; i < GridPollingSetting.RowCount; i++)
             {
                 Polling pl = new Polling();
+                pl.Id = int.Parse(GridViewPollSetting.GetRowCellValue(i, "DPC_ID").ToString());
                 pl.DeviceCode = GridViewPollSetting.GetRowCellValue(i, "DPC_DECODE").ToString();
                 pl.Interval = int.Parse(GridViewPollSetting.GetRowCellValue(i, "DPC_INTERVAL").ToString());
                 pl.Enable = GridViewPollSetting.GetRowCellValue(i, "DPC_ENABLE").ToString() != "0";
+                pl.Code = GridViewPollSetting.GetRowCellValue(i, "DPC_PLCODE").ToString();
                 if (pl.Enable)
                     pt.AddTask(RunTask, pl);
             }
-            PollingSign = true;
-            pt.StartAllTask();
         }
 
+        Dictionary<int, PollingTimer> Ptime = new Dictionary<int, PollingTimer>();
+
         private void RunTask(object i)
         {
-            while (PollingSign)
+            PollingTimer timer = new PollingTimer();
+            Polling pl = (Polling)i;
+            timer.Polling = i;
+            timer.Interval = pl.Interval * 1000;
+            timer.Elapsed += Timer_Tick;
+            Ptime.Add(pl.Id, timer);
+            timer.Start();
+        }
+
+        private void Timer_Tick(object sender, EventArgs e)
+        {
+            PollingTimer timer = (PollingTimer)sender;
+            Polling pl = (Polling)timer.Polling;
+            string Decode = pl.DeviceCode;
+            Console.WriteLine(Decode);
+        }
+
+        private void ButtonPausePolling_Click(object sender, EventArgs e)
+        {
+            foreach (var item in Ptime)
             {
-                Polling pl = (Polling)i;
-                int Interval = pl.Interval;
-                string Decode = pl.DeviceCode;
-                Thread.Sleep(Interval * 1000);
-                SystemInf.dh.ExecuteSql("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,'" + Decode + "','','' ,'' ,'' ,'' , '','' ,'')", "insert");
+                item.Value.Stop();
             }
         }
 
-        private void ButtonPausePolling_Click(object sender, EventArgs e)
+        private void GridViewPollSetting_CellValueChanging(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
         {
-            PollingSign = false;
+            if (e.Column.Name.ToUpper() == "DPC_ENABLE")
+            {
+                GridViewPollSetting.SetRowCellValue(e.RowHandle, e.Column, e.Value);
+                Console.WriteLine(GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ENABLE").ToString());
+                if (GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ENABLE").ToString() == "0")
+                {
+                    int id = int.Parse(GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ID").ToString());
+                    if (Ptime.ContainsKey(id))
+                    {
+                        Ptime[id].Stop();
+                        Ptime.Remove(id);
+                    }
+                }
+                else
+                {
+                    Polling pl = new Polling();
+                    pl.Id = int.Parse(GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ID").ToString());
+                    pl.DeviceCode = GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_DECODE").ToString();
+                    pl.Interval = int.Parse(GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_INTERVAL").ToString());
+                    pl.Enable = GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_ENABLE").ToString() != "0";
+                    pl.Code = GridViewPollSetting.GetRowCellValue(e.RowHandle, "DPC_PLCODE").ToString();
+                    if (pl.Enable)
+                        pt.AddTask(RunTask, pl);
+                }
+            }
         }
 
         /// <summary>

+ 32 - 21
UAS_DeviceMonitor/PublicMethod/PollingTask.cs

@@ -1,16 +1,17 @@
 using System;
-using System.Collections;
 using System.Collections.Generic;
-using System.Runtime.Serialization;
 using System.Threading;
 using System.Threading.Tasks;
+using UAS_DeviceMonitor.Entity;
 
 namespace UAS_DeviceMonitor.PublicMethod
 {
     class PollingTask
     {
-
-        List<Task> list = new List<Task>();
+        /// <summary>
+        /// 内部调用的任务,添加了取消标识符号
+        /// </summary>
+        Dictionary<string, Task> InTask = new Dictionary<string, Task>();
         /// <summary>
         /// 获取任务
         /// </summary>
@@ -26,24 +27,26 @@ namespace UAS_DeviceMonitor.PublicMethod
         /// </summary>
         /// <param name="TCode"></param>
         /// <returns></returns>
-        public void AddTask(Action action)
-        {
-            Task newTask = new Task(action);
-            list.Add(newTask);
-        }
-
+        //public void AddTask(Action action, string Code)
+        //{
+        //    Task newTask = Task.Factory.StartNew(() => action);
+        //    InTask.Add(Code, newTask);
+        //}
+       
         /// <summary>
         /// 添加任务,默认添加后自动执行,返回创建的TASK的ID
         /// </summary>
         /// <param name="TCode"></param>
         /// <returns></returns>
-        public void AddTask(Action<object> action,object obj)
+        public void AddTask(Action<object> action, object obj)
         {
-            Task newTask = new Task(action, obj);
-            list.Add(newTask);
+            Polling pl = (Polling)obj;
+            if (!InTask.ContainsKey(pl.Code))
+            {
+                InTask.Add(pl.Code, Task.Factory.StartNew(action, obj));
+            }
         }
 
-        /// <summary>
         /// 添加一系列任务
         /// </summary>
         /// <param name="action"></param>
@@ -66,8 +69,19 @@ namespace UAS_DeviceMonitor.PublicMethod
         /// 移除任务
         /// </summary>
         /// <returns></returns>
-        public bool RemoveTask()
+        public bool RemoveTask(string Code)
         {
+            InTask.Remove(Code);
+            return true;
+        }
+
+        /// <summary>
+        /// 移除所有的任务
+        /// </summary>
+        /// <returns></returns>
+        public bool RemoveAllTask()
+        {
+            InTask.Clear();
             return true;
         }
 
@@ -86,9 +100,9 @@ namespace UAS_DeviceMonitor.PublicMethod
         /// </summary>
         public void StartAllTask()
         {
-            for (int i = 0; i < list.Count; i++)
+            foreach (var item in InTask)
             {
-                list[i].Start();
+                item.Value.Start();
             }
         }
 
@@ -105,10 +119,7 @@ namespace UAS_DeviceMonitor.PublicMethod
         /// </summary>
         public void StopAllTask()
         {
-            for (int i = 0; i < list.Count; i++)
-            {
-                var tokenSource = new CancellationTokenSource();
-            }
+
         }
 
         /// <summary>

+ 25 - 0
UAS_DeviceMonitor/PublicMethod/PollingTimer.cs

@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace UAS_DeviceMonitor.PublicMethod
+{
+    class PollingTimer : System.Timers.Timer
+    {
+        private object polling;
+
+        public object Polling
+        {
+            get
+            {
+                return polling;
+            }
+
+            set
+            {
+                polling = value;
+            }
+        }
+    }
+}

+ 3 - 0
UAS_DeviceMonitor/UAS_DeviceMonitor.csproj

@@ -118,6 +118,9 @@
     <Compile Include="PublicMethod\LogManager.cs" />
     <Compile Include="PublicMethod\ModeBusTCPServer.cs" />
     <Compile Include="PublicMethod\PollingTask.cs" />
+    <Compile Include="PublicMethod\PollingTimer.cs">
+      <SubType>Component</SubType>
+    </Compile>
     <EmbeddedResource Include="CustomerControl\AutoDataGridControl\AutoDataGridControl.resx">
       <DependentUpon>AutoDataGridControl.cs</DependentUpon>
     </EmbeddedResource>