コード例 #1
0
        public static void SaveGlider(GliderModel glider)
        {
            string SqliteCmd = "insert into Glider (Brand, Model, EnCertification) values('"
                               + glider.Brand + "' , '"
                               + glider.Model + "' , '"
                               + glider.EnCertification + "')";

            using var connection = new SQLiteConnection(LoadConnectionString());
            connection.Open();
            using var cmd = new SQLiteCommand(SqliteCmd, connection);
            cmd.ExecuteNonQuery();
        }
コード例 #2
0
        public static int LoadLastSavedGlider()
        {
            string SqliteCmd = "SELECT GliderID, Brand, Model, EnCertification FROM Glider WHERE GliderID = (SELECT MAX(GliderID) FROM Glider)";

            using var connection = new SQLiteConnection(LoadConnectionString());
            connection.Open();
            using var cmd = new SQLiteCommand(SqliteCmd, connection);
            using SQLiteDataReader reader = cmd.ExecuteReader();
            reader.Read();
            GliderModel LastGlider = new GliderModel(reader.GetInt32(0),
                                                     reader.GetString(1),
                                                     reader.GetString(2),
                                                     reader.GetInt32(3));

            return(LastGlider.GliderID);
        }
コード例 #3
0
        public static int AddNewGlider()
        {
            Console.WriteLine("What is the brand of the new glider?");
            string Brand = Console.ReadLine();

            Console.WriteLine("What is the model of the new glider?");
            string Model = Console.ReadLine();

            Console.WriteLine("What is the EN certifcation of the new glider? [0 = not certified, 1 = A, 2 = B, 3 = C, 4 = D or 5 = CCC]");
            string answer = Console.ReadLine();
            int    EnCertification;

            while (!Int32.TryParse(answer, out EnCertification))
            {
                Console.WriteLine("EN Certification must be one of the following: [0 = not certified, 1 = A, 2 = B, 3 = C, 4 = D or 5 = CCC]");
                answer = Console.ReadLine();
            }
            GliderModel NewGlider = new GliderModel(0, Brand, Model, EnCertification);

            SqliteDataAccess.SaveGlider(NewGlider);
            int NewGliderID = SqliteDataAccess.LoadLastSavedGlider();

            return(NewGliderID);
        }