コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
 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);
     }
 }