예제 #1
0
        // exporting items to directories accordingly to type and zipping them together
        private void exportButton_Click(object sender, EventArgs e)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();

            saveFileDialog.InitialDirectory = "C:\\";
            saveFileDialog.Filter           = "Zip Files | *.zip";
            saveFileDialog.ShowDialog();
            if (saveFileDialog.FileName != "" && !File.Exists(saveFileDialog.FileName))
            {
                FileManipulation.CreateExportationFolders(saveFileDialog.FileName);

                // exporting each row according to type: list, reaction program, stroop program or experiment program
                foreach (DataGridViewRow row in exportDataGridView.Rows)
                {
                    if (row.Cells[1].Value.ToString() == LocRM.GetString("lists", currentCulture))
                    {
                        if ((row.Cells[0].Value.ToString().Split('_')[1] == "color") || (row.Cells[0].Value.ToString().Split('_')[1] == "words"))
                        {
                            exportFile(row.Cells[2].Value.ToString(), Path.GetDirectoryName(saveFileDialog.FileName) + "/ExportingFiles/Lists/" + row.Cells[0].Value.ToString() + ".lst");
                        }
                        else
                        {
                            exportListContent(row.Cells[0].Value.ToString(), Path.GetDirectoryName(saveFileDialog.FileName) + "/ExportingFiles/Lists");
                        }
                    }
                    else if (row.Cells[1].Value.ToString() == LocRM.GetString("reactionTest", currentCulture))
                    {
                        exportFile(row.Cells[2].Value.ToString(), Path.GetDirectoryName(saveFileDialog.FileName) + "/ExportingFiles/" + "ReactionProgram/" + row.Cells[0].Value.ToString() + ".prg");
                    }
                    else if (row.Cells[1].Value.ToString() == LocRM.GetString("stroopTest", currentCulture))
                    {
                        exportFile(row.Cells[2].Value.ToString(), Path.GetDirectoryName(saveFileDialog.FileName) + "/ExportingFiles/" + "StroopProgram/" + row.Cells[0].Value.ToString() + ".prg");
                    }
                    else if (row.Cells[1].Value.ToString() == LocRM.GetString("matchingTest", currentCulture))
                    {
                        exportFile(row.Cells[2].Value.ToString(), Path.GetDirectoryName(saveFileDialog.FileName) + "/ExportingFiles/" + "MatchingProgram/" + row.Cells[0].Value.ToString() + ".prg");
                    }
                    else if (row.Cells[1].Value.ToString() == LocRM.GetString("experiment", currentCulture))
                    {
                        exportFile(row.Cells[2].Value.ToString(), Path.GetDirectoryName(saveFileDialog.FileName) + "/ExportingFiles/" + "ExperimentProgram/" + row.Cells[0].Value.ToString() + ".prg");
                    }
                }

                ZipFile.CreateFromDirectory(Path.GetDirectoryName(saveFileDialog.FileName) + "/ExportingFiles/", @saveFileDialog.FileName);
                Directory.Delete(Path.GetDirectoryName(saveFileDialog.FileName) + "/ExportingFiles/", true);
                MessageBox.Show(LocRM.GetString("exportSuccess", currentCulture));
                Parent.Controls.Remove(this);
            }
            else
            {
                MessageBox.Show(LocRM.GetString("exportDirectory", currentCulture));
            }
        }