Example #1
0
        public override IMapsDirectlyToDatabaseTable[] SelectMany(string prompt, Type arrayElementType,
                                                                  IMapsDirectlyToDatabaseTable[] availableObjects, string initialSearchText)
        {
            if (!availableObjects.Any())
            {
                MessageBox.Show("There are no '" + arrayElementType.Name + "' objects in your RMDP");
                return(null);
            }

            SelectIMapsDirectlyToDatabaseTableDialog selectDialog = new SelectIMapsDirectlyToDatabaseTableDialog(this, availableObjects, false, false);

            selectDialog.Text = prompt;
            selectDialog.SetInitialFilter(initialSearchText);
            selectDialog.AllowMultiSelect = true;

            if (selectDialog.ShowDialog() == DialogResult.OK)
            {
                var ms       = selectDialog.MultiSelected.ToList();
                var toReturn = Array.CreateInstance(arrayElementType, ms.Count);

                for (int i = 0; i < ms.Count; i++)
                {
                    toReturn.SetValue(ms[i], i);
                }

                return((IMapsDirectlyToDatabaseTable[])toReturn);
            }

            return(null);
        }
Example #2
0
        public override IMapsDirectlyToDatabaseTable SelectOne(string prompt, IMapsDirectlyToDatabaseTable[] availableObjects,
                                                               string initialSearchText = null, bool allowAutoSelect = false)
        {
            if (!availableObjects.Any())
            {
                MessageBox.Show("There are no compatible objects in your RMDP for '" + prompt + "''");
                return(null);
            }

            //if there is only one object available to select
            if (availableObjects.Length == 1)
            {
                if (allowAutoSelect || YesNo("You only have one compatible object, use '" + availableObjects[0] + "'", "Select '" + availableObjects[0] + "'?"))
                {
                    return(availableObjects[0]);
                }
                else
                {
                    return(null);
                }
            }

            SelectIMapsDirectlyToDatabaseTableDialog selectDialog = new SelectIMapsDirectlyToDatabaseTableDialog(this, availableObjects, false, false);

            selectDialog.Text = prompt;
            selectDialog.SetInitialFilter(initialSearchText);


            if (selectDialog.ShowDialog() == DialogResult.OK)
            {
                return(selectDialog.Selected);
            }

            return(null); //user didn't select one of the IMapsDirectlyToDatabaseTable objects shown in the dialog
        }
Example #3
0
        /// <summary>
        /// Prompts user to select 1 of the objects of type T in the list you provide, returns true if they made a non null selection
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="availableObjects"></param>
        /// <param name="selected"></param>
        /// <param name="initialSearchText"></param>
        /// <param name="allowAutoSelect">True to silently auto select the object if there are only 1 <paramref name="availableObjects"/></param>
        /// <returns></returns>
        protected bool SelectOne <T>(IList <T> availableObjects, out T selected, string initialSearchText = null, bool allowAutoSelect = false) where T : DatabaseEntity
        {
            //if theres only one object available to select
            if (availableObjects.Count == 1)
            {
                if (allowAutoSelect || YesNo("You only have one compatible object, use '" + availableObjects[0] + "'", "Select '" + availableObjects[0] + "'?"))
                {
                    selected = availableObjects[0];
                    return(true);
                }
                else
                {
                    selected = null;
                    return(false);
                }
            }


            var dialog = new SelectIMapsDirectlyToDatabaseTableDialog(availableObjects, false, false);

            dialog.SetInitialFilter(initialSearchText);

            selected = dialog.ShowDialog() == DialogResult.OK? (T)dialog.Selected:null;

            return(selected != null);
        }
Example #4
0
        protected bool SelectMany <T>(T[] available, out T[] selected, string initialSearchText = null) where T : DatabaseEntity
        {
            var dialog = new SelectIMapsDirectlyToDatabaseTableDialog(available, false, false);

            dialog.AllowMultiSelect = true;
            dialog.SetInitialFilter(initialSearchText);
            dialog.ShowDialog();

            if (dialog.DialogResult != DialogResult.OK)
            {
                selected = null;
                return(false);
            }

            selected = dialog.MultiSelected.Cast <T>().ToArray();
            return(true);
        }
        public override void Execute()
        {
            var available = Activator.CoreChildProvider.AllCatalogueItems.Except(new[] { _toPopulate }).ToArray();
            var dialog    = new SelectIMapsDirectlyToDatabaseTableDialog(available, false, false);

            //if we have a CatalogueItem other than us that has same Name maybe that's the one they want
            if (available.Any(a => a.Name.Equals(_toPopulate.Name, StringComparison.CurrentCultureIgnoreCase)))
            {
                dialog.SetInitialFilter(_toPopulate.Name);
            }

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                var chosen = (CatalogueItem)dialog.Selected;
                CopyNonIDValuesAcross(chosen, _toPopulate, true);
                _toPopulate.SaveToDatabase();

                Publish(_toPopulate);
            }

            base.Execute();
        }