Пример #1
0
        void tbox_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            detail.Visibility = Visibility.Visible;
            Control box  = sender as Control;
            Node    node = box.Tag as Node;
            Point   p    = box.TranslatePoint(new Point(), grid_content);
            Point   p0   = box.TranslatePoint(new Point(), this);

            if (p0.Y <= this.Height / 2)
            {
                detail.Margin                = new Thickness(0, p.Y + rowHeight * 0.8, 0, 0);
                detail.img_top.Margin        = new Thickness(p.X + box.ActualWidth / 2 - detail.img_top.Width / 2, 0, 0, 0);
                detail.img_top.Visibility    = Visibility.Visible;
                detail.img_bottom.Visibility = Visibility.Hidden;
            }
            else
            {
                detail.Margin                = new Thickness(0, p.Y - detail.Height, 0, 0);
                detail.img_bottom.Margin     = new Thickness(p.X + box.ActualWidth / 2 - detail.img_bottom.Width / 2, 0, 0, 0);
                detail.img_bottom.Visibility = Visibility.Visible;
                detail.img_top.Visibility    = Visibility.Hidden;
            }
            if (node.ShowType == 11)
            {
                read(node.Address, int.Parse(node.Extra), true);
            }
            else if (node.ShowType == 13)
            {
                detail.showOutput(box as TextBox);
            }
            else
            {
                detail.showSwitch(node.Extra, Convert.ToInt32(AutoBox.getText(box), 16), box);
            }
        }
Пример #2
0
        void addItemTextBox(int address, int index, Node node)
        {
            List <string> items = node.Extra.Split('_').ToList();
            //判断何时用下拉框
            bool    useCbox = (node.NodeAuthority != Authority.R) && ((node.ShowType == 1 && node.Extra.Contains('_')) || node.ShowType == 2);
            Control box     = useCbox ? new ComboBox() as Control : new TextBox() as Control;

            box.Name = "Box" + address;
            box.Tag  = node;
            if (useCbox)
            {
                AutoBox.setBoxItems(box as ComboBox);
            }
            //取值0.8*,使行间留白,上下各留白0.1*,如下Margin.Top
            box.Height = 0.8 * rowHeight;
            box.VerticalContentAlignment   = VerticalAlignment.Center;
            box.HorizontalContentAlignment = HorizontalAlignment.Center;
            box.VerticalAlignment          = VerticalAlignment.Top;
            box.Margin = new Thickness(0, index / 5 * rowHeight + 0.1 * rowHeight, 10, 0);
            Grid.SetColumn(box, index % 5 * 3 + 1);
            Grid.SetColumnSpan(box, 2);
            grid_content.Children.Add(box);
            if (node.ShowType == 3 || node.ShowType == 11 || node.ShowType == 13)
            {
                box.MouseDoubleClick += tbox_MouseDoubleClick;
                box.BorderBrush       = Tools.GetBrush("#FFFF6501");
                box.BorderThickness   = new Thickness(2);
            }
            if (node.NodeAuthority != Authority.R)
            {
                box.GotFocus += tbox_GotFocus;
            }
        }
Пример #3
0
        void toggleSwitch_Click(object sender, RoutedEventArgs e)
        {
            WPFSpark.ToggleSwitch ts = sender as WPFSpark.ToggleSwitch;
            int index = int.Parse(ts.Tag.ToString());
            int bit   = ts.IsChecked == true ? 0 : 1;

            switchData = Tools.SetBit(switchData, index, bit);
            AutoBox.setText(box, string.Format("0x{0:X4}", switchData));
        }
