Ejemplo n.º 1
0
        public void Generate(WrapPanel parent, DataTableBackedList <ControlRow> templateTable)
        {
            // used for styling all content and label controls except ComboBoxes since the combo box style is commented out in DataEntryControls.xaml
            // and defined instead in MainWindow.xaml as an exception workaround
            DataEntryControls styleProvider = new DataEntryControls();

            parent.Children.Clear();
            foreach (ControlRow control in templateTable)
            {
                // instantiate control UX objects
                StackPanel stackPanel;
                switch (control.Type)
                {
                case Constant.Control.Note:
                case Constant.DatabaseColumn.Date:
                case Constant.DatabaseColumn.File:
                case Constant.DatabaseColumn.Folder:
                case Constant.DatabaseColumn.RelativePath:
                case Constant.DatabaseColumn.Time:
                    Label   noteLabel   = EditorControls.CreateLabel(styleProvider, control);
                    TextBox noteContent = EditorControls.CreateTextBox(styleProvider, control);
                    stackPanel = EditorControls.CreateStackPanel(styleProvider, noteLabel, noteContent);
                    break;

                case Constant.Control.Counter:
                    RadioButton   counterLabel   = EditorControls.CreateCounterLabelButton(styleProvider, control);
                    IntegerUpDown counterContent = EditorControls.CreateIntegerUpDown(styleProvider, control);
                    stackPanel                = EditorControls.CreateStackPanel(styleProvider, counterLabel, counterContent);
                    counterLabel.IsTabStop    = false;
                    counterContent.GotFocus  += this.Control_GotFocus;
                    counterContent.LostFocus += this.Control_LostFocus;
                    break;

                case Constant.Control.Flag:
                case Constant.DatabaseColumn.DeleteFlag:
                    Label    flagLabel   = EditorControls.CreateLabel(styleProvider, control);
                    CheckBox flagContent = this.CreateFlag(styleProvider, control);
                    flagContent.IsChecked = String.Equals(control.DefaultValue, Constant.BooleanValue.True, StringComparison.OrdinalIgnoreCase) ? true : false;
                    stackPanel            = EditorControls.CreateStackPanel(styleProvider, flagLabel, flagContent);
                    break;

                case Constant.Control.FixedChoice:
                case Constant.DatabaseColumn.ImageQuality:
                    Label    choiceLabel   = EditorControls.CreateLabel(styleProvider, control);
                    ComboBox choiceContent = EditorControls.CreateComboBox(styleProvider, control);
                    stackPanel = EditorControls.CreateStackPanel(styleProvider, choiceLabel, choiceContent);
                    break;

                case Constant.DatabaseColumn.DateTime:
                    Label          dateTimeLabel   = EditorControls.CreateLabel(styleProvider, control);
                    DateTimePicker dateTimeContent = this.CreateDateTimePicker(control);
                    stackPanel = EditorControls.CreateStackPanel(styleProvider, dateTimeLabel, dateTimeContent);
                    break;

                case Constant.DatabaseColumn.UtcOffset:
                    Label           utcOffsetLabel   = EditorControls.CreateLabel(styleProvider, control);
                    UtcOffsetUpDown utcOffsetContent = this.CreateUtcOffsetPicker(control);
                    stackPanel = EditorControls.CreateStackPanel(styleProvider, utcOffsetLabel, utcOffsetContent);
                    break;

                default:
                    throw new NotSupportedException(String.Format("Unhandled control type {0}.", control.Type));
                }

                stackPanel.Tag = control.DataLabel;
                if (control.Visible == false)
                {
                    stackPanel.Visibility = Visibility.Collapsed;
                }

                // add control to wrap panel
                parent.Children.Add(stackPanel);
            }
        }
