/* The function is responsible for initializing the file UI interface * in case of encrypted/decrypted/filetype change. */ private void initializeFile(Models.AccessType accessType) { this.isEncryptedCheckBox.Checked = currentFile.isEncrypted; if (currentFile.fileType == Models.FileType.Text) { this.FileTextBox.Visible = true; this.FileTextBox.Enabled = true; if (accessType.ToString().Contains("R")) { this.FileTextBox.Font = SystemFonts.DefaultFont; this.FileTextBox.Text = File.ReadAllText(currentFile.filePath); } else { this.FileTextBox.Font = SystemFonts.DefaultFont; this.FileTextBox.Text = "אינך יכול לקרוא את הקובץ"; MessageBox.Show("אין לך הרשאות לקרוא את הקובץ", "תקלה", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (!accessType.ToString().Contains("W")) { this.FileTextBox.Enabled = false; } } else { if (accessType.ToString().Contains("R")) { Bitmap newImage = null; using (var image = new Bitmap(currentFile.filePath)) { newImage = new Bitmap(image); } this.FilePictureBox.Image = newImage; this.FileTextBox.Visible = false; } else { this.FileTextBox.Visible = true; this.FileTextBox.Text = "אינך יכול לראות את התמונה"; this.FileTextBox.Enabled = false; MessageBox.Show("אין לך הרשאות לקרוא את הקובץ", "תקלה", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public FileForm(Models.File file, Models.AccessType accessType, Models.GrantDenyType grantDeny, Models.User currentUser) { InitializeComponent(); this.currentFile = file; this.accessType = accessType; this.currUser = currentUser; this.Text = file.fileName.Split('.')[0]; this.fileNameTextBox.Text = file.fileName; this.fileAccessTextBox.Text = accessType.ToString(); this.grantCheckBoxView.Checked = (int)grantDeny >= 2; this.DenyCheckBoxView.Checked = (int)grantDeny % 2 == 1; this.isEncryptedCheckBox.Checked = currentFile.isEncrypted; initializeFile(accessType); }