I have a UWP app in C # with SQLite.
The problem I have is with the datepicker, when DatetimeOffsetTimeConverter gives me an exception, if I remove the date 01/01/1001 (to make it out the correct date), the date of the DatePicker comes in another page, called Mypetpage. c# private async void AddButton_Click(object sender, RoutedEventArgs e) {
var selectedDate =Data1.Date.ToString();
DataBaseHelper Db_Pet = new DataBaseHelper();
if (txtnombre.Text != "" & txtchip.Text !="" & txtraza.Text !="" & SelectedgeneroText !="" & txtcolor.Text != "" )
{
Db_Pet.Insert(new Mascota(txtnombre.Text, txtchip.Text, txtraza.Text, SelectedgeneroText, txtcolor.Text, selectedDate));
}
else
{
MessageDialog md = new MessageDialog("Enter your pet");
await md.ShowAsync();
}
}
xaml
<DatePicker x:Name="Data1" Grid.Row="1"
Date="{Binding someDate, Mode=TwoWay, Converter={StaticResour DateTimeToDateTimeOffsetConverter}}"/>
ViewModel
public void CreateDataBase(string DB_PATH)
{
if (!CheckFileExists(DB_PATH).Result)
{
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), DB_PATH))
{
conn.CreateTable<Mascota>();
conn.CreateTable<Clinico>();
}
}
}
protected async Task<bool> CheckFileExists(string fileName)
{
try
{
var petstore = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync(fileName);
return true;
}
catch
{
return false;
}
}
public void Insert(Mascota objMascota)
{
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), App.DB_PATH))
{
conn.RunInTransaction(() =>
{
conn.Insert(objMascota);
});
}
}
public Mascota ReadMascota(int mascotaid)
{
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), App.DB_PATH))
{
var existmascot = conn.Query<Mascota>("select * from Mascota where Id =" + mascotaid).FirstOrDefault();
return existmascot;
}
}
public ObservableCollection<Mascota> ReadAllMascota()
{
try
{
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), App.DB_PATH))
{
List<Mascota> myMascota = conn.Table<Mascota>().ToList<Mascota>();
ObservableCollection<Mascota> MascotaList = new ObservableCollection<Mascota>(myMascota);
return MascotaList;
}
}
catch
{
return null;
}
}
//borra todo
public void DeleteAllMascota()
{
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), App.DB_PATH))
{
conn.DropTable<Mascota>();
conn.CreateTable<Mascota>();
conn.Dispose();
conn.Close();
}
}
public void DeleteMascota(int Id)
{
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), App.DB_PATH))
{
var existmascot = conn.Query<Mascota>("select * from Mascota where Id =" + Id).FirstOrDefault();
if (existmascot != null)
{
conn.RunInTransaction(() =>
{
conn.Delete(existmascot);
});
}
}
}
StaticResour
, shouldn't it beStaticResource
? – Keyur PATELDateTimeToDateTimeOffsetConverter
please if you still have issue. – Sunteen Wu