Ejemplo n.º 2
0
        private static void UpdateControl(XmlNode selectedNode, TemplateDatabase templateDatabase, string typeWanted, ControlRow control, ref List <string> errorMessages, ref List <string> dataLabels)
        {
            XmlNodeList selectedData = selectedNode.SelectNodes(Constant.ImageXml.Data);

            control.DefaultValue = GetColumn(selectedData, Constant.Control.DefaultValue);              // Default
            control.Width        = Int32.Parse(GetColumn(selectedData, Constant.Control.TextBoxWidth)); // Width

            // The tempTable should have defaults filled in at this point for labels, datalabels, and tooltips
            // Thus if we just get empty values, we should use those defaults rather than clearing them
            string label = GetColumn(selectedData, Constant.Control.Label);

            if (!String.IsNullOrEmpty(label))
            {
                control.Label = label;
            }

            string controlType = typeWanted;

            if (EditorControls.IsStandardControlType(typeWanted) == false)
            {
                controlType = GetColumn(selectedData, Constant.Control.DataLabel);
                if (String.IsNullOrWhiteSpace(controlType))
                {
                    controlType = label; // If there is no data label, use the label's value into it.
                }

                // string dataLabel = Regex.Replace(controlType, @"\s+", String.Empty);    // remove any white space that may be there
                string dataLabel = Regex.Replace(controlType, "[^a-zA-Z0-9_]", String.Empty);  // only allow alphanumeric and '_'.
                if (!dataLabel.Equals(controlType, StringComparison.InvariantCulture))
                {
                    errorMessages.Add("illicit characters: '" + controlType + "' changed to '" + dataLabel + "'");
                    controlType = dataLabel;
                }

                foreach (string sqlKeyword in EditorConstant.ReservedSqlKeywords)
                {
                    if (String.Equals(sqlKeyword, dataLabel, StringComparison.OrdinalIgnoreCase))
                    {
                        errorMessages.Add("reserved word:    '" + controlType + "' changed to '" + controlType + "_'");
                        controlType += "_";
                        break;
                    }
                }
            }

            // Now set the actual data label

            // First, check to see if the datalabel already exsists in the list, i.e., its not a unique key
            // If it doesn't, keep trying to add an integer to its end to make it unique.
            int    j = 0;
            string temp_datalabel = controlType;

            while (dataLabels.Contains(temp_datalabel))
            {
                temp_datalabel = controlType + j.ToString();
            }
            if (!controlType.Equals(temp_datalabel, StringComparison.InvariantCulture))
            {
                errorMessages.Add("duplicate data label:" + Environment.NewLine + "   '" + controlType + "' changed to '" + temp_datalabel + "'");
                controlType = temp_datalabel;
            }

            if (!String.IsNullOrEmpty(controlType))
            {
                if (controlType.Equals("Delete", StringComparison.InvariantCulture))
                {
                    controlType = Constant.ControlDefault.DeleteFlagLabel; // Delete is a reserved word!
                }
                control.DataLabel = controlType;
            }
            else
            {
                // If the data label was empty, the priority is to use the non-empty label contents
                // otherwise we stay with the default contents of the data label filled in previously
                label = Regex.Replace(label, @"\s+", String.Empty);
                if (!string.IsNullOrEmpty(label))
                {
                    control.DataLabel = label;
                }
            }
            dataLabels.Add(controlType); // and add it to the list of data labels seen

            string tooltip = GetColumn(selectedData, Constant.Control.Tooltip);

            if (!String.IsNullOrEmpty(tooltip))
            {
                control.Tooltip = tooltip;
            }

            // If there is no value supplied for Copyable, default is false for these data types (as they are already filled in by the system).
            // Counters are also not copyable be default, as we expect counts to change image by image. But there are cases where they user may want to alter this.
            bool defaultCopyable = true;

            if (EditorControls.IsStandardControlType(typeWanted))
            {
                defaultCopyable = false;
            }
            control.Copyable = ConvertToBool(TextFromNode(selectedData, 0, Constant.Control.Copyable), defaultCopyable);

            // If there is no value supplied for Visibility, default is true (i.e., the control will be visible in the interface)
            control.Visible = ConvertToBool(TextFromNode(selectedData, 0, Constant.Control.Visible), true);

            // if the type has a list, we have to do more work.
            if (typeWanted == Constant.DatabaseColumn.ImageQuality)
            {
                // For Image Quality, use the new list (longer than the one in old templates)
                control.List = Constant.ImageQuality.ListOfValues;
            }
            else if (typeWanted == Constant.DatabaseColumn.ImageQuality || typeWanted == Constant.Control.FixedChoice)
            {
                // Load up the menu items
                control.List = String.Empty; // For others, generate the list from what is stored

                XmlNodeList nodes     = selectedData[0].SelectNodes(Constant.Control.List + Constant.ImageXml.Slash + Constant.ImageXml.Item);
                bool        firstTime = true;
                foreach (XmlNode node in nodes)
                {
                    if (firstTime)
                    {
                        control.List = node.InnerText; // also clears the list's default values
                    }
                    else
                    {
                        control.List += "|" + node.InnerText;
                    }
                    firstTime = false;
                }
            }

            templateDatabase.SyncControlToDatabase(control);
        }