/// <summary> /// Generiert eine Liste von 'PhysicalInterfaceWithCount' aus der Tabelle der /// verwendeten Schnittstellen. Es werden die Schnittstellen und Anzahl der Vorkommen /// ermittelt und in die Liste geschrieben. /// </summary> /// <returns>Liste von PhysicalInterfaceWithCount</returns> private List<PhysicalInterfaceWithCount> BuildList() { PhysicalInterfaceDataAccess dataAccess = new PhysicalInterfaceDataAccess(); this.list = new List<PhysicalInterfaceWithCount>(); foreach (String interfaceName in this.usedList.Items) { bool foundEntity = false; for (int i = 0; i < list.Count; i++) { if (list[i].PhysicalInterface.Name.Equals(interfaceName)) { list[i].Number = list[i].Number + 1; foundEntity = true; } } if (!foundEntity) { PhysicalInterface physicalInterface = dataAccess.GetByName(interfaceName); list.Add(new PhysicalInterfaceWithCount(physicalInterface, 1)); } } return list; }
public void deletePhysicalInterfaceFromDatabase() { PhysicalInterfaceDataAccess dataAccess = new PhysicalInterfaceDataAccess(); PhysicalInterface physicalInterface = dataAccess.GetLastEntity<PhysicalInterface>(); dataAccess.Delete(physicalInterface.Id); Assert.IsTrue(dataAccess.GetLastEntity<PhysicalInterface>() == null || physicalInterface.Id == dataAccess.GetLastEntity<PhysicalInterface>().Id); }
/// <summary> /// Ruft die Informationen aus dem Formular ab und speichert sie in die Datenbank. /// Wirft eine Fehlermeldung, wenn die Validierung fehlschlägt. /// </summary> private void InterfaceSave_Click(object sender, RoutedEventArgs e) { PhysicalInterfaceDataAccess interfaceDataAccess = new PhysicalInterfaceDataAccess(); PhysicalInterfaceValidator validator = new PhysicalInterfaceValidator(); try { this.setEntityWithFormData(); if (!validator.CheckConsistency(this.entity)) { ErrorHandler.ShowErrorMessage("Validierung fehlgeschlagen", ErrorHandler.VALIDATION_FAILED); throw new FormatException(); } else { if (this.isAvailable) interfaceDataAccess.Update(this.entity); else interfaceDataAccess.Save(this.entity); this.Close(); } } catch (FormatException exception) { ErrorHandler.ShowErrorMessage(exception, ErrorHandler.WRONG_FORMAT); } catch (MySql.Data.MySqlClient.MySqlException exception) { ErrorHandler.ShowErrorMessage(exception, ErrorHandler.SAVE_WENT_WRONG); } catch (System.OverflowException exception) { ErrorHandler.ShowErrorMessage(exception, ErrorHandler.DATA_TOO_LONG); } }
/// <summary> /// Liest alle Beziehungen zu der Entität 'Schnittstelle' aus der Datenbank /// </summary> /// <param name="entity">Die Festplatte, zu welcher die Schnittstellen ermittelt werden</param> /// <returns>Liste von PhysicalInterfaceWithCount</returns> private List<PhysicalInterfaceWithCount> GetPhysicalInterfaces(Disk entity) { List<PhysicalInterfaceWithCount> physicalInterfaces = new List<PhysicalInterfaceWithCount>(); PhysicalInterfaceDataAccess physicalInterfaceDataAccess = new PhysicalInterfaceDataAccess(); MySqlConnection connection = this.CreateConnection(); MySqlCommand command = connection.CreateCommand(); command.CommandText = "SELECT * FROM `" + this.GetTableName() + "_schnittstelle` WHERE id_festplatte = " + entity.Id; connection.Open(); MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { PhysicalInterface physicalInterface = physicalInterfaceDataAccess.GetEntityById<PhysicalInterface>(Int32.Parse(reader.GetValue(1).ToString())); uint count = uint.Parse(reader.GetValue(2).ToString()); physicalInterfaces.Add(new PhysicalInterfaceWithCount(physicalInterface, count)); } return physicalInterfaces; }
public void getPhysicalInterfaceFromDatabase() { PhysicalInterfaceDataAccess dataAccess = new PhysicalInterfaceDataAccess(); PhysicalInterface physicalInterface = new PhysicalInterface(); physicalInterface.Name = "DVI"; physicalInterface.Description = "Digital Visual Interface - Eine elektronische Schnittstelle zur Übertragungn von Videodaten."; physicalInterface.Serial = true; physicalInterface.TransferRate = 10.4; dataAccess.Save(physicalInterface); PhysicalInterface dbPhysicalInterface = dataAccess.GetLastEntity<PhysicalInterface>(); Assert.AreEqual(physicalInterface.Description, dbPhysicalInterface.Description); }
public void getMotherboardFromDatabase() { MotherboardDataAccess dataAccess = new MotherboardDataAccess(); ProducerDataAccess producerDataAccess = new ProducerDataAccess(); PhysicalInterfaceDataAccess physicalInterfaceDataAccess = new PhysicalInterfaceDataAccess(); Motherboard motherboard = new Motherboard(); motherboard.Description = "Dies ist ein Test"; motherboard.Inch = 24.2; motherboard.Socket = "PGA 988B"; motherboard.Producer = producerDataAccess.GetLastEntity<Producer>(); motherboard.AddPhysicalInterface(new PhysicalInterfaceWithCount(physicalInterfaceDataAccess.GetLastEntity<PhysicalInterface>(), 3)); dataAccess.Save(motherboard); Motherboard dbMotherboard = dataAccess.GetLastEntity<Motherboard>(); Assert.AreEqual(motherboard.Socket, dbMotherboard.Socket); }
public void getMonitorFromDatabase() { MonitorDataAccess dataAccess = new MonitorDataAccess(); ProducerDataAccess producerDataAccess = new ProducerDataAccess(); PhysicalInterfaceDataAccess physicalInterfaceDataAccess = new PhysicalInterfaceDataAccess(); Monitor monitor = new Monitor(); monitor.Description = "Dies ist ein Test"; monitor.Resolution = "1280*800"; monitor.Inch = 24; monitor.AspectRatio = "16:9"; monitor.Producer = producerDataAccess.GetLastEntity<Producer>(); monitor.AddPhysicalInterface(new PhysicalInterfaceWithCount(physicalInterfaceDataAccess.GetLastEntity<PhysicalInterface>(), 3)); dataAccess.Save(monitor); Monitor dbMonitor = dataAccess.GetLastEntity<Monitor>(); Assert.AreEqual(monitor.Inch, dbMonitor.Inch); }
public void getGraphicCardFromDatabase() { GraphicCardDataAccess dataAccess = new GraphicCardDataAccess(); ProducerDataAccess producerDataAccess = new ProducerDataAccess(); PhysicalInterfaceDataAccess physicalInterfaceDataAccess = new PhysicalInterfaceDataAccess(); GraphicCard graphicCard = new GraphicCard(); graphicCard.Description = "Dies ist ein Test"; graphicCard.ClockRate = 5; graphicCard.Model = "GTX1234"; graphicCard.Memory = 2000; graphicCard.Producer = producerDataAccess.GetLastEntity<Producer>(); graphicCard.AddPhysicalInterface(new PhysicalInterfaceWithCount(physicalInterfaceDataAccess.GetLastEntity<PhysicalInterface>(), 3)); dataAccess.Save(graphicCard); GraphicCard dbGraphicCard = dataAccess.GetLastEntity<GraphicCard>(); Assert.AreEqual(graphicCard.Description, dbGraphicCard.Description); }
public void getDiskFromDatabase() { DiskDataAccess dataAccess = new DiskDataAccess(); ProducerDataAccess producerDataAccess = new ProducerDataAccess(); PhysicalInterfaceDataAccess physicalInterfaceDataAccess = new PhysicalInterfaceDataAccess(); Disk hdd = new Disk(); hdd.Description = "Dies ist ein Test"; hdd.Capacity = 1000; hdd.Ssd = false; hdd.Inch = 3.5; hdd.Producer = producerDataAccess.GetLastEntity<Producer>(); hdd.AddPhysicalInterface(new PhysicalInterfaceWithCount(physicalInterfaceDataAccess.GetLastEntity<PhysicalInterface>(), 3)); dataAccess.Save(hdd); Disk dbHDD = dataAccess.GetLastEntity<Disk>(); Assert.AreEqual(hdd.Capacity, dbHDD.Capacity); }
/// <summary> /// Mappt einen Datensatz aus der Datenbank auf ein Objekt vom Typ 'Monitor' /// </summary> /// <param name="reader">Der Datensatz, welcher gemappt wird</param> /// <returns>Monitor</returns> protected override object MapToEntity(MySqlDataReader reader) { Monitor monitor = new Monitor(); ProducerDataAccess producerDataAccess = new ProducerDataAccess(); PhysicalInterfaceDataAccess physicalInterfaceDataAccess = new PhysicalInterfaceDataAccess(); monitor.Id = Int32.Parse(reader.GetValue(0).ToString()); monitor.Description = reader.GetValue(1).ToString(); monitor.Resolution = reader.GetValue(2).ToString(); monitor.Inch = Double.Parse(reader.GetValue(3).ToString()); monitor.AspectRatio = reader.GetValue(4).ToString(); monitor.Producer = producerDataAccess.GetEntityById<Producer>(Int32.Parse(reader.GetValue(5).ToString())); monitor.PhysicalInterfaces = this.GetPhysicalInterfaces(monitor); return monitor; }
/// <summary> /// Füllt die Liste der verwendeten und nicht verwendeten Schnittstellen auf, damit diese auf /// der Oberfläche zu sehen sind. /// </summary> /// <param name="usedEntities"></param> private void FillLists(List<PhysicalInterfaceWithCount> usedEntities) { PhysicalInterfaceDataAccess dataAccess = new PhysicalInterfaceDataAccess(); List<PhysicalInterface> list = dataAccess.GetAllEntities<PhysicalInterface>(); for(int i = 0; i < list.Count; i++) { this.physicalInterfaceList.Items.Add(list[i].Name); } for(int i = 0; i < usedEntities.Count; i++) { for(int j = 0; j < usedEntities[i].Number; j++) { this.usedList.Items.Add(usedEntities[i].PhysicalInterface.Name); } } }