Exemple #1
0
 private bool filesHasNoDepedency()
 {
     if (mode == 'r' && destinationFilesList.Items.Count > 0)
     {
         for (int count = 0; count < destinationFilesList.Items.Count; count++)
         {
             if (this.type == LocRM.GetString("experiment"))
             {
                 ExperimentProgram experiment = new ExperimentProgram();
                 experiment.ExperimentName = Path.GetFileNameWithoutExtension(destinationFilesList.Items[count].ToString());
                 try
                 {
                     experiment.ReadProgramFile(true);
                 }
                 catch (MissingMemberException e)
                 {
                     MessageBox.Show(e.Message + " " + LocRM.GetString("cantBeFoundPleaseRocoverFirst", currentCulture) + destinationFilesList.Items[count].ToString() + ")");
                     return(false);
                 }
                 catch (FileNotFoundException e)
                 {
                     MessageBox.Show(LocRM.GetString("cannotRecoverFilesByMotive", currentCulture) + destinationFilesList.Items[count].ToString() + "\":\n" + e.Message);
                     return(false);
                 }
             }
             else
             {
                 if (type == LocRM.GetString("stroopTest", currentCulture))
                 {
                     StroopProgram program = new StroopProgram();
                     try
                     {
                         program.readProgramFile(Global.stroopTestFilesBackupPath + destinationFilesList.Items[count].ToString() + ".prg");
                     }
                     catch (FileNotFoundException e)
                     {
                         MessageBox.Show(LocRM.GetString("cannotRecoverFilesByMotive", currentCulture) + destinationFilesList.Items[count].ToString() + "\":\n" + e.Message);
                         return(false);
                     }
                 }
                 else if (type == LocRM.GetString("reactionTest", currentCulture))
                 {
                     ReactionProgram program = new ReactionProgram();
                     try
                     {
                         program.readProgramFile(Global.reactionTestFilesBackupPath + destinationFilesList.Items[count].ToString() + ".prg");
                     }
                     catch (FileNotFoundException e)
                     {
                         MessageBox.Show(LocRM.GetString("cannotRecoverFilesByMotive", currentCulture) + destinationFilesList.Items[count].ToString() + "\":\n" + e.Message);
                         return(false);
                     }
                 }
                 else if (type == LocRM.GetString("matchingTest", currentCulture))
                 {
                     MatchingProgram program = new MatchingProgram();
                     try
                     {
                         program.readProgramFile(Global.matchingTestFilesBackupPath + destinationFilesList.Items[count].ToString() + ".prg");
                     }
                     catch (FileNotFoundException e)
                     {
                         MessageBox.Show(LocRM.GetString("cannotRecoverFilesByMotive", currentCulture) + destinationFilesList.Items[count].ToString() + "\":\n" + e.Message);
                         return(false);
                     }
                 }
             }
         }
     }
     return(true);
 }
        private void editProgram()
        {
            MatchingProgram editProgram = new MatchingProgram();

            try
            {
                editProgram.readProgramFile(path + Global.programFolderName + editPrgName + ".prg");
            }
            catch (FileNotFoundException e)
            {
                MessageBox.Show(LocRM.GetString("cantEdìtProgramMissingFiles", currentCulture) + e.Message);
                return;
            }

            if (editProgram.getImageListFile() != null)
            {
                openImgListButton.Text         = editProgram.getImageListFile().ListName;
                this.stimuluType.SelectedIndex = 0;
            }
            else if (editProgram.getColorListFile() != null)
            {
                openColorListButton.Text       = editProgram.getColorListFile().ListName;
                openWordListButton.Text        = editProgram.getWordListFile().ListName;
                this.stimuluType.SelectedIndex = 2;
            }
            else
            {
                openWordListButton.Text        = editProgram.getWordListFile().ListName;
                this.stimuluType.SelectedIndex = 1;
            }
            if (editProgram.WordColor != "false")
            {
                wordSingleColor.Text     = editProgram.WordColor;
                WordColorPanel.BackColor = ColorTranslator.FromHtml(editProgram.WordColor);
            }
            programName.Text                = editProgram.ProgramName;
            stimuluNumber.Value             = editProgram.StimuluNumber;
            attemptNumber.Value             = editProgram.AttemptsNumber;
            expositionSize.Value            = editProgram.StimuluSize;
            randomStimuluPosition.Checked   = editProgram.RandomStimulusPosition;
            randomModelPosition.Checked     = editProgram.RandomModelPosition;
            closeExpoAWithClick.Checked     = editProgram.EndExpositionWithClick;
            stimulusInterval.Value          = editProgram.IntervalTime;
            randomAttemptTime.Checked       = editProgram.IntervalTimeRandom;
            stimulusExpoTime.Value          = editProgram.ExpositionTime;
            modelExpoTime.Value             = editProgram.ModelExpositionTime;
            omissionAudioResponse.Checked   = editProgram.OmissionAudioResponse;
            commissionAudioFeedback.Checked = editProgram.CommissionAudioResponse;
            attemptInterval.Value           = editProgram.AttemptsIntervalTime;
            randomOrder.Checked             = editProgram.ExpositionRandom;
            DMTSBackgroundColor.Text        = editProgram.BackgroundColor;
            DNMTSBackgroundColor.Text       = editProgram.DNMTSBackground;
            DMTSColorPanel.BackColor        = ColorTranslator.FromHtml(editProgram.BackgroundColor);
            DNMTSColorPanel.BackColor       = ColorTranslator.FromHtml(editProgram.DNMTSBackground);
            feedbackAudioResponse.Checked   = editProgram.FeedbackAudioResponse;
            expositonAudioResponse.Checked  = editProgram.ExpositionAudioResponse;
            randomModelStimulusTime.Checked = editProgram.RandomIntervalModelStimulus;
            switch (editProgram.getExpositionType())
            {
            case "DMTS":
                this.expositionType.SelectedIndex = 0;
                break;

            case "DNMTS":
                this.expositionType.SelectedIndex = 1;
                break;

            case "DMTS/DNMTS":
                this.expositionType.SelectedIndex = 2;
                break;
            }

            // reads program instructions to instruction box if there are any
            if (editProgram.InstructionText != null)
            {
                instructionsBox.ForeColor = Color.Black;
                instructionsBox.Text      = editProgram.InstructionText[0];
                for (int i = 1; i < editProgram.InstructionText.Count; i++)
                {
                    instructionsBox.AppendText(Environment.NewLine + editProgram.InstructionText[i]);
                }
            }
            else
            {
                instructionsBox.Text = "";
            }
            switch (stimuluType.SelectedIndex)
            {
            case 1:
                if (openImgListButton.Text != LocRM.GetString("open", currentCulture))
                {
                    StrList imagesListFile = new StrList(openImgListButton.Text, 0);
                    if (imagesListFile.ListContent.Count < stimuluNumber.Value)
                    {
                        errorProvider1.SetError(openImgListButton, LocRM.GetString("impossibleUseListWarn", currentCulture));
                        errorProvider2.Clear();
                        saveButton.Enabled = false;
                    }
                    else if (imagesListFile.ListContent.Count < attemptNumber.Value * stimuluNumber.Value)
                    {
                        errorProvider2.SetError(openImgListButton, LocRM.GetString("smallImageList", currentCulture));
                        saveButton.Enabled = true;
                    }
                    else
                    {
                        saveButton.Enabled = true;
                    }
                }
                break;

            case 2:
            case 3:
                StrList wordListFile = new StrList(openWordListButton.Text, 2);
                if (wordListFile.ListContent.Count < stimuluNumber.Value)
                {
                    errorProvider1.SetError(openWordListButton, LocRM.GetString("impossibleUseListWarn", currentCulture));
                    errorProvider2.Clear();
                    saveButton.Enabled = false;
                }
                else if (wordListFile.ListContent.Count < attemptNumber.Value * stimuluNumber.Value)
                {
                    errorProvider2.SetError(openWordListButton, LocRM.GetString("smallImageList", currentCulture));
                    saveButton.Enabled = true;
                }
                else
                {
                    saveButton.Enabled = true;
                }
                break;
            }
        }
        private bool isListUsed(string listName, string suffix, out bool stopProcess)
        {
            string currentProgram = "", originPath = "", programName = "", destinationPath = "";

            string[] TRPrograms       = Directory.GetFiles(Global.reactionTestFilesPath + Global.programFolderName);
            string[] StroopPrograms   = Directory.GetFiles(Global.stroopTestFilesPath + Global.programFolderName);
            string[] MatchingPrograms = Directory.GetFiles(Global.matchingTestFilesPath + Global.programFolderName);
            try
            {
                foreach (string file in TRPrograms)
                {
                    originPath      = Global.reactionTestFilesPath + Global.programFolderName;
                    destinationPath = Global.reactionTestFilesBackupPath;
                    programName     = Path.GetFileNameWithoutExtension(file);
                    currentProgram  = Path.GetFileNameWithoutExtension(file) + " (" + LocRM.GetString("reactionTest", currentCulture) + ")";
                    ReactionProgram program = new ReactionProgram();
                    program.readProgramFile(file);
                    if (suffix == "_image" && program.getImageListFile() != null && program.getImageListFile().ListName == listName)
                    {
                        stopProcess = false;
                        return(true);
                    }
                    else if (suffix == "_audio" && program.getAudioListFile() != null && program.getAudioListFile().ListName == listName)
                    {
                        stopProcess = false;
                        return(true);
                    }
                    else if (suffix == "_words_color")
                    {
                        if (program.getWordListFile() != null && ((program.getWordListFile().ListName + "_words") == listName))
                        {
                            stopProcess = false;
                            return(true);
                        }
                        else if (program.getColorListFile() != null && ((program.getColorListFile().ListName + "_color") == listName))
                        {
                            stopProcess = false;
                            return(true);
                        }
                    }
                }
                foreach (string file in StroopPrograms)
                {
                    originPath      = Global.stroopTestFilesPath + Global.programFolderName;
                    destinationPath = Global.stroopTestFilesBackupPath;
                    programName     = Path.GetFileNameWithoutExtension(file);
                    StroopProgram program = new StroopProgram();
                    currentProgram = Path.GetFileNameWithoutExtension(file) + " (" + LocRM.GetString("stroopTest", currentCulture) + ")";
                    program.readProgramFile(file);
                    if (suffix == "_image" && program.getImageListFile() != null && program.getImageListFile().ListName == listName)
                    {
                        stopProcess = false;
                        return(true);
                    }
                    else if (suffix == "_audio" && program.getAudioListFile() != null && program.getAudioListFile().ListName == listName)
                    {
                        stopProcess = false;
                        return(true);
                    }
                    else if (suffix == "_words_color")
                    {
                        if (program.getWordListFile() != null && ((program.getWordListFile().ListName + "_words") == listName))
                        {
                            stopProcess = false;
                            return(true);
                        }
                        else if (program.getColorListFile() != null && ((program.getColorListFile().ListName + "_color") == listName))
                        {
                            stopProcess = false;
                            return(true);
                        }
                    }
                }
                foreach (string file in MatchingPrograms)
                {
                    originPath      = Global.matchingTestFilesPath + Global.programFolderName;
                    destinationPath = Global.matchingTestFilesBackupPath;
                    programName     = Path.GetFileNameWithoutExtension(file);
                    MatchingProgram program = new MatchingProgram();
                    currentProgram = Path.GetFileNameWithoutExtension(file) + " (" + LocRM.GetString("matchingTest", currentCulture) + ")";
                    program.readProgramFile(file);
                    if (suffix == "_image" && program.getImageListFile() != null && program.getImageListFile().ListName == listName)
                    {
                        stopProcess = false;
                        return(true);
                    }
                    else if (suffix == "_audio" && program.getAudioListFile() != null && program.getAudioListFile().ListName == listName)
                    {
                        stopProcess = false;
                        return(true);
                    }
                    else if (suffix == "_words_color")
                    {
                        if (program.getWordListFile() != null && ((program.getWordListFile().ListName + "_words") == listName))
                        {
                            stopProcess = false;
                            return(true);
                        }
                        else if (program.getColorListFile() != null && ((program.getColorListFile().ListName + "_color") == listName))
                        {
                            stopProcess = false;
                            return(true);
                        }
                    }
                }
            }
            catch (FileNotFoundException e)
            {
                DialogResult dialogResult = MessageBox.Show(LocRM.GetString("wanstPossibleToRecoverLists", currentCulture) + "\"" + currentProgram + "\"" +
                                                            LocRM.GetString("hasMissingLists", currentCulture) + e.Message + "\""
                                                            + LocRM.GetString("missingListSolution", currentCulture), LocRM.GetString("error", currentCulture), MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.Yes)
                {
                    DialogResult shouldDelete = MessageBox.Show(LocRM.GetString("deleteProgram", currentCulture) + currentProgram + "?", LocRM.GetString("delete", currentCulture), MessageBoxButtons.YesNo);
                    if (shouldDelete == DialogResult.Yes)
                    {
                        try
                        {
                            File.Move(originPath + programName + ".prg", destinationPath + programName + ".prg");
                        }
                        catch (IOException)
                        {
                            File.Delete(destinationPath + programName + ".prg");
                            File.Move(originPath + programName + ".prg", destinationPath + programName + ".prg");
                        }
                        MessageBox.Show(LocRM.GetString("deletedSucessful", currentCulture));
                        this.Parent.Controls.Remove(this);
                        ListManagment newListManagment = new ListManagment(suffix, mode);
                        Global.GlobalFormMain._contentPanel.Controls.Add(newListManagment);
                        stopProcess = true;
                        return(false);
                    }
                    else
                    {
                        MessageBox.Show(LocRM.GetString("FilesNotDeleted", currentCulture));
                        this.Parent.Controls.Remove(this);
                        stopProcess = true;
                        return(false);
                    }
                }
                else
                {
                    this.Parent.Controls.Remove(this);
                    stopProcess = true;
                    return(false);
                }
            }
            stopProcess = false;
            return(false);
        }