private void exportQueryAsFileButton_Click(object sender, EventArgs e)
        {
            string Filename;
            string Outstring;

            if (thisFormResult.GetType() == typeof(RBACS.UserQueryResult))
            {
                UserQueryResult UQR = (UserQueryResult)thisFormResult;
                Filename  = parentReference.PreferredExportFilepath + "\\" + UQR.AccountName + ".txt";
                Outstring = FileHelperFuctions.ReturnFormattedPersonInfo(UQR, parentReference.GroupNamesAndDescriptionsAll, parentReference.ByTitle);
            }
            else if (thisFormResult.GetType() == typeof(RBACS.GroupingQueryResult))
            {
                GroupingQueryResult GQR = (GroupingQueryResult)thisFormResult;
                Filename  = parentReference.PreferredExportFilepath + "\\" + FileHelperFuctions.ReturnAcceptableFileName(GQR.GroupingName) + ".txt";
                Outstring = FileHelperFuctions.ReturnFormattedGroupInfo(parentReference.UserQueryResults, GQR, parentReference.GroupNamesAndDescriptionsAll);
            }
            else
            {
                Filename = ""; Outstring = "";
            }

            TextWriter QueryText = new StreamWriter(Filename);

            QueryText.Write(Outstring);
            QueryText.Dispose();
        }
        private void recommendTemplateButton_Click(object sender, EventArgs e)
        {
            List <QueryResult> QRList = new List <QueryResult>();
            string             Title;

            if (nNDataGridView.SelectedRows.Count > 0)
            {
                Title = $"User Selection from {nNDataGridView.Rows.Count} Nearest Neighbours, {qRName}";
            }
            else
            {
                Title = $"{nNDataGridView.Rows.Count} Nearest Neighbours, {qRName}";
            }
            if (thisFormResultType == typeof(UserQueryResult))
            {
                Converter <UserQueryResult, QueryResult> Converter = new Converter <UserQueryResult, QueryResult>(uQtoQR);
                QRList = HelperFunctions.DatagridViewToQueryResultList(nNDataGridView, 4, parentReference.UserQueryResults.ConvertAll <QueryResult>(Converter));
                QRList.Add(thisFormResult);
                string       InputString   = FileHelperFuctions.ReturnRecommendationString(QRList, parentReference.GroupNamesAndDescriptionsAll, parentReference.Threshold);
                TemplateForm ResultantForm = new TemplateForm(InputString, Title);
                ResultantForm.Show();
            }
            else
            {
                Converter <GroupingQueryResult, QueryResult> Converter = new Converter <GroupingQueryResult, QueryResult>(gQtoQR);
                QRList = HelperFunctions.DatagridViewToQueryResultList(nNDataGridView, 1, parentReference.GroupingQueryResults.ConvertAll <QueryResult>(Converter));
                QRList.Add(thisFormResult);
                string       InputString   = FileHelperFuctions.ReturnRecommendationString(QRList, parentReference.GroupNamesAndDescriptionsAll, parentReference.Threshold);
                TemplateForm ResultantForm = new TemplateForm(InputString, Title);
                ResultantForm.Show();
            }
        }
        private void recommendTemplateButton_Click(object sender, EventArgs e)
        {
            List <QueryResult> QRList = new List <QueryResult>();

            foreach (Cluster C in thisAlgo.Clusters)
            {
                string Title = $"Based on Cluster {C.ListPosition}, clustered by {thisAlgo.GetType().ToString().Split('.')[1]}";
                if (thisFormResultType == typeof(UserQueryResult))
                {
                    Converter <UserQueryResult, QueryResult> Converter = new Converter <UserQueryResult, QueryResult>(uQtoQR);
                    QRList = HelperFunctions.DatagridViewSubsetToQueryResultList(clustersDataGridView, 4, 0, C.ListPosition.ToString(), parentReference.UserQueryResults.ConvertAll <QueryResult>(Converter));

                    string       InputString   = FileHelperFuctions.ReturnRecommendationString(QRList, parentReference.GroupNamesAndDescriptionsAll, parentReference.Threshold);
                    TemplateForm ResultantForm = new TemplateForm(InputString, Title);
                    ResultantForm.Show();
                }
                else
                {
                    Converter <GroupingQueryResult, QueryResult> Converter = new Converter <GroupingQueryResult, QueryResult>(gQtoQR);
                    QRList = HelperFunctions.DatagridViewSubsetToQueryResultList(clustersDataGridView, 1, 0, C.ListPosition.ToString(), parentReference.GroupingQueryResults.ConvertAll <QueryResult>(Converter));

                    string       InputString   = FileHelperFuctions.ReturnRecommendationString(QRList, parentReference.GroupNamesAndDescriptionsAll, parentReference.Threshold);
                    TemplateForm ResultantForm = new TemplateForm(InputString, Title);
                    ResultantForm.Show();
                }
            }
        }
        private void exportAsCSVButton_Click(object sender, EventArgs e)
        {
            string CSVString = FileHelperFuctions.ReturnCSVString(clustersDataGridView);
            string FileName;

            if (thisFormResultType == typeof(UserQueryResult))
            {
                FileName = $"{parentReference.PreferredExportFilepath}\\ClusterResultsByUser.csv";
                File.WriteAllText(FileName, CSVString);
            }
            else if (thisFormResultType == typeof(GroupingQueryResult))
            {
                string TypeOfGroup;
                if (parentReference.ByTitle)
                {
                    TypeOfGroup = "Title";
                }
                else
                {
                    TypeOfGroup = "Description";
                }
                FileName = $"{parentReference.PreferredExportFilepath}\\ClusterResultsBy{TypeOfGroup}.csv";
                File.WriteAllText(FileName, CSVString);
            }
            else
            {
            }
        }
        private void kNNAsFileButton_Click(object sender, EventArgs e)
        {
            string FileName;
            string FileContent = "";

            if (thisFormResultType == typeof(UserQueryResult))
            {
                UserQueryResult      UQR     = (UserQueryResult)thisFormResult;
                List <UserKNNResult> UKRList = AllKNNResults.Cast <UserKNNResult>().ToList();
                FileName = $"{parentReference.PreferredExportFilepath}\\{UQR.Name} {kTextBox.Text} Nearest Neighbours.txt";
                int i = 1;
                foreach (UserKNNResult UKR in UKRList)
                {
                    FileContent = FileContent + FileHelperFuctions.FirstSecondEtc(i) + $" Nearest Neighbour to {UQR.AccountName}, Distance of {UKR.Distance}:\r\n\r\n#########################################################\r\n"
                                  + FileHelperFuctions.ReturnFormattedPersonInfo(new UserQueryResult(UKR.Title, UKR.Description, UKR.Name, UKR.AccountName, UKR.DistinguishedName, UKR.ReturnAccessVector()), parentReference.GroupNamesAndDescriptionsAll, parentReference.ByTitle);
                    i++;
                }

                TextWriter UTextWr = new StreamWriter(FileName);
                UTextWr.Write(FileContent);
                UTextWr.Dispose();
            }
            else if (thisFormResultType == typeof(GroupingQueryResult))
            {
                //only puts out single file at this point
                //don't see why multiple files would even be desirable for KNN Results

                GroupingQueryResult      GQR     = (GroupingQueryResult)thisFormResult;
                List <GroupingKNNResult> GKRList = AllKNNResults.Cast <GroupingKNNResult>().ToList();
                FileName = $"{parentReference.PreferredExportFilepath}\\{FileHelperFuctions.ReturnAcceptableFileName(GQR.GroupingName)} {kTextBox.Text} Nearest Neighbours.txt";
                int i2 = 1;
                foreach (GroupingKNNResult GKR in GKRList)
                {
                    FileContent = FileContent + FileHelperFuctions.FirstSecondEtc(i2) + $" Nearest Neighbour to {GQR.GroupingName}, Distance of {GKR.Distance}:\r\n\r\n#########################################################\r\n"
                                  + FileHelperFuctions.ReturnFormattedGroupSummary(new GroupingQueryResult(GKR), parentReference.GroupNamesAndDescriptionsAll);
                    i2++;
                }

                TextWriter GTextWr = new StreamWriter(FileName);
                GTextWr.Write(FileContent);
                GTextWr.Dispose();
            }
            else
            {
            }
        }
        private void kNNAsCSVButton_Click(object sender, EventArgs e)
        {
            string CSVString = FileHelperFuctions.ReturnCSVString(nNDataGridView);
            string FileName;

            if (thisFormResultType == typeof(UserQueryResult))
            {
                UserQueryResult UQR = (UserQueryResult)thisFormResult;
                FileName = $"{parentReference.PreferredExportFilepath}\\{UQR.Name} {kTextBox.Text} Nearest Neighbours.csv";
                File.WriteAllText(FileName, CSVString);
            }
            else if (thisFormResultType == typeof(GroupingQueryResult))
            {
                GroupingQueryResult GQR = (GroupingQueryResult)thisFormResult;
                FileName = $"{parentReference.PreferredExportFilepath}\\{FileHelperFuctions.ReturnAcceptableFileName(GQR.GroupingName)} {kTextBox.Text} Nearest Neighbours.csv";
                File.WriteAllText(FileName, CSVString);
            }
            else
            {
            }
        }