Ejemplo n.º 1
0
        /// <summary>
        /// Save results in file
        /// </summary>
        /// <param name="sender">Pressed button</param>
        /// <param name="e">Event data</param>
        private void saveButton_Click(object sender, EventArgs e)
        {
            string savedString;
            string header;
            string savePath  = destinationPathTextBox.Text;
            bool   saveState = false;

            switch (defaultsCheckBox.Checked)
            {
            case true:
                if (DialogResult.Yes == MessageBox.Show("Do you want to overwrite file \"results.txt\"", "Save results", MessageBoxButtons.YesNo, MessageBoxIcon.Information))
                {
                    File.WriteAllText(savePath, string.Empty);

                    foreach (var result in resultList)
                    {
                        savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                      result.Results.Count() + "," + result.Time;
                        saveState = saver.DefaultSaveResults(savedString);
                    }
                }
                else
                {
                    MessageBox.Show("Save failed.", "Save results", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                break;

            case false:
                if (savePath == "")
                {
                    MessageBox.Show("Please set destination path.", "Save results", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    if (File.Exists(savePath))
                    {
                        if (DialogResult.Yes == MessageBox.Show("Do you want to overwrite file " + path, "Save results", MessageBoxButtons.YesNo, MessageBoxIcon.Question))
                        {
                            File.WriteAllText(savePath, string.Empty);

                            if (rangeCheckBox.Checked && patternCheckBox.Checked && indexesCheckBox.Checked)
                            {
                                foreach (var result in resultList)
                                {
                                    savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                                  result.Results.Count() + "," + result.Time + "," + result.Range + "," + result.Pattern + "," + string.Join(",", result.Results.ToArray());
                                    header    = "Method,Range length,Pattern length,Sequences number,Search time,Range,Pattern,Indexes";
                                    saveState = saver.CustomSaveResults(savedString, header, savePath);
                                    saver.SetFirstSave(false);
                                }
                                saver.SetFirstSave(true);
                            }
                            else if (rangeCheckBox.Checked && patternCheckBox.Checked && !indexesCheckBox.Checked)
                            {
                                foreach (var result in resultList)
                                {
                                    savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                                  result.Results.Count() + "," + result.Time + "," + result.Range + "," + result.Pattern;
                                    header    = "Method,Range length,Pattern length,Sequences number,Search time,Range,Pattern";
                                    saveState = saver.CustomSaveResults(savedString, header, path);
                                    saver.SetFirstSave(false);
                                }
                                saver.SetFirstSave(true);
                            }
                            else if (rangeCheckBox.Checked && !patternCheckBox.Checked && indexesCheckBox.Checked)
                            {
                                foreach (var result in resultList)
                                {
                                    savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                                  result.Results.Count() + "," + result.Time + "," + result.Range + "," + string.Join(",", result.Results.ToArray());
                                    header    = "Method,Range length,Pattern length,Sequences number,Search time,Range,Indexes";
                                    saveState = saver.CustomSaveResults(savedString, header, savePath);
                                    saver.SetFirstSave(false);
                                }
                                saver.SetFirstSave(true);
                            }
                            else if (rangeCheckBox.Checked && !patternCheckBox.Checked && !indexesCheckBox.Checked)
                            {
                                foreach (var result in resultList)
                                {
                                    savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                                  result.Results.Count() + "," + result.Time + "," + result.Range;
                                    header    = "Method,Range length,Pattern length,Sequences number,Search time,Range";
                                    saveState = saver.CustomSaveResults(savedString, header, savePath);
                                    saver.SetFirstSave(false);
                                }
                                saver.SetFirstSave(true);
                            }
                            else if (!rangeCheckBox.Checked && patternCheckBox.Checked && indexesCheckBox.Checked)
                            {
                                foreach (var result in resultList)
                                {
                                    savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                                  result.Results.Count() + "," + result.Time + "," + result.Pattern + "," + string.Join(",", result.Results.ToArray());
                                    header    = "Method,Range length,Pattern length,Sequences number,Search time,Pattern,Indexes";
                                    saveState = saver.CustomSaveResults(savedString, header, savePath);
                                    saver.SetFirstSave(false);
                                }
                                saver.SetFirstSave(true);
                            }
                            else if (!rangeCheckBox.Checked && patternCheckBox.Checked && !indexesCheckBox.Checked)
                            {
                                foreach (var result in resultList)
                                {
                                    savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                                  result.Results.Count() + "," + result.Time + "," + result.Pattern + ",";
                                    header    = "Method,Range length,Pattern length,Sequences number,Search time,Pattern";
                                    saveState = saver.CustomSaveResults(savedString, header, savePath);
                                    saver.SetFirstSave(false);
                                }
                                saver.SetFirstSave(true);
                            }
                            else if (!rangeCheckBox.Checked && !patternCheckBox.Checked && indexesCheckBox.Checked)
                            {
                                foreach (var result in resultList)
                                {
                                    savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                                  result.Results.Count() + "," + result.Time + "," + string.Join(",", result.Results.ToArray());
                                    header    = "Method,Range length,Pattern length,Sequences number,Search time,Indexes";
                                    saveState = saver.CustomSaveResults(savedString, header, savePath);
                                    saver.SetFirstSave(false);
                                }
                                saver.SetFirstSave(true);
                            }
                            else if (!rangeCheckBox.Checked && !patternCheckBox.Checked && !indexesCheckBox.Checked)
                            {
                                foreach (var result in resultList)
                                {
                                    savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                                  result.Results.Count() + "," + result.Time;
                                    header    = "Method,Range length,Pattern length,Sequences number,Search time";
                                    saveState = saver.CustomSaveResults(savedString, header, savePath);
                                    saver.SetFirstSave(false);
                                }
                                saver.SetFirstSave(true);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Save failed.", "Save results", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            return;
                        }
                    }
                    else
                    {
                        if (rangeCheckBox.Checked && patternCheckBox.Checked && indexesCheckBox.Checked)
                        {
                            foreach (var result in resultList)
                            {
                                savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                              result.Results.Count() + "," + result.Time + "," + result.Range + "," + result.Pattern + "," + string.Join(",", result.Results.ToArray());
                                header    = "Method,Range length,Pattern length,Sequences number,Search time,Range,Pattern,Indexes";
                                saveState = saver.CustomSaveResults(savedString, header, savePath);
                                saver.SetFirstSave(false);
                            }
                            saver.SetFirstSave(true);
                        }
                        else if (rangeCheckBox.Checked && patternCheckBox.Checked && !indexesCheckBox.Checked)
                        {
                            foreach (var result in resultList)
                            {
                                savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                              result.Results.Count() + "," + result.Time + "," + result.Range + "," + result.Pattern;
                                header    = "Method,Range length,Pattern length,Sequences number,Search time,Range,Pattern";
                                saveState = saver.CustomSaveResults(savedString, header, path);
                                saver.SetFirstSave(false);
                            }
                            saver.SetFirstSave(true);
                        }
                        else if (rangeCheckBox.Checked && !patternCheckBox.Checked && indexesCheckBox.Checked)
                        {
                            foreach (var result in resultList)
                            {
                                savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                              result.Results.Count() + "," + result.Time + "," + result.Range + "," + string.Join(",", result.Results.ToArray());
                                header    = "Method,Range length,Pattern length,Sequences number,Search time,Range,Indexes";
                                saveState = saver.CustomSaveResults(savedString, header, savePath);
                                saver.SetFirstSave(false);
                            }
                            saver.SetFirstSave(true);
                        }
                        else if (rangeCheckBox.Checked && !patternCheckBox.Checked && !indexesCheckBox.Checked)
                        {
                            foreach (var result in resultList)
                            {
                                savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                              result.Results.Count() + "," + result.Time + "," + result.Range;
                                header    = "Method,Range length,Pattern length,Sequences number,Search time,Range";
                                saveState = saver.CustomSaveResults(savedString, header, savePath);
                                saver.SetFirstSave(false);
                            }
                            saver.SetFirstSave(true);
                        }
                        else if (!rangeCheckBox.Checked && patternCheckBox.Checked && indexesCheckBox.Checked)
                        {
                            foreach (var result in resultList)
                            {
                                savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                              result.Results.Count() + "," + result.Time + "," + result.Pattern + "," + string.Join(",", result.Results.ToArray());
                                header    = "Method,Range length,Pattern length,Sequences number,Search time,Pattern,Indexes";
                                saveState = saver.CustomSaveResults(savedString, header, savePath);
                                saver.SetFirstSave(false);
                            }
                            saver.SetFirstSave(true);
                        }
                        else if (!rangeCheckBox.Checked && patternCheckBox.Checked && !indexesCheckBox.Checked)
                        {
                            foreach (var result in resultList)
                            {
                                savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                              result.Results.Count() + "," + result.Time + "," + result.Pattern + ",";
                                header    = "Method,Range length,Pattern length,Sequences number,Search time,Pattern";
                                saveState = saver.CustomSaveResults(savedString, header, savePath);
                                saver.SetFirstSave(false);
                            }
                            saver.SetFirstSave(true);
                        }
                        else if (!rangeCheckBox.Checked && !patternCheckBox.Checked && indexesCheckBox.Checked)
                        {
                            foreach (var result in resultList)
                            {
                                savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                              result.Results.Count() + "," + result.Time + "," + string.Join(",", result.Results.ToArray());
                                header    = "Method,Range length,Pattern length,Sequences number,Search time,Indexes";
                                saveState = saver.CustomSaveResults(savedString, header, savePath);
                                saver.SetFirstSave(false);
                            }
                            saver.SetFirstSave(true);
                        }
                        else if (!rangeCheckBox.Checked && !patternCheckBox.Checked && !indexesCheckBox.Checked)
                        {
                            foreach (var result in resultList)
                            {
                                savedString = result.Method.ToString() + "," + result.Range.Length + "," + result.Pattern.Length + "," +
                                              result.Results.Count() + "," + result.Time;
                                header    = "Method,Range length,Pattern length,Sequences number,Search time";
                                saveState = saver.CustomSaveResults(savedString, header, savePath);
                                saver.SetFirstSave(false);
                            }
                            saver.SetFirstSave(true);
                        }
                    }
                }
                break;
            }
            if (saveState)
            {
                MessageBox.Show("File saved", "Save results", MessageBoxButtons.OK, MessageBoxIcon.Information);
                mainWindow.saveFileMenuItem.Enabled  = false;
                mainWindow.saveResultsButton.Enabled = false;
                resultList.Clear();
                Close();
            }
            else
            {
                MessageBox.Show("File can't be saved.", "Save results", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }