//Sends a given array to a .HTML file and opens said file. public static void SendToHTML(string[,] FileHolder1, int NoElements) { string[] FilePaths = Class1.SortArrayBubble(); //holds all file paths List <string> lines = new List <string>(); // list used to stored .HTML code for writing to file //>HTML code for a table lines.Add("<html>"); lines.Add("<body>"); lines.Add("<table>"); lines.Add("<tr>"); //strips all file paths down till the name of said file is left, used to heading in the .HTML table for (int i = 0; i < 11; i++) { FilePaths[i] = Regex.Replace(Path.GetFileNameWithoutExtension(FilePaths[i]), @"[\d-]", string.Empty).Replace("_", ""); lines.Add("<td><b>||" + FilePaths[i] + "<b></td>"); } lines.Add("</tr>"); //loops through array displaying all its contents into a table for (int i = 0; i < NoElements; i++) { lines.Add("<tr>"); for (int y = 0; y < 11; y++) { lines.Add("<td>||" + FileHolder1[y, i] + "</td>"); } lines.Add("<tr>"); } lines.Add("</table>"); lines.Add("</body>"); lines.Add("</html>"); File.WriteAllLines(@"K:\Algorithms_Complexity\MergeTwoFiles - Testing 3\Spare Files\myfile.htm", lines.ToArray()); //writes the list to a given .HTML file System.Diagnostics.Process.Start(@"K:\Algorithms_Complexity\MergeTwoFiles - Testing 3\Spare Files\myfile.htm"); //opens said .HTML file }
//Entering data for searching all data files public static void EnterDataSearch(ref string[] DataHolder) { //All of the 1st set of files in array string[] FilePaths = Class1.SortArrayBubble(); Console.WriteLine("You will now have to enter 11 peices of data to search by: "); for (int i = 0; i < 11; i++) { //strip file path down to file down FilePaths[i] = Regex.Replace(Path.GetFileNameWithoutExtension(FilePaths[i]), @"[\d-]", string.Empty).Replace("_", ""); bool TF = false; while (TF == false) { Console.WriteLine("Please Enter the {0} you would like to search for:", FilePaths[i]); try { DataHolder[i] = Console.ReadLine(); TF = true; if (DataHolder[i] == "") { TF = false; } } //catches errors catch (System.FormatException e) { Console.WriteLine("Exception caught: {0}", e); Console.WriteLine(); } } } }
//Sorts in Ascending or Descending Order public static void AsendingDesendingOrder(ref string[,] FileHolder1, int size, int SortChoice, ref bool Menu3) { string[] FilePaths = Class1.SortArrayBubble(); // assigns array all file paths from folder bool ExitFirstWhile = false; // used for first whils loop bool TF2 = false; // used for two while loop bool TF3 = false; //used for thrid while loop int PositionToOrder = -1; while (ExitFirstWhile == false) { //output all files avaliable for sorting Console.Clear(); Console.WriteLine("Below Shows all Avaliable file Titles: "); for (int i = 0; i < 11; i++) { FilePaths[i] = Regex.Replace(Path.GetFileNameWithoutExtension(FilePaths[i]), @"[\d-]", string.Empty).Replace("_", "");// displays the file names for user to chose from Console.WriteLine(FilePaths[i]); } Console.WriteLine("Please Enter the File you Wish to sort: "); string UserChoice = Console.ReadLine();// user input data bool EnterCorrect = false; for (int i = 0; i < 11; i++) { if (UserChoice == FilePaths[i]) // checks if the user has input a valid file path name { EnterCorrect = true; PositionToOrder = i; } } try { if (EnterCorrect == true) { while (TF2 == false) { Console.WriteLine(""); Console.WriteLine("Please Enter A for ascending or D for Descending: "); char UserInput; try { //checks the following statements for errors UserInput = Convert.ToChar(Console.ReadLine()); if ((UserInput == 'd' || UserInput == 'D' || UserInput == 'a' || UserInput == 'A')) //checks the user entered a valid letter for either choice Descending or Ascending { int Choice = -1; if (UserInput == 'd' || UserInput == 'D') //Descending { Choice = 0; //Descending = 0 if (SortChoice == 1) //bubble sort { BubbleSort.SortBubble(ref FileHolder1, size, PositionToOrder); //bubble sorts the array given Class1.SendToHTML(FileHolder1, size); //outputs to .HTML file } else if (SortChoice == 2) //heap sort { int OperationCount = 0; HeapSortSortDataFiles hs = new HeapSortSortDataFiles(); Class1.ChangeMonthsToInt(ref FileHolder1, size, 1); //changes months to ints hs.PerformHeapSort(ref FileHolder1, PositionToOrder, size, ref OperationCount); //performs a heap sort Class1.ChangeIntToMonth(ref FileHolder1, size); // changes int to months Class1.SwapValues(ref FileHolder1, size); // swaps values for descending Class1.SendToHTML(FileHolder1, size); //outputs to .HTML file //outputs the number of operations takesn for the sort Console.WriteLine("In this Heap sort, there were {0} operations in changing data!", OperationCount); Console.ReadLine(); } } else if (UserInput == 'a' || UserInput == 'A') //Ascending { Choice = 1; //Descending = 0 if (SortChoice == 1) //bubble sort { BubbleSort.SortBubble(ref FileHolder1, size, PositionToOrder); //bubble sorts the array given Class1.SwapValues(ref FileHolder1, size); //swaps values becuase descending was chose Class1.SendToHTML(FileHolder1, size); //outputs to .HTML file } else if (SortChoice == 2) //heap sort { int OperationCount = 0; HeapSortSortDataFiles hs = new HeapSortSortDataFiles(); Class1.ChangeMonthsToInt(ref FileHolder1, size, 1); //changes months to ints hs.PerformHeapSort(ref FileHolder1, PositionToOrder, size, ref OperationCount); //performs a heap sort Class1.ChangeIntToMonth(ref FileHolder1, size); // changes int to months Class1.SendToHTML(FileHolder1, size); //outputs to .HTML file //outputs the number of operations takesn for the sort Console.WriteLine("In this Heap sort, there were {0} operations in changing data!", OperationCount); Console.ReadLine(); } } } TF2 = true; } catch (System.FormatException e)//Exception handling { Console.WriteLine("Exception caught: {0}", e); Console.WriteLine(); } } while (TF3 == false) { Console.WriteLine("Would you like to sort another file? Enter Y/N "); string UserExitInput; try { //checks user input UserExitInput = Console.ReadLine(); if (UserExitInput == "y" || UserExitInput == "Y") //checks if user enter YES { TF3 = true; TF2 = true; ExitFirstWhile = true; } //if they didnt enter YES else { TF3 = true; TF2 = true; ExitFirstWhile = true; Menu3 = true; } } catch (System.FormatException e)//Exception handling { Console.WriteLine("Exception caught: {0}", e); Console.WriteLine(); } } } } catch (System.FormatException e) //Exception handling { Console.WriteLine("Exception caught: {0}", e); Console.WriteLine(); } Class1.WriteToFile(FileHolder1, size); //writes to .CSV file } }
public static void SearchingIndividual(string[,] FileHolder, int Size, int SortChoice, ref bool ExitCase) { //Class1.SendToHTML(FileHolder,Size); int UserInput3 = -1; bool Menu3 = false; while (Menu3 == false) { //sorts all the files into a array FilePaths string[] FilePaths = Class1.SortArrayBubble(); Console.Clear(); Console.WriteLine("Below Shows all Avaliable file Titles: "); //strips all the file path and leaves the name of file for (int i = 0; i < 11; i++) { FilePaths[i] = Regex.Replace(Path.GetFileNameWithoutExtension(FilePaths[i]), @"[\d-]", string.Empty).Replace("_", ""); Console.WriteLine("{0} : {1}", i, FilePaths[i]); } Console.WriteLine("Please Enter the number for the file you wish to search: "); try { //User Input checked UserInput3 = Convert.ToInt16(Console.ReadLine()); bool Menu4 = false; while (Menu4 == false) { string UserInput4; Console.WriteLine("Please Enter the Data you want to search for: (enure When you enter a decimal you make it three decimal places) "); try { //User Input checked UserInput4 = Console.ReadLine(); if (SortChoice == 1) { //changes the input into a int using chnage to int method string[,] TempChoice = new string[1, 1]; TempChoice[0, 0] = UserInput4; Class1.ChangeMonthsToInt(ref TempChoice, 1, 0); UserInput4 = TempChoice[0, 0]; BinarySearchClass.BinarySearch(FileHolder, UserInput4, UserInput3, -1, -1, Size); //binary search } else if (SortChoice == 2) { LinearSearch.SearchLinear(FileHolder, UserInput4, UserInput3, Size); //linear search } bool Menu5 = false; while (Menu5 == false) { Console.WriteLine("Please Enter y/n if you want to search again: "); string UserInput5; try { //User Input checked UserInput5 = Console.ReadLine(); if (UserInput5 == "y" || UserInput5 == "Y") //checks to see if its yes { Menu5 = true; Menu4 = true; } else { Menu5 = true; Menu4 = true; Menu3 = true; ExitCase = true; } } catch (System.FormatException e) //Exception Handling { Console.Clear(); Console.WriteLine("Exception caught: {0}", e); Console.WriteLine(); } } } catch (System.FormatException e) //Exception Handling { Console.Clear(); Console.WriteLine("Exception caught: {0}", e); Console.WriteLine(); } } } catch (System.FormatException e) //Exception Handling { Console.Clear(); Console.WriteLine("Exception caught: {0}", e); Console.WriteLine(); } } }