public static Users GetUserByLogin(string username) { Result result; string sql = ""; username = username.Replace("'", "\'"); sql = string.Format("SELECT Author_ID, Author_Name FROM Author WHERE Author_Name = '{0}'", username); try { result = SQLet.GetResult(sql); } catch (Microsoft.Data.SqlClient.SqlException e) { Logger.WriteToFile(e); return(null); } if (result.Count == 0) { return(null); } Users user = new Users(int.Parse(result[0]["Author_ID"]), result[0]["Author_Name"]); return(user); }
public static Users GetUser(int userID) { string sql = ""; sql = string.Format("SELECT Author_ID, Author_Name FROM Author WHERE Author_ID = '{0}'", userID); Result result = SQLet.GetResult(sql); if (result.Count == 0) { return(null); } Users user = new Users(int.Parse(result[0]["Author_ID"]), result[0]["Author_Name"]); return(user); }
public static List <Users> GetUsers() { List <Users> users = new List <Users>(); Result result = SQLet.GetResult("SELECT Author_ID, Author_Name FROM Author"); int number1 = 0; foreach (var row in result) { int.TryParse(row["Author_ID"], out number1); Users user = new Users(number1, row["Author_Name"]); users.Add(user); } return(users); }
public static void SelectAllAuthors() { string sql = @" SELECT * FROM Author ORDER BY Author_ID DESC"; string formatted = string.Format(sql); //Console.WriteLine(formatted); Result result = SQLet.GetResult(formatted); foreach (var record in result) { Console.WriteLine(record["Author_Name"]); } }
public static void SelectAllMessage() { string sql = @" SELECT * FROM Messages ORDER BY Message_ID DESC"; string formatted = string.Format(sql); //Console.WriteLine(formatted); Result result = SQLet.GetResult(formatted); foreach (var record in result) { Console.WriteLine(record["Message_ID"] + "\t" + record["Message_Text"] + "\t" + record["Message_Author_ID"] + "\t" + record["Message_Date"]); } }
static void Main(string[] args) { SQLet.ConnectSQLite("webshop.db"); Console.Write("Indtast kundens fornavn: "); string firstName = Console.ReadLine(); Console.Write("Indtast kundens efternavn: "); string lastName = Console.ReadLine(); Console.Write("Indtast kundens postnummer: "); string zipCode = Console.ReadLine(); string sql = $"INSERT INTO customer (firstName, lastName, zipcode) VALUES ('{firstName}', '{lastName}', {zipCode})"; SQLet.Execute(sql); PrintResults(SQLet.GetResult("SELECT * FROM customer")); }
public static List <Message> GetMessages() { List <Message> messages = new List <Message>(); Result result = SQLet.GetResult(@"SELECT * FROM Discard_Info"); int number = 0; foreach (var row in result) { int.TryParse(row["Message_Author_ID"], out number); //Parser tekseten Athor_ID om til et tal Message msg = new Message(row["Message_Text"], number); //Opretter en instans af message msg.Message_Date = DateTime.Parse(row["Message_Date"]); //Sætter Datoen på instansen til samme dato som fra databasen int.TryParse(row["Message_ID"], out number); //Parser teksten fra MessageId om til et tal og lægger det i number msg.Message_ID = number; //Putter tallet fra number over i MessageId på instansen // Sæt propertien Users til en bruger instans int.TryParse(row["Message_Author_ID"], out number); msg.User = new Users(number, row["Author_Name"]); //Tilføj instansen til listen messages.Add(msg); } return(messages); }