private bool CheckAddr(out ushort Addr)
        {
            Addr = 0;
            try
            {
                Addr = (ushort)ConvertFuncs.StrToShort(addrTextBox.Text);
            }
            catch
            {
                MessageBox.Show(texts[6], "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (Addr > 0x3FFF)
            {
                MessageBox.Show(texts[6], "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (ConvertFuncs.GetBit(Addr, 0))
            {
                MessageBox.Show(texts[7], "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            return(true);
        }
コード例 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(appTexts.ParameterName(88), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                DialogResult = System.Windows.Forms.DialogResult.No;
                short[] us = new short[7];
                try
                {
                    us[0] = ConvertFuncs.StrToShort(textBox1.Text);
                    us[1] = ConvertFuncs.StrToShort(textBox2.Text);
                    us[2] = ConvertFuncs.StrToShort(textBox3.Text);
                    us[3] = ConvertFuncs.StrToShort(textBox4.Text);
                    us[4] = ConvertFuncs.StrToShort(textBox5.Text);
                    us[5] = ConvertFuncs.StrToShort(textBox6.Text);
                    us[6] = ConvertFuncs.StrToShort(textBox7.Text);
                }
                catch
                {
                    MessageBox.Show(appTexts.ParameterName(89), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                systemConfiguration.StartMeasureAddr  = (ushort)us[0];
                systemConfiguration.EventCodeAddr     = (ushort)us[1];
                systemConfiguration.EventTimeAddr     = (ushort)us[2];
                systemConfiguration.EventBlockCount   = (ushort)us[3];
                systemConfiguration.LoadEventAddr     = (ushort)us[4];
                systemConfiguration.LoadEventDataAddr = (ushort)us[5];
                systemConfiguration.EventCount        = (ushort)us[6];
            }
        }
コード例 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            NewEventCodes = new Hashtable();

            if (MessageBox.Show("Внести изменения в профиль?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.OK)
            {
                DialogResult = System.Windows.Forms.DialogResult.No;
                return;
            }


            try
            {
                for (int i = 0; i < (dataGridView1.Rows.Count - 1); i++)
                {
                    short  u   = ConvertFuncs.StrToShort(dataGridView1.Rows[i].Cells[0].Value.ToString());
                    string st1 = "0x" + u.ToString("X4");
                    string st2 = dataGridView1.Rows[i].Cells[1].Value.ToString();
                    NewEventCodes.Add(st1, st2);
                }
            }
            catch
            {
                MessageBox.Show("Неправильно заданы коды события!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }
コード例 #4
0
        public bool GetDigitPlate(out DigitPlate DigitPlate)
        {
            bool       b          = true;
            DigitPlate digitPlate = new DigitPlate();

            digitPlate.Titl = textBox1.Text;

            try
            {
                short u = ConvertFuncs.StrToShort(textBox2.Text);
                digitPlate.StartAddr = (ushort)u;
            }
            catch
            {
                b = false;
            }

            try
            {
                short u = ConvertFuncs.StrToShort(textBox3.Text);
                digitPlate.EventStructAddr = (ushort)u;
            }
            catch
            {
                b = false;
            }

            ushort step  = 1;
            ushort value = 0;

            for (int i = 0; i < 16; i++)
            {
                digitPlate.DigitNames[i] = textBoxs[i].Text;
                if (checkBoxs[i].Checked)
                {
                    value = (ushort)(value | step);
                }
                step = (ushort)(step << 1);
            }

            digitPlate.UseMask = value;

            if (radioButton1.Checked)
            {
                digitPlate.DigitType = DigitType.DigInput;
            }
            else
            {
                digitPlate.DigitType = DigitType.DigOutput;
            }

            digitPlate.Invert = radioButton4.Checked;
            DigitPlate        = digitPlate;
            return(b);
        }
コード例 #5
0
 bool CheckValue()
 {
     try
     {
         value = (ushort)ConvertFuncs.StrToShort(textBox2.Text);
     }
     catch
     {
         return(false);
     }
     return(true);
 }
コード例 #6
0
        //********************************************************************************************************//
        //********************************************************************************************************//
        bool CheckParams()
        {
            try
            {
                startAddr = (ushort)ConvertFuncs.StrToShort(textBox1.Text);
            }
            catch
            {
                MessageBox.Show(appTexts.ParameterName(60), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            if (startAddr > 0x3FFF)
            {
                MessageBox.Show(appTexts.ParameterName(60), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            try
            {
                endAddr = (ushort)ConvertFuncs.StrToShort(textBox2.Text);
            }
            catch
            {
                MessageBox.Show(appTexts.ParameterName(61), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }


            if (endAddr > 0x3FFF)
            {
                MessageBox.Show(appTexts.ParameterName(60), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            blockCount = endAddr - startAddr + 1;
            if (blockCount < 16)
            {
                MessageBox.Show(appTexts.ParameterName(62), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }


            if ((blockCount % 16) != 0)
            {
                MessageBox.Show(appTexts.ParameterName(62), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
            blockCount = blockCount / 16;

            return(true);
        }
コード例 #7
0
 bool CheckAddr()
 {
     try
     {
         addr = (ushort)ConvertFuncs.StrToShort(textBox1.Text);
     }
     catch
     {
         return(false);
     }
     if (addr > 0x3FFF)
     {
         return(false);
     }
     return(true);
 }
コード例 #8
0
        private void loadSensorPanelBtn_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            // ofd.Filter = appTexts.ParameterName(102);

            if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                List <ushort[]> loadEventDataPanel = new List <ushort[]>();
                FileStream      fs = new FileStream(ofd.FileName, FileMode.Open);
                StreamReader    sr = new StreamReader(fs);
                try
                {
                    for (int i1 = 0; i1 < systemConfiguration.EventCount; i1++)
                    {
                        ushort[] us = new ushort[systemConfiguration.EventBlockCount * 32];
                        for (int i2 = 0; i2 < us.Length; i2++)
                        {
                            us[i2] = (ushort)ConvertFuncs.StrToShort(sr.ReadLine());
                        }
                        loadEventDataPanel.Add(us);
                    }
                    fs.Close();
                    sr.Close();
                }
                catch
                {
                    MessageBox.Show(appTexts.ParameterName(110), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                SaveFileDialog sfd = new SaveFileDialog();
                sfd.DefaultExt = "*.xml";
                sfd.Filter     = appTexts.ParameterName(102);
                sfd.FileName   = DateTime.Now.Day.ToString("D2") + "." + DateTime.Now.Month.ToString("D2") + "." + DateTime.Now.Year.ToString("D4") + " " +
                                 DateTime.Now.Hour.ToString("D2") + "." + DateTime.Now.Minute.ToString("D2") + "." + DateTime.Now.Second.ToString("D2") +
                                 " (" + appTexts.ParameterName(99) + ")";

                if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    EventLogFile eventLogFile = new EventLogFile(systemConfiguration, appTexts, loadEventDataPanel);
                    eventLogFile.CreateEventlogXMLFile(sfd.FileName);
                    EventlogViewerForm elvf = new EventlogViewerForm(sfd.FileName, appTexts);
                    elvf.Show();
                }
            }
        }
コード例 #9
0
        private void textBox2_TextChanged(object sender, EventArgs e)
        {
            ushort u = addr;

            try
            {
                u = (ushort)ConvertFuncs.StrToShort(textBox2.Text);
                textBox2.BackColor = Color.White;
                addrCorrect        = true;
            }
            catch
            {
                textBox2.BackColor = Color.Red;
                addrCorrect        = false;
                u = 0;
            }

            addr = u;
        }
コード例 #10
0
        public bool GetWarningParam(out WarningParam WarningParam)
        {
            WarningParam warningParam = new WarningParam(textBox1.Text);

            try
            {
                short u = ConvertFuncs.StrToShort(textBox2.Text);
                warningParam.EventPosAddr = (ushort)u;
            }
            catch
            {
                WarningParam = warningParam;
                return(false);
            }

            for (int i = 0; i < 16; i++)
            {
                warningParam.Names[i] = textBoxs[i].Text;
            }
            WarningParam = warningParam;
            return(true);
        }
コード例 #11
0
        public MeasureParam(string ParameterName, string Addr, string Format)
        {
            this.ParameterName = ParameterName;

            try
            {
                addr = (ushort)ConvertFuncs.StrToShort(Addr);
            }
            catch
            {
                addr = 0;
            }


            try
            {
                format = Format.ToConvertFormats();
            }
            catch
            {
                format = ConvertFormats.Percent;
            }
        }
コード例 #12
0
        void OpenFileBody(string FileName)
        {
            XDocument document;

            try
            {
                document = XDocument.Load(FileName);
            }
            catch
            {
                throw new Exception("Error open xml file!");
            }
            digitPlates = new List <DigitPlate>();

            int digitCount = 0;

            try
            {
                XElement element = document.Root.Element("Digits");
                digitCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                digitCount = 0;
                //throw new Exception("Errors in part Digits of xml file!");
            }

            for (int i = 0; i < digitCount; i++)
            {
                try
                {
                    XElement   element = document.Root.Element("Digit" + (i + 1).ToString());
                    DigitPlate dp      = new DigitPlate();
                    dp.Titl = element.Attribute("Title").Value;


                    if (element.Attribute("Type").Value == "DigInput")
                    {
                        dp.DigitType = DigitType.DigInput;
                    }
                    else
                    {
                        dp.DigitType = DigitType.DigOutput;
                    }

                    if (element.Attribute("Invert").Value.ToString().ToUpper() == "TRUE")
                    {
                        dp.Invert = true;
                    }
                    else
                    {
                        dp.Invert = false;
                    }


                    dp.StartAddr       = (ushort)ConvertFuncs.StrToShort(element.Attribute("Addr").Value.ToString());
                    dp.EventStructAddr = (ushort)ConvertFuncs.StrToShort(element.Attribute("EventPos").Value.ToString());

                    dp.UseMask = Convert.ToUInt16(element.Attribute("UseMask").Value, 10);
                    for (int i2 = 0; i2 < 16; i2++)
                    {
                        dp.DigitNames[i2] = element.Attribute("Line" + (i2).ToString()).Value;
                    }



                    digitPlates.Add(dp);
                }
                catch
                {
                    throw new Exception("Errors in part Digit" + (i + 1).ToString() + " of xml file!");
                }
            }


            int measureCount = 0;

            measureParams = new List <MeasureParam>();
            try
            {
                XElement element = document.Root.Element("MeasureParams");
                measureCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                measureCount = 0;
                //throw new Exception("Errors in part MeasureParams of xml file!");
            }

            for (int i = 0; i < measureCount; i++)
            {
                try
                {
                    XElement element = document.Root.Element("MeasureParam" + (i + 1).ToString());
                    string   str1, str2, str3;
                    str1 = element.Attribute("Name").Value;
                    str2 = element.Attribute("Addr").Value;
                    str3 = element.Attribute("Format").Value;

                    MeasureParam dp = new MeasureParam(str1, str2, str3);
                    measureParams.Add(dp);
                }
                catch
                {
                    throw new Exception("Errors in part MeasureParam" + (i + 1).ToString() + " of xml file!");
                }
            }

            int eventCount = 0;

            eventCodes = new Hashtable();
            try
            {
                XElement element = document.Root.Element("EventCodes");
                eventCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                eventCount = 0;
                //throw new Exception("Errors in part MeasureParams of xml file!");
            }


            for (int i = 0; i < eventCount; i++)
            {
                try
                {
                    XElement element = document.Root.Element("EventCode" + (i + 1).ToString());
                    string   str1, str2;
                    str1 = element.Attribute("Name").Value;
                    str2 = element.Attribute("Code").Value;
                    eventCodes.Add(str2, str1);
                }
                catch
                {
                    throw new Exception("Errors in part EventCode" + (i + 1).ToString() + " of xml file!");
                }
            }

            try
            {
                XElement element = document.Root.Element("OtherParams");
                StartMeasureAddr  = (ushort)ConvertFuncs.StrToShort(element.Attribute("StartMeasureAddr").Value.ToString());
                EventCodeAddr     = (ushort)ConvertFuncs.StrToShort(element.Attribute("EventCodeAddr").Value.ToString());
                EventTimeAddr     = (ushort)ConvertFuncs.StrToShort(element.Attribute("EventTimeAddr").Value.ToString());
                EventBlockCount   = (ushort)ConvertFuncs.StrToShort(element.Attribute("EventBlockCount").Value.ToString());
                LoadEventAddr     = (ushort)ConvertFuncs.StrToShort(element.Attribute("LoadEventAddr").Value.ToString());
                LoadEventDataAddr = (ushort)ConvertFuncs.StrToShort(element.Attribute("LoadEventDataAddr").Value.ToString());
                EventCount        = (ushort)ConvertFuncs.StrToShort(element.Attribute("EventCount").Value.ToString());
            }
            catch
            {
                //eventCount = 0;
                throw new Exception("Errors in part OtherParams of xml file!");
            }

            XElement otherelements = document.Root.Element("OtherParams");

            if (otherelements.Attribute("EnaDigits") == null)
            {
                EnaDigits = false;
            }
            else
            {
                EnaDigits = otherelements.Attribute("EnaDigits").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaDirectAccess") == null)
            {
                EnaDirectAccess = false;
            }
            else
            {
                EnaDirectAccess = otherelements.Attribute("EnaDirectAccess").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaFloatDirectAccess") == null)
            {
                EnaFloatDirectAccess = false;
            }
            else
            {
                EnaFloatDirectAccess = otherelements.Attribute("EnaFloatDirectAccess").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaScope") == null)
            {
                EnaScope = false;
            }
            else
            {
                EnaScope = otherelements.Attribute("EnaScope").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaEventLog") == null)
            {
                EnaEventLog = false;
            }
            else
            {
                EnaEventLog = otherelements.Attribute("EnaEventLog").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaLoadSyms") == null)
            {
                EnaLoadSyms = false;
            }
            else
            {
                EnaLoadSyms = otherelements.Attribute("EnaLoadSyms").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaJog") == null)
            {
                EnaJog = false;
            }
            else
            {
                EnaJog = otherelements.Attribute("EnaJog").Value.ToBoolean();
            }


            if (otherelements.Attribute("EnaAngle") == null)
            {
                EnaAngle = false;
            }
            else
            {
                EnaAngle = otherelements.Attribute("EnaAngle").Value.ToBoolean();
            }

            if (otherelements.Attribute("EnaForceDig") == null)
            {
                EnaForceDig = false;
            }
            else
            {
                EnaForceDig = otherelements.Attribute("EnaForceDig").Value.ToBoolean();
            }



            /*
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaDigits").Value;
             *             EnaDigits = (o != null);
             *         }
             *         catch
             *         {
             *             EnaDigits = false;
             *         }
             *
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaDirectAccess").Value;
             *             EnaDirectAccess = (o != null);
             *         }
             *         catch
             *         {
             *             EnaDirectAccess = false;
             *         }
             *
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaFloatDirectAccess").Value;
             *             EnaFloatDirectAccess = (o != null);
             *         }
             *         catch
             *         {
             *             EnaFloatDirectAccess = false;
             *         }
             *
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaScope").Value;
             *             EnaScope = (o != null);
             *         }
             *         catch
             *         {
             *             EnaScope = false;
             *         }
             *
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaEventLog").Value;
             *             EnaEventLog = (o != null);
             *         }
             *         catch
             *         {
             *             EnaEventLog = false;
             *         }
             *         try
             *         {
             *             object o = otherelements.Attribute("EnaLoadSyms").Value;
             *             EnaLoadSyms = (o != null);
             *         }
             *         catch
             *         {
             *             EnaLoadSyms = false;
             *         }
             *
             */


            int readyCount = 0;

            try
            {
                XElement element = document.Root.Element("Readys");
                readyCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                readyCount = 0;
                //throw new Exception("Errors in part Digits of xml file!");
            }


            for (int i = 0; i < readyCount; i++)
            {
                try
                {
                    XElement     element = document.Root.Element("Ready" + (i + 1).ToString());
                    WarningParam dp      = new WarningParam(element.Attribute("Title").Value.ToString());
                    dp.Titl = element.Attribute("Title").Value;



                    dp.EventPosAddr = (ushort)ConvertFuncs.StrToShort(element.Attribute("Addr").Value.ToString());
                    for (int i2 = 0; i2 < 16; i2++)
                    {
                        dp.Names[i2] = element.Attribute("Line" + (i2).ToString()).Value;
                    }


                    readyParams.Add(dp);
                }
                catch
                {
                    throw new Exception("Errors in part Ready" + (i + 1).ToString() + " of xml file!");
                }
            }


            int warningCount = 0;

            try
            {
                XElement element = document.Root.Element("Warnings");
                warningCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                warningCount = 0;
                //throw new Exception("Errors in part Digits of xml file!");
            }


            for (int i = 0; i < warningCount; i++)
            {
                try
                {
                    XElement     element = document.Root.Element("Warning" + (i + 1).ToString());
                    WarningParam dp      = new WarningParam(element.Attribute("Title").Value.ToString());
                    dp.Titl = element.Attribute("Title").Value;



                    dp.EventPosAddr = (ushort)ConvertFuncs.StrToShort(element.Attribute("Addr").Value.ToString());
                    for (int i2 = 0; i2 < 16; i2++)
                    {
                        dp.Names[i2] = element.Attribute("Line" + (i2).ToString()).Value;
                    }


                    warningParams.Add(dp);
                }
                catch
                {
                    throw new Exception("Errors in part Warning" + (i + 1).ToString() + " of xml file!");
                }
            }


            int alarmCount = 0;

            try
            {
                XElement element = document.Root.Element("Alarms");
                alarmCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                alarmCount = 0;
                //throw new Exception("Errors in part Digits of xml file!");
            }


            for (int i = 0; i < alarmCount; i++)
            {
                try
                {
                    XElement     element = document.Root.Element("Alarm" + (i + 1).ToString());
                    WarningParam dp      = new WarningParam(element.Attribute("Title").Value.ToString());
                    dp.Titl = element.Attribute("Title").Value;

                    dp.EventPosAddr = (ushort)ConvertFuncs.StrToShort(element.Attribute("Addr").Value.ToString());
                    for (int i2 = 0; i2 < 16; i2++)
                    {
                        dp.Names[i2] = element.Attribute("Line" + (i2).ToString()).Value;
                    }


                    alarmParams.Add(dp);
                }
                catch
                {
                    throw new Exception("Errors in part Alarm" + (i + 1).ToString() + " of xml file!");
                }
            }



            try
            {
                XElement element = document.Root.Element("TimeSettings");
                timeConfig = new TimeConfig(element);
            }

            catch
            {
                throw new Exception("Errors in part TimeSettings of xml file!");
            }
        }
コード例 #13
0
        private void openOldStyleButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter     = appTexts.ParameterName(102);
            ofd.DefaultExt = "*.xml";

            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            XDocument document;
            XElement  element;
            int       measureCounts;

            try
            {
                document = XDocument.Load(ofd.FileName);
            }

            catch
            {
                MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                element       = document.Root.Element("MeasureParams");
                measureCounts = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            List <MeasureParam> loadMeasureParams = new List <MeasureParam>();

            for (int i = 0; i < measureCounts; i++)
            {
                try
                {
                    element = document.Root.Element("MeasureParam" + (i + 1).ToString());
                    string       str1 = element.Attribute("Name").Value.ToString() + ", " + element.Attribute("UnitName").Value.ToString();
                    string       str2 = element.Attribute("Addr").Value.ToString();
                    short        i2   = ConvertFuncs.StrToShort(str2);
                    string       str3 = element.Attribute("Format").Value.ToString();
                    short        i3   = ConvertFuncs.StrToShort(str3);
                    MeasureParam mp   = new MeasureParam(str1, (ushort)i2, (ConvertFormats)i3);
                    loadMeasureParams.Add(mp);
                }
                catch
                {
                    MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            flowLayoutPanel2.Controls.Clear();
            measureParams.Clear();

            foreach (MeasureParam mp in loadMeasureParams)
            {
                measureParams.Add(new MeasureParamPanel());
                flowLayoutPanel2.Controls.Add(measureParams[measureParams.Count - 1]);
                measureParams[measureParams.Count - 1].RemoveClick  += new EventHandler(RemoveClick);
                measureParams[measureParams.Count - 1].ParameterName = mp.ParameterName;
                measureParams[measureParams.Count - 1].Addr          = mp.Addr;
                measureParams[measureParams.Count - 1].Format        = mp.Format;
            }
        }
コード例 #14
0
        //***********************************************************************************************//
        //***********************************************************************************************//
        //***********************************************************************************************//
        private void loadOldStyleButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter     = appTexts.ParameterName(102);
            ofd.DefaultExt = "*.xml";

            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            XDocument           document;
            XElement            element;
            int                 warnigsCount;
            List <WarningParam> loadWarningParams = new List <WarningParam>();

            try
            {
                document = XDocument.Load(ofd.FileName);
            }

            catch
            {
                MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            try
            {
                element      = document.Root.Element(loadFromOldFileString);
                warnigsCount = Convert.ToInt16(element.Attribute("CountWord").Value.ToString(), 10);
            }
            catch
            {
                MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            for (int i = 0; i < warnigsCount; i++)
            {
                try
                {
                    WarningParam wp   = new WarningParam("");
                    string       str1 = element.Attribute("EventPos" + (i).ToString()).Value.ToString();
                    wp.EventPosAddr = (ushort)ConvertFuncs.StrToShort(str1);
                    for (int i2 = 0; i2 < 16; i2++)
                    {
                        wp.Names[i2] = element.Attribute("Line" + (i * 16 + i2).ToString()).Value.ToString();
                    }
                    loadWarningParams.Add(wp);
                }
                catch
                {
                    MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            warningSelect21.SetWarningParams(loadWarningParams);
        }
コード例 #15
0
        private void loadOldStyleButton_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter     = appTexts.ParameterName(102);
            ofd.DefaultExt = "*.xml";

            if (ofd.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }

            XDocument document;
            XElement  element;
            int       digitCount;

            try
            {
                document = XDocument.Load(ofd.FileName);
            }
            catch
            {
                MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            try
            {
                element    = document.Root.Element("Digits");
                digitCount = Convert.ToInt16(element.Attribute("Count").Value.ToString(), 10);
            }
            catch
            {
                MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }


            List <DigitPlate> loadDigitPlates = new List <DigitPlate>();

            for (int i = 0; i < digitCount; i++)
            {
                try
                {
                    element = document.Root.Element("Digit" + (i + 1).ToString());
                    string str1 = element.Attribute("Title").Value.ToString();
                    string str2 = element.Attribute("EventPos").Value.ToString();
                    string str3 = element.Attribute("Addr1").Value.ToString();
                    string str4 = element.Attribute("Type").Value.ToString();
                    string str5 = element.Attribute("Invert").Value.ToString();
                    string str6 = element.Attribute("UseMask").Value.ToString();

                    DigitPlate dp = new DigitPlate(str1);
                    dp.EventStructAddr = (ushort)ConvertFuncs.StrToShort(str2);
                    dp.StartAddr       = (ushort)(ConvertFuncs.StrToShort(str3) - 1);
                    if (str4 == "0")
                    {
                        dp.DigitType = DigitType.DigInput;
                    }
                    else
                    {
                        dp.DigitType = DigitType.DigOutput;
                    }
                    dp.Invert = (str5 != "0");

                    dp.UseMask = (ushort)ConvertFuncs.StrToShort(str6);
                    for (int i2 = 0; i2 < 16; i2++)
                    {
                        dp.DigitNames[i2] = element.Attribute("Line" + i2.ToString()).Value.ToString();
                    }

                    loadDigitPlates.Add(dp);
                }
                catch
                {
                    MessageBox.Show(appTexts.ParameterName(103), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            DigitPlates = loadDigitPlates;
        }