/// <summary> /// Open a file button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void NextButton_Click(object sender, RoutedEventArgs e) { try { if (FileList.SelectedCells.Count() == 0) { throw new Exception("No File selected"); } // getting data of the file fileDir file = FileList.SelectedCells[0].Item as fileDir; if (file == null) { throw new Exception("File is null ..."); } FileList.Visibility = Visibility.Hidden; OpenFile.Visibility = Visibility.Visible; // loading the openfile type this.OpenTypeCombobox.ItemsSource = Enum.GetValues(typeof(OpenType)); this.NextButton.IsEnabled = this.DeleteFileButton.IsEnabled = this.AddFileButton.IsEnabled = this.InformationButton.IsEnabled = this.UpdateFileButton.IsEnabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// DeleteFile operation, FileOption /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void DeleteFileButton_Click(object sender, RoutedEventArgs e) { try { if (FileList.SelectedCells.Count() == 0) { throw new Exception("No File selected"); } fileDir file = FileList.SelectedCells[0].Item as fileDir; if (file == null) { throw new Exception("File is null ..."); } if (MessageBox.Show("Are you sur to delete the file, this is irreversible", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { disk.Delfile(file.name, file.owner); MessageBox.Show("File succefully deleted :)", "Information", MessageBoxButton.OK, MessageBoxImage.Information); PrintFile(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// ExtendFile, Window /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Extended_Click(object sender, RoutedEventArgs e) { try { uint result; if (!uint.TryParse(FileSizeTextBox.Text, out result)) { throw new Exception("Size could not be letter but only number"); } if (result > 3192 || result < 0) { throw new Exception("Overflow or Underflow prevention"); } uint tmp = 0; if (result % 2 == 0) { tmp = result / 2; } else { tmp = (result / 2) + 1; } if (tmp > disk.Howmuchempty(disk.myDiskPointer)) { this.NextButton.IsEnabled = false; } if (FileList.SelectedCells.Count() == 0) { throw new Exception("No File selected"); } fileDir file = FileList.SelectedCells[0].Item as fileDir; if (file == null) { throw new Exception("File is null ..."); } disk.Extendfile(file.name, file.owner, result); MessageBox.Show("Success :)"); Extend.Visibility = Visibility.Hidden; FileList.Visibility = Visibility.Visible; this.DeleteFileButton.IsEnabled = this.AddFileButton.IsEnabled = this.InformationButton.IsEnabled = true; PrintFile(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }
/// <summary> /// Open a file with a specific opentype /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OpenFileButton_Click(object sender, RoutedEventArgs e) { try { // getting the file info fileDir file = FileList.SelectedCells[0].Item as fileDir; // getting the opentype string open = ((OpenType)OpenTypeCombobox.SelectedValue).ToString(); if (open == "") { throw new Exception("No choice selected"); } string type = ""; switch (open) { case "Input": type = "I"; break; case "Output": type = "O"; break; case "Input_Output": type = "IO"; break; case "Extend": type = "E"; break; default: throw new Exception("A problem occur when checking the value of the combobox"); } // openfile fcb = disk.Openfile(file.name, file.owner, type); // checking if a problem occurs if (fcb == null) { throw new Exception("Unable to open the file"); } FileMenu.Visibility = Visibility.Hidden; OpenFile.Visibility = Visibility.Hidden; RecordMenu.Visibility = Visibility.Visible; // if the type is student if (file.type == "S") { // show his grid and priting all the record inside the file RecordList.Visibility = Visibility.Visible; RecordList.ItemsSource = from item in getAllRecord <Student>() select new Student(item.Id, item.Name, item.Year, item.Average); } // if the type is course else { // show his grid and priting all the record inside the file CourseList.Visibility = Visibility.Visible; CourseList.ItemsSource = from item in getAllRecord <Course>() select new Course(item.Id, item.Name, item.Credit); } this.NextButton.IsEnabled = false; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } }