private void deleteFileButton_Click(object sender, RoutedEventArgs e) { if (App.UserAccessLevel > AccessLevel.Manager) { MessageBox.Show("אינך מורשה לבצע שינויים בדף זה יש לפנות למנהל המערכת", "בעיה בהרשאות", MessageBoxButton.OK, MessageBoxImage.Error); return; } if (FileListBox.SelectedItems.Count == 0) { MessageBox.Show("לא נבחר אף קובץ", "בחר קובץ", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } using (MainModel modelContainer = new MainModel(App.WorkMode)) { int selectedFileId = int.Parse(((ListBoxItem)FileListBox.SelectedItems[0]).Tag.ToString()); File file = modelContainer.FileSet.Single(x => x.Id == selectedFileId); modelContainer.FileSet.Remove(file); modelContainer.SaveChanges(); } RefreshFilesList(); }
private void addFileButton_Click(object sender, RoutedEventArgs e) { if (App.UserAccessLevel > AccessLevel.Manager) { MessageBox.Show("אינך מורשה לבצע שינויים בדף זה יש לפנות למנהל המערכת", "בעיה בהרשאות", MessageBoxButton.OK, MessageBoxImage.Error); return; } OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Multiselect = false; if (openFileDialog.ShowDialog() != true) { return; } File newFile = new File(); newFile.SwitchId = (int)_switchIdToEdit; newFile.DateTime = DateTime.Now; newFile.Content = System.IO.File.ReadAllBytes(openFileDialog.FileName); string newFileName = new FileInfo(openFileDialog.FileName).Name; newFile.Name = newFileName; using (MainModel modelContainer = new MainModel(App.WorkMode)) { modelContainer.FileSet.Add(newFile); modelContainer.SaveChanges(); } RefreshFilesList(); }
private void FileMouseDoubleClick(object sender, MouseButtonEventArgs e) { using (MainModel modelContainer = new MainModel(App.WorkMode)) { int selectedFileId = int.Parse(((ListBoxItem)FileListBox.SelectedItems[0]).Tag.ToString()); File file = modelContainer.FileSet.Single(x => x.Id == selectedFileId); // save the file to temp path string tempPath = Path.GetTempPath(); string newFilePath = Path.Combine(tempPath, file.Name); System.IO.File.WriteAllBytes(newFilePath, file.Content); Process.Start(newFilePath); } }