/// <summary>
        /// Speichert ein Objekt der Entität 'Hersteller' in der Datenbank
        /// </summary>
        /// <param name="entity">Das Objekt, welches gespeichert wird</param>
        public void Save(Producer entity)
        {
            MySqlConnection connection = this.CreateConnection();
            MySqlCommand command = connection.CreateCommand();
            command.CommandText = "INSERT INTO `" + this.GetTableName() + "`(`Firma`, `Telefon`, `Email`, `Webseite`, `PLZ`, `Ort`, `Straße`, `Hausnummer`) "
                                + "VALUES ('" + entity.CompanyName + "','" + entity.PhoneNumber + "','" + entity.Email + "',"
                                + "'" + entity.Website + "'," + entity.PostalCode + ",'" + entity.Place + "','" + entity.Street + "'," + entity.HouseNumber + ")";

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        /// <summary>
        /// Verändert einen bestehenden Datensatz der Entität 'Hersteller' 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(Producer entity)
        {
            MySqlConnection connection = this.CreateConnection();
            MySqlCommand command = connection.CreateCommand();

            command.CommandText = "UPDATE `" + this.GetTableName() + "` SET `Firma`='" + entity.CompanyName + "', `Telefon`='" + entity.PhoneNumber + "', `Email`='" + entity.Email
                                + "', `Webseite`='" + entity.Website + "', `PLZ`=" + entity.PostalCode + ", `Ort`='" + entity.Place + "', `Straße`='" + entity.Street
                                + "', `Hausnummer`=" + entity.HouseNumber + " WHERE id = " + entity.Id;

            connection.Open();
            command.ExecuteNonQuery();
            connection.Close();
        }
        /// <summary>
        /// Prüft die Konsistenz der Attribute der Entität 'Hersteller'
        /// </summary>
        /// <param name="entity">Das Objekt, welches geprüft wird</param>
        /// <returns>true: Objekt Konsistent, false: Objekt fehlerhaft</returns>
        public bool CheckConsistency(Producer entity)
        {
            bool result = true;
            Regex emailReg = new Regex(this.emailPattern, RegexOptions.IgnoreCase);
            Regex websiteReg = new Regex(this.websitePattern, RegexOptions.IgnoreCase);
            Regex placeReg = new Regex(this.placePattern);
            Regex phoneReg = new Regex(this.phonePattern);

            if(entity.CompanyName.Length == 0)
            {
                result = false;
            }

            if(!phoneReg.Match(entity.PhoneNumber).Success)
            {
                result = false;
            }

            if(!emailReg.Match(entity.Email).Success)
            {
                result = false;
            }

            if(!websiteReg.Match(entity.Website).Success)
            {
                result = false;
            }

            if(entity.PostalCode > 99999999 || entity.PostalCode <= 999)
            {
                result = false;
            }

            if(!placeReg.Match(entity.Place).Success)
            {
                result = false;
            }

            if(entity.Street.Length == 0)
            {
                result = false;
            }

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

            return result;
        }
 /// <summary>
 /// Konstruktor: Setzt die Wert für die Initialisierung des Dialoges
 /// </summary>
 /// <param name="entity">Objekt eines Herstellers</param>
 public CreateProducer(Producer entity = null)
 {
     InitializeComponent();
     if (entity != null)
     {
         this.entity = entity;
         this.isAvailable = true;
         this.SetAllFields();
     }
     else
     {
         this.entity = new Producer();
         this.isAvailable = false;
     }
 }
        /// <summary>
        /// Mappt einen Datensatz aus der Datenbank auf ein Objekt vom Typ 'Hersteller'
        /// </summary>
        /// <param name="reader">Der Datensatz, welcher gemappt wird</param>
        /// <returns>Producer</returns>
        protected override object MapToEntity(MySqlDataReader reader)
        {
            Producer producer = new Producer();

            producer.Id = Int32.Parse(reader.GetValue(0).ToString());
            producer.CompanyName = reader.GetValue(1).ToString();
            producer.PhoneNumber = reader.GetValue(2).ToString();
            producer.Email = reader.GetValue(3).ToString();
            producer.Website = reader.GetValue(4).ToString();
            producer.PostalCode = uint.Parse(reader.GetValue(5).ToString());
            producer.Place = reader.GetValue(6).ToString();
            producer.Street = reader.GetValue(7).ToString();
            producer.HouseNumber = uint.Parse(reader.GetValue(8).ToString());

            return producer;
        }
        public void getProducerFromDatabase()
        {
            ProducerDataAccess dataAccess = new ProducerDataAccess();
            Producer producer = new Producer();

            producer.CompanyName = "Siemens";
            producer.PhoneNumber = "123456";
            producer.Email = "*****@*****.**";
            producer.Website = "www.siemens.de";
            producer.PostalCode = 21335;
            producer.Place = "Lüneburg";
            producer.Street = "Lüneburger Straße";
            producer.HouseNumber = 1;

            dataAccess.Save(producer);
            Producer dbProducer = dataAccess.GetLastEntity<Producer>();

            Assert.AreEqual(producer.Website, dbProducer.Website);
        }
        public void validateProducer()
        {
            Producer producer = new Producer();
            ProducerValidator validator = new ProducerValidator();

            producer.CompanyName = "Siemens";
            producer.PhoneNumber = "123456";
            producer.Email = "*****@*****.**";
            producer.Website = "http://siemens.de";
            producer.PostalCode = 21335;
            producer.Place = "Lüneburg";
            producer.Street = "Lüneburger Straße";
            producer.HouseNumber = 1;

            Assert.AreEqual(false, validator.CheckConsistency(producer));
        }