/// <summary> /// Prüft die Konsistenz der Attribute der Entität 'Prozessor' /// </summary> /// <param name="entity">Das Objekt, welches geprüft wird</param> /// <returns>true: Objekt Konsistent, false: Objekt fehlerhaft</returns> public bool CheckConsistency(Processor entity) { bool result = true; Regex modelReg = new Regex(this.modelPattern); Regex commandSetReg = new Regex(this.commandSetPattern); if(!modelReg.Match(entity.Model).Success) { result = false; } if (entity.Core == 0) { result = false; } if(!commandSetReg.Match(entity.CommandSet).Success) { result = false; } if (entity.Architecture == 0) { result = false; } if(entity.ClockRate <= 0) { result = false; } return result; }
/// <summary> /// Verändert einen bestehenden Datensatz der Entität 'Prozessor' in der Datenbank. /// </summary> /// <param name="entity">Die veränderte Entität</param> public void Update(Processor entity) { MySqlConnection connection = this.CreateConnection(); MySqlCommand command = connection.CreateCommand(); command.CommandText = "UPDATE `" + this.GetTableName() + "` SET `Beschreibung`='" + entity.Description + "', `Modell`='" + entity.Model + "', `Kerne`=" + entity.Core + ", `Befehlssatz`='" + entity.CommandSet + "', `Architektur`=" + entity.Architecture + ", `Taktrate`='" + entity.ClockRate.ToString().Replace(',','.') + "', `ID_Hersteller`=" + entity.Producer.Id + " WHERE id = " + entity.Id; connection.Open(); command.ExecuteNonQuery(); connection.Close(); }
/// <summary> /// Speichert ein Objekt der Entität 'Prozessor' in der Datenbank /// </summary> /// <param name="entity">Das Objekt, welches gespeichert wird</param> public void Save(Processor entity) { MySqlConnection connection = this.CreateConnection(); MySqlCommand command = connection.CreateCommand(); command.CommandText = "INSERT INTO `" + this.GetTableName() + "`(`Beschreibung`, `Modell`, `Kerne`, `Befehlssatz`, `Architektur`, `Taktrate`, " + "`ID_Hersteller`) VALUES ('" + entity.Description + "','" + entity.Model + "'," + entity.Core + ",'" + entity.CommandSet + "'," + entity.Architecture + ",'" + entity.ClockRate.ToString().Replace(',','.') + "'," + entity.Producer.Id + ")"; connection.Open(); command.ExecuteNonQuery(); connection.Close(); }
public void validateProcessor() { Processor processor = new Processor(); ProcessorValidator validator = new ProcessorValidator(); processor.Description = "Dies ist ein Test"; processor.Model = "i5"; processor.Core = 6; processor.CommandSet = "RISCC!"; processor.Architecture = 64; processor.ClockRate = 3.40; Assert.AreEqual(false, validator.CheckConsistency(processor)); }
/// <summary> /// Konstruktor: Setzt die Wert für die Initialisierung des Dialoges /// </summary> /// <param name="entity">Objekt eines Prozessors</param> public CreateProcessor(Processor entity = null) { InitializeComponent(); this.GetProducers(); if (entity != null) { this.entity = entity; this.isAvailable = true; this.SetAllFields(); } else { this.entity = new Processor(); this.isAvailable = false; } }
/// <summary> /// Mappt einen Datensatz aus der Datenbank auf ein Objekt vom Typ 'Prozessor' /// </summary> /// <param name="reader">Der Datensatz, welcher gemappt wird</param> /// <returns>Processor</returns> protected override object MapToEntity(MySqlDataReader reader) { Processor processor = new Processor(); ProducerDataAccess producerDataAccess = new ProducerDataAccess(); processor.Id = Int32.Parse(reader.GetValue(0).ToString()); processor.Description = reader.GetValue(1).ToString(); processor.Model = reader.GetValue(2).ToString(); processor.Core = uint.Parse(reader.GetValue(3).ToString()); processor.CommandSet = reader.GetValue(4).ToString(); processor.Architecture = uint.Parse(reader.GetValue(5).ToString()); processor.ClockRate = Double.Parse(reader.GetValue(6).ToString()); processor.Producer = producerDataAccess.GetEntityById<Producer>(Int32.Parse(reader.GetValue(7).ToString())); return processor; }
public void getProcessorFromDatabase() { ProcessorDataAccess dataAccess = new ProcessorDataAccess(); ProducerDataAccess producerDataAccess = new ProducerDataAccess(); Processor processor = new Processor(); processor.Description = "Dies ist ein Test"; processor.Model = "i5"; processor.Core = 4; processor.CommandSet = "RISC"; processor.Architecture = 64; processor.ClockRate = 3.40; processor.Producer = producerDataAccess.GetLastEntity<Producer>(); dataAccess.Save(processor); Processor dbProcessor = dataAccess.GetLastEntity<Processor>(); Assert.AreEqual(processor.CommandSet, dbProcessor.CommandSet); }