Example #1
0
        public void CheckTagValue()
        {
            access_data aa = new access_data();

            try
            {
                aa.get_info_by_url(aa.GetUrlByUsingId(id));

                metroGrid1.DataSource = aa.CheckEveryTagValue(aa.GetUrlByUsingId(id));
                HtmlWeb web = new HtmlWeb();
                HtmlAgilityPack.HtmlDocument doc = web.Load("http://" + aa.a);

                DataGridViewImageColumn delbut = new DataGridViewImageColumn();
                delbut.HeaderText   = "Result";
                delbut.Width        = 20;
                delbut.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
                metroGrid1.Columns.Add(delbut);

                int i = metroGrid1.Rows.Count;
                for (int j = 0; j < i; j++)
                {
                    try
                    {
                        string tagname  = metroGrid1.Rows[j].Cells["Tag Name"].Value.ToString();
                        string tagvalue = metroGrid1.Rows[j].Cells["Tag Value"].Value.ToString();

                        var    link        = doc.DocumentNode.SelectSingleNode(tagname);
                        string ParsedValue = link.InnerText.ToString();

                        if (ParsedValue == "")
                        {
                            metroGrid1.Rows[j].Cells[2].Value = Image.FromFile(Environment.CurrentDirectory + "/notavailable.png");
                        }
                        else if (ParsedValue == tagvalue)
                        {
                            metroGrid1.Rows[j].Cells[2].Value = Image.FromFile(Environment.CurrentDirectory + "/correct.png");
                        }
                        else
                        {
                            metroGrid1.Rows[j].Cells[2].Value = Image.FromFile(Environment.CurrentDirectory + "/invalid.png");
                        }
                    }
                    catch (System.NullReferenceException)
                    {
                        metroGrid1.Rows[j].Cells[2].Value = Image.FromFile(Environment.CurrentDirectory + "/notavailable.png");
                    }
                }
            }
            catch (System.Net.WebException)
            {
                MetroMessageBox.Show(this, "The webpage at " + aa.a + " might be temporarily down or it may have moved permanently to a new web address", "WSH notify", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }