Exemple #1
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            ElementAddressType Type   = (ElementAddressType)Enum.ToObject(typeof(ElementAddressType), EleTypeCombox.SelectedIndex);
            Device             device = PLCDeviceManager.GetPLCDeviceManager().SelectDevice;

            if (EleTypeCombox.SelectedIndex == 0 || EleTypeCombox.SelectedIndex == 1 || EleTypeCombox.SelectedIndex == 13 || EleTypeCombox.SelectedIndex == 14)
            {
                LocalizedMessageBox.Show(Properties.Resources.Message_Can_Not_Be_Written, LocalizedMessageIcon.Error);
            }
            else if (!ElementAddressHelper.AssertAddrRange(Type, uint.Parse(textBox.Text) + uint.Parse(LengthTextbox.Text), device))
            {
                LocalizedMessageBox.Show(Properties.Resources.Message_Over_Max_Len, LocalizedMessageIcon.Error);
            }
            else
            {
                if (ElementAddressHelper.IsBitAddr(Type))
                {
                    for (uint i = 0; i < uint.Parse(LengthTextbox.Text); i++)
                    {
                        AddElement(GenerateElementModel(true, Type.ToString(), uint.Parse(textBox.Text) + i, 0));
                    }
                }
                else
                {
                    for (uint i = 0; i < uint.Parse(LengthTextbox.Text); i++)
                    {
                        AddElement(GenerateElementModel(false, Type.ToString(), uint.Parse(textBox.Text) + i, DataTypeCombox.SelectedIndex + 1));
                    }
                }
            }
        }
Exemple #2
0
        private void EnsureButton_Click(object sender, RoutedEventArgs e)
        {
            ElementAddressType Type   = (ElementAddressType)Enum.ToObject(typeof(ElementAddressType), comboBox.SelectedIndex);
            Device             device = PLCDeviceManager.GetPLCDeviceManager().SelectDevice;

            if (Type == ElementAddressType.H || Type == ElementAddressType.K)
            {
                LocalizedMessageBox.Show(Properties.Resources.Constant_Monitor, LocalizedMessageIcon.Warning);
            }
            else if (ElementAddressHelper.AssertAddrRange(Type, uint.Parse(textBox.Text), device))
            {
                if ((bool)checkbox1.IsChecked && !ElementAddressHelper.AssertAddrRange(ElementAddressHelper.GetIntrasegmentAddrType(comboBox1.SelectedIndex), uint.Parse(textBox1.Text), device))
                {
                    LocalizedMessageBox.Show(Properties.Resources.Intra_Cross, LocalizedMessageIcon.Warning);
                }
                else if ((bool)checkbox.IsChecked && !ElementAddressHelper.AssertAddrRange(Type, uint.Parse(textBox.Text) + uint.Parse(rangeTextBox.GetTextBox().Text) - 1, device))
                {
                    LocalizedMessageBox.Show(Properties.Resources.Exceed_Adddress, LocalizedMessageIcon.Warning);
                }
                else
                {
                    if (EnsureButtonClick != null)
                    {
                        AddrType  = Type.ToString();
                        StartAddr = uint.Parse(textBox.Text);
                        if ((bool)checkbox1.IsChecked)
                        {
                            IntrasegmentType = ElementAddressHelper.GetIntrasegmentAddrType(comboBox1.SelectedIndex).ToString();
                            IntrasegmentAddr = uint.Parse(textBox1.Text);
                        }
                        if (ElementAddressHelper.IsBitAddr(Type))
                        {
                            DataType = 0;
                        }
                        else
                        {
                            DataType = DataTypeCombox.SelectedIndex + 1;
                        }
                        if ((bool)checkbox.IsChecked)
                        {
                            AddNums = int.Parse(rangeTextBox.GetTextBox().Text);
                        }
                        else
                        {
                            AddNums = 1;
                        }
                        EnsureButtonClick.Invoke(this, new RoutedEventArgs());
                    }
                }
            }
            else
            {
                LocalizedMessageBox.Show(Properties.Resources.Address_Cross, LocalizedMessageIcon.Warning);
            }
        }