private bool LoadTemplateInfo()
        {
            if (givenTemplate != null)
            {
                templateInfo = givenTemplate.info; return(true);
            }                                                                              // nothing to do, if an other caller than the UI already provided a loaded template

            if (givenTemplateName != null)
            {
                templatePath = givenTemplateName;                               // another caller than the UI provided the name of the template to load
            }
            else
            {
                templatePath = (comboBox1.SelectedItem as TemplateItem).Value;  // UI-call
            }
            if (XML_handling.ParseTemplateInfo(templatePath, out templateInfo, out ErrorCollector errorCollector))
            {
                return(true);
            }

            MessageBox.Show(errorCollector.GetErrorMessage());
            if (givenTemplateName != null)
            {
                DialogResult = DialogResult.Cancel;
                Close(); // terminate the whole selection process if an other caller than the UI provided rubbish input
            }
            return(false);
        }
        List <int> selectedIndices = new List <int>();    // store the order of selection for Alts

        public SelectBaseAltsForm(Template.TemplateInfo templateInfo)
        {
            InitializeComponent();

            this.templateInfo = templateInfo;

            labCaption.Text = templateInfo.name;

            // try to retieve selected paths from UI-user-settings, if not successful set to UI-output-folder
            string storedBaseOutputFolder = UISessionInfo.GetRetainedUserSetting(StatisticsPresenter.USER_SETTINGS_ID, StatisticsPresenter.BASE_OUTPUT_FOLDER);

            textBasePath.Text = string.IsNullOrEmpty(storedBaseOutputFolder) ? UISessionInfo.GetOutputFolder() : storedBaseOutputFolder;
            string storedAltOutputFolder = UISessionInfo.GetRetainedUserSetting(StatisticsPresenter.USER_SETTINGS_ID, StatisticsPresenter.REFORM_OUTPUT_FOLDER);

            textAltPath.Text = string.IsNullOrEmpty(storedAltOutputFolder) ? textBasePath.Text : storedAltOutputFolder;

            //template.FilePackageDefinition.GetMinMaxNumberOfAlternatives(out minAlts, out maxAlts, template.TemplateType);
            if (templateInfo.maxFiles == 1)
            {
                listAlt.SelectionMode    = SelectionMode.One;
                lblMultiSelect.Visible   = false;
                lblOrderRetained.Visible = false;
            }
            else
            {
                listAlt.SelectionMode = SelectionMode.MultiExtended;
            }
        }
        public SelectFilesForm(Template.TemplateInfo _templateInfo)
        {
            InitializeComponent();

            templateInfo      = _templateInfo;
            requiredVariables = templateInfo.GetRequiredVariables();
            requiredVariables.Add(DataGenerator.HHTYPE_NAME);
            labCaption.Text = templateInfo.name;
            textPath.Text   = UISessionInfo.GetOutputFolder();
        }
        public SelectHHTypesForm(Template.TemplateInfo _templateInfo, List <string> hhTypes)
        {
            InitializeComponent();

            templateInfo    = _templateInfo;
            labCaption.Text = templateInfo.name;

            foreach (string hhType in hhTypes)
            {
                listHHTypes.Items.Add(hhType);
            }
        }
        internal static bool isValidInput(string filePath, Template.TemplateInfo template)
        {
            // Check if this is a valid output file containing all the required fields for this template
            string[] headers = null;
            try
            {
                string firstLine = File.ReadLines(filePath).FirstOrDefault();
                if (firstLine == null || firstLine.Length < 1)
                {
                    return(false);                         // ignore empty files
                }
                headers = firstLine.ToLower().Split('\t'); // get the header line from the file - assume that the file is Tab-separated and first row is headers
            }
            catch (IOException)
            {
                return(false);   // if the file is locked (e.g. open in Excel) ignore it
            }
            catch (Exception ex)
            {
                MessageBox.Show(filePath + " has returned the unexpected error: '" + ex.Message + "'");
                return(false);   // unexpected error
            }
            string missing = string.Empty;

            // check all required fields to see if they exist as headers
            foreach (string rf in template.GetRequiredVariables())
            {
                if (!headers.Contains(rf.ToLower()))
                {
                    missing += Environment.NewLine + rf;
                }
            }
            // if not, return false and keep an error message
            if (missing != string.Empty)
            {
                missing = "The following variables are missing from \"" + filePath + "\":" + missing;
            }
            return(missing == string.Empty);
        }
        readonly List <int> selectedIndices             = new List <int>(); // store the order of selection for Alts

        public SelectFilesForm(Template.TemplateInfo templateInfo)
        {
            InitializeComponent();

            this.templateInfo = templateInfo;

            labCaption.Text = templateInfo.name;

            // try to retieve selected path from UI-user-settings, if not successful set to UI-output-folder
            string storedBaseOutputFolder = UISessionInfo.GetRetainedUserSetting(StatisticsPresenter.USER_SETTINGS_ID, StatisticsPresenter.BASE_OUTPUT_FOLDER);

            textPath.Text = string.IsNullOrEmpty(storedBaseOutputFolder) ? UISessionInfo.GetOutputFolder() : storedBaseOutputFolder;

            if (templateInfo.maxFiles == 1)
            {
                listFiles.SelectionMode  = SelectionMode.One;
                lblMultiSelect.Visible   = false;
                lblOrderRetained.Visible = false;
            }
            else
            {
                listFiles.SelectionMode = SelectionMode.MultiExtended;
            }
        }
        List <int> selectedIndices = new List <int>();    // store the order of selection for Alts

        public SelectPackagesForm(Template.TemplateInfo templateInfo)
        {
            InitializeComponent();
            this.templateInfo = templateInfo;
            labCaption.Text   = templateInfo.name;
        }
