示例#1
0
        private void exitApplicationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "CSV Files(.csv)|*.csv";

            PopUp exitPopUp = new PopUp();

            exitPopUp.message = "Do you want to Save your work before you Quit?";
            exitPopUp.caption = "Confirm";
            exitPopUp.buttons = MessageBoxButtons.YesNoCancel;
            exitPopUp.result  = MessageBox.Show(exitPopUp.message, exitPopUp.caption, exitPopUp.buttons);

            if (exitPopUp.result == DialogResult.Yes)
            {
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    ExportToCSV(dataGridView1, saveFileDialog1.FileName);
                }
                else
                {
                    MessageBox.Show("Error!");
                }
                this.Close();
            }
            else if (exitPopUp.result == DialogResult.No)
            {
                exitPopUp.message = "Are you sure you want to Quit without Saving?\nPotential Fileloss!";
                exitPopUp.caption = "Are you sure?";
                exitPopUp.buttons = MessageBoxButtons.YesNo;

                if (exitPopUp.result == DialogResult.Yes)
                {
                    this.Close();
                }
                else if (exitPopUp.result == DialogResult.No)
                {
                    if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                    {
                        ExportToCSV(dataGridView1, saveFileDialog1.FileName);
                    }

                    if (exitPopUp.result == DialogResult.OK)
                    {
                        this.Close();
                    }
                }
            }
        }
示例#2
0
        private void exportLocalisationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Initializes the PopUp class and a SaveFileDialog
            PopUp toolStripPopUp = new PopUp();

            toolStripPopUp.message = ("The File was saved succesfully!");

            SaveFileDialog saveFileDialog1 = new SaveFileDialog();

            saveFileDialog1.Filter = "CSV Files(.csv)|*.csv";

            //If the User sucessfully managed to choose a File Name, do ExportToCSV.
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                ExportToCSV(dataGridView1, saveFileDialog1.FileName);
            }
        }
示例#3
0
        private void openTextFile()
        {
            if ((Control.MouseButtons & MouseButtons.Left) == MouseButtons.Left)
            {
                PopUp errorMessage = new PopUp();

                errorMessage.message = "The File path was invalid!";
                errorMessage.caption = "Warning!";
                errorMessage.buttons = MessageBoxButtons.OK;
                errorMessage.icon    = MessageBoxIcon.Error;

                if (Directory.Exists(fileLabel2.Text))
                {
                    var fileToOpen = fileLabel2.Text;

                    var process = new Process();
                    process.StartInfo = new ProcessStartInfo()
                    {
                        UseShellExecute = true,
                        FileName        = fileToOpen
                    };

                    process.Start();
                }
                else if (!Directory.Exists(fileLabel2.Text))
                {
                    MessageBox.Show(errorMessage.message, errorMessage.caption, errorMessage.buttons, errorMessage.icon, errorMessage.defaultButtons);
                }
                else
                {
                    errorMessage.message = "CRITICAL ERROR!";

                    MessageBox.Show(errorMessage.message, errorMessage.caption, errorMessage.buttons, errorMessage.icon, errorMessage.defaultButtons);
                }
            }
        }
示例#4
0
        private void importEventsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Lets the User select an Event file to import
            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.Filter      = "Text files(.txt)|*.txt";
            openFileDialog1.FilterIndex = 1;

            //If the user has selected a "*.txt" file, start scanning the lines of said file.
            if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName.Contains(".txt"))
            {
                PopUp importPopUp = new PopUp();

                if (dt.Rows.Count > 0)
                {
                    importPopUp.message = "Do you want to clear the Data Table?";
                    importPopUp.caption = "Confirm";
                    importPopUp.buttons = MessageBoxButtons.YesNo;
                    importPopUp.result  = MessageBox.Show(importPopUp.message, importPopUp.caption, importPopUp.buttons);
                }

                if (importPopUp.result == DialogResult.Yes)
                {
                    dt.Rows.Clear();
                    dataGridView1.Refresh();
                }
                #region StringsTextSearch
                int    index = 0;
                string currentLine;
                string evtDesc    = "desc = ";
                string optName    = "name = ";
                string delimiter1 = "has_";
                string delimiter2 = " ";

                #endregion

                //Reads all lines in the file, and puts them in an Array
                string[] lines = File.ReadAllLines(openFileDialog1.FileName);

                //Checks if the scanned line contains any of the characters needed to identify which kind of line it is
                for (int i = 0; i < lines.Length; i++)
                {
                    //Stores the currently selected line's index
                    currentLine = lines[i];

                    if (currentLine.Contains(evtDesc) && !currentLine.Contains('{'))
                    {
                        ProcessLines(currentLine, index);
                    }
                    else if (currentLine.Contains(optName) && !currentLine.Contains(delimiter1) && !currentLine.Contains('{'))
                    {
                        ProcessLines(currentLine, index);
                    }
                }

                importPopUp.message = "Your file was successfully imported!";
                importPopUp.icon    = MessageBoxIcon.None;
                importPopUp.caption = "Success!";

                importPopUp.result = MessageBox.Show(importPopUp.message, importPopUp.caption, importPopUp.buttons);

                fileLabel2.Text = openFileDialog1.SafeFileName;
            }
        }
示例#5
0
        private void ExportToCSV(DataGridView gridIn, string outputFilePath)
        {
            //Checks if the DataGridView has any rows, and if it does the saving process is started.
            if (gridIn.RowCount > 0)
            {
                PopUp           exportPopUp = new PopUp();
                string          value       = "";
                DataGridViewRow gridRow     = new DataGridViewRow();
                StreamWriter    export      = new StreamWriter(outputFilePath, true);

                //Write header rows to csv
                for (int i = 0; i <= gridIn.Columns.Count - 1; i++)
                {
                    if (i > 0)
                    {
                        export.Write(";");
                    }
                    export.Write(gridIn.Columns[i].HeaderText);
                }

                export.WriteLine();

                //Write DataGridView rows to csv
                for (int j = 0; j <= gridIn.Rows.Count - 1; j++)
                {
                    if (j > 0)
                    {
                        export.WriteLine();
                    }

                    gridRow = gridIn.Rows[j];

                    for (int i = 0; i <= gridIn.Columns.Count - 1; i++)
                    {
                        if (i > 0)
                        {
                            export.Write(";");
                        }

                        //Partly stolen, hence I'm researching exactly what the whole embedded newlines business is about.
                        value = gridRow.Cells[i].Value.ToString();
                        //Replace comma's with spaces
                        value = value.Replace(',', ' ');
                        //Replace embedded newlines with spaces
                        value = value.Replace(Environment.NewLine, " ");

                        export.Write(value);
                    }
                }
                exportPopUp.message = "Your file was successfully exported!";
                exportPopUp.caption = "Success";
                exportPopUp.buttons = MessageBoxButtons.OK;
                exportPopUp.result  = MessageBox.Show(exportPopUp.message, exportPopUp.caption, exportPopUp.buttons);

                if (exportPopUp.result == DialogResult.OK)
                {
                    export.Close();
                }
            }
            else
            {
                PopUp errorBox = new PopUp();
                errorBox.message = ("The File could not be saved, missing rows");
                errorBox.caption = ("Critical Error");
                errorBox.icon    = (MessageBoxIcon.Error);

                MessageBox.Show(errorBox.message, errorBox.caption, errorBox.buttons, errorBox.icon, errorBox.defaultButtons);
            }
        }