Esempio n. 1
0
        private void MibDataGrid_GotMouseCapture(object sender, MouseEventArgs e)
        {
            try
            {
                if ((e.OriginalSource as DataGrid).Items.CurrentItem is DyDataGrid_MIBModel)
                {
                    DyDataGrid_MIBModel SelectedIter = new DyDataGrid_MIBModel();

                    foreach (var iter in (e.OriginalSource as DataGrid).SelectedCells)
                    {
                        Console.WriteLine("User Selected:" + iter.Item.GetType() + "and Header is" + iter.Column.Header.ToString());
                        SelectedIter = iter.Item as DyDataGrid_MIBModel;

                        DataGrid item = e.OriginalSource as DataGrid;

                        // 在MouseMove事件当中可以添加鼠标拖拽事件;
                        if (e.LeftButton == System.Windows.Input.MouseButtonState.Pressed)
                        {
                            DragDropEffects myDropEffect = DragDrop.DoDragDrop(item, new DataGridCell_MIB_MouseEventArgs()
                            {
                                HeaderName   = iter.Column.Header.ToString(),
                                SelectedCell = SelectedIter
                            }, DragDropEffects.Copy);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 每有一条新的MIB数据,都会调用该函数;
        /// </summary>
        /// <param name="ar"></param>
        /// <param name="oid_cn"></param>
        /// <param name="oid_en"></param>
        /// <param name="contentlist"></param>
        public void UpdateMibDataGrid(IAsyncResult ar, Dictionary <string, string> oid_cn, Dictionary <string, string> oid_en, ObservableCollection <DyDataGrid_MIBModel> contentlist)
        {
            SnmpMessageResult res = ar as SnmpMessageResult;

            // 将信息回填到DataGrid当中;
            this.MibDataGrid.Dispatcher.Invoke(new Action(() =>
            {
                this.MibDataGrid.Columns.Clear();                          //以最后一次为准即可;
                dynamic model = new DyDataGrid_MIBModel();

                // 遍历GetNext的结果;
                foreach (KeyValuePair <string, string> iter in res.AsyncState as Dictionary <string, string> )
                {
                    Console.WriteLine("NextIndex" + iter.Key.ToString() + " Value:" + iter.Value.ToString());

                    // 通过基站反馈回来的一行结果,动态生成一个类型,用来与DataGrid对应;
                    foreach (var iter2 in oid_cn)
                    {
                        // 如果存在对应关系;
                        if (iter.Key.ToString().Contains(iter2.Key))
                        {
                            Console.WriteLine("Add Property:" + oid_en[iter2.Key] + " Value:" + iter.Value.ToString() + " and Header is:" + iter2.Value.ToString());
                            model.AddProperty(oid_en[iter2.Key], new DataGrid_Cell_MIB()
                            {
                                m_Content  = iter.Value.ToString(),
                                oid        = iter.Key,
                                MibName_CN = iter2.Value,
                                MibName_EN = oid_en[iter2.Key]
                            }, iter2.Value.ToString());
                        }
                    }
                }

                // 将这个整行数据填入List;
                if (model.Properties.Count != 0)
                {
                    // 向单元格内添加内容;
                    contentlist.Add(model);
                }

                foreach (var iter3 in oid_en)
                {
                    Console.WriteLine("new binding is:" + iter3.Value + ".m_Content");
                    DataGridTextColumn column = new DataGridTextColumn();
                    column.Header             = oid_cn[iter3.Key];
                    column.Binding            = new Binding(iter3.Value + ".m_Content");

                    this.MibDataGrid.Columns.Add(column);
                }

                this.MibDataGrid.DataContext = contentlist;
            }));
        }
Esempio n. 3
0
        /// <summary>
        /// 针对DataGrid的鼠标操作;
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MibDataGrid_MouseMove(object sender, MouseEventArgs e)
        {
            //(e.OriginalSource as DataGridCell).DataContext is MS.Internal.NamedObject;
            try
            {
                if (e.OriginalSource is DataGridCell)
                {
                    Console.WriteLine("MouseMove;函数参数e反馈的实体是单元格内数据内容:" +
                                      ((e.OriginalSource as DataGridCell).Column).Header.ToString());

                    DyDataGrid_MIBModel SelectedIter = new DyDataGrid_MIBModel();

                    foreach (var iter in (e.Source as DataGrid).SelectedCells)
                    {
                        Console.WriteLine("User Selected:" + iter.Item.GetType());
                        SelectedIter = iter.Item as DyDataGrid_MIBModel;
                    }

                    DataGridCell item = e.OriginalSource as DataGridCell;

                    // 在MouseMove事件当中可以添加鼠标拖拽事件;
                    if (e.MiddleButton == System.Windows.Input.MouseButtonState.Pressed)
                    {
                        DragDropEffects myDropEffect = DragDrop.DoDragDrop(item, new DataGridCell_MIB_MouseEventArgs()
                        {
                            HeaderName   = (e.OriginalSource as DataGridCell).Column.Header.ToString(),
                            SelectedCell = SelectedIter
                        }, DragDropEffects.Copy);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("MouseMove Exception" + ex.ToString());
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 当SNMP模块收集全整表数据后,调用该函数;
        /// </summary>
        /// <param name="ar">GetNext之后,得到的整表数据;</param>
        /// <param name="oid_cn"></param>
        /// <param name="oid_en"></param>
        /// <param name="contentlist"></param>
        public void UpdateAllMibDataGrid(Dictionary <string, string> ar, Dictionary <string, string> oid_cn, Dictionary <string, string> oid_en,
                                         ObservableCollection <DyDataGrid_MIBModel> contentlist, string ParentOID, int IndexCount)
        {
            // 将信息回填到DataGrid当中;
            this.MibDataGrid.Dispatcher.Invoke(new Action(() =>
            {
                this.MibDataGrid.Columns.Clear();                             // 清除上一次的结果;

                if (IndexCount == 0)                                          // 如果索引个数为0,按照1来处理;
                {
                    IndexCount = 1;
                }

                List <string> AlreadyRead = new List <string>();

                // 调试打印,正式版本记得删除;
                foreach (var iter in ar)
                {
                    string[] temp     = iter.Key.ToString().Split('.');
                    string NowIndex   = "";
                    string NowNodeOID = "";

                    for (int i = temp.Length - IndexCount; i < temp.Length; i++)
                    {
                        NowIndex += "." + temp[i];
                    }
                    for (int i = 0; i < temp.Length - IndexCount; i++)
                    {
                        NowNodeOID += "." + temp[i];
                    }

                    Console.WriteLine("NextIndex " + iter.Key.ToString() + " and Value is " + iter.Value.ToString() + " OID Index is " + NowIndex +
                                      " Node OID is " + NowNodeOID.Substring(1, NowNodeOID.Length - NowIndex.Length + 1));
                }

                // 遍历GetNext结果后,将结果填入到DataGrid控件当中;
                foreach (var iter in ar)
                {
                    // 获取当前遍历到的节点的索引值(即取最后N位数字);
                    string[] temp   = iter.Key.ToString().Split('.');
                    string NowIndex = "";
                    for (int i = temp.Length - IndexCount; i < temp.Length; i++)
                    {
                        NowIndex += "." + temp[i];
                    }
                    Console.WriteLine("NextIndex " + iter.Key.ToString() + " and Value is " + iter.Value.ToString() + " OID Index is " + NowIndex);

                    // 如果存在索引,且索引没有被添加到表中;
                    if (iter.Key.ToString().Contains(NowIndex) && !AlreadyRead.Contains(NowIndex))
                    {
                        dynamic model = new DyDataGrid_MIBModel();

                        // 将ar当中所有匹配的结果取出,最后会取出了一行数据;
                        foreach (var iter3 in ar)
                        {
                            // 将所有相同索引取出;
                            if (iter3.Key.ToString().Contains(NowIndex))
                            {
                                foreach (var iter2 in oid_cn)
                                {
                                    // 将GetNext整表的OID数值取出到temp_compare;
                                    string[] temp_nowoid = iter3.Key.ToString().Split('.');
                                    string NowNodeOID    = "";
                                    for (int i = 0; i < temp_nowoid.Length - IndexCount; i++)
                                    {
                                        NowNodeOID += "." + temp_nowoid[i];
                                    }
                                    string temp_compare = NowNodeOID.Substring(1);

                                    // 如果OID匹配;
                                    if (temp_compare == iter2.Key.ToString())
                                    {
                                        Console.WriteLine("Add Property:" + oid_en[iter2.Key] + " Value:" + iter3.Value.ToString() + " and Header is:" + iter2.Value.ToString());

                                        model.AddProperty(oid_en[iter2.Key], new DataGrid_Cell_MIB()
                                        {
                                            m_Content  = iter3.Value.ToString(),
                                            oid        = iter3.Key,
                                            MibName_CN = iter2.Value,
                                            MibName_EN = oid_en[iter2.Key]
                                        }, iter2.Value.ToString());

                                        // 已经查询过该索引,后续不再参与查询;
                                        AlreadyRead.Add(NowIndex);
                                    }
                                }
                            }
                        }

                        // 将这个整行数据填入List;
                        if (model.Properties.Count != 0)
                        {
                            // 向单元格内添加内容;
                            contentlist.Add(model);
                        }
                    }
                }

                foreach (var iter3 in oid_en)
                {
                    Console.WriteLine("new binding is:" + iter3.Value + ".m_Content");
                    DataGridTextColumn column = new DataGridTextColumn();
                    column.Header             = oid_cn[iter3.Key];
                    column.Binding            = new Binding(iter3.Value + ".m_Content");

                    this.MibDataGrid.Columns.Add(column);
                }

                this.MibDataGrid.DataContext = contentlist;
            }));
        }