예제 #8
0
        public TakeUserInput(Template.TemplateInfo templateInfo)
        {
            InitializeComponent();

            labCaption.Text = templateInfo.name;

            int x = 12, y = 20, space = 12, dialogWidth = Math.Max(labCaption.Width, labSubCaption.Width), tabIndex = 0; Control selControl = null;

            foreach (Template.TemplateInfo.UserVariable uv in templateInfo.GetUserVariables())
            {
                // draw control-label (i.e. the instruction for the user)
                Label label = new Label()
                {
                    Text = uv.title, Left = x, Top = y, Anchor = AnchorStyles.Top | AnchorStyles.Left, AutoSize = true
                };
                panContent.Controls.Add(label);
                y          += label.Size.Height;
                dialogWidth = Math.Max(dialogWidth, label.Size.Width);

                // draw control either as TextBox or ComboBox
                Control control;
                if (uv.inputType == HardDefinitions.UserInputType.Categorical_Numeric ||
                    uv.inputType == HardDefinitions.UserInputType.Categorical_VariableName) // user is expected to select a value of a list (with optionaly being able to type)
                {
                    control = new ComboBox()
                    {
                        DropDownStyle = false ? ComboBoxStyle.DropDown : ComboBoxStyle.DropDownList,
                        Left          = x, Top = y, Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
                    };
                    foreach (Template.TemplateInfo.ComboItem t in uv.comboItems)
                    {
                        (control as ComboBox).Items.Add(new ComboItem {
                            Text = t.name, Value = t.value
                        });
                    }
                    (control as ComboBox).SelectedIndex = 0;
                }
                else // user is expected to type a value
                {
                    control = new TextBox()
                    {
                        Text   = uv.defaultValue, Left = x, Top = y,
                        Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right
                    }
                };
                y                  += control.Height + space;
                control.Tag         = uv; control.TabIndex = tabIndex++;
                control.Validating += inputBox_Validating;
                panContent.Controls.Add(control); if (selControl == null)
                {
                    selControl = control;
                }

                // if there is an additional description for the user, draw an info-button
                if (uv.description != string.Empty)
                {
                    Button infoButton = new Button()
                    {
                        Font     = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))),
                        Location = new Point(ClientSize.Width - x - 30, control.Top), ForeColor = Color.CornflowerBlue, TabIndex = tabIndex++,
                        Size     = new System.Drawing.Size(30, 30), // tried to use Control.Height instead, but got different values for Text and Combo
                        Anchor   = AnchorStyles.Top | AnchorStyles.Right, Text = "i", TextAlign = ContentAlignment.MiddleCenter, Tag = uv.description
                    };
                    infoButton.Click += infoButton_Click;
                    panContent.Controls.Add(infoButton);
                    control.Width = ClientSize.Width - infoButton.Width - space - 2 * x;
                }
                else
                {
                    control.Width = ClientSize.Width - 2 * x;
                }
            }

            // adapt width and height of the dialog and position OK- and Cancel-buttons
            SetClientSizeCore(dialogWidth + 50, panCaptions.Height + y + btnOK.Height + 4 * space);

            btnOK.Location     = new Point(ClientSize.Width / 2 - btnOK.Width - space, ClientSize.Height - btnOK.Height - space);
            btnCancel.Location = new Point(ClientSize.Width / 2 + space, btnOK.Top);

            panContent.Select(); if (selControl != null)
            {
                selControl.Select();
            }
        }

        void infoButton_Click(object sender, EventArgs e)
        {
            MessageBox.Show((sender as Button).Tag.ToString());
        }