/// <summary> /// Update the db from json /// </summary> /// <param name="list"> List of vehicle </param> /// <param name="connStr"> String of connection </param> public void UpdateDb(SerializableBindingList <Vehicles> list, string connStr) { if (connStr != null) { OleDbConnection con = new OleDbConnection(connStr); using (con) { con.Open(); dbUtilities.DropTable("Auto"); dbUtilities.DropTable("Moto"); dbUtilities.CreateTable("Auto"); dbUtilities.CreateTable("Moto"); OleDbCommand cmd = new OleDbCommand(); cmd.Connection = con; for (int i = 0; i < list.Count; i++) { if (list[i] is Cars) { dbUtilities.AddNewItem("Auto", list[i].Brand, list[i].Model, list[i].Color, list[i].Displacement, list[i].PowerKw, list[i].Matriculation, list[i].IsUsed, list[i].IsKm0, list[i].KmDone, list[i].Price, (list[i] as Cars).NumAirbag, "", list[i].Img); } else { dbUtilities.AddNewItem("Moto", list[i].Brand, list[i].Model, list[i].Color, list[i].Displacement, list[i].PowerKw, list[i].Matriculation, list[i].IsUsed, list[i].IsKm0, list[i].KmDone, list[i].Price, 0, (list[i] as Motorbikes).SaddleBrand, list[i].Img); } } } } }
static void Main(string[] args) { #region Main char choice; do { menu(); Console.Write("DIGIT YOUR CHOICE "); choice = Console.ReadKey().KeyChar; switch (choice) { case '1': table = vehicle(); if (table != "x") { dbUtilities.CreateTable(table); Console.WriteLine("\nTable created"); Thread.Sleep(3000); } break; case '2': table = vehicle(); if (table != "x") { takeParameters(); dbUtilities.AddNewItem(table, brand, model, color, displacement, powerKw, matriculation, isUsed, isKm0, kmDone, price, numAirbag, saddleBrand); Console.WriteLine("\nNew item added corectly"); Thread.Sleep(3000); } break; case '3': table = vehicle(); if (table != "x") { dbUtilities.ListTable(table); } break; case '4': table = vehicle(); if (table != "x") { id = takeId(table); takeParameters(); dbUtilities.Update(table, id, brand, model, color, displacement, powerKw, matriculation, isUsed, isKm0, kmDone, price, numAirbag, saddleBrand); id = 0; Console.WriteLine($"\nTable {table} updated"); Thread.Sleep(3000); } break; case '5': table = vehicle(); if (table != "x") { id = takeId(table); dbUtilities.Delete(table, id); id = 0; Console.WriteLine("\nItem removed corectly"); Thread.Sleep(3000); } break; case '6': table = vehicle(); if (table != "x") { dbUtilities.DropTable(table); Console.WriteLine($"\nTable {table} removed"); Thread.Sleep(3000); } break; case '7': dbUtilities.CreateBackup(dbFilePath); Console.WriteLine($"\nBackup created"); Thread.Sleep(3000); break; case '8': dbUtilities.RestoresBackup(dbFilePath); Console.WriteLine($"\nBackup restored"); Thread.Sleep(3000); break; default: break; } }while (choice != 'X' && choice != 'x'); #endregion }