private void PopulateFromDb(string filterString = "") { Thread th = new Thread(() => { Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { //new CitySQLiteRepository().Sync(cityService); CityListResponse cityResp = new CitySQLiteRepository().GetCitiesForPopupCountry(MainWindow.CurrentCompanyId, CurrentCountry?.Identifier ?? null, filterString); if (cityResp.Success) { CitiesFromDB = new ObservableCollection <CityViewModel>(cityResp.Cities ?? new List <CityViewModel>()); } else { CitiesFromDB = new ObservableCollection <CityViewModel>(); } }) ); }); th.IsBackground = true; th.Start(); }
private void DisplayData() { CityDataLoading = true; CityListResponse response = new CitySQLiteRepository().GetCitiesByPage(CitiesearchObject, currentPage, itemsPerPage); if (response.Success) { CitiesFromDB = new ObservableCollection <CityViewModel>(response.Cities); totalItems = response.TotalItems; } else { CitiesFromDB = new ObservableCollection <CityViewModel>(); totalItems = 0; MainWindow.ErrorMessage = response.Message; } int itemFrom = totalItems != 0 ? (currentPage - 1) * itemsPerPage + 1 : 0; int itemTo = currentPage * itemsPerPage < totalItems ? currentPage * itemsPerPage : totalItems; PaginationDisplay = itemFrom + " - " + itemTo + " od " + totalItems; CityDataLoading = false; }
private void btnDeleteCity_Click(object sender, RoutedEventArgs e) { if (CurrentCity == null) { MainWindow.WarningMessage = "Morate odabrati grad za brisanje!"; return; } SirmiumERPVisualEffects.AddEffectOnDialogShow(this); // Create confirmation window DeleteConfirmation deleteConfirmationForm = new DeleteConfirmation("grad", CurrentCity.Name); var showDialog = deleteConfirmationForm.ShowDialog(); if (showDialog != null && showDialog.Value) { CityResponse response = cityService.Delete(CurrentCity.Identifier); if (!response.Success) { MainWindow.ErrorMessage = "Greška kod brisanja sa servera!"; SirmiumERPVisualEffects.RemoveEffectOnDialogShow(this); return; } response = new CitySQLiteRepository().Delete(CurrentCity.Identifier); if (!response.Success) { MainWindow.ErrorMessage = "Greška kod lokalnog brisanja!"; SirmiumERPVisualEffects.RemoveEffectOnDialogShow(this); return; } MainWindow.SuccessMessage = "Grad je uspešno obrisan!"; Thread displayThread = new Thread(() => DisplayData()); displayThread.IsBackground = true; displayThread.Start(); } SirmiumERPVisualEffects.RemoveEffectOnDialogShow(this); }
private void btnSave_Click(object sender, RoutedEventArgs e) { #region Validation if (String.IsNullOrEmpty(CurrentCity.Name)) { MainWindow.WarningMessage = "Obavezno polje: Naziv grada"; return; } #endregion Thread th = new Thread(() => { SaveButtonContent = " Čuvanje u toku... "; SaveButtonEnabled = false; CurrentCity.CreatedBy = new UserViewModel() { Id = MainWindow.CurrentUserId }; CurrentCity.IsSynced = false; CurrentCity.UpdatedAt = DateTime.Now; CityResponse response = new CitySQLiteRepository().Delete(CurrentCity.Identifier); response = new CitySQLiteRepository().Create(CurrentCity); if (!response.Success) { MainWindow.ErrorMessage = "Greška kod lokalnog čuvanja!"; SaveButtonContent = " Sačuvaj "; SaveButtonEnabled = true; return; } response = cityService.Create(CurrentCity); if (!response.Success) { MainWindow.ErrorMessage = "Podaci su sačuvani u lokalu!. Greška kod čuvanja na serveru!"; SaveButtonContent = " Sačuvaj "; SaveButtonEnabled = true; } if (response.Success) { new CitySQLiteRepository().UpdateSyncStatus(response.City.Identifier, response.City.Id, true); MainWindow.SuccessMessage = "Podaci su uspešno sačuvani!"; SaveButtonContent = " Sačuvaj "; SaveButtonEnabled = true; CityCreatedUpdated(); if (IsCreateProcess) { CurrentCity = new CityViewModel(); CurrentCity.Code = new CitySQLiteRepository().GetNewCodeValue().ToString(); CurrentCity.Identifier = Guid.NewGuid(); Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { txtCityName.Focus(); }) ); } else { Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, new Action(() => { FlyoutHelper.CloseFlyout(this); }) ); } } }); th.IsBackground = true; th.Start(); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { Thread th = new Thread(() => { CityDataLoading = true; if (CurrentCity == null) { MainWindow.WarningMessage = ((string)Application.Current.FindResource("Morate_odabrati_grad_za_brisanjeUzvičnik")); CityDataLoading = false; return; } CityResponse response = cityService.Delete(CurrentCity.Identifier); if (!response.Success) { MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_brisanja_sa_serveraUzvičnik")); CityDataLoading = false; return; } response = new CitySQLiteRepository().Delete(CurrentCity.Identifier); if (!response.Success) { MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_lokalnog_brisanjaUzvičnik")); CityDataLoading = false; return; } MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Grad_je_uspešno_obrisanUzvičnik")); DisplayData(); CityDataLoading = false; }); th.IsBackground = true; th.Start(); //if (CurrentCity == null) //{ // MainWindow.WarningMessage = ((string)Application.Current.FindResource("Morate_odabrati_grad_za_brisanjeUzvičnik")); // return; //} //SirmiumERPVisualEffects.AddEffectOnDialogShow(this); //// Create confirmation window //DeleteConfirmation deleteConfirmationForm = new DeleteConfirmation("grad", CurrentCity.ZipCode + " " + CurrentCity.Name); //var showDialog = deleteConfirmationForm.ShowDialog(); //if (showDialog != null && showDialog.Value) //{ // CityResponse response = cityService.Delete(CurrentCity.Identifier); // if (!response.Success) // { // MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_brisanja_sa_serveraUzvičnik")); // SirmiumERPVisualEffects.RemoveEffectOnDialogShow(this); // return; // } // response = new CitySQLiteRepository().Delete(CurrentCity.Identifier); // if (!response.Success) // { // MainWindow.ErrorMessage = ((string)Application.Current.FindResource("Greška_kod_lokalnog_brisanjaUzvičnik")); // SirmiumERPVisualEffects.RemoveEffectOnDialogShow(this); // return; // } // MainWindow.SuccessMessage = ((string)Application.Current.FindResource("Grad_je_uspešno_obrisanUzvičnik")); // Thread displayThread = new Thread(() => SyncData()); // displayThread.IsBackground = true; // displayThread.Start(); //} //SirmiumERPVisualEffects.RemoveEffectOnDialogShow(this); }