mekasu0124

Untitled

Jan 8th, 2024
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.32 KB | None | 0 0
  1. public void CreateDatabase()
  2. {
  3.     using SQLiteConnection conn = new(_dbPath);
  4.     using SQLiteCommand createShiftsTable = conn.CreateCommand();
  5.     using SQLiteCommand createGasTable = conn.CreateCommand();
  6.     using SQLiteCommand createMaintenanceTable = conn.CreateCommand();
  7.  
  8.     conn.Open();
  9.  
  10.     createShiftsTable.CommandText = @"CREATE TABLE IF NOT EXISTS
  11.                                        [shifts] (
  12.                                        [Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  13.                                        [Date] VARCHAR(2048),
  14.                                        [StartTime] VARCHAR(2048),
  15.                                        [EndTime] VARCHAR(2048),
  16.                                        [StartMileage] INTEGER,
  17.                                        [EndMileage] INTEGER,
  18.                                        [Earnings] REAL)";
  19.  
  20.     createGasTable.CommandText = @"CREATE TABLE IF NOT EXISTS
  21.                                    [gas] (
  22.                                    [Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  23.                                    [Date] VARCHAR(2048),
  24.                                    [Amount] REAL,
  25.                                    [Location] VARCHAR(2048))";
  26.  
  27.     createMaintenanceTable.CommandText = @"CREATE TABLE IF NOT EXISTS
  28.                                            [maintenance] (
  29.                                            [Id] INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
  30.                                            [Date] VARCHAR(2048),
  31.                                            [Amount] REAL,
  32.                                            [Location] VARCHAR(2048),
  33.                                            [Notes] VARCHAR(2048))";
  34.  
  35.     try
  36.     {
  37.         createShiftsTable.ExecuteNonQuery();
  38.  
  39.         try
  40.         {
  41.             createGasTable.ExecuteNonQuery();
  42.  
  43.             try
  44.             {
  45.                 createMaintenanceTable.ExecuteNonQuery();
  46.             }
  47.             catch (Exception ex)
  48.             {
  49.                 ColorPrint.Write(ex.Message, ConsoleColor.Red);
  50.             }
  51.         }
  52.         catch (Exception ex)
  53.         {
  54.             ColorPrint.Write(ex.Message, ConsoleColor.Red);
  55.         }
  56.     }
  57.     catch (Exception ex)
  58.     {
  59.         ColorPrint.Write(ex.Message, ConsoleColor.Red);
  60.     }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment