|
| 1 | +using System; |
| 2 | +using Crayon; |
| 3 | +// Import Microsoft.Data.Sqlite namespaces |
| 4 | +using Microsoft.Data.Sqlite; |
| 5 | + |
| 6 | +namespace TheSystemNet |
| 7 | +{ |
| 8 | + class Program |
| 9 | + { |
| 10 | + public static void Main() |
| 11 | + { |
| 12 | + Console.Clear(); |
| 13 | + Console.WriteLine(" ... Startup Sequence ..."); |
| 14 | + |
| 15 | + Console.ForegroundColor = ConsoleColor.White; |
| 16 | + Console.BackgroundColor = ConsoleColor.DarkBlue; |
| 17 | + Console.WriteLine("Welcome to The System"); |
| 18 | + Console.ResetColor(); |
| 19 | + |
| 20 | + |
| 21 | + Console.WriteLine(Output.Red("System Initialisation in progress ...")); |
| 22 | + Console.ResetColor(); |
| 23 | + |
| 24 | + Console.WriteLine(Output.BrightBlue("Accessing Database ...")); |
| 25 | + |
| 26 | + // Setup and open database. This is created as a file in the same folder as the program if it doesn't exist |
| 27 | + SqliteConnection sqlite_conn; |
| 28 | + sqlite_conn = CreateConnection(); |
| 29 | + CreateTable(sqlite_conn); |
| 30 | + InsertData(sqlite_conn); |
| 31 | + ReadData(sqlite_conn); |
| 32 | + |
| 33 | + sqlite_conn.Close(); // Close the database connection. This cleans up all memory etc |
| 34 | + |
| 35 | + } |
| 36 | + static SqliteConnection CreateConnection() |
| 37 | + { |
| 38 | + |
| 39 | + SqliteConnection sqlite_conn; |
| 40 | + // Create a new database connection: |
| 41 | + sqlite_conn = new SqliteConnection("Data Source=TheSystem.db; "); |
| 42 | + // Open the connection: |
| 43 | + try |
| 44 | + { |
| 45 | + sqlite_conn.Open(); |
| 46 | + } |
| 47 | + catch (Exception ex) |
| 48 | + { |
| 49 | + |
| 50 | + } |
| 51 | + return sqlite_conn; |
| 52 | + } |
| 53 | + static void InsertData(SqliteConnection conn) |
| 54 | + { |
| 55 | + |
| 56 | + // Insert data into the Menu table |
| 57 | + |
| 58 | + SqliteCommand sqlite_cmd; |
| 59 | + sqlite_cmd = conn.CreateCommand(); |
| 60 | + |
| 61 | + |
| 62 | + sqlite_cmd.CommandText = "INSERT INTO menu (`menuid`, `parentid`, `sortid`, `url`, `name`, `desc`, `seclevel`) VALUES (1, 0, 0, 'index.php', 'Home', 'Return to the website''s home page', 0); "; |
| 63 | + sqlite_cmd.ExecuteNonQuery(); |
| 64 | + |
| 65 | + sqlite_cmd.CommandText = "INSERT INTO menu (`menuid`, `parentid`, `sortid`, `url`, `name`, `desc`, `seclevel`) VALUES (2, 0, 1, 'Search.php', 'Search', 'Search for what you need', 0); "; |
| 66 | + sqlite_cmd.ExecuteNonQuery(); |
| 67 | + |
| 68 | + sqlite_cmd.CommandText = "INSERT INTO menu (`menuid`, `parentid`, `sortid`, `url`, `name`, `desc`, `seclevel`) VALUES (3, 0, 2, '#', 'About This Site', 'All you ever wanted to know about this site', 0); "; |
| 69 | + sqlite_cmd.ExecuteNonQuery(); |
| 70 | + |
| 71 | + sqlite_cmd.CommandText = "INSERT INTO menu (`menuid`, `parentid`, `sortid`, `url`, `name`, `desc`, `seclevel`) VALUES (4, 3, 1, '#', 'FAQs', 'Frequently Asked Questions (and Frequently Questioned Answers)', 0), (5, 4, 1, 'Advertising_FAQ.php', 'FAQ for advertisers', 'The Important Stuff for advertisers.', 0), (6, 4, 2, 'User_FAQ.php', 'FAQ for users', 'Frequently Asked Questions (and Frequently Questioned Answers) for Users', 0), (7, 3, 3, 'Add_Stuff.php', 'Add Stuff', 'Add Some Stuff', 0), (8, 3, 4, 'Costs.php', 'Costs', 'What part of FREE didn''t you understand?', 0), (9, 8, 2, 'test1.php', 'Test 1', 'This is the first test', 0), (10, 8, 1, 'test2.php', 'Test 2', 'This is the second Test', 0), (11, 0, 10, '#', 'Admin', 'The Admin Area', 10),(12, 11, 1, '#', 'Reports', 'Various reports', 10), (13, 16, 2, '#', 'Edit a Record', 'Admin can edit a record''s content here', 10), (14, 12, 1, 'Admin_listall.php', 'List All ', 'List every little record that there is', 10), (15, 16, 2, 'Admin_Delete.php', 'Delete a Record', 'Be Careful. Once it''s gone, it''s gone!', 1), (16, 11, 2, '#', 'Manage Stuff', '', 10), (17, 11, 5, '#', 'Edit Menu', 'Edit the Actual menu Items', 0), (18, 17, 1, 'Admin_Edit_Menu.php', 'Edit Menu', 'Edit the Actual menu Items', 10), (19, 0, 0, 'https://sourceforge.net/projects/dynamicjqueryme/', 'SourceForge Project', 'Source Forge Project Page', 0), (20, 19, 1, 'https://sourceforge.net/projects/dynamicjqueryme/files/', 'Project Files', 'Project Files', 0), (21, 19, 2, 'https://sourceforge.net/projects/dynamicjqueryme/support', 'Support', 'Support Page', 0); "; |
| 72 | + sqlite_cmd.ExecuteNonQuery(); |
| 73 | + |
| 74 | + } |
| 75 | + static void CreateTable(SqliteConnection conn) |
| 76 | + { |
| 77 | + // Create menu table if it doesn't already exist |
| 78 | + SqliteCommand sqlite_cmd; |
| 79 | + string Createsql = "CREATE TABLE IF NOT EXISTS menu (menuid INTEGER PRIMARY KEY NOT NULL, parentid INTEGER NOT NULL default(0), sortid INTEGER NOT NULL default(0), url TEXT NOT NULL default('#'), name TEXT NOT NULL default('Unknown'), desc TEXT NOT NULL default('Unknown'), seclevel INTEGER NOT NULL default(0))"; |
| 80 | + // string Createsql1 = "CREATE TABLE SampleTable1 (Col1 VARCHAR(20), Col2 INT)"; |
| 81 | + sqlite_cmd = conn.CreateCommand(); |
| 82 | + |
| 83 | + sqlite_cmd.CommandText = "Drop Table menu;"; |
| 84 | + sqlite_cmd.ExecuteNonQuery(); |
| 85 | + |
| 86 | + |
| 87 | + sqlite_cmd.CommandText = Createsql; |
| 88 | + sqlite_cmd.ExecuteNonQuery(); |
| 89 | + // sqlite_cmd.CommandText = Createsql1; |
| 90 | + // sqlite_cmd.ExecuteNonQuery(); |
| 91 | + |
| 92 | + } |
| 93 | + static void ReadData(SqliteConnection conn) |
| 94 | + { |
| 95 | + |
| 96 | + // Select text from the Menu table |
| 97 | + |
| 98 | + // while (query.Read()) // Loop through the menu data and write out text from the fields |
| 99 | + // { |
| 100 | + // Console.WriteLine(query.GetString(0) + " = " + query.GetString(1) + " = " + query.GetString(2) + " = " + query.GetString(3) + " = " + query.GetString(4) + " = " + query.GetString(5));// First selected field is index 0 |
| 101 | + |
| 102 | + |
| 103 | + SqliteDataReader sqlite_datareader; |
| 104 | + SqliteCommand sqlite_cmd; |
| 105 | + sqlite_cmd = conn.CreateCommand(); |
| 106 | + sqlite_cmd.CommandText = "SELECT * FROM menu"; |
| 107 | + |
| 108 | + sqlite_datareader = sqlite_cmd.ExecuteReader(); |
| 109 | + while (sqlite_datareader.Read()) |
| 110 | + { |
| 111 | + string myreader = sqlite_datareader.GetString(0); |
| 112 | + Console.WriteLine(sqlite_datareader.GetString(0) + " = " + sqlite_datareader.GetString(1) + " = " + sqlite_datareader.GetString(2) + " = " + sqlite_datareader.GetString(3) + " = " + sqlite_datareader.GetString(4) + " = " + sqlite_datareader.GetString(5));// First selected field is index 0 |
| 113 | + |
| 114 | + // Console.WriteLine(myreader); |
| 115 | + } |
| 116 | + |
| 117 | + } |
| 118 | + } |
| 119 | +} |
0 commit comments