Пример #4
0
 public void executeInfluence(Panel parent, int nResult, string strResult)
 {
     nResult = InfBitType < 0 ? nResult : Tools.GetBit(nResult, InfBitType);
     if (InfName != null)
     {
         Label lblName = Tools.GetChild <Label>(parent, "Name" + Address);
         lblName.Content = InfName[nResult] == "-" ? string.Empty : InfName[nResult];
     }
     if (InfUnit != null)
     {
         Label lblUnit = Tools.GetChild <Label>(parent, "Unit" + Address);
         lblUnit.Content = InfUnit[nResult] == "-" ? string.Empty : InfUnit[nResult];
     }
     if (InfFactor != null)
     {
         Control box    = Tools.GetChild <Control>(parent, "Box" + Address);
         Node    node   = box.Tag as Node;
         string  factor = InfFactor.Count == 0 ? nResult.ToString() : InfFactor[nResult];
         node.Extra = Regex.Replace(node.Extra, @"^\d+(\.\d+)?", factor);
     }
     if (InfItems != null)
     {
         ComboBox box      = Tools.GetChild <ComboBox>(parent, "Box" + Address);
         Node     node     = box.Tag as Node;
         bool     infExtra = true;
         if (node.Address == 0x200B)
         {
             infExtra = false;
             bool isTg    = (node.Extra.Contains("接地") || node.Extra.Contains("*")) && InfItems.Values.First().Contains('*');
             bool isTf    = (node.Extra.Contains("漏电") || node.Extra.Contains("0.8")) && InfItems.Values.First().Contains("0.8");
             bool isFirst = node.Extra.Contains("Null");
             infExtra |= isTg | isTg | isFirst;
         }
         if (infExtra)
         {
             node.Extra = Regex.Match(node.Extra, @"^\d+").Value + "_" + InfItems[nResult];
             AutoBox.setBoxItems(box);
         }
     }
     if (InfItemsLinkage != InfLinkage.NULL)
     {
         ComboBox box     = Tools.GetChild <ComboBox>(parent, "Box" + Address);
         Node     node    = box.Tag as Node;
         string   pattern = InfItemsLinkage == InfLinkage.LOWER ? @"(?<=_)\d+(\.\d+)?(?=\*)" : @"(?<=\*)\d+(\.\d+)?$";
         node.Extra = Regex.Replace(node.Extra, pattern, strResult);
         AutoBox.setBoxItems(box);
     }
 }
Пример #5
0
        private void addBox(string name, char value, string extra, int column)
        {
            var    items = extra.Split('_').ToList();
            string item  = Convert.ToInt32(value).ToString();
            int    index = items.IndexOf(item);

            item = index < 0 ? string.Empty : items[index + 1];
            ComboBox box = new ComboBox();

            box.Name              = name;
            box.SelectionChanged += box_SelectionChanged;
            box.ItemsSource       = items.Where((t, i) => i % 2 == 1).ToList();
            AutoBox.setText(box, item);
            box.Height = rowHeight;
            System.Windows.Controls.Grid.SetColumn(box, column);
            System.Windows.Controls.Grid.SetColumnSpan(box, 2);
            mySwitch.Children.Add(box);
        }
Пример #6
0
        void box_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox      cBox          = sender as ComboBox;
            Node          node          = box.Tag as Node;
            List <string> items         = node.Extra.Split('_').ToList();
            int           item          = int.Parse(items[2 * cBox.SelectedIndex]);
            string        selectedValue = Convert.ToChar(item).ToString();
            string        value         = null;

            if (cBox.Name == "output1")
            {
                value = Convert.ToChar(item) + " " + AutoBox.getText(box)[2];
            }
            else
            {
                value = AutoBox.getText(box)[0] + " " + Convert.ToChar(item);
            }
            AutoBox.setText(box, value);
        }
