public override void CreateBody() { // создание стилей ячеек XmlStyle objectStyle = new XmlStyle(); objectStyle.Border.LineStyle = Borderline.Continuous; objectStyle.Border.Sides = BorderSides.Bottom; objectStyle.Border.Weight = 2; XmlStyle textStyle = new XmlStyle(); textStyle.Alignment = new AlignmentOptions() { Horizontal = HorizontalAlignment.Left, Vertical = VerticalAlignment.Center, WrapText = true }; textStyle.Border.LineStyle = Borderline.Continuous; textStyle.Border.Sides = BorderSides.All; textStyle.Border.Weight = 1; textStyle.Font.Size = 13; textStyle.Font.Name = "Calibri"; XmlStyle numbersStyle = new XmlStyle(textStyle); numbersStyle.Alignment = new AlignmentOptions() { Horizontal = HorizontalAlignment.Center, Vertical = VerticalAlignment.Center, WrapText = true }; numbersStyle.Font.Name = "Century Gothic"; numbersStyle.Font.Size = 14; XmlStyle valuesStyle = new XmlStyle(numbersStyle); valuesStyle.Alignment = new AlignmentOptions() { Horizontal = HorizontalAlignment.Right, Vertical = VerticalAlignment.Center, WrapText = false }; valuesStyle.DisplayFormat = DisplayFormatType.Custom; valuesStyle.CustomFormatString = "# ##0"; int rowCount = 0; foreach (var item in this.collectors) { rowCount += item.CountersCount; } const int startRow = 7; int rowIndex = startRow; int collectorIndex = 0; foreach (Collector collector in this.collectors) { int columnIndex = 1; int collectorRowSpan = collector.Objects.Sum(o => o.Counters.Sum(c => c.TarifsCount == 1 ? 1 : 3)); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collectorIndex + 1, numbersStyle); ChangeRangeStyle(rowIndex, columnIndex - 1, collectorRowSpan, _columnsCount, objectStyle); int oldObjectColumnIndex = columnIndex; for (int objectIndex = 0; objectIndex < collector.Objects.Count; objectIndex++) { AccountingObject aobject = collector.Objects[objectIndex]; int countersCount = aobject.CountersCount; int objectRowSpan = aobject.Counters.Sum(c => c.TarifsCount == 1 ? 1 : 3); columnIndex = oldObjectColumnIndex; CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.Contract, textStyle); CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, String.Format("{0} / {1}", aobject.Subscriber, aobject.Name), textStyle); bool isCounterMultiTariff = false; int oldCounterColumnIndex = columnIndex; for (int counterIndex = 0; counterIndex < countersCount; counterIndex++) { Counter counter = aobject.Counters[counterIndex]; isCounterMultiTariff = aobject.Counters[counterIndex].TarifsCount != 1; int counterRowSpan = isCounterMultiTariff ? 3 : 1; columnIndex = oldCounterColumnIndex; CreateRange(rowIndex + counterIndex, columnIndex++, counterRowSpan, 1, counter.AccountingPoint, textStyle); CreateRange(rowIndex + counterIndex, columnIndex++, counterRowSpan, 1, counter.CounterType, textStyle); CreateRange(rowIndex + counterIndex, columnIndex++, counterRowSpan, 1, counter.SerialNumber, numbersStyle); // тариф if (isCounterMultiTariff) // счётчик многотарифный { // TƩ CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, "TƩ", textStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.PreviousIndications.Tarriff0), valuesStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.NextIndications.Tarriff0), valuesStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.Difference), valuesStyle); rowIndex++; // T1 columnIndex = oldCounterColumnIndex + 3; CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, "T1", textStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.PreviousIndications.Tarriff1), valuesStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.NextIndications.Tarriff1), valuesStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.DifferenceT1), valuesStyle); rowIndex++; // T2 columnIndex = oldCounterColumnIndex + 3; CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, "T2", textStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.PreviousIndications.Tarriff2), valuesStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.NextIndications.Tarriff2), valuesStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.DifferenceT2), valuesStyle); } // однотарифный else { CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, "TƩ", textStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.PreviousIndication), valuesStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.NextIndication), valuesStyle); CreateRange(rowIndex + counterIndex, columnIndex++, 1, 1, GetIndication(counter.Difference), valuesStyle); } } rowIndex += countersCount; } collectorIndex++; } }
public override void CreateBody() { // создание стилей ячеек XmlStyle textStyle = new XmlStyle(); textStyle.Alignment = new AlignmentOptions() { Horizontal = HorizontalAlignment.Left, Vertical = VerticalAlignment.Center, WrapText = true }; textStyle.Border.LineStyle = Borderline.Continuous; textStyle.Border.Sides = BorderSides.All; textStyle.Border.Weight = 1; textStyle.Font.Size = 12; textStyle.Font.Name = "Calibri"; XmlStyle numbersStyle = new XmlStyle(textStyle); numbersStyle.Alignment = new AlignmentOptions() { Horizontal = HorizontalAlignment.Center, Vertical = VerticalAlignment.Center, WrapText = true }; numbersStyle.Font.Name = "Century Gothic"; XmlStyle valuesStyle = new XmlStyle(numbersStyle); valuesStyle.Alignment = new AlignmentOptions() { Horizontal = HorizontalAlignment.Right, Vertical = VerticalAlignment.Center, WrapText = false }; valuesStyle.DisplayFormat = DisplayFormatType.Custom; valuesStyle.CustomFormatString = "# ##0"; XmlStyle highlightValuesStyle = new XmlStyle(valuesStyle); highlightValuesStyle.Font.Bold = true; highlightValuesStyle.Interior.Color = System.Drawing.Color.LightGray; int rowCount = 0; foreach (var item in this.collectors) { rowCount += item.CountersCount; } const int startRow = 7; int rowIndex = startRow; int collectorIndex = 0; int columnIndex, oldObjectColumnIndex, countersCount, objectRowSpan = 1, oldRowIndex, oldCounterColumnIndex, collectorRowSpan, counterRowSpan; bool isCounterMultiTariff, hasTarifDifference; XmlStyle _valueStyle; Range r; foreach (Collector collector in this.collectors) { columnIndex = 1; oldRowIndex = rowIndex; collectorRowSpan = collector.Objects.Sum(o => o.Counters.Sum(c => c.TarifsCount == 1 ? c.HasDifferenceBetweenT1AndT0 ? 2 : 1 : c.TarifsCount + 1)); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collectorIndex + 1, numbersStyle); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collector.IsAnswered == true ? "OK" : "не отвечает", textStyle); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collector.IsUSPD == true ? "УСПД" : string.Empty, textStyle); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collector.NetworkAddress, numbersStyle); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collector.PhoneNumber, numbersStyle); oldObjectColumnIndex = columnIndex; for (int objectIndex = 0; objectIndex < collector.Objects.Count; objectIndex++) { AccountingObject aobject = collector.Objects[objectIndex]; countersCount = aobject.CountersCount; objectRowSpan = aobject.Counters.Sum(c => c.TarifsCount == 1 ? c.HasDifferenceBetweenT1AndT0 ? 2 : 1 : c.TarifsCount + 1); columnIndex = oldObjectColumnIndex; CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.City, textStyle); CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.Contract, textStyle); CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.Subscriber, textStyle); CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.Name, textStyle); CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.Tp, textStyle); isCounterMultiTariff = false; oldCounterColumnIndex = columnIndex; for (int counterIndex = 0; counterIndex < countersCount; counterIndex++) { Counter counter = aobject.Counters[counterIndex]; isCounterMultiTariff = aobject.Counters[counterIndex].TarifsCount != 1; counterRowSpan = isCounterMultiTariff ? aobject.Counters[counterIndex].TarifsCount + 1 : counter.HasDifferenceBetweenT1AndT0 ? 2 : 1; hasTarifDifference = counter.HasDifferenceBetweenT1AndT0; _valueStyle = counter.MissingPersonalAccount || hasTarifDifference ? highlightValuesStyle : valuesStyle; columnIndex = oldCounterColumnIndex; CreateRange(rowIndex, columnIndex++, counterRowSpan, 1, counter.IsAnswered == true ? "OK" : "не отвечает", textStyle); CreateRange(rowIndex, columnIndex++, counterRowSpan, 1, counter.AccountingPoint, textStyle); CreateRange(rowIndex, columnIndex++, counterRowSpan, 1, counter.CounterType, textStyle); CreateRange(rowIndex, columnIndex++, counterRowSpan, 1, counter.CounterNetworkAdress, numbersStyle); CreateRange(rowIndex, columnIndex++, counterRowSpan, 1, counter.SerialNumber, numbersStyle); // тариф if (isCounterMultiTariff) // счётчик многотарифный { // TƩ CreateRange(rowIndex, columnIndex++, 1, 1, "TƩ", textStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.PreviousIndications.Tarriff0), _valueStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.NextIndications.Tarriff0), _valueStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.Difference), _valueStyle); rowIndex++; for (int i = 1; i <= aobject.Counters[counterIndex].TarifsCount; i++) { columnIndex = oldCounterColumnIndex + 5; CreateRange(rowIndex, columnIndex++, 1, 1, "T" + i.ToString(), textStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.PreviousIndications[i]), _valueStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.NextIndications[i]), _valueStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.Differences(i)), _valueStyle); rowIndex++; } } // однотарифный else { CreateRange(rowIndex, columnIndex++, 1, 1, "TƩ", textStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.PreviousIndication), _valueStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.NextIndication), _valueStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.Difference), _valueStyle); rowIndex++; if (hasTarifDifference) { // T1 columnIndex = oldCounterColumnIndex + 5; CreateRange(rowIndex, columnIndex++, 1, 1, "T1", textStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.PreviousIndications.Tarriff1), _valueStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.NextIndications.Tarriff1), _valueStyle); CreateRange(rowIndex, columnIndex++, 1, 1, GetIndication(counter.DifferenceT1), _valueStyle); rowIndex++; } } } } collectorIndex++; } }
public static SelectElementModel ViewElement(string data, string parentId, ProgressDialogController progressController) { //Debug.Assert(String.IsNullOrEmpty(data), "data is empty!"); SelectElementModel result = new SelectElementModel(); //data = System.IO.File.ReadAllText("data"); HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument(); doc.LoadHtml(data); if (doc.DocumentNode.ChildNodes.Count > 1) { HtmlAgilityPack.HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@id='collectorsDiv']/table/tbody/tr"); if (null != nodes) { HtmlAgilityPack.HtmlNode row; HtmlAgilityPack.HtmlNodeCollection fields; bool nextIsObject = false; bool nextIsCounter = false; int startIndex = 0; int toProcessRows = 0; HtmlNode td; HtmlNode img; string text; int collectorId = 1; try { result.Collectors = new List <Collector>(); // количество точек int pointsCount = nodes.Count; if (progressController != null) { progressController.SetMessage(String.Format("Найдено {0} расчётных точек. Получение данных...", nodes.Count)); } double progress = 0.0d; int globalRowIndex = 0; while (globalRowIndex < nodes.Count) { row = nodes[globalRowIndex]; fields = row.SelectNodes("td"); toProcessRows = 1; if (fields[0].HasAttributes && fields[0].Attributes["rowspan"] != null) { Int32.TryParse(fields[0].Attributes["rowspan"].Value, out toProcessRows); } Collector collector = new Collector(); try { #region разбор системы collector.Id = collectorId.ToString(); collectorId++; // статус модема td = fields[0]; if (td.ChildNodes["img"] != null) { img = td.ChildNodes["img"]; if (img.Attributes["src"] != null) { if (img.Attributes["src"].Value.Contains("не отвечает")) { collector.IsAnswered = false; } else { collector.IsAnswered = true; } } } // это УСПД td = fields[1]; if (td.HasChildNodes && td.ChildNodes["img"] != null) { collector.IsUSPD = true; img = td.ChildNodes["img"]; if (img.Attributes["src"] != null) { if (img.Attributes["src"].Value.Contains("не отвечает")) { collector.IsAnsweredUSPD = false; } else { collector.IsAnsweredUSPD = true; } } } else { collector.IsUSPD = false; } // УСПД сетевой адрес td = fields[2]; text = td.InnerText; byte bvalue; Byte.TryParse(text, out bvalue); collector.NetworkAddress = bvalue; // номер GSM - PhoneNumberColumn td = fields[3]; text = td.InnerText; collector.PhoneNumber = text; #endregion } catch (Exception e) { throw e; } nextIsObject = true; int processedRows = 0; while (processedRows < toProcessRows) { row = nodes[globalRowIndex]; fields = row.SelectNodes("td"); startIndex = nextIsObject ? 4 : 0; int countersCount = 1; if (fields[startIndex].HasAttributes && fields[startIndex].Attributes["rowspan"] != null) { Int32.TryParse(fields[startIndex].Attributes["rowspan"].Value, out countersCount); } AccountingObject accountingObject = new AccountingObject(); try { #region разбор объекта // населенный пункт - CityColumn td = fields[startIndex++]; text = td.InnerText; accountingObject.City = text; // № договора - ContractColumn td = fields[startIndex++]; text = td.InnerText; accountingObject.Contract = text; // Наименование абонента - SubscriberColumn td = fields[startIndex++]; text = td.InnerText; accountingObject.Subscriber = text; // Объект учета - ObjectColumn td = fields[startIndex++]; text = td.InnerText; accountingObject.Name = text; // Номер ТП - TpColumn td = fields[startIndex++]; text = td.InnerText; accountingObject.Tp = text; if (td.Attributes["onclick"] != null) { string link = td.Attributes["onclick"].Value; string[] linkParts = link.Split(new char[] { '(', ',', ')' }); if (linkParts.Length != 4) { throw new ArgumentException("Не удалось разобрать ссылку объекта."); } string deviceId = linkParts[1]; string selectedElementId = linkParts[2].Trim(new char[] { '\'', '\'' }); accountingObject.TpLink = link; accountingObject.Id = deviceId; } else { Debugger.Break(); } #endregion } catch (Exception e) { throw e; } nextIsCounter = true; for (int k = 0; k < countersCount; k++) { row = nodes[globalRowIndex]; fields = row.SelectNodes("td"); startIndex = nextIsObject ? 9 : (nextIsCounter ? 5 : 0); nextIsObject = false; nextIsCounter = false; try { #region разбор учёта Counter counter = new Counter(); long lvalue = 0; // статус счётчика td = fields[startIndex++]; if (td.ChildNodes["img"] != null) { img = td.ChildNodes["img"]; if (img.Attributes["src"] != null) { if (img.Attributes["src"].Value.Contains("не отвечает")) { counter.IsAnswered = false; } else { counter.IsAnswered = true; } if (img.Attributes["src"].Value.Contains("wrongSettings")) { counter.HasWrongSettings = true; } else { counter.HasWrongSettings = false; } } counter.AmperPointId = img.Attributes["alt"].Value; string link = td.Attributes["onclick"].Value; if (string.IsNullOrEmpty(link)) { Debugger.Break(); } string[] linkParts = link.Split(new char[] { '(', ',', ')' }); if (linkParts.Length != 4) { System.Diagnostics.Debugger.Break(); } string counterId = linkParts[1]; string selectedElementId = linkParts[2].Trim(new char[] { '\'', '\'' }); counter.Id = counterId; counter.CounterLink = link; } // Расчётная точка td = fields[startIndex++]; text = td.InnerText; counter.AccountingPoint = text; if (td.HasAttributes && td.Attributes["class"] != null) { if (td.Attributes["class"].Value.Contains("noPersonalAccount")) { counter.MissingPersonalAccount = true; } else { counter.MissingPersonalAccount = false; } } // тип td = fields[startIndex++]; text = td.InnerText; counter.CounterType = text; // сетевой аддрес td = fields[startIndex++]; text = td.InnerText; counter.CounterNetworkAdress = text; // заводской номер td = fields[startIndex++]; text = td.InnerText; counter.SerialNumber = text; // предыдущие показания td = fields[startIndex++]; text = td.InnerText; lvalue = 0; long.TryParse(text, out lvalue); counter.PreviousIndication = String.IsNullOrWhiteSpace(text) ? new Nullable <long>() : lvalue; counter.PreviousIndications = new Indications(); counter.PreviousIndications.Tarriff0 = GetIndication(text); // текущие показания td = fields[startIndex++]; text = td.InnerText; lvalue = 0; long.TryParse(text, out lvalue); counter.NextIndication = String.IsNullOrWhiteSpace(text) ? new Nullable <long>() : lvalue; counter.NextIndications = new Indications(); counter.NextIndications.Tarriff0 = GetIndication(text); // разница td = fields[startIndex++]; text = td.InnerText; lvalue = 0; long.TryParse(text, out lvalue); counter.Difference = String.IsNullOrWhiteSpace(text) ? new Nullable <long>() : lvalue; #endregion accountingObject.Counters.Add(counter); } catch (Exception e) { throw e; } processedRows++; globalRowIndex++; progress = (double)globalRowIndex / pointsCount; if (progressController != null) { progressController.SetProgress(progress); } } collector.Objects.Add(accountingObject); } result.Collectors.Add(collector); } } catch (Exception e) { throw new ArgumentOutOfRangeException("Ошибка разбора данных: структура данных информации об объекте изменилась.\r\nОбратитесь к разработчику.", e); } } // статистика nodes = doc.DocumentNode.SelectNodes("/div/div/div/table/tbody/tr"); if (null != nodes) { Statistics statistics = new Statistics(); HtmlNode td; string text; int value = 0; #region азбор данных // Всего модемов td = nodes[0].SelectNodes("td[2]").Single(); text = td.InnerText; statistics.ModemsCount = Int32.TryParse(text, out value) ? value : 0; // Отвечающих модемов td = nodes[1].SelectNodes("td[2]").Single(); text = td.InnerText; statistics.AnsweredModemsCount = Int32.TryParse(text, out value) ? value : 0; // Не отвечающих модемов td = nodes[2].SelectNodes("td[2]").Single(); text = td.InnerText; statistics.NotAnsweredModemsCount = Int32.TryParse(text, out value) ? value : 0; // Всего УСПД td = nodes[3].SelectNodes("td[2]").Single(); text = td.InnerText; statistics.UspdCount = Int32.TryParse(text, out value) ? value : 0; // Отвечающих УСПД td = nodes[4].SelectNodes("td[2]").Single(); text = td.InnerText; statistics.AnsweredUspdCount = Int32.TryParse(text, out value) ? value : 0; // Не отвечающих УСПД td = nodes[5].SelectNodes("td[2]").Single(); text = td.InnerText; statistics.NotAnsweredUspdCount = Int32.TryParse(text, out value) ? value : 0; // Всего точек td = nodes[6].SelectNodes("td[2]").Single(); text = td.InnerText; statistics.CountersCount = Int32.TryParse(text, out value) ? value : 0; // Отвечающих счетчиков td = nodes[7].SelectNodes("td[2]").Single(); text = td.InnerText; statistics.AnsweredCountersCount = Int32.TryParse(text, out value) ? value : 0; // Не отвечающих счетчиков td = nodes[8].SelectNodes("td[2]").Single(); text = td.InnerText; statistics.NotAnsweredCountersCount = Int32.TryParse(text, out value) ? value : 0; // Недостающих данных td = nodes[9].SelectNodes("td[2]").Single(); text = td.InnerText; statistics.MissingDataCount = Int32.TryParse(text, out value) ? value : 0; #endregion result.Statistics = statistics; } } return(result); }
public override void CreateBody() { // создание стилей ячеек XmlStyle textStyle = new XmlStyle(); textStyle.Alignment = new AlignmentOptions() { Horizontal = HorizontalAlignment.Left, Vertical = VerticalAlignment.Center, WrapText = true }; textStyle.Border.LineStyle = Borderline.Continuous; textStyle.Border.Sides = BorderSides.All; textStyle.Border.Weight = 1; textStyle.Font.Size = 13; textStyle.Font.Name = "Calibri"; XmlStyle numbersStyle = new XmlStyle(textStyle); numbersStyle.Alignment = new AlignmentOptions() { Horizontal = HorizontalAlignment.Center, Vertical = VerticalAlignment.Center, WrapText = true }; numbersStyle.Font.Name = "Century Gothic"; numbersStyle.Font.Size = 14; XmlStyle valuesStyle = new XmlStyle(numbersStyle); valuesStyle.Alignment = new AlignmentOptions() { Horizontal = HorizontalAlignment.Right, Vertical = VerticalAlignment.Center, WrapText = false }; valuesStyle.DisplayFormat = DisplayFormatType.Custom; valuesStyle.CustomFormatString = "# ##0"; int rowCount = 0; foreach (var item in this.collectors) { rowCount += item.CountersCount; } const int startRow = 6; int rowIndex = startRow; int collectorIndex = 0; foreach (Collector collector in this.collectors) { int columnIndex = 1; int collectorRowSpan = collector.Objects.Sum(o => o.Counters.Sum(c => c.TarifsCount == 1 ? 1 : 3)); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collectorIndex + 1, numbersStyle); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collector.IsAnswered == true ? "OK" : "не отвечает", textStyle); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collector.IsUSPD == true ? "УСПД" : string.Empty, textStyle); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collector.NetworkAddress, numbersStyle); CreateRange(rowIndex, columnIndex++, collectorRowSpan, 1, collector.PhoneNumber, numbersStyle); int oldObjectColumnIndex = columnIndex; for (int objectIndex = 0; objectIndex < collector.Objects.Count; objectIndex++) { AccountingObject aobject = collector.Objects[objectIndex]; int countersCount = aobject.CountersCount; int objectRowSpan = aobject.Counters.Sum(c => c.TarifsCount == 1 ? 1 : 3); columnIndex = oldObjectColumnIndex; CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.City, textStyle); CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.Contract, textStyle); CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.Subscriber, textStyle); CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.Name, textStyle); CreateRange(rowIndex, columnIndex++, objectRowSpan, 1, aobject.Tp, textStyle); bool isCounterMultiTariff = false; int oldCounterColumnIndex = columnIndex; for (int counterIndex = 0; counterIndex < countersCount; counterIndex++) { Counter counter = aobject.Counters[counterIndex]; isCounterMultiTariff = aobject.Counters[counterIndex].TarifsCount != 1; int counterRowSpan = isCounterMultiTariff ? 3 : 1; columnIndex = oldCounterColumnIndex; CreateRange(rowIndex + counterIndex, columnIndex++, counterRowSpan, 1, counter.IsAnswered == true ? "OK" : "не отвечает", textStyle); CreateRange(rowIndex + counterIndex, columnIndex++, counterRowSpan, 1, counter.AccountingPoint, textStyle); CreateRange(rowIndex + counterIndex, columnIndex++, counterRowSpan, 1, counter.CounterType, textStyle); CreateRange(rowIndex + counterIndex, columnIndex++, counterRowSpan, 1, counter.CounterNetworkAdress, numbersStyle); CreateRange(rowIndex + counterIndex, columnIndex++, counterRowSpan, 1, counter.SerialNumber, numbersStyle); } rowIndex += countersCount; } collectorIndex++; } }