protected override void OnCreated() { using (IDataContextWrapper dataContext = _dataContextLocator()) { Group noneGroup = new Group() { Id = -1, GroupName = "None" }; GroupsList = new BindableCollection <Group>(dataContext.Table <Group>().OrderBy(g => g.GroupName).ToList()); GroupsList.Insert(0, noneGroup); if (!IsAdding) { var client = dataContext.Table <Client>().First(x => x.Id == ClientId); Forename = client.Forename; Surname = client.Surname; Birthdate = client.Birthdate; Latitude = client.Latitude; Longitude = client.Longitude; IsActive = client.IsActive; Group = client.Group ?? noneGroup; Photo = IsoStorageHelper.PhotoFromFile(client.Photo); } else { IsActive = true; Group = noneGroup; } } }
public void Delete(Client client) { using (IDataContextWrapper dataContext = _dataContextLocator()) { var clientEntity = dataContext.Table <Client>().First(x => x.Id == client.Id); IsoStorageHelper.DeleteFile(clientEntity.Photo); dataContext.DeleteOnSubmit(clientEntity); dataContext.SubmitChanges(); } Clients.Remove(client); }
protected override void OnActivate() { base.OnActivate(); using (IDataContextWrapper dataContext = _dataContextLocator()) { Client client = dataContext.Table <Client>().FirstOrDefault(x => x.Id == ClientID); if (client != null) { FullName = client.FullName; Photo = IsoStorageHelper.PhotoFromFile(client.Photo); } } }
void UploadCallback(SkyDriveResult <bool> result) { ShowLoading = false; dbStream.Close(); IsoStorageHelper.DeleteFile("ClientsManager_backup.sdf"); if (result.Succeded) { GoBack(); MessageBox.Show("Backup has been uploaded."); } else { MessageBox.Show("Error occured while uploading backup: \n" + result.Exception.Message); } }
public void SaveBackup() { if (!_skyDriveManager.Logged) { MessageBox.Show("You must be logged to SkyDrive to backup your data.", "Not logged", MessageBoxButton.OK); } else if (String.IsNullOrEmpty(_currentFolderID)) { MessageBox.Show("None of the folders have been chosen."); } else if (MessageBox.Show("Do you want to upload backup to:\n" + FolderPath + " ?", "Backup", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { dbStream = IsoStorageHelper.GetDatabaseStream(); _skyDriveManager.Upload(_currentFolderID, "ClientsManager.sdf", dbStream, OverwriteOption.Rename, UploadCallback); ShowLoading = true; } }
private void LoadZoomPage(string id, int pageZeroBase) { int page = pageZeroBase + 1; var path = string.Format("Catalogs/{0}/zoom/{1}.jpg", id, page); IsoStorageHelper isoStore = new IsoStorageHelper(); //var path = string.Format("Catalogs/{0}/{1}.jpg", id, page); if (isoStore.FileExists(path)) { zoomImage.Source = new ImageHelper().ConvertIsoFileStreamToBitmapImage(path); zoomImage.Visibility = System.Windows.Visibility.Visible; slideView.Visibility = System.Windows.Visibility.Collapsed; return; } ThreadPool.QueueUserWorkItem(state => { WebClient client = new WebClient(); string uri = CatalogPageHelper.GetPageUri(id, page.ToString(), ImageResolution.Zoom); client.OpenReadAsync(new Uri(uri)); client.OpenReadCompleted += (sender, e) => { string temp = uri; if (e.Error != null || e.Cancelled) { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("Ups, kunne ikke hente zoom siden"); zoomImage.Source = null; zoomImage.Visibility = System.Windows.Visibility.Collapsed; slideView.Visibility = System.Windows.Visibility.Visible; }); return; } using (var stream = e.Result) { if (isoStore.FileExists(path)) { zoomImage.Source = new ImageHelper().ConvertIsoFileStreamToBitmapImage(path); zoomImage.Visibility = System.Windows.Visibility.Visible; slideView.Visibility = System.Windows.Visibility.Collapsed; return; } using (IsolatedStorageFileStream fileStream = isoStore.CreateFile(path)) { stream.CopyTo(fileStream); fileStream.Close(); } } Deployment.Current.Dispatcher.BeginInvoke(() => { zoomImage.Source = new ImageHelper().ConvertIsoFileStreamToBitmapImage(path); zoomImage.Visibility = System.Windows.Visibility.Visible; slideView.Visibility = System.Windows.Visibility.Collapsed; }); return; }; }); }
public void Save() { if (!string.IsNullOrWhiteSpace(Forename) || !string.IsNullOrWhiteSpace(Surname)) { if (Latitude != null && (Latitude < -90.0 || Latitude > 90.0)) { MessageBox.Show("Incorrect latitude."); return; } if (Longitude != null && (Longitude < -180.0 || Longitude > 180.0)) { MessageBox.Show("Incorrect longitude."); return; } using (IDataContextWrapper dataContext = _dataContextLocator()) { Group selectedGroup = dataContext.Table <Group>().FirstOrDefault(x => x.Id == Group.Id); DateTime?onlyDate = Birthdate.HasValue ? new DateTime?(Birthdate.Value.Date) : Birthdate; if (IsAdding) { Client newClient = new Client() { Forename = this.Forename, Surname = this.Surname, Birthdate = onlyDate, Longitude = this.Longitude, Latitude = this.Latitude, IsActive = this.IsActive, Group = selectedGroup }; dataContext.InsertOnSubmit(newClient); if (!String.IsNullOrEmpty(lastPhotoName) && Photo != null) { dataContext.SubmitChanges(); newClient.Photo = IsoStorageHelper.SavePhoto(Photo, newClient.Id, lastPhotoName); } } else { Client clientToEdit = dataContext.Table <Client>().FirstOrDefault(x => x.Id == ClientId); if (clientToEdit != null) { clientToEdit.Surname = Surname; clientToEdit.Forename = Forename; clientToEdit.Birthdate = onlyDate; clientToEdit.Longitude = Longitude; clientToEdit.Latitude = Latitude; clientToEdit.IsActive = IsActive; clientToEdit.Group = selectedGroup; if (Photo == null) { IsoStorageHelper.DeleteFile(clientToEdit.Photo); //delete old photo clientToEdit.Photo = null; } else { if (!String.IsNullOrEmpty(lastPhotoName)) //if new photo were chosen { IsoStorageHelper.DeleteFile(clientToEdit.Photo); //delete old photo clientToEdit.Photo = IsoStorageHelper.SavePhoto(Photo, clientToEdit.Id, lastPhotoName); } } } } dataContext.SubmitChanges(); } GoBack(); } else { MessageBox.Show("Client must have Forename or Surname"); } }
public static void ResetStorage() { IsoStorageHelper iso = new IsoStorageHelper(); iso.DeleteDiretory(EtaSDK.Properties.Resources.CatalogBaseIsoFolder); }