//hien thi dialog ve nhan xet luon kalo da an private async void XongBtn_Click(object sender, RoutedEventArgs e) { if (kaloSum == 0) { var ms = new MessageDialog("Bạn nên chọn lượng Kcal nhập vào \nđể thống kê chính xác nhất"); await ms.ShowAsync(); return; } var msKalo = new MessageDialog("Tổng lượng Kcal bạn đã ăn là: " + kaloSum); await msKalo.ShowAsync(); if (muctieu != null && thongkengay != null) { connection.Execute("DELETE FROM ThucDon WHERE IdThongKeNgay =?", thongkengay.IdThongKeNgay); //add cac thuc an da chon vao database foreach (var item in monanChonList) { connection.Insert(item); } thongkengay.LuongKaloDuaVao = connection.ExecuteScalar <double>("SELECT SUM(LuongKalo) FROM THUCDON WHERE IdThongKeNgay =?", thongkengay.IdThongKeNgay); connection.Update(thongkengay); } Frame.Navigate(typeof(TrangChu), nguoidung); }
private int GetCount() { string dbFile = "Properties.db"; try { var conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(), dbPath + dbFile); var count = conn.ExecuteScalar <int>("SELECT Count(*) FROM Property"); return(count); } catch (Exception ex) { return(-1); } }
private bool IsDuplicateName(string name) { string dbFile = "Properties.db"; try { var conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(), dbPath + dbFile); var count = conn.ExecuteScalar <int>("SELECT Count(*) FROM Property where name = '" + name + "'"); if (count > 0) { return(true); } else { return(false); } } catch (Exception ex) { return(true); } }
private void DelBtn_Click(object sender, EventArgs e) { AlertDialog.Builder alert = new AlertDialog.Builder(this.Context); alert.SetMessage("Do you want to remove this property?"); alert.SetCancelable(false); alert.SetPositiveButton("Yes", delegate { string name = ((ImageView)sender).GetTag(Resource.Id.deleteProperty).ToString(); try { string dbPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "//"; string dbFile = "Properties.db"; var conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.XamarinAndroid.SQLitePlatformAndroid(), dbPath + dbFile); int count = conn.ExecuteScalar <int>("DELETE FROM Property where name='" + name + "'"); Toast.MakeText(this.Context, "Property " + name + " is deleted.", ToastLength.Short).Show(); DataList.Remove(DataList.Find(d => d.Name == name)); alert.Dispose(); NotifyDataSetChanged(); if (DataList == null || DataList.Count == 0) { var textView = Context.FindViewById <TextView>(Resource.Id.NoPropSaved); textView.Visibility = ViewStates.Visible; var elv = Context.FindViewById <ExpandableListView>(Resource.Id.elvSavedProperties); elv.Visibility = ViewStates.Invisible; } } catch (Exception ex) { Toast.MakeText(this.Context, "Could not delete the property. Please try again.", ToastLength.Short).Show(); } }); alert.SetNegativeButton("No", delegate { alert.Dispose(); }); alert.Create().Show(); }
public void Migrate() { var database = DependencyService.Get <ISQLite> (); SQLite.Net.SQLiteConnection connection = null; if (!database.Exists()) { connection = database.GetConnection(); connection.BeginTransaction(); connection.Execute(@"CREATE TABLE DBVersion (Version INT NOT NULL, ExecutionTime TEXT NOT NULL)" ); connection.Execute("INSERT INTO DBVersion (Version, ExecutionTime) VALUES (?,?)", new object[] { 0, DateTime.Now }); connection.Commit(); } if (connection == null) { connection = database.GetConnection(); } foreach (var migration in Migrations) { int currentVersion = connection.ExecuteScalar <int> ("SELECT Version FROM DBVersion ORDER BY Version DESC LIMIT 1"); if (migration.Key == (currentVersion + 1)) { connection.BeginTransaction(); foreach (var step in migration.Value) { connection.Execute(step); } connection.Execute("INSERT INTO DBVersion (Version, ExecutionTime) VALUES (?,?)", new object[] { migration.Key, DateTime.Now }); connection.Commit(); } } }
/// <summary> /// Khi người dùng tap vào một ngày, sẽ hiện ra thống kê cho ngày hôm đó /// </summary> private void Grid_Tapped(object sender, TappedRoutedEventArgs e) { thongkengayFlipView.Visibility = Visibility.Visible; btdetailStackPanel.Visibility = Visibility.Collapsed; Initialize_Calendar(calendarDate); // change background of the grid that is tapped (sender as Grid).Background = new SolidColorBrush(Colors.LightSeaGreen); TextBlock textblock = (sender as Grid).Children[0] as TextBlock; // nếu ô trống thì bỏ qua if (textblock.Text == null || textblock.Text == "") { return; } string date = Int32.Parse(textblock.Text).ToString("00") + "/" + CalendarHeader.Tag.ToString(); /* dd/MM/yyyy */ ngayTextBlock.Text = date; //DateTime date = DateTime.ParseExact(str, "dd/MM/yyyy", new CultureInfo("vi-vn")); ThongKeNgay tkn = connection.Table <ThongKeNgay>().Where(r => r.IdMucTieu == muctieu.IdMucTieu && r.Ngay == date).FirstOrDefault(); if (tkn != null) { thongkeFlipView.Visibility = Visibility.Visible; muctieuTextBlock.Text = tkn.IdMucTieu.ToString(); kaloduavaoTextBlock.Text = tkn.LuongKaloDuaVao.ToString(); kalotieuhaoTextBlock.Text = tkn.LuongKaloTieuHao.ToString(); int soluongbaitap = connection.ExecuteScalar <int>("SELECT COUNT(*) FROM ThongKeBaiTap WHERE IdThongKeNgay =?", tkn.IdThongKeNgay); soluongbtTextBlock.Text = soluongbaitap.ToString(); int tongthoigiantap = connection.ExecuteScalar <int>("SELECT SUM(ThoiGianTap) FROM THONGKEBAITAP WHERE IdThongKeNgay =?", tkn.IdThongKeNgay); thoigiantapTextBlock.Text = tongthoigiantap.ToString(); var q = connection.Table <ThongKeBaiTap>().Where(r => r.IdThongKeNgay == tkn.IdThongKeNgay); List <BaiTapDaTap> baidatapList = new List <BaiTapDaTap>(); foreach (var item in q) { var tenbaitap = connection.Table <BaiTap>().Where(r => r.IdBaiTap == item.IdBaiTap).FirstOrDefault().TenBaiTap; baidatapList.Add(new BaiTapDaTap() { IdThongKeBaiTap = item.IdThongKeNgay, IdThongKeNgay = item.IdThongKeNgay, IdBaiTap = item.IdBaiTap, TenBaiTap = tenbaitap, LuongKaloTieuHao = item.LuongKaloTieuHao, QuangDuong = item.QuangDuong, ThoiGianTap = item.ThoiGianTap }); } (PieChart.Series[0] as PieSeries).ItemsSource = baidatapList; } else { thongkengayFlipView.Visibility = Visibility.Collapsed; //kaloduavaoTextBlock.Text = "0"; //kalotieuhaoTextBlock.Text = "0"; //soluongbtTextBlock.Text = "0"; //thoigiantapTextBlock.Text = "0"; } }
private static int RowCount <T>(this SQLite.Net.SQLiteConnection connection) { //this could potentially create a new mapping if it doesn't exist in the connection already, alternative is to search //the TableMappings enumerable for an existing mapping but that would be slower return(connection.ExecuteScalar <int>(string.Format("select count(*) from {0}", connection.GetMapping <T>().TableName))); }
/// <summary> /// Checks if the database exists, if not create one /// </summary> private void ChechIfDbExist() { var sqlpath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "GameHistoryDB.sqlite"); //Path for the DB using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), sqlpath))//The connection { var tableExistsQuery = "SELECT name FROM sqlite_master WHERE type='table' AND name='GameHistory'"; //SQL-Query var result = conn.ExecuteScalar<string>(tableExistsQuery); if (result == null) { conn.CreateTable<GameHistory>(); } connection = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), sqlpath); } }