private void SaveConfirmedProgress(ConfirmationRequest request) { if (request.Type == ConfirmationType.Challenge) { var progress = new ChallengeProgress { ChallengeId = request.TargetId, Id = request.ChallengeProgressId, LastModified = DateTime.UtcNow, Status = ProgressStatus.Confirmed, UserId = request.UserId }; using (var db = new SQLite.SQLiteConnection(AppState.State.Instance.DbPath)) { db.InsertOrReplace(progress); } } else { using (var db = new SQLite.SQLiteConnection(AppState.State.Instance.DbPath)) { var challenge = AppState.State.Instance .Challenges.FirstOrDefault((c) => c.BasicTasks.Any(t => t.Id == request.TargetId) || c.ExtraTasks.Any(t => t.Id == request.TargetId)); var challengeProgress = db .Table <ChallengeProgress>() .ToList() .FirstOrDefault(c => c.ChallengeId == challenge.Id); // If a user started a challenge and has not synced yet, confirming a task from that challenge // could crash the app - thus, a new challenge progress object is created on the device of the // confirming participant. On nearest synchronization, thi progress is passed to the db. if (challengeProgress == null) { challengeProgress = new ChallengeProgress { ChallengeId = challenge.Id, Id = request.ChallengeProgressId, LastModified = DateTime.UtcNow, Status = ProgressStatus.InProgress, UserId = request.UserId, }; db.InsertOrReplace(challengeProgress, typeof(ChallengeProgress)); } var progress = new TaskProgress { TaskId = request.TargetId, Id = request.TaskProgressId, LastModified = DateTime.UtcNow, Status = ProgressStatus.Confirmed, ChallengeProgressId = request.ChallengeProgressId, }; db.InsertOrReplace(progress, typeof(TaskProgress)); } } }
public void Update_Params(Params p) { Console.WriteLine("begin Update param"); SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(_dbPath); connection.InsertOrReplace(p); Console.WriteLine("end Update param"); }
private void Mod_button_Click(object sender, RoutedEventArgs e) { Konto newInfo = new Konto() { Id = _loggedInAccount.Id, Nazwa_firmy = Company_name.Text, Imie = Name.Text, Nazwisko = Surname.Text, Pesel = PESEL.Text, Regon = REGON.Text, Nip = NIP.Text, Ulica = Street.Text, Numer = Number.Text, Miasto = City.Text, Kod_pocztowy = ZIP_code.Text, Email = _loggedInAccount.Email, Login = _loggedInAccount.Login, Haslo = _loggedInAccount.Haslo, Role = _loggedInAccount.Role, Points = _loggedInAccount.Points }; using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.databasePath)) { conn.CreateTable <Konto>(); conn.InsertOrReplace(newInfo); } MessageBox.Show("Konto zaktualizowane."); MainWindow mw = new MainWindow(_loggedInAccount); mw.Show(); this.Close(); }
//Insertion Params public void InsertParams(Params p) { Console.WriteLine("begin Insert Params"); SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(_dbPath); connection.CreateTable <Params>(); connection.InsertOrReplace(p); Console.WriteLine("end Insert Params"); }
private void SyncCollection <T>(IEnumerable <T> fetchedCollection) { using (var db = new SQLite.SQLiteConnection(AppState.State.Instance.DbPath)) { foreach (var entry in fetchedCollection) { db.InsertOrReplace(entry, typeof(T)); } } }
//sets checkin entry in preparation for saving a time entry to the database //inserts a soll entry to the database (overwrites if one already exists on that day) public void checkin(object sender, EventArgs e) { var ce = new CheckinEntry(DateTime.Now.TimeOfDay); ce.comment = comment.Text; string check = type.SelectedItem.ToString(); // save switch (check) // save { case "Notfall": ce.type = "NF"; break; case "Meeting": ce.type = "M"; break; case "Wiiterbildig": ce.type = "WB"; break; default: ce.type = " "; break; } var se = new SollEntry(SollZeit.Time, DateTime.Now); using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_Path)) { conn.CreateTable <CheckinEntry>(); conn.InsertOrReplace(ce); conn.CreateTable <SollEntry>(); conn.InsertOrReplace(se); } check_out.IsEnabled = true; check_in.IsEnabled = false; }
public static void Save <T>(T[] items) where T : new() { using (var db = new SQLite.SQLiteConnection(SqliteDbPath)) { lock (lck) { db.CreateTable <T>(); db.BeginTransaction(); foreach (var item in items) { db.InsertOrReplace(item); } db.Commit(); } } }
public static bool InsertOrReplaceSafe(this SQLite.SQLiteConnection conn, object obj) { while (true) { try { conn.InsertOrReplace(obj); return(true); } catch (SQLite.SQLiteException ex) { if (ex.Result == SQLite.SQLite3.Result.Constraint) { return(false); } if (ex.Result != SQLite.SQLite3.Result.Busy) { throw ex; } System.Threading.Thread.Sleep(10); } } }
private async void Button_Click_1(object sender, RoutedEventArgs e) { string a = txt1.Text; var db = new SQLite.SQLiteConnection(App.DBPath); lawyer lw = new lawyer(); var d1 = (db.Table <lawyer>().Where(em => em.username == a)).SingleOrDefault(); bool r = true; if (d1 != null) { r = false; } if (d1 == null) { r = true; } if (r == false) { //string a = txt1.Text; //var db = new SQLite.SQLiteConnection(App.DBPath); //lawyer lw = new lawyer(); //var d1 = (db.Table<lawyer>().Where(em => em.username == a)).Single(); lw.username = txt1.Text; lw.working_field = txt2.Text; lw.exp = txt3.Text; lw.about = txt4.Text; lw.location = txt5.Text; lw.contactno = txt6.Text; lw.email = txt7.Text; lw.image = txtPath.Text; db.Update(lw); tbl1.Text = "Information Updated Successfully"; } if (r == true) { //var db = new SQLite.SQLiteConnection(App.DBPath); //lawyer lw = new lawyer(); lw.username = txt1.Text; lw.working_field = txt2.Text; lw.exp = txt3.Text; lw.about = txt4.Text; lw.location = txt5.Text; lw.contactno = txt6.Text; lw.email = txt7.Text; lw.image = txtPath.Text; //string a = txt1.Text; //var db = new SQLite.SQLiteConnection(App.DBPath); //var d1 = (db.Table<lawyer>().Where(em => em.username == a)).Single(); //var targetFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(d1.username + ".jpg"); //if (targetFile != null) //{ // await file.MoveAndReplaceAsync(targetFile); //} db.InsertOrReplace(lw); tbl1.Text = "Information Added Successfully"; } }
public bool SaveOrder(OrderEntity order) { return(_connection.InsertOrReplace(order) != -1); }
public static void Cache(TileDownloadOptions options, List <double[]> boundsList, BruTile.Web.HttpTileSource tileSource) { double[] originalBounds = new double[4] { double.MaxValue, double.MaxValue, double.MinValue, double.MinValue }; // In WGS1984, the total extent of all bounds List <TileInfo> tileInfos = new List <TileInfo>(); foreach (double[] xy in boundsList) { if (xy[0] < originalBounds[0]) { originalBounds[0] = xy[0]; } if (xy[1] < originalBounds[1]) { originalBounds[1] = xy[1]; } if (xy[2] > originalBounds[2]) { originalBounds[2] = xy[2]; } if (xy[3] > originalBounds[3]) { originalBounds[3] = xy[3]; } ToMercator(ref xy[0], ref xy[1]); ToMercator(ref xy[2], ref xy[3]); // xy is now in SphericalMercator projection BruTile.Extent extent = new BruTile.Extent(xy[0], xy[1], xy[2], xy[3]); var curTileInfos = tileSource.Schema.GetTileInfos(extent, options.Level.ToString()); foreach (var tileInfo in curTileInfos) { TileInfo ti = tileInfos.Where(x => x.Index.Col == tileInfo.Index.Col && x.Index.Row == tileInfo.Index.Row && x.Index.Level == tileInfo.Index.Level).FirstOrDefault(); if (ti != null) // This tile is already in the list { continue; } tileInfos.Add(tileInfo); } } if (options.MaxAge.HasValue) { using (var db = new SQLite.SQLiteConnection(options.DBFilename)) { // Create the tables, so at least they will exist db.CreateTable <MBTiles.Domain.metadata>(); db.CreateTable <MBTiles.Domain.tiles>(); for (int i = 0; i < tileInfos.Count; i++) { TileInfo tileInfo = tileInfos[i]; int tileLevel = int.Parse(tileInfo.Index.Level); int tileRow = OSMtoTMS(tileLevel, tileInfo.Index.Row); MBTiles.Domain.tiles oldTile = db.Table <MBTiles.Domain.tiles>().Where(x => x.zoom_level == tileLevel && x.tile_column == tileInfo.Index.Col && x.tile_row == tileRow).FirstOrDefault(); if (oldTile != null && (DateTime.Now - oldTile.createDate) <= options.MaxAge.Value) { // This tile hasn't expired yet, so don't download it. tileInfos.Remove(tileInfo); i--; } } } } // Make sure we have any tiles left to download. If not, we are done! if (tileInfos.Count == 0) { return; } ConcurrentBag <LoadedTile> bag = new ConcurrentBag <LoadedTile>(); using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()) { List <Task> fetchTasks = new List <Task>(); foreach (var ti in tileInfos) { fetchTasks.Add(Task.Run(async() => await FetchTile(ti, client, bag, options.UriFormat))); if (fetchTasks.Count > 1) // Limit 2 to concurrent download threads { Task.WaitAll(fetchTasks.ToArray()); fetchTasks.Clear(); } } Task.WaitAll(fetchTasks.ToArray()); } using (var db = new SQLite.SQLiteConnection(options.DBFilename)) { db.CreateTable <MBTiles.Domain.metadata>(); db.CreateTable <MBTiles.Domain.tiles>(); var metaList = new List <MBTiles.Domain.metadata>(); metaList.Add(new MBTiles.Domain.metadata { name = "name", value = options.DBName }); metaList.Add(new MBTiles.Domain.metadata { name = "type", value = "baselayer" }); metaList.Add(new MBTiles.Domain.metadata { name = "version", value = "1" }); metaList.Add(new MBTiles.Domain.metadata { name = "description", value = options.DBDescription }); metaList.Add(new MBTiles.Domain.metadata { name = "format", value = bag.First().mimeType.Contains("/png") ? "png" : "jpg" }); foreach (var meta in metaList) { db.InsertOrReplace(meta); } // Expand the bounds var existingBounds = db.Table <MBTiles.Domain.metadata>().Where(x => x.name == "bounds").FirstOrDefault(); if (existingBounds != null) { var components = existingBounds.value.Split(','); var existingExtent = new double[4] { double.Parse(components[0], NumberFormatInfo.InvariantInfo), double.Parse(components[1], NumberFormatInfo.InvariantInfo), double.Parse(components[2], NumberFormatInfo.InvariantInfo), double.Parse(components[3], NumberFormatInfo.InvariantInfo) }; if (originalBounds[0] < existingExtent[0]) { existingExtent[0] = originalBounds[0]; } if (originalBounds[1] < existingExtent[1]) { existingExtent[1] = originalBounds[1]; } if (originalBounds[2] > existingExtent[2]) { existingExtent[2] = originalBounds[2]; } if (originalBounds[3] > existingExtent[3]) { existingExtent[3] = originalBounds[3]; } existingExtent.CopyTo(originalBounds, 0); } db.InsertOrReplace(new MBTiles.Domain.metadata { name = "bounds", value = String.Join(",", originalBounds) }); foreach (var lt in bag) { MBTiles.Domain.tiles tile = new MBTiles.Domain.tiles(); tile.zoom_level = int.Parse(lt.ti.Index.Level); tile.tile_column = lt.ti.Index.Col; tile.tile_row = lt.ti.Index.Row; tile.tile_data = lt.data; tile.createDate = DateTime.Now; tile.tile_row = OSMtoTMS(tile.zoom_level, tile.tile_row); MBTiles.Domain.tiles oldTile = db.Table <MBTiles.Domain.tiles>().Where(x => x.zoom_level == tile.zoom_level && x.tile_column == tile.tile_column && x.tile_row == tile.tile_row).FirstOrDefault(); if (oldTile != null) { tile.id = oldTile.id; db.Update(tile); } else { db.Insert(tile); } } } }
private void Salvar(Model.Usuario usuario) { using (var db = new SQLite.SQLiteConnection(DB_PATH)) { if (db.InsertOrReplace(usuario) > 0) { int index = this.ListaDeUsuarios.IndexOf(usuario); if (index > -1) this.ListaDeUsuarios[index] = usuario; else this.ListaDeUsuarios.Add(usuario); } } SelectedUsuario = usuario; Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(View.MainPage), this); }
// Dialog response private void VerifyConfirmation(Confirmation confirmation) { var signerId = confirmation.SignerId; try { var res = Verify(Newtonsoft.Json.JsonConvert.SerializeObject(confirmation.Request), confirmation.Signature, signerId); if (res) { string responseText; using (var db = new SQLite.SQLiteConnection(AppState.State.Instance.DbPath)) { if (confirmation.Request.Type == ConfirmationType.Task) { var tp = new TaskProgress { TaskId = confirmation.Request.TargetId, ChallengeProgressId = confirmation.Request.ChallengeProgressId, Id = confirmation.Request.TaskProgressId, Status = ProgressStatus.Completed, LastModified = DateTime.UtcNow, }; db.InsertOrReplace(tp); responseText = $"Splnìní úkolu úspìšnì potvrzeno! Gratulujeme"; } else { var cp = new ChallengeProgress { ChallengeId = confirmation.Request.TargetId, Id = confirmation.Request.ChallengeProgressId, Status = ProgressStatus.Completed, LastModified = DateTime.UtcNow, UserId = confirmation.Request.UserId }; db.InsertOrReplace(cp); responseText = $"Splnìní zkoušky úspìšnì potvrzeno. Gratulujeme!"; } } new AlertDialog.Builder(this) .SetMessage(responseText) .SetNeutralButton("Ok", (o, e) => { SetResult(Android.App.Result.Ok); Finish(); }) .SetCancelable(false) .Create() .Show(); } else { throw new ConfirmationException("Elektronický podpis nesouhlasí."); } } catch (Exception e) { new AlertDialog.Builder(this) .SetMessage($"Potvrzení nebylo úspìšné: {e.Message}") .SetNeutralButton("Ok", (o, ev) => { SetResult(Android.App.Result.Canceled); Finish(); }) .SetCancelable(false) .Create() .Show(); } }
public void UpdateParams(Params p) { SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(DB_PATH); connection.InsertOrReplace(p); }
public void InsertParams(Params p) { SQLite.SQLiteConnection connection = new SQLite.SQLiteConnection(DB_PATH); connection.CreateTable <Params>(); connection.InsertOrReplace(p); }
private void Update(Model.Usuario Usuario) { using (var db = new SQLite.SQLiteConnection(DB_PATH)) { if (db.InsertOrReplace(Usuario) > 0) { int index = this.ListaDeUsuarios.IndexOf(Usuario); if (index > -1) this.ListaDeUsuarios[index] = Usuario; else this.ListaDeUsuarios.Add(Usuario); } } Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(View.SelecionaUsuarioPage), this); }
public void Devolver(Model.Emprestimo emprestimo) { emprestimo.DataDevolucao = DateTime.Now; using (var db = new SQLite.SQLiteConnection(DB_PATH)) { db.CreateTable<Model.Emprestimo>(); } using (var db = new SQLite.SQLiteConnection(DB_PATH)) { if (db.InsertOrReplace(emprestimo) > 0) { int index = this.ListaDeEmprestimos.IndexOf(emprestimo); if (index > -1) this.ListaDeEmprestimos[index] = emprestimo; else this.ListaDeEmprestimos.Add(emprestimo); } } Frame rootFrame = Window.Current.Content as Frame; rootFrame.Navigate(typeof(View.PivotPage)); }
// thanks to https://www.youtube.com/watch?v=JhWwBOoqXQ8&t=1801s&ab_channel=AltexSoft public async void enterToDB(object sender, EventArgs e) { TimeSpan TimeIn = TimeInPicked.Time; TimeSpan TimeOut = TimeOutPicked.Time; /* * if (TimeIn > TimeOut) * { * Debug.WriteLine("------"); * bool answer = await DisplayAlert("Obacht!", "Hesch würkli über Mitternach gschaffet oder dich vertippt", "stimmt scho so", "ups..."); * * if(!answer) * { * return; * } * } */ string Type; string Comment = comment.Text; string check = type.SelectedItem.ToString(); switch (check) { case "Notfall": Type = "NF"; break; case "Meeting": Type = "M"; break; case "Wiiterbiudig": Type = "WB"; break; default: Type = " "; break; } TimeEntry manualEntry = new TimeEntry(DatePicked.Date, TimeIn, TimeOut, Comment); manualEntry.Type = Type; var se = new SollEntry(SollTimePicked.Time, DatePicked.Date); using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.DB_Path)) { conn.CreateTable <TimeEntry>(); conn.Insert(manualEntry); if (Type != "NF") { conn.CreateTable <SollEntry>(); conn.InsertOrReplace(se); } } if (changeEntry) { this.SendBackButtonPressed(); } }