public void validateMonitor()
        {
            Monitor monitor = new Monitor();
            MonitorValidator validator = new MonitorValidator();

            monitor.Description = "Dies ist ein Test";
            monitor.Resolution = "1280*800";
            monitor.Inch = 24;
            monitor.AspectRatio = "16:9";

            Assert.AreEqual(true, validator.CheckConsistency(monitor));
        }
 /// <summary>
 /// Konstruktor: Setzt die Wert für die Initialisierung des Dialoges
 /// </summary>
 /// <param name="entity">Objekt eines Monitor</param>
 public CreateMonitor(Monitor entity = null)
 {
     InitializeComponent();
     this.GetProducers();
     if (entity != null)
     {
         this.entity = entity;
         this.isAvailable = true;
         this.SetAllFields();
     }
     else
     {
         this.entity = new Monitor();
         this.isAvailable = false;
     }
 }
        /// <summary>
        /// Verändert einen bestehenden Datensatz der Entität 'Monitor' in der Datenbank.
        /// Ermittelt auch nicht mehr genutzte Referenzen und löscht diese aus der Beziehungstabelle.
        /// </summary>
        /// <param name="entity">Die veränderte Entität</param>
        public void Update(Monitor entity)
        {
            MySqlConnection connection = this.CreateConnection();
            MySqlCommand command = connection.CreateCommand();
            MySqlCommand interfaceCommand = connection.CreateCommand();
            string usedInterfaces = "";

            command.CommandText = "UPDATE `" + this.GetTableName() + "` SET `Beschreibung`='" + entity.Description + "', `Auflösung`='" + entity.Resolution + "', `Zoll`='" + entity.Inch.ToString().Replace(',','.') + "', "
                                + "`Seitenverhältnis`='" + entity.AspectRatio + "', `ID_Hersteller`=" + entity.Producer.Id + " WHERE id = " + entity.Id;

            connection.Open();

            for (int i = 0; i < entity.PhysicalInterfaces.Count; i++)
            {
                if(this.IsInterfaceInUse(entity.PhysicalInterfaces[i].PhysicalInterface, entity)) {
                    interfaceCommand.CommandText = "UPDATE `" + this.GetTableName() + "_schnittstelle` SET `Anzahl`=" + entity.PhysicalInterfaces[i].Number
                                             + " WHERE `ID_Monitor` = " + entity.Id + " AND `ID_Schnittstelle` = " + entity.PhysicalInterfaces[i].PhysicalInterface.Id;
                } else {
                    interfaceCommand.CommandText = "INSERT INTO `" + this.GetTableName() + "_schnittstelle`(`ID_Monitor`, `ID_Schnittstelle`, `Anzahl`) "
                                                 + "VALUES (" + entity.Id + "," + entity.PhysicalInterfaces[i].PhysicalInterface.Id + ","
                                                 + entity.PhysicalInterfaces[i].Number + ")";
                }

                interfaceCommand.ExecuteNonQuery();
                usedInterfaces += entity.PhysicalInterfaces[i].PhysicalInterface.Id;
                if (i != entity.PhysicalInterfaces.Count - 1)
                {
                    usedInterfaces += ",";
                }
            }
            if (usedInterfaces.Length > 0)
            {
                interfaceCommand.CommandText = "DELETE FROM `" + this.GetTableName() + "_schnittstelle` WHERE `ID_Monitor` = " + entity.Id
                                             + " AND `ID_Schnittstelle` NOT IN (" + usedInterfaces + ")";
            }
            else
            {
                interfaceCommand.CommandText = "DELETE FROM `" + this.GetTableName() + "_schnittstelle` WHERE `ID_Monitor` = " + entity.Id;
            }
            interfaceCommand.ExecuteNonQuery();
            command.ExecuteNonQuery();
            connection.Close();
        }
        /// <summary>
        /// Speichert ein Objekt der Entität 'Monitor' in der Datenbank
        /// </summary>
        /// <param name="entity">Das Objekt, welches gespeichert wird</param>
        public void Save(Monitor entity)
        {
            MySqlConnection connection = this.CreateConnection();
            MySqlCommand command = connection.CreateCommand();

            command.CommandText = "INSERT INTO `" + this.GetTableName() + "`(`Beschreibung`, `Auflösung`, `Zoll`, `Seitenverhältnis`, "
                                + "`ID_Hersteller`) VALUES ('" + entity.Description + "','" + entity.Resolution + "','" + entity.Inch.ToString().Replace(',','.') + "',"
                                + "'" + entity.AspectRatio + "'," + entity.Producer.Id + ")";

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();

            for (int i = 0; i < entity.PhysicalInterfaces.Count; i++)
            {
                command.CommandText = "INSERT INTO `" + this.GetTableName() + "_schnittstelle`(`ID_Monitor`, `ID_Schnittstelle`, `Anzahl`) "
                                    + "VALUES (" + this.GetLastEntity<Monitor>().Id + "," + entity.PhysicalInterfaces[i].PhysicalInterface.Id + ","
                                    + entity.PhysicalInterfaces[i].Number + ")";
                connection.Open();
                command.ExecuteNonQuery();
                connection.Close();
            }
        }
        /// <summary>
        /// Prüft die Konsistenz der Attribute der Entität 'Monitor'
        /// </summary>
        /// <param name="entity">Das Objekt, welches geprüft wird</param>
        /// <returns>true: Objekt Konsistent, false: Objekt fehlerhaft</returns>
        public bool CheckConsistency(Monitor entity)
        {
            bool result = true;
            Regex resolutionReg = new Regex(this.resolutionPattern);
            Regex aspectRatioReg = new Regex(this.aspectRatioPattern);

            if(!resolutionReg.Match(entity.Resolution).Success)
            {
                result = false;
            }

            if(entity.Inch <= 0)
            {
                result = false;
            }

            if(!aspectRatioReg.Match(entity.AspectRatio).Success)
            {
                result = false;
            }

            return result;
        }
        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);
        }
        /// <summary>
        /// Prüft, ob ein Interface bereits der Entität zugewiesen ist
        /// </summary>
        /// <param name="physicalInterface">Die Schnittstelle auf welche geprüft wird</param>
        /// <param name="entity">Die Entität, welche geprüft wird</param>
        /// <returns>true, wenn eine Schnittstelle zugewiesen wurde</returns>
        private bool IsInterfaceInUse(PhysicalInterface physicalInterface, Monitor entity)
        {
            MySqlConnection connection = this.CreateConnection();
            MySqlCommand command = connection.CreateCommand();
            bool result;

            connection.Open();
            command.CommandText = "SELECT * FROM `" + this.GetTableName() + "_schnittstelle` WHERE `ID_Monitor` = " + entity.Id
                                + " AND `ID_Schnittstelle` = " + physicalInterface.Id;
            result = command.ExecuteReader().HasRows;
            connection.Close();

            return result;
        }
        /// <summary>
        /// Liest alle Beziehungen zu der Entität 'Schnittstelle' aus der Datenbank
        /// </summary>
        /// <param name="entity">Der Monitor, zu welchem die Schnittstellen ermittelt werden</param>
        /// <returns>Liste von PhysicalInterfaceWithCount</returns>
        private List<PhysicalInterfaceWithCount> GetPhysicalInterfaces(Monitor 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_monitor = " + 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;
        }
        /// <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>
 /// Wandelt ein Objekt der Entität 'Monitor' in eine grafisches Objekt.
 /// Übersetzt englische Begriffe und zählt alle Schnittstellen in einer Liste auf.
 /// </summary>
 /// <param name="entity">Objekt vom Typ 'Monitor'</param>
 public void MapFromEntity(Monitor entity)
 {
     this.Id = entity.Id;
     this.Beschreibung = entity.Description;
     this.Auflösung = entity.Resolution;
     this.Zoll = entity.Inch;
     this.Seitenverhältnis = entity.AspectRatio;
     this.Hersteller = entity.Producer.CompanyName;
     string schnittstellen = "";
     for (int i = 0; i < entity.PhysicalInterfaces.Count; i++)
     {
         if (i > 0)
             schnittstellen += ", ";
         schnittstellen += entity.PhysicalInterfaces[i].PhysicalInterface.Name;
         schnittstellen += " (" + entity.PhysicalInterfaces[i].Number + ")";
     }
     this.Schnittstellen = schnittstellen;
 }