private void CheckUserInput(CreateFileBindingModel createFileBindingModel) { //Uses CreateFileBindingModel to set its properties //Checks if user has pressed OK for saving the source directory if (result == DialogResult.OK) { //Saves the destination path in createFileBindingModel.DestPath destPath = createFileBindingModel.DestPath = createFileDialog.SelectedPath; //Shows the CreateFileForm to the user. try { CreateFileForm.ShowDialog(); } catch (InvalidOperationException) { MessageBox.Show("Please, enter a name for a file before trying to search file again", "Enter name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, 0, MessageBoxOptions.DefaultDesktopOnly); return; } //Checks if Cancel is pressed in the CreateFileForm form. CheckIfCancelIsPressed(CreateFileForm.GetCreateFileBindingModel()); } }
public void CreatePowerPoint(CreateFileBindingModel createPPBindingModel) { //Uses CreateFileBindingModel to get specific information from it. //Creates a excel application that runs in the background. //In the background the application adds the things it needs to be opened after being created. PowerPoint.Application objPowerPoint = new PowerPoint.Application(); PowerPoint.Presentation objPresentation = objPowerPoint.Presentations.Add(Microsoft.Office.Core.MsoTriState.msoFalse); Microsoft.Office.Interop.PowerPoint.Slides slides; Microsoft.Office.Interop.PowerPoint._Slide slide; Microsoft.Office.Interop.PowerPoint.TextRange objText; Microsoft.Office.Interop.PowerPoint.CustomLayout custLayout = objPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText]; slides = objPresentation.Slides; slide = slides.AddSlide(1, custLayout); objText = slide.Shapes[1].TextFrame.TextRange; objText.Text = "Title of page"; objText.Font.Name = "Arial"; objText.Font.Size = 32; Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2]; //After the user has given a directory and a name for the file, it is saved there with that name. objPresentation.SaveAs(createPPBindingModel.DestPath + @"\" + $"{createPPBindingModel.FileName}", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, Microsoft.Office.Core.MsoTriState.msoTrue); //This closes the created in the background application and quits it. objPresentation.Close(); objPowerPoint.Quit(); }
public void CreateMethodCreatesRarFileSuccesfully() { CurrentUser.user.username = "******"; CreateRarFileService fileService = new CreateRarFileService(); CreateFileBindingModel bindingModel = new CreateFileBindingModel(); bindingModel.FileName = "gogo"; bindingModel.DestPath = @"C:\Users\Nikih\Desktop\Resources"; fileService.CreateRar(bindingModel); FileAssert.Exists(@"C:\Users\Nikih\Desktop\Resources\gogo.zip"); }
private void CheckIfCancelIsPressed(CreateFileBindingModel createFileBindingModel) { //Uses CreateFileBindingModel to set its properties if (createFileBindingModel.IsPressed == false) { //Checks the user input in CreateFile form if the users hasn't pressed Cancel CheckUserPressedButton(createFileBindingModel); } CreateFileForm.Dispose(); CreateFileForm = new CreateFile(); }
public void CreateRar(CreateFileBindingModel createRarFileBindingModel) { //Uses CreateFileBindingModel to get specific information from it. //Sets the directory that the rar will be created with the name in a string string rarfolderDir = $@"{createRarFileBindingModel.DestPath}" + @"\" + $"{createRarFileBindingModel.FileName}"; //Creates a directory with the file Directory.CreateDirectory(rarfolderDir); //Creates the Rar file CreateRarFolder(rarfolderDir, rarfolderDir + ".zip"); //Deletes the rar folder and only the rar file is left Directory.Delete(rarfolderDir); }
public void CreateExcel(CreateFileBindingModel createExcelFileBindingModel) { //Uses CreateFileBindingModel to get specific information from it. //Creates a excel application that runs in the background. //In the background the application adds the things it needs to be opened after being created. Excel.Application objExcelApplication = new Excel.Application(); Excel.Workbook excelWorkbook = objExcelApplication.Workbooks.Add(Excel.XlWBATemplate.xlWBATWorksheet); Excel.Worksheet excelWorksheet = excelWorkbook.Worksheets[1]; //After the user has given a directory and a name for the file, it is saved there with that name. excelWorkbook.SaveAs(createExcelFileBindingModel.DestPath + @"\" + $"{createExcelFileBindingModel.FileName}"); //This closes the created in the background application and quits it. excelWorkbook.Close(); objExcelApplication.Quit(); }
public void CreateWord(CreateFileBindingModel createWordFileBindingModel) { //Uses CreateFileBindingModel to get specific information from it. //Creates a excel application that runs in the background. //In the background the application adds the things it needs to be opened after being created. Word.Application objWord = new Word.Application(); objWord.Visible = false; Word.Document objDoc = objWord.Documents.Add(); Word.Paragraph objPara; objPara = objDoc.Paragraphs.Add(); objPara.Range.Text = ""; //After the user has given a directory and a name for the file, it is saved there with that name. objDoc.SaveAs2(createWordFileBindingModel.DestPath + @"\" + $"{createWordFileBindingModel.FileName}"); //This closes the created in the background application and quits it. objDoc.Close(); objWord.Quit(); }
public void Create(CreateFileBindingModel textFileBindingModel) { //Uses CreateFileBindingModel to get specific information from it. File.Create(textFileBindingModel.DestPath + @"\" + $"{textFileBindingModel.FileName}.txt"); }
//Shows created file with its extension private void ShowCreatedFile(CreateFileBindingModel createFileBindingModel) { MessageBox.Show($"File {createFileBindingModel.FileName + Path.GetExtension(createFileBindingModel.FileName)} created!", "File Created!", MessageBoxButtons.OK, MessageBoxIcon.Information, 0, MessageBoxOptions.DefaultDesktopOnly); }
private void CheckAndCreateFile(CreateFileBindingModel createFileBindingModel) { if (createFileBindingModel.TextButtonPressed == true) { string file = createFileBindingModel.DestPath + @"\" + $"{createFileBindingModel.FileName}.txt"; if (!File.Exists(file)) { createTextFileService.Create(createFileBindingModel); fileName = $"Created {createFileBindingModel.FileName}.txt successfully"; createFileBindingModel.FileType = "Text"; fileType = $"File type: {createFileBindingModel.FileType}"; createFileBindingModel.TextButtonPressed = false; ShowCreatedFile(createFileBindingModel); } else { fileName = $"File {createFileBindingModel.FileName}.txt already exists"; createFileBindingModel.TextButtonPressed = false; ShowFileAlreadyExists(); } } else if (createFileBindingModel.WordButtonPressed == true) { string file = createFileBindingModel.DestPath + @"\" + $"{createFileBindingModel.FileName}.docx"; if (!File.Exists(file)) { createWordFileService.CreateWord(createFileBindingModel); fileName = $"Created {createFileBindingModel.FileName}.docx successfully"; createFileBindingModel.FileType = "Document"; fileType = $"File type: {createFileBindingModel.FileType}"; createFileBindingModel.WordButtonPressed = false; ShowCreatedFile(createFileBindingModel); } else { fileName = $"File {createFileBindingModel.FileName}.docx already exists"; createFileBindingModel.WordButtonPressed = false; ShowFileAlreadyExists(); } } else if (createFileBindingModel.PowerPointButtonPressed == true) { string file = createFileBindingModel.DestPath + @"\" + $"{createFileBindingModel.FileName}.pptx"; if (!File.Exists(file)) { createPowerPointFileService.CreatePowerPoint(createFileBindingModel); fileName = $"Created {createFileBindingModel.FileName}.pptx successfully"; createFileBindingModel.FileType = "Presentation"; fileType = $"File type: {createFileBindingModel.FileType}"; createFileBindingModel.PowerPointButtonPressed = false; ShowCreatedFile(createFileBindingModel); } else { fileName = $"File {createFileBindingModel.FileName}.pptx already exists"; createFileBindingModel.PowerPointButtonPressed = false; ShowFileAlreadyExists(); } } else if (createFileBindingModel.ExcelButtonPressed == true) { string file = createFileBindingModel.DestPath + @"\" + $"{createFileBindingModel.FileName}.xlsx"; if (!File.Exists(file)) { createExcelFileService.CreateExcel(createFileBindingModel); fileName = $"Created {createFileBindingModel.FileName}.xlsx successfully"; createFileBindingModel.FileType = "Excel Worksheet"; fileType = $"File type: {createFileBindingModel.FileType}"; createFileBindingModel.ExcelButtonPressed = false; ShowCreatedFile(createFileBindingModel); } else { fileName = $"File {createFileBindingModel.FileName}.xlsx already exists"; createFileBindingModel.ExcelButtonPressed = false; ShowFileAlreadyExists(); } } else if (createFileBindingModel.RarButtonPressed == true) { string file = createFileBindingModel.DestPath + @"\" + $"{createFileBindingModel.FileName}.rar"; if (!File.Exists(file)) { createRartFileService.CreateRar(createFileBindingModel); fileName = $"Created {createFileBindingModel.FileName}.rar successfully"; createFileBindingModel.FileType = "Rar Archive"; fileType = $"File type: {createFileBindingModel.FileType}"; createFileBindingModel.RarButtonPressed = false; ShowCreatedFile(createFileBindingModel); } else { fileName = $"File {createFileBindingModel.FileName}.rar already exists"; createFileBindingModel.RarButtonPressed = false; ShowFileAlreadyExists(); } } else { return; } }
private void CheckUserPressedButton(CreateFileBindingModel createFileBindingModel) { CheckAndCreateFile(createFileBindingModel); }
private static void CheckIfTextBoxIsEmpty(string textBoxText, CreateFile CreateFileForm, CreateFileBindingModel bindingModel) { //uses string textBoxText to get user input for a name of a file //uses CreateFile Form, KeyPressEventArgs to check if user has done everything properly on that form. //uses CreateFileBindingModel to set its properties. if (textBoxText != "") { SetCreateFileBindingModelName(textBoxText, bindingModel); CreateFileForm.Close(); } else { ShowMessage(); } }
public static async void CheckIfUserPressesEnterAsync(string textBoxText, CreateFile CreateFileForm, KeyPressEventArgs e, CreateFileBindingModel bindingModel) { //uses string textBoxText to get user input for a name of a file //uses CreateFile Form, KeyPressEventArgs to check if user has done everything properly on that form. //uses CreateFileBindingModel to set its properties. if (e.KeyChar == (char)Keys.Enter) { //checks if user has pressed Enter in CreateFile Form await Task.Run(() => CheckIfTextBoxIsEmpty(textBoxText, CreateFileForm, bindingModel)); } }
//Sets when user has pressed Rar button asynchronously on the CreateFile Form //Method is called in CreateFile Form to get the input of user public static async void SetCreateFileBindingModelRarPressedAsync(CreateFileBindingModel createFileBindingModel) { //uses CreateFileBindingModel to set its properties. await Task.Run(() => SetCreateFileBindingModelRarPressed(createFileBindingModel)); }
//Sets when user has pressed Rar //Method is called to be done asynchronously private static void SetCreateFileBindingModelRarPressed(CreateFileBindingModel createFileBindingModel) { //uses CreateBindingModel to get the user input for a pressed button and set it to binding model createFileBindingModel.RarButtonPressed = true; }
//Sets the name of the file that the user wants to be created private static void SetCreateFileBindingModelName(string text, CreateFileBindingModel createFileBindingModel) { //uses string text and CreateBindingModel to get the user input for a name of a file and set it to binding model createFileBindingModel.FileName = text; }