public static ViewDeviceModel ViewDevice(string data, ProgressDialogController progressController) { ViewDeviceModel result = new ViewDeviceModel(); try { HtmlNode td; string text; //data = System.IO.File.ReadAllText("data"); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); if (doc == null) { return(null); } doc.LoadHtml(data); if (doc.DocumentNode == null && doc.DocumentNode.ChildNodes == null) { return(null); } if (doc.DocumentNode.ChildNodes.Count > 1) { #region азбор секции с информацией о канале связи HtmlAgilityPack.HtmlNode jqTabsDevices = doc.DocumentNode.SelectNodes("//div[@id='jqTabsDevices']").Single(); if (jqTabsDevices == null) { return(null); } HtmlNodeCollection sessionInformation = jqTabsDevices.SelectNodes("div[2]/div/table/tbody/tr"); if (sessionInformation == null) { return(null); } result.Session = new SessionInformation(); // производитель модема td = sessionInformation[2].SelectNodes("td[2]").Single(); text = td.InnerText; result.Session.ModemManufacturer = text; // Модель устройства td = sessionInformation[3].SelectNodes("td[2]").Single(); text = td.InnerText; result.Session.Model = text; // описание td = sessionInformation[4].SelectNodes("td[2]").Single(); text = td.InnerText; result.Session.Description = text; // статус td = sessionInformation[6].SelectNodes("td[2]").Single(); text = td.InnerText; result.Session.CurrentStatus = text; // сеанс td = sessionInformation[7].SelectNodes("td[2]").Single(); text = td.InnerText; DateTime date = new DateTime(); result.Session.LastSessionDate = DateTime.TryParse(text, out date) ? date : date; #endregion #region азбор секции с показаниями HtmlAgilityPack.HtmlNode jqTabsBalances = doc.DocumentNode.SelectNodes("//div[@id='jqTabsBalances']").Single(); if (jqTabsBalances == null) { return(null); } HtmlNodeCollection counters = jqTabsBalances.SelectNodes("table/tbody/tr"); if (counters == null) { return(null); } result.CountersIndications = new List <IndicationViewItem>(); byte startIndex = 0; for (int i = 0; i < counters.Count; i++) { HtmlNodeCollection hnc = counters[i].SelectNodes("td"); startIndex = 0; IndicationViewItem ivi = new IndicationViewItem(); ivi.PreviousIndications = new Indications(); ivi.NextIndications = new Indications(); #region Парсинг // точка td = hnc[startIndex++]; text = td.InnerText; ivi.AccountingPoint = text; // тип td = hnc[startIndex++]; text = td.InnerText; ivi.CounterType = text; // предыдущие показания T0 td = hnc[startIndex++]; ivi.PreviousIndications.Tarriff0 = GetIndication(td.InnerText); // предыдущие показания T1 td = hnc[startIndex++]; ivi.PreviousIndications.Tarriff1 = GetIndication(td.InnerText); // предыдущие показания T2 td = hnc[startIndex++]; ivi.PreviousIndications.Tarriff2 = GetIndication(td.InnerText); // предыдущие показания T3 td = hnc[startIndex++]; ivi.PreviousIndications.Tarriff3 = GetIndication(td.InnerText); // предыдущие показания T4 td = hnc[startIndex++]; ivi.PreviousIndications.Tarriff4 = GetIndication(td.InnerText); // предыдущие показания достоверность td = hnc[startIndex++]; text = td.InnerText; ivi.PreviousIndications.DataReliability = text; // текущие показания T0 td = hnc[startIndex++]; ivi.NextIndications.Tarriff0 = GetIndication(td.InnerText); // текущие показания T1 td = hnc[startIndex++]; ivi.NextIndications.Tarriff1 = GetIndication(td.InnerText); // текущие показания T2 td = hnc[startIndex++]; ivi.NextIndications.Tarriff2 = GetIndication(td.InnerText); // текущие показания T3 td = hnc[startIndex++]; ivi.NextIndications.Tarriff3 = GetIndication(td.InnerText); // текущие показания T4 td = hnc[startIndex++]; ivi.NextIndications.Tarriff4 = GetIndication(td.InnerText); // предыдущие показания достоверность td = hnc[startIndex++]; text = td.InnerText; ivi.NextIndications.DataReliability = text; // разница td = hnc[startIndex++]; ivi.Difference = GetIndication(td.InnerText); #endregion result.CountersIndications.Add(ivi); } #endregion #region Качество показаний if (result.QualityIndications == null) { result.QualityIndications = new List <QualityIndications>(); } HtmlNodeCollection indicationsQualityMonths = doc.DocumentNode.SelectNodes("//table[contains(@class,'tableQualityIndications')]"); if (indicationsQualityMonths != null) { int monthsCount = indicationsQualityMonths.Count; for (int monthIndex = 0; monthIndex < monthsCount; monthIndex++) { QualityIndications qi = new QualityIndications(); HtmlNode m = indicationsQualityMonths[monthIndex].SelectNodes("thead/tr[1]/th[2]").Single(); qi.Period = m == null ? "???" : m.InnerText; qi.PointsData = ParseMonthQualityIndications(indicationsQualityMonths[monthIndex].SelectNodes("tbody/tr")); result.QualityIndications.Add(qi); } } #endregion } } catch (Exception ex) { //TODO: Добавить логирование _logger?.Error(ex); return(null); } return(result); }
public static ViewCounterModel ViewCounter(string data, ProgressDialogController progressController) { HtmlNode td; string text; ViewCounterModel result = new ViewCounterModel(); //data = System.IO.File.ReadAllText("data"); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); if (doc == null) { return(null); } doc.LoadHtml(data); if (doc.DocumentNode == null && doc.DocumentNode.ChildNodes == null) { return(null); } if (doc.DocumentNode.ChildNodes.Count > 1) { #region азбор секции с информацией о канале связи HtmlAgilityPack.HtmlNode jqTabsDevices = doc.DocumentNode.SelectNodes("//div[@id='jqTabsDevices']").Single(); if (jqTabsDevices == null) { return(null); } HtmlNodeCollection info = jqTabsDevices.SelectNodes("div[2]/table/tbody/tr"); if (info == null) { return(null); } // Наименование точки учета td = info[0].SelectNodes("td[2]").Single(); text = td.InnerText; result.AccountPoint = text; // Тип счетчика td = info[1].SelectNodes("td[2]").Single(); text = td.InnerText; result.CounterType = text; // Заводской номер td = info[2].SelectNodes("td[2]").Single(); text = td.InnerText.Trim(); result.CounterNumber = text; // Сетевой адрес td = info[3].SelectNodes("td[2]").Single(); text = td.InnerText; result.CounterNetworkAddress = text; // Коэффициент трансформации td = info[5].SelectNodes("td[2]").Single(); text = td.InnerText; result.Ktt = text; // Производитель td = info[6].SelectNodes("td[2]").Single(); text = td.InnerText.Trim(); result.CounterManufacturer = text; // Тип учёта td = info[7].SelectNodes("td[2]").Single(); text = td.InnerText.Trim(); result.AccountType = text; // Полное название абонента td = info[8].SelectNodes("td[2]").Single(); text = td.InnerText.Trim(); result.AbonentFullName = text; // Название абонента td = info[9].SelectNodes("td[2]").Single(); text = td.InnerText.Trim(); result.AbonentName = text; // Короткое название абонента td = info[10].SelectNodes("td[2]").Single(); text = td.InnerText.Trim(); result.AbonentShortName = text; // Подстанция td = info[11].SelectNodes("td[2]").Single(); text = td.InnerText; result.Substation = text; // Название объекта td = info[12].SelectNodes("td[2]").Single(); text = td.InnerText; result.ObjectName = text; // Название точки учета td = info[13].SelectNodes("td[2]").Single(); text = td.InnerText; result.AccountPointName = text; // Номер ТП td = info[14].SelectNodes("td[2]").Single(); text = td.InnerText; result.TP = text; // Адрес объекта td = info[15].SelectNodes("td[2]").Single(); text = td.InnerText; result.ObjectAddress = text; // Населенный пункт объекта td = info[16].SelectNodes("td[2]").Single(); text = td.InnerText; result.ObjectState = text; // Адрес абонента td = info[17].SelectNodes("td[2]").Single(); text = td.InnerText; result.AbonentAddress = text; // Фидер td = info[18].SelectNodes("td[2]").Single(); text = td.InnerText; result.Fider = text; // Номер договора td = info[19].SelectNodes("td[2]").Single(); text = td.InnerText; result.DogNumber = text; // Родительский лиц счет td = info[20].SelectNodes("td[2]").Single(); text = td.InnerText.Trim(); result.AmperParentPointId = text; // РЭС td = info[21].SelectNodes("td[2]").Single(); text = td.InnerText; result.Departament = text; // Зав. номер из расч системы td = info[22].SelectNodes("td[2]").Single(); text = td.InnerText; result.AmperCounterNumber = text; // Лицевой счет td = info[23].SelectNodes("td[2]").Single(); text = td.InnerText.Trim(); result.AmperPointId = text; // Текущий статус td = info[24].SelectNodes("td[2]").Single(); text = td.InnerText; result.Status = text; // Последний сеанс td = info[25].SelectNodes("td[2]").Single(); text = td.InnerText.Trim(); DateTime date = new DateTime(); result.LastSessionDate = DateTime.TryParse( text, System.Globalization.CultureInfo.CreateSpecificCulture("en-US"), System.Globalization.DateTimeStyles.None, out date) ? date : date; #endregion #region азбор секции с показаниями HtmlAgilityPack.HtmlNode jqTabsSingleMeterIndications = doc.DocumentNode.SelectNodes("//div[@id='jqTabsSingleMeterIndications']").Single(); info = jqTabsSingleMeterIndications.SelectNodes("table/tbody/tr/td"); if (info == null) { return(null); } IndicationViewItem ivi = new IndicationViewItem(); ivi.PreviousIndications = new Indications(); ivi.NextIndications = new Indications(); #region Парсинг int startIndex = 0; // точка td = info[startIndex++]; text = td.InnerText; ivi.AccountingPoint = text; // тип td = info[startIndex++]; text = td.InnerText; ivi.CounterType = text; // предыдущие показания T0 td = info[startIndex++]; ivi.PreviousIndications.Tarriff0 = GetIndication(td.InnerText); // предыдущие показания T1 td = info[startIndex++]; ivi.PreviousIndications.Tarriff1 = GetIndication(td.InnerText); // предыдущие показания T2 td = info[startIndex++]; ivi.PreviousIndications.Tarriff2 = GetIndication(td.InnerText); // предыдущие показания T3 td = info[startIndex++]; ivi.PreviousIndications.Tarriff3 = GetIndication(td.InnerText); // предыдущие показания T4 td = info[startIndex++]; ivi.PreviousIndications.Tarriff4 = GetIndication(td.InnerText); // предыдущие показания достоверность td = info[startIndex++]; text = td.InnerText; ivi.PreviousIndications.DataReliability = text; // текущие показания T0 td = info[startIndex++]; ivi.NextIndications.Tarriff0 = GetIndication(td.InnerText); // текущие показания T1 td = info[startIndex++]; ivi.NextIndications.Tarriff1 = GetIndication(td.InnerText); // текущие показания T2 td = info[startIndex++]; ivi.NextIndications.Tarriff2 = GetIndication(td.InnerText); // текущие показания T3 td = info[startIndex++]; ivi.NextIndications.Tarriff3 = GetIndication(td.InnerText); // текущие показания T4 td = info[startIndex++]; ivi.NextIndications.Tarriff4 = GetIndication(td.InnerText); // предыдущие показания достоверность td = info[startIndex++]; text = td.InnerText; ivi.NextIndications.DataReliability = text; // разница td = info[startIndex++]; ivi.Difference = GetIndication(td.InnerText); #endregion result.IndicationViewItem = ivi; #endregion } return(result); }
public ViewCounterModel() { IndicationViewItem = new IndicationViewItem(); }