Exemplo n.º 1
0
        public static bool AllControlsPopulated(
            List <Control> controls,
            bool focusOnBlankControl,
            bool displayErrorMessage,
            out string errorMessage)
        {
            Control blankControl = null;

            errorMessage = null;
            foreach (Control c in controls)
            {
                Type type = c.GetType();
                if (c is TextBox && string.IsNullOrEmpty(((TextBox)c).Text))
                {
                    blankControl = c;
                    break;
                }
                else if (c is NumericTextBoxWindows && string.IsNullOrEmpty(((TextBox)c).Text))
                {
                    blankControl.Focus();
                }
            }
            if (blankControl != null)
            {
                string friendlyControlName = blankControl.Name.Substring(DataShaperWindows.GetIndexOfFirstUpperCaseLetter(blankControl.Name));
                errorMessage = string.Format("{0} not entered.", DataShaperWindows.ShapeCamelCaseString(friendlyControlName));
                if (focusOnBlankControl)
                {
                    blankControl.Focus();
                    return(false);
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public static void PopulateControlsFromEntity(
            Dictionary <string, Control> controls,
            object entity,
            List <string> hiddenProperties,
            List <string> unmanagedProperties,
            bool shapeColumnNames)
        {
            Dictionary <string, Type> controlMappings = GetTypeNameToControlTypeMappings();
            Type entityType = entity.GetType();

            foreach (PropertyInfo p in entityType.GetProperties())
            {
                string propertyNameMatch = shapeColumnNames ? DataShaperWindows.ShapeCamelCaseString(p.Name) : p.Name;
                if (hiddenProperties.Contains(propertyNameMatch) || unmanagedProperties.Contains(propertyNameMatch))
                {
                    continue; //Don't populate any control for hidden and unmanaged properties.
                }
                Type propertyType = null;
                if (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    propertyType = p.PropertyType.GetGenericArguments()[0];
                }
                else
                {
                    propertyType = p.PropertyType;
                }
                if (!controlMappings.ContainsKey(propertyType.FullName))
                {
                    //throw new NullReferenceException(string.Format(
                    //    "No mapping to control exists for property with name {0} and of type {1}.",
                    //    p.Name,
                    //    propertyType.FullName));
                    continue;
                }
                Type    expectedControlType = controlMappings[propertyType.FullName];
                object  propertyValue       = p.GetValue(entity, null);
                Panel   pnlInputControl     = (Panel)controls[string.Format("pnl{0}", p.Name)]; //S5hould be a panel containing the input control.
                Control control             = null;
                foreach (Control c in pnlInputControl.Controls)
                {
                    if (!(c is LinkLabel))
                    {
                        control = c;
                    }
                }
                if (control.GetType() != expectedControlType)
                {
                    throw new ArgumentException(string.Format(
                                                    "Expected to populate a {0} control for property {1} of type {2} for entity {3}, but received a {4} control to populate.",
                                                    expectedControlType.FullName,
                                                    p.Name,
                                                    propertyType.FullName,
                                                    entityType.FullName,
                                                    control.GetType().FullName));
                }
                PopulateControl(control, propertyValue);
            }
        }
Exemplo n.º 3
0
 public static void PopulateDataGridViewRowFromEntity(object entity, DataGridViewRow row, bool shapePropertyNames, Type entityType)
 {
     foreach (PropertyInfo p in entityType.GetProperties())
     {
         object propertyValue = EntityReader.GetPropertyValue(p.Name, entity, true);
         string propertyName  = shapePropertyNames ? DataShaperWindows.ShapeCamelCaseString(p.Name) : p.Name;
         row.Cells[propertyName].Value = propertyValue;
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Cache the associated Form View and add the actions
        /// </summary>
        /// <param name="parentSelectionFormView">Containing form</param>
        ///
        void IFormViewControl.Initialize(FormView parentSelectionFormView)
        {
            _settingsFormView = (SettingsFormViewWindows)parentSelectionFormView;

            // Add the actions
            _settingsFormView.SelectionData.ActionsPaneItems.Clear();
            _settingsFormView.SelectionData.ActionsPaneItems.Add(new Microsoft.ManagementConsole.Action(
                                                                     DataShaperWindows.ShapeCamelCaseString(SnapInActionWindows.Edit.ToString()),
                                                                     "Shows the Names of the selected Items in the FormView's ListView.",
                                                                     -1,
                                                                     SnapInActionWindows.Edit)); //The tag is the action identifier.
        }
Exemplo n.º 5
0
        public static DataGridTableStyle GetDataGridTableStyle <T>(int width, List <string> hiddenColumns, bool shapeColumnNames)
        {
            DataGridTableStyle result = new DataGridTableStyle();

            result.MappingName = shapeColumnNames ? DataShaperWindows.ShapeCamelCaseString(typeof(T).Name) : typeof(T).Name;
            List <string> columns = EntityReaderGeneric <T> .GetAllPropertyNames(shapeColumnNames);

            foreach (string c in columns)
            {
                int modifiedWidth = width;
                if (hiddenColumns.Contains(c))
                {
                    modifiedWidth = -1;
                }
                result.GridColumnStyles.Add(GetColumnStyle(c, c, modifiedWidth));
            }
            return(result);
        }
Exemplo n.º 6
0
        public SettingItem(
            string category,
            string settingName,
            object settingValue,
            Type settingType,
            bool autoFormatDisplayName,
            string settingDisplayName,
            string settingDescription,
            int categorySequenceId,
            char passwordChar,
            SettingsControlWindows settingControl,
            SettingsCategoryInfo settingsCategoryInfo)
        {
            _category             = category;
            _settingName          = settingName;
            _settingValue         = settingValue;
            _settingType          = settingType;
            _settingsCategoryInfo = settingsCategoryInfo;
            if (string.IsNullOrEmpty(settingDisplayName))
            {
                _settingDisplayName = autoFormatDisplayName ? DataShaper.ShapeCamelCaseString(settingName) : settingName;
            }
            else
            {
                _settingDisplayName = settingDisplayName;
            }
            _settingDescription = settingDescription;
            _categorySequenceId = categorySequenceId;
            _passwordChar       = passwordChar;

            _listViewItem = new ListViewItem(_settingDisplayName);
            if (_passwordChar != '\0')
            {
                _listViewItem.SubItems.Add(DataShaperWindows.MaskPasswordString(_settingValue.ToString(), _passwordChar));
            }
            else
            {
                _listViewItem.SubItems.Add(_settingValue != null ? _settingValue.ToString() : null);
            }
            _listViewItem.SubItems.Add(_settingDescription);
            _listViewItem.Tag = this;
            _settingControl   = settingControl;
        }
Exemplo n.º 7
0
        public string DispatchSqlQueryRunner(
            string ormAssemblyName,
            string ormTypeName,
            string sqlQueryString,
            string acceptContentType,
            string connectionString,
            bool includeOrmTypeNamesInJsonResponse)
        {
            AppDomain queryRunnerDomain = null;

            try
            {
                SqlQueryRunnerInputWindows input = new SqlQueryRunnerInputWindows(
                    ormAssemblyName,
                    ormTypeName,
                    sqlQueryString,
                    acceptContentType,
                    connectionString,
                    includeOrmTypeNamesInJsonResponse);
                AppDomainSetup domainSetup = new AppDomainSetup()
                {
                    ApplicationBase = Path.GetDirectoryName(_sqlQueryRunnerConfig.SqlQueryRunnerAssemblyPath)
                };
                queryRunnerDomain = AppDomain.CreateDomain(DataShaperWindows.GetUniqueIdentifier(), null, domainSetup);
                queryRunnerDomain.SetData(SQL_QUERY_RUNNER_EXECUTE_QUERY_METHOD_NAME, input);
                queryRunnerDomain.DoCallBack(new CrossAppDomainDelegate(ExecuteSqlQueryRunnerInAnotherDomain));
                SqlQueryRunnerOutputWindows result = (SqlQueryRunnerOutputWindows)queryRunnerDomain.GetData(SQL_QUERY_RUNNER_EXECUTE_QUERY_METHOD_RESULT_NAME);
                if (!result.Success)
                {
                    throw new Exception(result.ResultMessage);
                }
                return(result.ResultMessage);
            }
            finally
            {
                if (queryRunnerDomain != null)
                {
                    AppDomain.Unload(queryRunnerDomain);
                }
            }
        }
Exemplo n.º 8
0
        public EntityCacheGeneric <string, SettingItem> GetSettingsByCategory(SettingsCategoryInfo settingsCategoryInfo, SettingsControlWindows settingsControl)
        {
            string             categoryLower = settingsCategoryInfo.Category.Trim().ToLower();
            Type               settingsType  = this.GetType();
            List <SettingItem> settingItems  = new List <SettingItem>();

            foreach (PropertyInfo p in settingsType.GetProperties())
            {
                object[] categoryAttributes = p.GetCustomAttributes(typeof(SettingInfoAttribute), true);
                if (categoryAttributes == null)
                {
                    continue;
                }
                foreach (SettingInfoAttribute c in categoryAttributes)
                {
                    if (c.Category.Trim().ToLower() == categoryLower)
                    {
                        SettingItem settingItem = new SettingItem(
                            c.Category,
                            p.Name,
                            EntityReader.GetPropertyValue(p.Name, this, false),
                            p.PropertyType,
                            c.AutoFormatDisplayName,
                            c.DisplayName,
                            c.Description,
                            c.CategorySequenceId,
                            c.PasswordChar,
                            settingsControl,
                            settingsCategoryInfo);
                        settingItems.Add(settingItem);
                    }
                }
            }
            string entityCacheName = string.Format("{0} {1} Settings", DataShaperWindows.ShapeCamelCaseString(settingsType.Name).Replace("Settings", "").Trim(), settingsCategoryInfo.Category);
            EntityCacheGeneric <string, SettingItem> result = new EntityCacheGeneric <string, SettingItem>(entityCacheName);

            settingItems.OrderBy(p => p.CategorySequenceId).ToList().ForEach(p => result.Add(p.SettingName, p));
            return(result);
        }
Exemplo n.º 9
0
        public static Dictionary <string, Control> GetControlsForEntity(
            Type entityType,
            bool includeLabels,
            DockStyle dockStyle,
            Color backColor,
            List <string> hiddenProperties,
            List <string> unmanagedProperties,
            bool shapeColumnNames,
            List <LinkLabel> resetLinks,
            Color resetLinksBackColor)
        {
            if (resetLinks != null)
            {
                resetLinks.Clear();
            }
            Dictionary <string, Control> controls        = new Dictionary <string, Control>();
            Dictionary <string, Type>    controlMappings = GetTypeNameToControlTypeMappings();

            PropertyInfo[] entityProperties = entityType.GetProperties();
            for (int i = 0; i < entityProperties.Length; i++)
            {
                PropertyInfo p = entityProperties[i];
                string       propertyNameMatch = shapeColumnNames ? DataShaperWindows.ShapeCamelCaseString(p.Name) : p.Name;
                if (hiddenProperties.Contains(propertyNameMatch) || unmanagedProperties.Contains(propertyNameMatch))
                {
                    continue;
                }
                Type propertyType = null;
                if (p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>))
                {
                    propertyType = p.PropertyType.GetGenericArguments()[0];
                }
                else
                {
                    propertyType = p.PropertyType;
                }
                if (!controlMappings.ContainsKey(propertyType.FullName))
                {
                    continue;
                }
                Type    controlType = controlMappings[propertyType.FullName];
                Control control     = (Control)Activator.CreateInstance(controlType);
                control.Name    = string.Format("{0}", p.Name);
                control.Tag     = p.PropertyType;
                control.Dock    = DockStyle.Fill;
                control.TabStop = true;
                //control.TabIndex = i;
                //control.Height = 40;

                Panel pnlInputControl = new Panel()
                {
                    Name = string.Format("pnl{0}", p.Name), Dock = dockStyle, Height = control.Height
                };
                pnlInputControl.Controls.Add(control);
                if (resetLinks != null)
                {
                    LinkLabel lnkReset = new LinkLabel()
                    {
                        Name = string.Format("lnk{0}", p.Name), Text = "Reset", Tag = control, Dock = DockStyle.Right, Width = 60, BackColor = resetLinksBackColor
                    };
                    pnlInputControl.Controls.Add(lnkReset);
                    resetLinks.Add(lnkReset);
                }
                if (!(control is TextBox) && !(control is NumericTextBoxWindows) && !(control is NumericUpDown) && !(control is DateTimePicker) && !(control is ComboBox))
                {
                    control.BackColor = backColor;
                }
                if (control is NumericUpDown)
                {
                    ((NumericUpDown)control).Maximum = int.MaxValue;
                }
                if (control is NumericTextBoxWindows && (propertyType == typeof(Single)) || propertyType == typeof(Double) || propertyType == typeof(Decimal))
                {
                    NumericTextBoxWindows numericTextBox = (NumericTextBoxWindows)control;
                    numericTextBox.AllowDecimal = true;
                }
                if (includeLabels)
                {
                    Label label = new Label()
                    {
                        Name      = string.Format("lbl{0}", p.Name),
                        Text      = string.Format("{0}:", DataShaperWindows.ShapeCamelCaseString(p.Name)),
                        Dock      = dockStyle,
                        BackColor = backColor,
                        //Height = 40,
                    };
                    controls.Add(label.Name, label);
                }
                controls.Add(pnlInputControl.Name, pnlInputControl);
            }
            return(DataHelperWindows.ReverseDictionaryOrder <string, Control>(controls));
        }