public Dictionary <Guid, bool> GetFetchingMap()
        {
            Dictionary <Guid, bool> list = new Dictionary <Guid, bool>();

            for (int i = 0; i < dataGridViewX1.Rows.Count; i++)
            {
                DataGridViewCheckBoxXCell cbk = dataGridViewX1.Rows[i].Cells[5] as DataGridViewCheckBoxXCell;
                if (cbk != null && cbk.Value != null)
                {
                    Guid id = (Guid)cbk.Tag;
                    Data.NetDataFetcher fe = GlobalTable.GlobalTables.Instance.GetFetcher(id) as Data.NetDataFetcher;
                    if (fe != null)
                    {
                        list.Add(id, (bool)cbk.Value);
                    }
                }
            }
            return(list);
        }
示例#2
0
        private void InitEventHandler()
        {
            #region Curve
            //Data.NetDataFetcher.Instance.ProgressChanged += (sender, e) =>
            //    {
            //        if (e.Points != null && e.Points.Length != 0)
            //        {
            //            double height = e.Points[e.Points.Length - 1].X;
            //            //Graph.SetBaseValue(height-Graph.GetDeltaValue()*Graph.GetVerticalCellsCount());

            //            Graph.Repaint();
            //        }
            //    };
            CKB_Auto.CheckedChanged += (sender, e) =>
            {
                if (CKB_Auto.Checked)
                {
                    SL_XRange.Enabled = false;
                }
                else
                {
                    SL_XRange.Enabled = true;
                }
            };
            #endregion
            #region ValueChanged
            DI_SrollRate.ValueChanged += (sender, e) =>
            {
                if (DI_SrollRate.Value <= 0)
                {
                    DI_SrollRate.Value = 0.1;
                }
            };
            SL_XRange.ValueChanged += (sender, e) =>
            {
                try
                {
                    double pecentage = (double)SL_XRange.Value / (double)SL_XRange.Maximum;
                    Graph.CurrentDepth = (1 - pecentage) * Graph.XRange;
                    //Graph.SetPercentage(DI_SrollRate.Value*(1-pecentage));
                }
                catch (Exception ex)
                {
                    Program.SetStatusMessage(ex.Message);
                }
            };
            #endregion
            #region ClearAllCurve
            BTN_ClearAllCurve.Click += (sender, e) =>
            {
                try
                {
                    if (MessageBox.Show("确定删除面板上的所有曲线?", "提示", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        //Graph.RemoveAllCurve();
                        Program.SetStatusMessage("清除失败!");
                    }
                }
                catch (Exception ex)
                {
                    Program.SetStatusMessage(ex.Message);
                }
            };
            #endregion
            #region ViewSetting
            BTN_ViewSetting.Click += (sender, e) =>
            {
                try
                {
                    ViewSettingForm form = new ViewSettingForm(this.Graph);
                    form.Show();
                }
                catch (Exception ex)
                {
                    Program.SetStatusMessage(ex.Message);
                }
            };
            #endregion
            #region BeginFetcher
            BTN_BeginFetcher.Click += (sender, e) =>
            {
                List <Model.Curve>  clist = Model.DataHelper.GetAllObject <Model.Curve>();
                List <Model.Device> dlist = Model.DataHelper.GetAllObject <Model.Device>();
                ListSelectForm      form  = new ListSelectForm();
                form.SetRows(clist, dlist);
                if (form.ShowDialog() == DialogResult.OK)
                {
                    Dictionary <Guid, bool> dic = form.GetFetchingMap();
                    foreach (Guid id in dic.Keys)
                    {
                        #region Fetcher
                        Data.NetDataFetcher fe = GlobalTable.GlobalTables.Instance.GetFetcher(id) as Data.NetDataFetcher;
                        if (fe != null)
                        {
                            if (dic[id])
                            {
                                fe.Start(id);
                            }
                            else
                            {
                                fe.Pause(id);
                            }
                        }
                        #endregion
                    }
                }
            };
            #endregion
            #region PauseFetcher
            BTN_PauseAllFetcher.Click += (sender, e) =>
            {
                //if (MessageBox.Show("确定停止数据源?", "警告", MessageBoxButtons.OKCancel) == DialogResult.OK)
                //{
                Data.NetDataFetcher.Instance.PauseAll();
                // }
            };
            #endregion
        }
        public void SetRows(List <Model.Curve> curveList, List <Model.Device> deviceList)
        {
            this.curveList  = curveList;
            this.deviceList = deviceList;
            dataGridViewX1.Rows.Clear();
            for (int i = 0; i < curveList.Count; i++)
            {
                DataGridViewRow        row    = new DataGridViewRow();
                Model.Device           device = deviceList.Find((de) => { return(de.CurveId == curveList[i].Id); });
                DataGridViewLabelXCell cell1  = new DataGridViewLabelXCell();
                row.Cells.Add(cell1);
                cell1.Value = curveList[i].CurveName;
                DataGridViewLabelXCell cell2 = new DataGridViewLabelXCell();
                row.Cells.Add(cell2);
                DataGridViewLabelXCell cell3 = new DataGridViewLabelXCell();
                row.Cells.Add(cell3);
                if (device != null)
                {
                    cell2.Value = device.Name;
                    cell3.Value = device.SamplingRate;
                }
                else
                {
                    cell2.Value = "未设定";
                    cell3.Value = "未设定";
                }

                DataGridViewLabelXCell cell4 = new DataGridViewLabelXCell();
                row.Cells.Add(cell4);
                cell4.Tag = curveList[i].Id;
                DataGridViewCheckBoxXCell cell5 = new DataGridViewCheckBoxXCell();
                row.Cells.Add(cell5);
                cell5.Tag = curveList[i].Id;
                DataGridViewCheckBoxXCell cell6 = new DataGridViewCheckBoxXCell();
                row.Cells.Add(cell6);
                cell6.Tag = curveList[i].Id;


                cell5.ReadOnly = true;
                Data.NetDataFetcher fe = GlobalTable.GlobalTables.Instance.GetFetcher(curveList[i].Id) as Data.NetDataFetcher;
                if (fe == null)
                {
                    cell4.Value    = "未设定";
                    cell5.Value    = false;
                    cell6.Value    = false;
                    cell6.ReadOnly = true;
                }
                else
                {
                    cell4.Value = fe.ToString();
                    if (fe.GetFetcherState(curveList[i].Id) != Data.NetDataFetcher.UnknownStateDescription)
                    {
                        cell5.Value = true;
                        if (fe.GetFetcherState(curveList[i].Id) == Data.NetDataFetcher.PausedStateDescription)
                        {
                            cell6.Value    = false;
                            cell6.ReadOnly = false;
                        }
                        else
                        {
                            cell6.Value    = true;
                            cell6.ReadOnly = false;
                        }
                    }
                    else
                    {
                        cell5.Value    = false;
                        cell6.Value    = false;
                        cell6.ReadOnly = false;
                    }
                }



                dataGridViewX1.Rows.Add(row);
            }
        }