private void confirmButton_Click(object sender, System.EventArgs e) { // Load engines from the database using (AppDatabase db = new AppDatabase()) using (SQLiteTransaction trans = db.BeginTransaction()) { try { // Remove all truck engines in the database foreach (TruckEngine eng in Truck.TruckEngines) { db.TruckEngines.Remove(eng); } // Add all engines in the list foreach (ListViewItem item in engineListView2.Items) { Engine engine = item.Tag as Engine; TruckEngine truckEng = new TruckEngine() { Engine = engine, Truck = Truck }; db.TruckEngines.Add(truckEng); } trans.Commit(); } catch (Exception ex) { trans.Rollback(); // Tell the user about the failed validation error MessageBox.Show(ex.Message, "Database Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } } this.DialogResult = DialogResult.OK; }
static void Main(string[] args) { //Herencia Engine truckEngine = new TruckEngine(6); Utilities.WriteSpeed(truckEngine); Engine carEngine = CarEngineBuilder.WithCylinders(2).Build(); Utilities.WriteSpeed(carEngine); //Composicion ProtoEngine motorbikeEngine = new MotorbikeEngine(new HyperSpeedBehavior()); Utilities.WriteSpeed(motorbikeEngine); ProtoEngine busEngine = BusEngineBuilder.WithCylinders(4).WithSpeedUpBehavior(new PublicTransportSpeedBehavior()).Build(); Utilities.WriteSpeed(busEngine); busEngine.ChangeSpeedUpBehavior(new HyperSpeedBehavior()); Utilities.WriteSpeed(busEngine); Console.ReadKey(); }