Skip to content

Instantly share code, notes, and snippets.

View wtuts's full-sized avatar

Windows App Tutorials wtuts

View GitHub Profile
@wtuts
wtuts / Fetch.cs
Last active January 9, 2016 18:57
public static ObservableCollection<Schema.Students> GetAllStudents()
{
SQLiteConnection connection;
using (connection = new SQLiteConnection(DbPath))
{
var myCollection = connection.Table<Schema.Students>().ToList<Schema.Students>();
var studentsList = new ObservableCollection<Schema.Students>(myCollection);
return studentsList;
}
}
public static bool DeleteStudent(int id)
{
SQLiteConnection connection;
using (connection = new SQLiteConnection(DbPath))
{
var existingstudent =
connection.Query<Schema.Students>("select * from Students where Id =" + id).FirstOrDefault();
connection.RunInTransaction(() =>
{
connection.Delete(existingstudent);
public static void UpdateStudent(int id,int newmarks)
{
SQLiteConnection connection;
using (connection = new SQLiteConnection(DbPath))
{
var existingstudent =
connection.Query<Schema.Students>("select * from Students where Id =" + id).FirstOrDefault();
if (existingstudent != null)
{
existingstudent.Marks = newmarks;
public static void AddNewStudent(Schema.Students obj)
{
SQLiteConnection connection;
using (connection = new SQLiteConnection(DbPath))
{
connection.RunInTransaction(() =>
{
connection.Insert(obj);
});
}
public static async Task<bool> DeleteDatabase()
{
try
{
var storageFile = await StorageFile.GetFileFromPathAsync(DbPath);
await storageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
return true;
}
catch (Exception ex)
{
//Database name
public static string DbName = "Records.sqlite";
//Full Database Path
public static string DbPath = Path.Combine(ApplicationData.Current.LocalFolder.Path, DbName);
public async static Task<bool> Createdatabase()
{
var result = await Checkdatabase();
if (!result)
class Schema
{
public class Students
{
[PrimaryKey, AutoIncrement]
public int Id { get; set; }
public string Name { get; set; }
public int Marks { get; set; }
@wtuts
wtuts / AlphabetToColorConverter.cs
Created November 4, 2015 07:12
Alphabet to color converter
public class AlphabetToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string culture)
{
string[] colors= { "#7998f3", "#bbf379", "#f379df", "#79f3e3", "#f3bf79", "#9c79f3", "#7af379", "#f3799d", "#79c1f3", "#e4f379", "#f37e79", "#de79f3", "#79f3ba", "#f39779", "#797ff3", "#a2f379", "#f379c6", "#79e9f3", "#f3d979", "#b579f3", "#79f392", "#f37984", "#79a8f3", "#cbf379", "#f379ee", "#79f3d3" };
string input = (string) value;
char initialCharacter = input.ToLower().ToCharArray()[0];
int charCode = initialCharacter;
function insert(item, user, request) {
var table = tables.getTable('User');
table.where({
userId: user.userId
}).read({
success: upsertItem
});
function upsertItem(existingItems) {
if (existingItems.length === 0) {
public static async Task<byte[]> GetBytesAsync(StorageFile file)
{
byte[] fileBytes = null;
if (file == null) return null;
using (var stream = await file.OpenReadAsync())
{
fileBytes = new byte[stream.Size];
using (var reader = new DataReader(stream))
{
await reader.LoadAsync((uint)stream.Size);