コード例 #1
0
        /// <summary>
        /// Saves the values in the EditViews controls and returns them as a Dictionary with key = attributename, value = the value from the control
        /// </summary>
        /// <param name="controls">The list of controls in the EditView</param>
        /// <returns>Key = attributename, value = the value from the control</returns>
        private Dictionary <string, object> ViewControlsToDictionary(Control.ControlCollection controls)
        {
            Dictionary <string, object> controlValues = new Dictionary <string, object>();

            foreach (Control c in controls)
            {
                if (c is NumberTextBox)
                {
                    NumberTextBox numTextBox = (NumberTextBox)c;
                    if (numTextBox.Text.Length > 0)
                    {
                        try
                        {
                            controlValues[c.Name] = Int32.Parse(numTextBox.Text);
                        }
                        catch (Exception e)
                        {
                            if (e is OverflowException || e is FormatException)
                            {
                                EditView.SetResponseLabel("Ett nummer är för stort, försök igen");
                            }
                            return(null);
                        }
                    }
                    else
                    {
                        controlValues[c.Name] = null;
                    }
                }
                else if (c is TextBox)
                {
                    TextBox txtBox = (TextBox)c;
                    controlValues[c.Name] = String.IsNullOrEmpty(txtBox.Text) ? null : txtBox.Text;
                }
                else if (c is DateTimePicker)
                {
                    controlValues[c.Name] = ((DateTimePicker)c).Value;
                }
                else if (c is ComboBox)
                {
                    IModel selectedIModel = (IModel)((ComboBox)c).SelectedItem;
                    if (selectedIModel != null)
                    {
                        controlValues[c.Name] = selectedIModel.GetIdentifyingAttributes().First().Value;
                    }
                    else
                    {
                        controlValues[c.Name] = null;
                    }
                }
                else if (c is CheckedListBox)
                {
                    // Skip, handled after the main-query is done
                }
            }
            return(controlValues);
        }