コード例 #1
0
        public void deleteMotherboardFromDatabase()
        {
            MotherboardDataAccess dataAccess = new MotherboardDataAccess();
            Motherboard motherboard = dataAccess.GetLastEntity<Motherboard>();

            dataAccess.Delete(motherboard.Id);

            Assert.IsTrue(dataAccess.GetLastEntity<Motherboard>() == null || motherboard.Id == dataAccess.GetLastEntity<Motherboard>().Id);
        }
コード例 #2
0
        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);
        }
        /// <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 MainboardSave_Click(object sender, RoutedEventArgs e)
        {
            ProducerDataAccess dataProducer = new ProducerDataAccess();
            MotherboardDataAccess diskDataAccess = new MotherboardDataAccess();
            MotherboardValidator validator = new MotherboardValidator();

            try
            {
                this.setEntityWithFormData(dataProducer);

                if (!validator.CheckConsistency(this.entity))
                {
                    ErrorHandler.ShowErrorMessage("Validierung fehlgeschlagen", ErrorHandler.VALIDATION_FAILED);
                }
                else
                {
                    if (this.isAvailable)
                        diskDataAccess.Update(this.entity);
                    else
                        diskDataAccess.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);
            }
        }