Пример #1
0
 /// <summary>
 /// Zapis wartości do bazy danych.
 /// </summary>
 public void AddNewElementsToDataBase()
 {
     foreach (var element in counter)
     {
         if (element.NewValue != String.Empty)
         {
             Reading newRecord = new Reading();
             newRecord.CollectorId = this.collectorId;
             newRecord.Date = DateTime.Now;
             newRecord.CounterNo = Convert.ToInt32(element.CounterNo);
             newRecord.Value = Convert.ToDouble(element.NewValue);
             newRecord.ReadingId = Guid.NewGuid();
             newRecord.InsertIntoDB();
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Generuje losowo odczyty.
        /// </summary>
        static void GenerateReadings()
        {
            Random rnd = new Random();
            Reading reading;
            Guid g;

            using (var dataBase = new CollectorsManagementSystemEntities())
            {
            for (int i = 0; i < numberOfReadings; i++)
            {
                reading = new Reading();

                do
                {
                    g = Guid.NewGuid();
                } while (g == Guid.Empty);

                reading.ReadingId = g;// Guid.NewGuid();
                reading.CounterNo = Convert.ToInt32(ChooseRandomId(0));

                    //var counters = (from counter in dataBase.Counters
                    //                select counter.CounterNo).ToList();

                    List<int> test = (from c in dataBase.Counters select c.CounterNo).ToList();

                    var tmp = (from c in dataBase.Counters where c.CounterNo == reading.CounterNo select c.AddressId).FirstOrDefault();
                    var tmp2 = (from a in dataBase.Addresses where a.AddressId == tmp select a.AreaId).FirstOrDefault();
                    reading.CollectorId = (from a in dataBase.Areas where a.AreaId == tmp2 select a.CollectorId).FirstOrDefault().ToString();

                    var friendsOfReading = from r in dataBase.Readings where r.CounterNo == reading.CounterNo orderby r.Date descending select r;
                    if (friendsOfReading.Count() == 0)
                        reading.Value = rnd.Next(0, 1000);
                    else
                    {
                        reading.Value = friendsOfReading.FirstOrDefault().Value + rnd.Next(0, 1000);

                        foreach (Reading friendOfReading in friendsOfReading)
                            friendOfReading.Date = friendOfReading.Date.AddDays(-30);

                        dataBase.SaveChanges();
                    }

                    reading.Date = DateTime.Now;

                reading.InsertIntoDB();
            }
            }
        }
Пример #3
0
        /// <summary>
        /// Funkcja pozwalająca inicjować formę odczyty.
        /// </summary>
        private void InitializeReading()
        {
            modifRecord = new Reading();
            using (var dataBase = new CollectorsManagementSystemEntities())
            {
                try
                {
                    var item = (from reading in dataBase.Readings
                                where reading.ReadingId == editId
                                select reading).FirstOrDefault();

                    {
                        modifRecord.CollectorId = item.CollectorId;
                        modifRecord.CounterNo = item.CounterNo;
                        modifRecord.Date = item.Date;
                        modifRecord.ReadingId = item.ReadingId;
                        modifRecord.Value = item.Value;
                    }

                    comboBoxesKeys = item.CollectorId;
                    textBoxesTexts = new string[] { item.ReadingId.ToString(), item.CounterNo.ToString(), item.Date.ToString(), item.Value.ToString() };

                    Label[] labels = InitializeLabels();
                    TextBox[] textBoxes = InitializeText();

                    CBConfig = new ComboBoxConfig(TableNames, comboBoxesNames, new Point(150, 30 * (5)), comboBoxesKeys);

                    this.Controls.AddRange(labels);
                    this.Controls.AddRange(textBoxes);
                    this.Controls.Add(CBConfig.comboBox);
                }
                catch
                {
                    MessageBox.Show("Błąd ładowania odczytu!");
                }
            }
        }