/// <summary> /// Metoda inicjalizująca wyświetlanie listy rekordów. /// </summary> public void InitializeForm() { listViewC = new ListView(); cCollection = new CountersCollection(); cCollection.collectorId = this.collectorId; int i = 1; using (var dataBase = new CollectorsManagementSystemEntities()) { var items = from collector in dataBase.Collectors join area in dataBase.Areas on collector.CollectorId equals area.CollectorId join address in dataBase.Addresses on area.AreaId equals address.AreaId join counter in dataBase.Counters on address.AddressId equals counter.AddressId where collector.CollectorId == this.collectorId select new { CounterNo = counter.CounterNo, CircuitNo = counter.CircuitNo, CounterAddress = area.Street + " " + address.HouseNo + "/" + address.FlatNo, CustomerId = counter.CustomerId }; foreach (var element in items) { var dateSub = DateTime.Now.Subtract(new TimeSpan(30, 0, 0, 0)); var firstMethod = from read in dataBase.Readings where read.Date > dateSub where read.CounterNo == element.CounterNo select read; if (firstMethod.Count() == 0) { string date, value, collectorId, collectorName, customerName; date = value = collectorName = String.Empty; var lastReading = from read in dataBase.Readings where read.CounterNo == element.CounterNo select read; if (lastReading.Count() > 0) { var lastRead = lastReading.OrderByDescending(x => x.Date).FirstOrDefault(); date = lastRead.Date.ToShortDateString() ?? String.Empty; value = lastRead.Value.ToString() ?? String.Empty; collectorId = lastRead.CollectorId ?? String.Empty; try { var collectorRead = (from collector in dataBase.Collectors where collector.CollectorId == collectorId select new { collector.Name, collector.LastName }).FirstOrDefault(); collectorName = collectorId + " " + collectorRead.Name + " " + collectorRead.LastName; } catch { collectorName = "---"; } } else date = value = collectorName = String.Empty; var cutomerRead = (from customer in dataBase.Customers where element.CustomerId == customer.CustomerId select new { customer.Name, customer.LastName }).FirstOrDefault(); if (cutomerRead != null) customerName = cutomerRead.Name + " " + cutomerRead.LastName; else customerName = String.Empty; { CounterXML newItem = new CounterXML(); newItem.ReadId = i++.ToString(); newItem.CounterNo = element.CounterNo.ToString(); newItem.CircuitNo = element.CircuitNo.ToString(); newItem.Customer = customerName; newItem.Address = element.CounterAddress; newItem.LastReadDate = date; newItem.LastValue = value; newItem.LastCollector = collectorName; newItem.NewValue = String.Empty; cCollection.AddNewElement(newItem); nrOfCounters++; } } } } listViewC = ListViewConfig.ListViewInit(columnList, this.GetType().Name); if ( cCollection.RecordsCount > 0 ) foreach (var element in cCollection.counter) ListViewConfig.AddItem(listViewC, element.PrintStringArray); listViewC.MultiSelect = false; listViewC.Size = new System.Drawing.Size(750, 450); if (nrOfCounters == 0) btExport.Enabled = false; this.Controls.Add(listViewC); }
/// <summary> /// Dodanie nowego elementu do listy elementów XML. /// </summary> /// <param name="item">Element, który ma być dodany do listy.</param> public void AddNewElement(CounterXML item) { if (counter == null) counter = new List<CounterXML>(); counter.Add(item); }