Пример #1
0
        public Plant Insert(Plant entity)
        {
            using (SQLiteConnection connection = db.Connection)
            {
                string query = @"INSERT INTO Plant 	VALUES (null, :naam, :plant_grootte_id, :zaailing, :verplant, :opmerking, :voorraad)";
                using (SQLiteCommand command = new SQLiteCommand(query, connection))
                {
                    command.Parameters.AddWithValue("naam", entity.Naam);
                    command.Parameters.AddWithValue("plant_grootte_id", ConvertPlantGrootte.GetPlantGrootteId(entity.PlantGrootte));
                    command.Parameters.AddWithValue("zaailing", entity.Zaailing);
                    command.Parameters.AddWithValue("verplant", entity.Verplant);
                    command.Parameters.AddWithValue("opmerking", entity.Opmerking);
                    command.Parameters.AddWithValue("voorraad", entity.Voorraad);
                    try
                    {
                        //command.ExecuteNonQuery();
                        command.ExecuteScalar(System.Data.CommandBehavior.KeyInfo);
                        entity.Id = db.getLastInsertedId(connection);
                        return(entity);
                    }
                    catch (SQLiteException e)
                    {
                        // If a PK constraint was violated, handle the exception
                        if (e.ResultCode == SQLiteErrorCode.Constraint)
                        {
                            return(entity);
                        }

                        // Unexpected error: rethrow to let the caller handle it
                        throw;
                    }
                }
            }
        }
Пример #2
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (validateFields())
     {
         Plant.Naam         = txtNaam.Text;
         Plant.Opmerking    = txtOpmerking.Text;
         Plant.PlantGrootte = ConvertPlantGrootte.Convert(Convert.ToInt32(nudMinHoogte.Value), Convert.ToInt32(nudMaxHoogte.Value));
         Plant.Zaailing     = Convert.ToInt32(nudJaarling.Value);
         Plant.Verplant     = Convert.ToInt32(nudVerplant.Value);
         Plant.Voorraad     = Convert.ToInt32(nudAantal.Value);
         DialogResult       = DialogResult.OK;
     }
 }
Пример #3
0
        private void PlantAddEdit_Load(object sender, EventArgs e)
        {
            Text = Plant.Naam + " bewerken";
            if (Plant.Naam == null)
            {
                Text = "Nieuwe plant";
            }

            txtNaam.Text      = Plant.Naam;
            txtOpmerking.Text = Plant.Opmerking;
            nudAantal.Value   = Plant.Voorraad;

            int[] plantGrootte = ConvertPlantGrootte.Convert(Plant.PlantGrootte);

            nudMinHoogte.Value = Plant.MinHoogte();
            nudMaxHoogte.Value = Plant.MaxHoogte();

            nudJaarling.Value = Plant.Zaailing;
            nudVerplant.Value = Plant.Verplant;
        }
Пример #4
0
        public bool Update(Plant entity)
        {
            using (SQLiteConnection connection = db.Connection)
            {
                string query = string.Format(@"UPDATE Plant
								SET naam=:naam,plant_grootte_id=:plant_grootte_id,zaailing=:zaailing,verplant=:verplant,opmerking=:opmerking,voorraad=:voorraad
								WHERE id = {0};"                                , entity.Id);
                using (SQLiteCommand command = new SQLiteCommand(query, connection))
                {
                    command.Parameters.AddWithValue("naam", entity.Naam);
                    command.Parameters.AddWithValue("plant_grootte_id", ConvertPlantGrootte.GetPlantGrootteId(entity.PlantGrootte));
                    command.Parameters.AddWithValue("zaailing", entity.Zaailing);
                    command.Parameters.AddWithValue("verplant", entity.Verplant);
                    command.Parameters.AddWithValue("opmerking", entity.Opmerking);
                    command.Parameters.AddWithValue("voorraad", entity.Voorraad);
                    try
                    {
                        //command.ExecuteNonQuery();
                        var key = command.ExecuteScalar(System.Data.CommandBehavior.KeyInfo);

                        return(true);
                    }
                    catch (SQLiteException e)
                    {
                        // If a PK constraint was violated, handle the exception
                        if (e.ResultCode == SQLiteErrorCode.Constraint)
                        {
                            return(false);
                        }

                        // Unexpected error: rethrow to let the caller handle it
                        throw;
                    }
                }
            }
        }
 public void TestGetPlantGrootteId()
 {
     Assert.AreEqual(1, ConvertPlantGrootte.GetPlantGrootteId(Plant.Grootte.G0020));
     Assert.AreEqual(2, ConvertPlantGrootte.GetPlantGrootteId(Plant.Grootte.G2040));
     Assert.AreEqual(3, ConvertPlantGrootte.GetPlantGrootteId(Plant.Grootte.G4060));
 }
 public void TestNumbersToEnum()
 {
     Plant.Grootte plantGrootte = ConvertPlantGrootte.Convert(120, 140);
     Assert.AreEqual(Plant.Grootte.G120140, plantGrootte);
 }
 public void TestEumToNumbers()
 {
     int[] plantGrootte = ConvertPlantGrootte.Convert(Plant.Grootte.G120140);
     Assert.AreEqual(120, plantGrootte[0]);
     Assert.AreEqual(140, plantGrootte[1]);
 }
Пример #8
0
 public int MaxHoogte()
 {
     return(ConvertPlantGrootte.Convert(PlantGrootte)[1]);
 }
Пример #9
0
 public int MinHoogte()
 {
     return(ConvertPlantGrootte.Convert(PlantGrootte)[0]);
 }