97 lines
3.2 KiB
C#
97 lines
3.2 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.SQLite;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
namespace Simpsons_generator;
|
|
|
|
class Program
|
|
{
|
|
public static readonly string root_path = "C:\\Users\\pgeeraert\\OneDrive - Prometheus Group\\Documents\\Code\\SQLLITE\\";
|
|
public static readonly string folder_path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Simpsons_generator");
|
|
public static readonly string overrideBrowser = Path.Combine(folder_path, "overrideBrowser.xml");
|
|
static SQLiteConnection CreateConnection()
|
|
{
|
|
|
|
SQLiteConnection sqliteconn;
|
|
// Create a new database connection:
|
|
var sqllite_datasource = $"Data Source={folder_path}/database.db;Version=3;New=True;Compress=True;";
|
|
sqliteconn = new SQLiteConnection(sqllite_datasource);
|
|
// Open the connection:
|
|
try
|
|
{
|
|
sqliteconn.Open();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
return sqliteconn;
|
|
}
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
SQLiteConnection sqliteconn;
|
|
sqliteconn = CreateConnection();
|
|
//CreateTableSimpsons(sqliteconn);
|
|
//InsertDataSimpsons(sqliteconn);
|
|
//readexcel(Path.Combine(root_path, "simpsons-episodes-list.xlsx"));
|
|
ReadData(sqliteconn);
|
|
}
|
|
|
|
static void readexcel(string filePath)
|
|
{
|
|
var linesRead = File.ReadLines(filePath);
|
|
|
|
// iterate through each element within the array and
|
|
// print it out
|
|
//
|
|
foreach (var lineRead in linesRead)
|
|
{
|
|
Console.WriteLine(lineRead);
|
|
}
|
|
}
|
|
|
|
static void CreateTableSimpsons(SQLiteConnection conn)
|
|
{
|
|
|
|
SQLiteCommand sqlite_cmd;
|
|
string Createsql = "CREATE TABLE episodes(season int(3), episode INT(3),url VARCHAR(100),seen INT(1))";
|
|
sqlite_cmd = conn.CreateCommand();
|
|
sqlite_cmd.CommandText = Createsql;
|
|
sqlite_cmd.ExecuteNonQuery();
|
|
|
|
}
|
|
static void InsertDataSimpsons(SQLiteConnection conn)
|
|
{
|
|
SQLiteCommand sqlite_cmd;
|
|
sqlite_cmd = conn.CreateCommand();
|
|
sqlite_cmd.CommandText = "INSERT INTO episodes(season, episode,url,seen) VALUES (1,1,'https://kisscartoon.sh/Cartoon/The-Simpsons-Season-01.47729/Episode-001?id=1072', 0);";
|
|
sqlite_cmd.ExecuteNonQuery();
|
|
}
|
|
|
|
|
|
static void ReadData(SQLiteConnection conn)
|
|
{
|
|
SQLiteDataReader sqlite_datareader;
|
|
SQLiteCommand sqlite_cmd;
|
|
sqlite_cmd = conn.CreateCommand();
|
|
sqlite_cmd.CommandText = "SELECT * FROM episodes";
|
|
|
|
sqlite_datareader = sqlite_cmd.ExecuteReader();
|
|
while (sqlite_datareader.Read())
|
|
{
|
|
int season = Convert.ToInt32(sqlite_datareader["season"]);
|
|
int episode = Convert.ToInt32(sqlite_datareader["episode"]);
|
|
string url = sqlite_datareader["url"].ToString();
|
|
string seen = sqlite_datareader["seen"].ToString();
|
|
|
|
Console.WriteLine($"{season}, {episode}, {url}, {seen}");
|
|
}
|
|
conn.Close();
|
|
}
|
|
|
|
} |