Example #1
0
        /// <summary>
        /// формируем пакет для блока отображения
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void accept_Click(object sender, EventArgs e)
        {
            if (listView1.Items.Count > 0)
            {
                packet.Description = textBoxComment.Text;
                packet.Device      = (int)numericUpDownDevice.Value;

                packet.Period = new TimeSpan(0, 0, 0, 0, (int)numericUpDownPeriod.Value);

                if (comboBox1.SelectedIndex == 0)
                {
                    packet.TypePort = TypePort.Primary;
                }
                else
                if (comboBox1.SelectedIndex == 1)
                {
                    packet.TypePort = TypePort.Secondary;
                }
                else
                {
                    packet.TypePort = TypePort.Default;
                }

                packet.Clear();
                foreach (ListViewItem item in listView1.Items)
                {
                    if (item != null)
                    {
                        if (item.Tag != null)
                        {
                            if (item.Tag is Parameter)
                            {
                                packet.Insert(item.Tag as Parameter);
                            }
                        }
                    }
                }
            }
            else
            {
                packet = null;
            }
        }
        /// <summary>
        /// Добавить параметр
        /// </summary>
        /// <param name="node">Узел в котором сохранены параметры пакета</param>
        protected void InsertPacket(XmlNode node)
        {
            try
            {
                if (node.HasChildNodes)
                {
                    DisplayPacket packet = new DisplayPacket();
                    foreach (XmlNode child in node.ChildNodes)
                    {
                        switch (child.Name)
                        {
                        case parameterName:

                            try
                            {
                                Parameter parameter = new Parameter();
                                parameter.InstanceFromXml(child);

                                packet.Insert(parameter);
                            }
                            catch
                            {
                            }
                            break;

                        case commentName:

                            try
                            {
                                packet.Description = child.InnerText;
                            }
                            catch
                            {
                            }
                            break;

                        case deviceName:

                            try
                            {
                                packet.Device = int.Parse(child.InnerText);
                            }
                            catch
                            {
                            }
                            break;

                        case activedName:

                            try
                            {
                                packet.IsActived = bool.Parse(child.InnerText);
                            }
                            catch { }
                            break;

                        case toPortName:

                            try
                            {
                                packet.ToPort = bool.Parse(child.InnerText);
                            }
                            catch { }
                            break;

                        case "port_type":

                            try
                            {
                                packet.TypePort = (TypePort)Enum.Parse(typeof(TypePort), child.InnerText);
                            }
                            catch { }
                            break;

                        case "period":

                            try
                            {
                                packet.Period = TimeSpan.Parse(child.InnerText);
                            }
                            catch { }
                            break;

                        default:
                            break;
                        }
                    }

                    Insert(packet);
                }
            }
            catch
            {
            }
        }
        /// <summary>
        /// Добавить параметр
        /// </summary>
        /// <param name="node">Узел в котором сохранены параметры пакета</param>
        protected void InsertPacket(XmlNode node)
        {
            try
            {
                if (node.HasChildNodes)
                {
                    DisplayPacket packet = new DisplayPacket();
                    foreach (XmlNode child in node.ChildNodes)
                    {
                        switch (child.Name)
                        {
                            case parameterName:

                                try
                                {
                                    Parameter parameter = new Parameter();
                                    parameter.InstanceFromXml(child);

                                    packet.Insert(parameter);
                                }
                                catch
                                {
                                }
                                break;

                            case commentName:

                                try
                                {
                                    packet.Description = child.InnerText;
                                }
                                catch
                                {
                                }
                                break;

                            case deviceName:

                                try
                                {
                                    packet.Device = int.Parse(child.InnerText);
                                }
                                catch
                                {
                                }
                                break;

                            case activedName:

                                try
                                {
                                    packet.IsActived = bool.Parse(child.InnerText);
                                }
                                catch { }
                                break;

                            case toPortName:

                                try
                                {
                                    packet.ToPort = bool.Parse(child.InnerText);
                                }
                                catch { }
                                break;

                            case "port_type":

                                try
                                {
                                    packet.TypePort = (TypePort)Enum.Parse(typeof(TypePort), child.InnerText);
                                }
                                catch { }
                                break;

                            case "period":

                                try
                                {
                                    packet.Period = TimeSpan.Parse(child.InnerText);
                                }
                                catch { }
                                break;

                            default:
                                break;
                        }
                    }

                    Insert(packet);
                }
            }
            catch
            {
            }
        }