Пример #7
0
        private void btn_write_Click(object sender, RoutedEventArgs e)
        {
            Control box  = btn_write.Tag as Control;
            Node    node = box.Tag as Node;

            byte[] snd = new byte[9];
            snd[0] = comAddress;
            snd[1] = 0x10;
            snd[2] = (byte)(node.Address / 256);
            snd[3] = (byte)(node.Address % 256);
            snd[5] = 0x1;
            snd[6] = 0x2;
            byte[] data = (byte[])typeof(ComConverter).GetMethod("CvtW" + node.ShowType).Invoke(cvt, new object[] { AutoBox.getText(box), node.Extra });
            if (data == null)
            {
                lbl_msg.Content = string.Format("修改:0x{0:X4}  {1} 【失败】——格式出错", node.Address, node.Name);
            }
            else
            {
                data.CopyTo(snd, 7);
                byte[] rcv = com.Execute(snd);
                if (rcv == null || rcv.Length != 1)
                {
                    lbl_msg.Content = string.Format("修改:0x{0:X4}  {1} 【失败】{2}", node.Address, node.Name, DateTime.Now.ToLongTimeString());
                }
                else
                {
                    lbl_msg.Content = string.Format("修改:0x{0:X4}  {1} 【成功】{2}", node.Address, node.Name, DateTime.Now.ToLongTimeString());
                    read(node.Address, 1);
                }
            }
        }
Пример #8
0
 private void read(int address, int length, bool readArray = false, int offset = 0)
 {
     Task.Factory.StartNew(() =>
     {
         lock (threadLock)
         {
             int realAddr = address + offset * length;
             byte[] snd   = new byte[6];
             snd[0]       = comAddress;
             snd[1]       = 0x3;
             snd[2]       = (byte)(realAddr / 256);
             snd[3]       = (byte)(realAddr % 256);
             snd[4]       = (byte)(length / 256);
             snd[5]       = (byte)(length % 256);
             byte[] rcv   = com.Execute(snd);
             this.Dispatcher.Invoke(new Action(() =>
             {
                 if (rcv.Length == length * 2)
                 {
                     lbl_msg.Content = string.Format("读取:{0:X4},位数:{1}【成功】{2}", address, length, DateTime.Now.ToLongTimeString());
                     if (readArray)
                     {
                         Control tbox = Tools.GetChild <Control>(grid_content, "Box" + address);
                         Node node    = tbox.Tag as Node;
                         int[] data   = (int[])typeof(ComConverter).GetMethod("CvtR" + node.ShowType).Invoke(cvt, new object[] { rcv, node.Extra });
                         detail.showChart(data);
                     }
                     else
                     {
                         for (int i = 0; i < length; i++)
                         {
                             Control box   = Tools.GetChild <Control>(grid_content, "Box" + (address + i));
                             byte[] source = new byte[] { rcv[2 * i], rcv[2 * i + 1] };
                             Node node     = box.Tag as Node;
                             int nResult   = source[0] * 256 + source[1];
                             string result = typeof(ComConverter).GetMethod("CvtR" + node.ShowType).Invoke(cvt, new object[] { source, node.Extra }).ToString();
                             AutoBox.setText(box, result);
                             if (node.Influences != null)
                             {
                                 foreach (Influence inf in node.Influences)
                                 {
                                     inf.executeInfluence(grid_content, nResult, AutoBox.getText(box));
                                 }
                             }
                             //处理一些没有规律特殊的节点
                             if (node.Address == 0x7007 || node.Address == 0x6007)
                             {
                                 Control box0 = Tools.GetChild <Control>(grid_content, "Box" + (node.Address - 7));
                                 if (AutoBox.getText(box0) == "相序")
                                 {
                                     AutoBox.setText(box, nResult == 0 ? "逆序" : "正序");
                                 }
                             }
                             else if (node.Address == 0x8001)
                             {
                                 Control box0x8000 = Tools.GetChild <Control>(grid_content, "Box" + (0x8000));
                                 string value      = AutoBox.getText(box0x8000);
                                 if (value == "存储器故障")
                                 {
                                     AutoBox.setText(box, string.Format("0x{0:X4}", nResult));
                                 }
                                 else if (value == "相序")
                                 {
                                     AutoBox.setText(box, nResult == 0 ? "逆序" : "正序");
                                 }
                             }
                         }
                     }
                 }
                 else
                 {
                     lbl_msg.Content = string.Format("读取:{0:X4},位数:{1}【失败】{2}", address, length, DateTime.Now.ToLongTimeString());
                 }
             }));
         }
     });
 }