void BtnAdd_Clicked(object sender, EventArgs e) { var artFound = App.dbHandler.db.Find <Article> (tbArticleID.Text); if (string.IsNullOrEmpty(tbArticleID.Text) || artFound == null) { DisplayAlert(AppResources.Warning, AppResources.EnterValidArticleNr, AppResources.OK); return; } decimal qty = 0; Decimal.TryParse(tbQty.Text, out qty); if (string.IsNullOrEmpty(tbQty.Text) || qty <= 0) { DisplayAlert(AppResources.Warning, AppResources.EnterValidQty, AppResources.OK); return; } //artFound and qty are valid // var artRegFound = App.dbHandler.db.FindWithQuery <ArticleReg>("select * from ArticleReg where PlanningID=? and ArticleID=?", planning.ID, artFound.ID); if (artRegFound != null) { artRegFound.IsChanged = true; artRegFound.IsDeleted = false; artRegFound.Qty = qty; App.dbHandler.db.Update(artRegFound); } else { artRegFound = new ArticleReg() { ID = ArticleReg.CreateID(tbArticleID.Text, planning.ID), ArticleID = tbArticleID.Text, PlanningID = planning.ID, OrderID = planning.OrderID, Qty = qty, IsChanged = true, IsDeleted = false }; App.dbHandler.db.Insert(artRegFound); } tbQty.Text = tbArticleID.Text = string.Empty; article = null; ShowArticleName("", false); ShowArticleRegs(); tbQty.Unfocus(); }
async void LvPlanning_ItemTapped(object sender, ItemTappedEventArgs e) { db = App.dbHandler.db; //set db could be cleaned up Planning p = e.Item as Planning; // if planningItem tapped then load registrations from server // only if status == Planned if (p.StatusID == StatusTypes.Planned) { try { SetWaitStatus(true); lbProgress.Text = AppResources.lblProgressRegistrations; MobRegService service = new MobRegService(ProgramVars.URL); RegResult result = await service.GetRegistrationsAsync(new GetRegistrationInput() { userID = App.appSettings.loginVars.userID.ToString(), installationID = App.appSettings.installationID, planningID = p.ID }); if (result.statusCode == 0) { // Has Registrations // if (result.Registrations != null) { foreach (rsRegistration rg in result.Registrations) { Registration registration = new Registration() { ID = rg.ID.ToString(), PlanningID = rg.PlanningID.ToString(), OrderID = rg.OrderID.ToString(), UserID = rg.UserID.ToString(), RegTypeID = rg.RegTypeID, Priority = rg.Priority, IsDisplayed = rg.IsDisplayed, IsOnReport = rg.IsOnReport, IsRequired = rg.IsRequired, IsReadingOnly = rg.IsReadingOnly, Caption = rg.Caption, Result = rg.Result, PathName = rg.PathName, Input = rg.Input, Date = rg.Date, IsChanged = rg.IsChanged, IsClientReg = rg.IsClientReg, IsDeleted = rg.IsDeleted }; db.Insert(registration); if (registration.RegTypeID == RegistrationTypes.Picture) { IFileSystem fileSystem = DependencyService.Get <IFileSystem> (); using (Stream saveToStream = fileSystem.CreateFileStream(fileSystem.GetDataPath($"{registration.ID}.jpg"))) { MobRegService httpService = new MobRegService(ProgramVars.ImageHandlerUrl); string handlerUrl = string.Format("{0}?regid={1}&userid={2}&instid={3:d}&mode=down", ProgramVars.ImageHandlerUrl, registration.ID, registration.UserID, App.appSettings.installationID); await httpService.LoadBinaryAsync(handlerUrl, saveToStream); await saveToStream.FlushAsync(); } // end using } //end load picture } // foreach registration } // if has registrations // Has Articles // if (result.Articles != null) { foreach (rsArticleReg ar in result.Articles) { ArticleReg articleReg = new ArticleReg() { ID = ArticleReg.CreateID(ar.ArticleID, ar.PlanningID.ToString()), ArticleID = ar.ArticleID, OrderID = ar.OrderID.ToString(), PlanningID = ar.PlanningID.ToString(), Qty = ar.Qty, PriceIn = ar.PriceIn, PriceOut = ar.PriceOut, IsChanged = ar.IsChanged, IsDeleted = ar.IsDeleted }; db.Insert(articleReg); } } SetWaitStatus(false); await App.Current.MainPage.Navigation.PushAsync(new MainMenuPage (p)); } // result.StatusCode == 0 else { SetWaitStatus(false); lvPlanning.SelectedItem = null; await DisplayAlert(AppResources.Error, result.status, AppResources.OK); } } //try catch (Exception ex) { SetWaitStatus(false); await DisplayAlert(AppResources.Error, ex.Message, AppResources.Cancel); //Roll back all changes try { Common.DeleteAllRegistationAndPossibleAssignedPicturesFromPlanning(p); //db.Execute("delete from Registration where PlanningID=?", p.ID); //not needed since previous call also deletes all registrations, not only the one with pictures db.Execute("delete from ArticleReg where PlanningID=?", p.ID); } catch (Exception ex2) { string msg = ex.Message; } lvPlanning.SelectedItem = null; } } // end if StatusID == else { await App.Current.MainPage.Navigation.PushAsync(new MainMenuPage (p)); } } //end event ItemTapped