Esempio n. 1
0
        //------------------------------------------------------------------------------------------------------
        public override object EditValue(
            ITypeDescriptorContext context, 
            IServiceProvider provider, 
            object value)
        {
            if ((context != null) && (context.Instance != null) && (provider != null))
            {
                // Получаем интерфейс сервиса
                service =
                    (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(
                    typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                if (service != null)
                { 
                    Channel4_20Control cntrl =
                        new Channel4_20Control();
                    cntrl.ValueChanged +=
                        new  MeasuringDeviceTech.Classes.MeasuringDevice.UITypeEditors.ValueChangedEventHandler(cntrl_ValueChanged);
                    cntrl.Value = (UInt32)value;
                    service.DropDownControl(cntrl);
                    value = cntrl.Value;
                }
            }
            else
            {
                return base.EditValue(context, provider, value);
            }

            return value;
        }
Esempio n. 2
0
        /// <summary>
        /// Overrides the method used to provide basic behaviour for selecting editor.
        /// Shows our custom control for editing the value.
        /// </summary>
        /// <param name="context">The context of the editing control</param>
        /// <param name="provider">A valid service provider</param>
        /// <param name="value">The current value of the object to edit</param>
        /// <returns>The new value of the object</returns>
        public override object EditValue(ITypeDescriptorContext context,
                                         IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)
                        provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    lb                       = new System.Windows.Forms.ListBox();
                    lb.BorderStyle           = System.Windows.Forms.BorderStyle.None;
                    lb.SelectedIndexChanged += new EventHandler(lb_SelectedIndexChanged);
                    lb.Items.Add("onclick");
                    lb.Items.Add("ondblclick");
                    lb.Items.Add("onmouseover");
                    lb.Items.Add("onfocus");
                    lb.Items.Add("oncontextmenu");
                    edSvc.DropDownControl(lb);
                    if (lb.SelectedIndex == -1)
                    {
                        return(value);
                    }
                    return(lb.SelectedItem);
                }
            }

            return(value);
        }
Esempio n. 3
0
        /// <summary>
        /// Overrides the method used to provide basic behaviour for selecting editor.
        /// Shows our custom control for editing the value.
        /// </summary>
        /// <param name="context">The context of the editing control</param>
        /// <param name="provider">A valid service provider</param>
        /// <param name="value">The current value of the object to edit</param>
        /// <returns>The new value of the object</returns>
        public override object EditValue(ITypeDescriptorContext context,
                                         IServiceProvider provider, object value)
        {
            if (context != null && context.Instance != null && provider != null)
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)
                        provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
                if (edSvc != null)
                {
                    lb                       = new System.Windows.Forms.ListBox();
                    lb.BorderStyle           = System.Windows.Forms.BorderStyle.None;
                    lb.SelectedIndexChanged += new EventHandler(lb_SelectedIndexChanged);
                    foreach (Control ctrl in ((Control)context.Instance).Page.Controls)
                    {
                        if (ctrl.GetType().IsSubclassOf(typeShow) ||
                            ctrl.GetType().FullName == typeShow.FullName)
                        {
                            lb.Items.Add(ctrl.ID);
                        }
                    }
                    edSvc.DropDownControl(lb);
                    if (lb.SelectedIndex == -1)
                    {
                        return(value);
                    }
                    return(lb.SelectedItem);
                }
            }

            return(value);
        }
Esempio n. 4
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var retval = false;

            try
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                var column = (ColumnBase)context.Instance;
                retval = column.AllowNull;

                //Create the list box
                var newBox = new System.Windows.Forms.ListBox();
                newBox.Click         += new EventHandler(newBox_Click);
                newBox.IntegralHeight = false;

                var values = new List <string>();
                values.Add(false.ToString());
                values.Add(true.ToString());

                newBox.Items.AddRange(values.ToArray());
                newBox.SelectedIndex = (column.AllowNull ? 1 : 0);

                edSvc.DropDownControl(newBox);
                if ((column != null) && (newBox.SelectedIndex != -1))
                {
                    retval = (newBox.SelectedIndex == 0 ? false : true);
                }
            }
            catch (Exception ex) { }
            return(retval);
        }
Esempio n. 5
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var retval = System.Data.SqlDbType.VarChar;

            try
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                var column = (ColumnBase)context.Instance;
                retval = column.DataType;

                //Create the list box
                var newBox = new System.Windows.Forms.ListBox();
                newBox.Click         += new EventHandler(newBox_Click);
                newBox.IntegralHeight = false;

                var values = new List <string>();
                foreach (var t in Enum.GetNames(typeof(System.Data.SqlDbType)).OrderBy(x => x))
                {
                    values.Add(t);
                }

                newBox.Items.AddRange(values.ToArray());
                newBox.SelectedIndex = newBox.FindString(column.DataType.ToString());

                edSvc.DropDownControl(newBox);
                if ((column != null) && (newBox.SelectedIndex != -1))
                {
                    retval = (System.Data.SqlDbType)Enum.Parse(typeof(System.Data.SqlDbType), values[newBox.SelectedIndex]);
                }
            }
            catch (Exception ex) { }
            return(retval);
        }
 /// <summary>
 /// Overrides the method used to provide basic behaviour for selecting editor.
 /// Shows our custom control for editing the value.
 /// </summary>
 /// <param name="context">The context of the editing control</param>
 /// <param name="provider">A valid service provider</param>
 /// <param name="value">The current value of the object to edit</param>
 /// <returns>The new value of the object</returns>
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context == null || context.Instance == null || provider == null)
     {
         return base.EditValue(context, provider, value);
     }
     if ((m_EdSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService))) == null)
     {
         return value;
     }
     // Create a CheckedListBox and populate it with all the propertylist values
     m_List = new System.Windows.Forms.ListBox();
     m_List.BorderStyle = System.Windows.Forms.BorderStyle.None;
     foreach (GXCategory cat in (context.Instance as GXKeepalive).Parent.Categories)
     {
         foreach (GXProperty prop in cat.Properties)
         {
             m_List.Items.Add(prop);
         }
     }
     if (value != null)
     {
         m_List.SelectedIndex = m_List.Items.IndexOf(value);
     }
     m_List.SelectedIndexChanged += new System.EventHandler(this.OnSelectedIndexChanged);
     // Show Listbox as a DropDownControl. This methods returns only when the dropdowncontrol is closed
     m_EdSvc.DropDownControl(m_List);
     (context.Instance as GXKeepalive).Target = m_List.SelectedItem;
     return value;
 }
Esempio n. 7
0
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			var retval = Guid.Empty;
			try
			{
				edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

				var moduleRule = context.Instance as ModuleRule;
				var modulelist = moduleRule.Module.nHydrateModel.Modules.OrderBy(x => x.Name).Where(x => x.Id != moduleRule.Module.Id).ToList();
				var selected = modulelist.FirstOrDefault(x=>x.Id == moduleRule.DependentModule); 

				//Create the list box
				var newBox = new System.Windows.Forms.ListBox();
				newBox.Click += new EventHandler(newBox_Click);
				newBox.IntegralHeight = false;

				var values = new List<string>();
				values.Add(false.ToString());
				values.Add(true.ToString());

				newBox.Items.AddRange(modulelist.Select(x => x.Name).ToArray());
				if (selected != null)
					newBox.SelectedIndex = modulelist.IndexOf(selected);

				edSvc.DropDownControl(newBox);
				if ((moduleRule != null) && (newBox.SelectedIndex != -1))
					retval = modulelist[newBox.SelectedIndex].Id;

			}
			catch (Exception ex) { }
			return retval;
		}
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			Reference retval = null;
			try
			{
				edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

				var table = (Table)context.Instance;
				var root = (ModelRoot)table.Root;
				var referenceCollection = table.Columns;

				//Create the list box 
				var newBox = new System.Windows.Forms.ListBox();
				newBox.Click += new EventHandler(newBox_Click);
				newBox.IntegralHeight = false;

				newBox.Items.Add("(Not Set)");
				foreach(Reference reference in referenceCollection)
				{
					var column = ((ModelRoot)reference.Root).Database.Columns.GetById(reference.Ref)[0];
					newBox.Items.Add(column);
				}

				edSvc.DropDownControl(newBox);
				if((newBox.SelectedIndex > 0) && (newBox.SelectedItem != null))
					retval = ((Column)newBox.SelectedItem).CreateRef();

			}
			catch(Exception ex) { }
			return retval;
		}
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Reference retval = null;

            try
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                var table = (Table)context.Instance;
                var root  = (ModelRoot)table.Root;
                var referenceCollection = table.Columns;

                //Create the list box
                var newBox = new System.Windows.Forms.ListBox();
                newBox.Click         += new EventHandler(newBox_Click);
                newBox.IntegralHeight = false;

                newBox.Items.Add("(Not Set)");
                foreach (Reference reference in referenceCollection)
                {
                    var column = ((ModelRoot)reference.Root).Database.Columns.GetById(reference.Ref)[0];
                    newBox.Items.Add(column);
                }

                edSvc.DropDownControl(newBox);
                if ((newBox.SelectedIndex > 0) && (newBox.SelectedItem != null))
                {
                    retval = ((Column)newBox.SelectedItem).CreateRef();
                }
            }
            catch (Exception ex) { }
            return(retval);
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var retval = Guid.Empty;
            try
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                var indexColumn = context.Instance as IndexColumn;
                var field = indexColumn.Index.Entity.Fields.FirstOrDefault(x => x.Id == indexColumn.FieldID);
                var fieldList = indexColumn.Index.Entity.Fields.OrderBy(x => x.Name).ToList();

                //Create the list box
                var newBox = new System.Windows.Forms.ListBox();
                newBox.Click += new EventHandler(newBox_Click);
                newBox.IntegralHeight = false;

                newBox.Items.AddRange(fieldList.Select(x => x.Name).ToArray());
                if (field != null)
                    newBox.SelectedIndex = fieldList.IndexOf(field);

                edSvc.DropDownControl(newBox);
                if ((indexColumn != null) && (newBox.SelectedIndex != -1))
                    retval = fieldList[newBox.SelectedIndex].Id;

            }
            catch (Exception ex) { }
            return retval;
        }
Esempio n. 11
0
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			var retval = false;
			try
			{
				edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

				var column = (ColumnBase)context.Instance;
				retval = column.AllowNull;

				//Create the list box
				var newBox = new System.Windows.Forms.ListBox();
				newBox.Click += new EventHandler(newBox_Click);
				newBox.IntegralHeight = false;

				var values = new List<string>();
				values.Add(false.ToString()); 
				values.Add(true.ToString());

				newBox.Items.AddRange(values.ToArray());
				newBox.SelectedIndex = (column.AllowNull ? 1 : 0);

				edSvc.DropDownControl(newBox);
				if ((column != null) && (newBox.SelectedIndex != -1))
					retval = (newBox.SelectedIndex == 0 ? false : true);

			}
			catch (Exception ex) { }
			return retval;
		}
Esempio n. 12
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var retval = Guid.Empty;

            try
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                var indexColumn = context.Instance as IndexColumn;
                var field       = indexColumn.Index.Entity.Fields.FirstOrDefault(x => x.Id == indexColumn.FieldID);
                var fieldList   = indexColumn.Index.Entity.Fields.OrderBy(x => x.Name).ToList();

                //Create the list box
                var newBox = new System.Windows.Forms.ListBox();
                newBox.Click         += new EventHandler(newBox_Click);
                newBox.IntegralHeight = false;

                newBox.Items.AddRange(fieldList.Select(x => x.Name).ToArray());
                if (field != null)
                {
                    newBox.SelectedIndex = fieldList.IndexOf(field);
                }

                edSvc.DropDownControl(newBox);
                if ((indexColumn != null) && (newBox.SelectedIndex != -1))
                {
                    retval = fieldList[newBox.SelectedIndex].Id;
                }
            }
            catch (Exception ex) { }
            return(retval);
        }
Esempio n. 13
0
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			var retval = System.Data.SqlDbType.VarChar;
			try
			{
				edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

				var column = (ColumnBase)context.Instance;
				retval = column.DataType;

				//Create the list box
				var newBox = new System.Windows.Forms.ListBox();
				newBox.Click += new EventHandler(newBox_Click);
				newBox.IntegralHeight = false;

				var values = new List<string>();
				foreach (var t in Enum.GetNames(typeof(System.Data.SqlDbType)).OrderBy(x => x))
				{
					values.Add(t);
				}

				newBox.Items.AddRange(values.ToArray());
				newBox.SelectedIndex = newBox.FindString(column.DataType.ToString());

				edSvc.DropDownControl(newBox);
				if ((column != null) && (newBox.SelectedIndex != -1))
					retval = (System.Data.SqlDbType)Enum.Parse(typeof(System.Data.SqlDbType), values[newBox.SelectedIndex]);

			}
			catch (Exception ex) { }
			return retval;
		}
Esempio n. 14
0
        //------------------------------------------------------------------------------------------------------
        public override object EditValue(
            ITypeDescriptorContext context,
            IServiceProvider provider,
            object value)
        {
            if ((context != null) && (context.Instance != null) && (provider != null))
            {
                // Получаем интерфейс сервиса
                service =
                    (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(
                        typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                if (service != null)
                {
                    Channel4_20Control cntrl =
                        new Channel4_20Control();
                    cntrl.ValueChanged +=
                        new  MeasuringDeviceTech.Classes.MeasuringDevice.UITypeEditors.ValueChangedEventHandler(cntrl_ValueChanged);
                    cntrl.Value = (UInt32)value;
                    service.DropDownControl(cntrl);
                    value = cntrl.Value;
                }
            }
            else
            {
                return(base.EditValue(context, provider, value));
            }

            return(value);
        }
Esempio n. 15
0
        //------------------------------------------------------------------------------------------------------
        public override object EditValue(
            System.ComponentModel.ITypeDescriptorContext context, 
            IServiceProvider provider, 
            object value)
        {
            if ((context != null) && (context.Instance != null) && (provider != null))
            {
                service = 
                    (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(
                    typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                if (service != null)
                {
                    if (context.Instance is MeasuringDeviceMainPower)
                    {
                        MeasuringPeriodMainPowerControl cntr =
                            new MeasuringPeriodMainPowerControl(TYPE_NGK_DEVICE.BI_MAIN_POWERED);
                        cntr.ValueChanged += new ValueChangedEventHandler(cntr_ValueChanged);
                        cntr.Value = (UInt32)value;
                        service.DropDownControl(cntr);
                        value = cntr.Value;
                    }
                    else if (context.Instance is MeasuringDeviceBatteryPower)
                    {
                        MeasuringPeriodMainPowerControl cntr =
                            new MeasuringPeriodMainPowerControl(TYPE_NGK_DEVICE.BI_BATTERY_POWER);
                        cntr.ValueChanged += new ValueChangedEventHandler(cntr_ValueChanged);
                        cntr.Value = (UInt32)value;
                        service.DropDownControl(cntr);
                        value = cntr.Value;
                    }
                    else
                    {
                        throw new InvalidOperationException(
                            "Объект для которого вызывается редактор не яввляется устройством БИ");
                    }
                }
            }
            else
            {
                return base.EditValue(context, provider, value);
            }
            return value;
        }
Esempio n. 16
0
        //------------------------------------------------------------------------------------------------------
        public override object EditValue(
            System.ComponentModel.ITypeDescriptorContext context,
            IServiceProvider provider,
            object value)
        {
            if ((context != null) && (context.Instance != null) && (provider != null))
            {
                service =
                    (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(
                        typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                if (service != null)
                {
                    if (context.Instance is MeasuringDeviceMainPower)
                    {
                        MeasuringPeriodMainPowerControl cntr =
                            new MeasuringPeriodMainPowerControl(TYPE_NGK_DEVICE.BI_MAIN_POWERED);
                        cntr.ValueChanged += new ValueChangedEventHandler(cntr_ValueChanged);
                        cntr.Value         = (UInt32)value;
                        service.DropDownControl(cntr);
                        value = cntr.Value;
                    }
                    else if (context.Instance is MeasuringDeviceBatteryPower)
                    {
                        MeasuringPeriodMainPowerControl cntr =
                            new MeasuringPeriodMainPowerControl(TYPE_NGK_DEVICE.BI_BATTERY_POWER);
                        cntr.ValueChanged += new ValueChangedEventHandler(cntr_ValueChanged);
                        cntr.Value         = (UInt32)value;
                        service.DropDownControl(cntr);
                        value = cntr.Value;
                    }
                    else
                    {
                        throw new InvalidOperationException(
                                  "Объект для которого вызывается редактор не яввляется устройством БИ");
                    }
                }
            }
            else
            {
                return(base.EditValue(context, provider, value));
            }
            return(value);
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            Reference retval = null;

            try
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                ModelRoot root = null;
                if (context.Instance is Relation)
                {
                    root = (ModelRoot)((Relation)context.Instance).Root;
                }
                else if (context.Instance is Table)
                {
                    root = (ModelRoot)((Table)context.Instance).Root;
                }

                var tableCollection = root.Database.Tables;

                //Create the list box
                var newBox = new System.Windows.Forms.ListBox();
                newBox.Click         += new EventHandler(newBox_Click);
                newBox.IntegralHeight = false;

                var sortedList = new SortedList();
                foreach (Table table in tableCollection)
                {
                    //Ensure key is unique to avoid error
                    var text = table.Name.ToLower();
                    var key  = text;
                    var ii   = 0;
                    while (sortedList.ContainsKey(key))
                    {
                        key = text + ii.ToString();
                        ii++;
                    }
                    sortedList.Add(key, table);
                }

                //Re-add them in order
                foreach (DictionaryEntry di in sortedList)
                {
                    newBox.Items.Add((Table)di.Value);
                }

                edSvc.DropDownControl(newBox);
                if ((newBox.SelectedIndex > -1) && (newBox.SelectedItem != null))
                {
                    retval = ((Table)newBox.SelectedItem).CreateRef();
                }
            }
            catch (Exception ex) { }
            return(retval);
        }
Esempio n. 18
0
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
 {
     System.Windows.Forms.Design.IWindowsFormsEditorService edSvc =
         (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
     if (edSvc != null)
     {
         GenerePicker genereEdit = new GenerePicker((Book.BookGenere)value);
         edSvc.DropDownControl(genereEdit);
         return(genereEdit.Genere);
     }
     return(value);
 }
 /// <summary>
 /// Overrides the method used to provide basic behaviour for selecting editor.
 /// Shows our custom control for editing the value.
 /// </summary>
 /// <param name="context">The context of the editing control</param>
 /// <param name="provider">A valid service provider</param>
 /// <param name="value">The current value of the object to edit</param>
 /// <returns>The new value of the object</returns>
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context == null || context.Instance == null || provider == null)
     {
         return(base.EditValue(context, provider, value));
     }
     if ((m_EdSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService))) == null)
     {
         return(value);
     }
     Target = value;
     // Create a CheckedListBox and populate it with all the propertylist values
     button        = new Button();
     button.Text   = "Disable All Tests";
     button.Click += new System.EventHandler(OnDisable);
     m_EdSvc.DropDownControl(button);
     return(value);
 }
Esempio n. 20
0
        //-------------------------------------------------------------------------------
        #endregion
        //-------------------------------------------------------------------------------
        #region Methods
        //-------------------------------------------------------------------------------
        public override object EditValue(
            System.ComponentModel.ITypeDescriptorContext context, 
            IServiceProvider provider, 
            object value)
        {
            if ((context != null) && (context.Instance != null) && (provider != null))
            {
                service =
                    (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(
                    typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                if (service != null)
                {
                    if (context.Instance is IDataLinkLayer)
                    {
                        System.IO.Ports.SerialPort port = (System.IO.Ports.SerialPort)value; 
                        SerialPortSettings cntr =
                            new SerialPortSettings(port);
                        cntr.EditingIsComplete += new EditingIsCompleteEventHandler(cntr_EditingIsComplete);

                        if (port.IsOpen)
                        {
                            // Запрещаем редактирование
                            cntr.Enabled = false;
                        }
                        
                        service.DropDownControl(cntr);
                        value = cntr.SerialPort;
                    }
                    else
                    {
                        throw new InvalidOperationException(
                            "Объект для которого вызывается редактор не яввляется IDataLinkLayer");
                    }
                }
            }
            else
            {
                return base.EditValue(context, provider, value);
            }
            return value;
        }
Esempio n. 21
0
        //-------------------------------------------------------------------------------
        #endregion
        //-------------------------------------------------------------------------------
        #region Methods
        //-------------------------------------------------------------------------------
        public override object EditValue(
            System.ComponentModel.ITypeDescriptorContext context,
            IServiceProvider provider,
            object value)
        {
            if ((context != null) && (context.Instance != null) && (provider != null))
            {
                service =
                    (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(
                        typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                if (service != null)
                {
                    if (context.Instance is IDataLinkLayer)
                    {
                        System.IO.Ports.SerialPort port = (System.IO.Ports.SerialPort)value;
                        SerialPortSettings         cntr =
                            new SerialPortSettings(port);
                        cntr.EditingIsComplete += new EditingIsCompleteEventHandler(cntr_EditingIsComplete);

                        if (port.IsOpen)
                        {
                            // Запрещаем редактирование
                            cntr.Enabled = false;
                        }

                        service.DropDownControl(cntr);
                        value = cntr.SerialPort;
                    }
                    else
                    {
                        throw new InvalidOperationException(
                                  "Объект для которого вызывается редактор не яввляется IDataLinkLayer");
                    }
                }
            }
            else
            {
                return(base.EditValue(context, provider, value));
            }
            return(value);
        }
Esempio n. 22
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            var retval = Guid.Empty;

            try
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                var moduleRule = context.Instance as ModuleRule;
                var modulelist = moduleRule.Module.nHydrateModel.Modules.OrderBy(x => x.Name).Where(x => x.Id != moduleRule.Module.Id).ToList();
                var selected   = modulelist.FirstOrDefault(x => x.Id == moduleRule.DependentModule);

                //Create the list box
                var newBox = new System.Windows.Forms.ListBox();
                newBox.Click         += new EventHandler(newBox_Click);
                newBox.IntegralHeight = false;

                var values = new List <string>();
                values.Add(false.ToString());
                values.Add(true.ToString());

                newBox.Items.AddRange(modulelist.Select(x => x.Name).ToArray());
                if (selected != null)
                {
                    newBox.SelectedIndex = modulelist.IndexOf(selected);
                }

                edSvc.DropDownControl(newBox);
                if ((moduleRule != null) && (newBox.SelectedIndex != -1))
                {
                    retval = modulelist[newBox.SelectedIndex].Id;
                }
            }
            catch (Exception ex) { }
            return(retval);
        }
Esempio n. 23
0
 /// <summary>
 /// Overrides the method used to provide basic behaviour for selecting editor.
 /// Shows our custom control for editing the value.
 /// </summary>
 /// <param name="context">The context of the editing control</param>
 /// <param name="provider">A valid service provider</param>
 /// <param name="value">The current value of the object to edit</param>
 /// <returns>The new value of the object</returns>
 public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
 {
     if (context == null || context.Instance == null || provider == null)
     {
         return base.EditValue(context, provider, value);
     }
     if ((m_EdSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService))) == null)
     {
         return value;
     }
     // Create a CheckedListBox and populate it with all the propertylist values
     m_List = new System.Windows.Forms.ListBox();
     m_List.DrawItem += new System.Windows.Forms.DrawItemEventHandler(OnDrawItem);
     m_List.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
     m_List.BorderStyle = System.Windows.Forms.BorderStyle.None;
     if (context.PropertyDescriptor.PropertyType == typeof(Type))
     {
         m_List.Items.Add(typeof(string));
         m_List.Items.Add(typeof(DateTime));
         m_List.Items.Add(typeof(byte));
         m_List.Items.Add(typeof(UInt16));
         m_List.Items.Add(typeof(UInt32));
         m_List.Items.Add(typeof(UInt64));
         m_List.Items.Add(typeof(sbyte));
         m_List.Items.Add(typeof(Int16));
         m_List.Items.Add(typeof(Int32));
         m_List.Items.Add(typeof(Int64));
     }
     else
     {
         foreach(object it in Enum.GetValues(context.PropertyDescriptor.PropertyType))
         {
             m_List.Items.Add(it);
         }
     }
     if (value != null)
     {
         m_List.SelectedIndex = m_List.Items.IndexOf(value);
     }
     m_List.SelectedIndexChanged += new System.EventHandler(this.OnSelectedIndexChanged);
     // Show Listbox as a DropDownControl. This methods returns only when the dropdowncontrol is closed
     m_EdSvc.DropDownControl(m_List);
     m_List.SelectedIndexChanged -= new System.EventHandler(this.OnSelectedIndexChanged);
     if (m_List.SelectedItem != null)
     {
         return m_List.SelectedItem ;
     }
     return value;
 }
        /// <summary>
        /// Overrides the method used to provide basic behaviour for selecting editor.
        /// Shows our custom control for editing the value.
        /// </summary>
        /// <param name="context">The context of the editing control</param>
        /// <param name="provider">A valid service provider</param>
        /// <param name="value">The current value of the object to edit</param>
        /// <returns>The new value of the object</returns>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            if (context != null
                && context.Instance != null
                && provider != null)
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                if (edSvc != null)
                {
                    // Create a CheckedListBox and populate it with all the enum values
                    clb = new System.Windows.Forms.CheckedListBox();
                    clb.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    clb.CheckOnClick = true;
                    clb.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
                    clb.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OnMouseMoved);

                    tooltipControl = new System.Windows.Forms.ToolTip();
                    tooltipControl.ShowAlways = true;

                    foreach (string name in System.Enum.GetNames(context.PropertyDescriptor.PropertyType))
                    {
                        // Get the enum value
                        object enumVal = System.Enum.Parse(context.PropertyDescriptor.PropertyType, name);
                        // Get the int value
                        int intVal = (int)System.Convert.ChangeType(enumVal, typeof(int), System.Globalization.CultureInfo.CurrentCulture);

                        // Get the description attribute for this field
                        System.Reflection.FieldInfo fi = context.PropertyDescriptor.PropertyType.GetField(name);
                        System.ComponentModel.DescriptionAttribute[] attrs = (System.ComponentModel.DescriptionAttribute[])fi.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);

                        // Store the the description
                        string tooltip = attrs.Length > 0 ? attrs[0].Description : string.Empty;

                        // Get the int value of the current enum value (the one being edited)
                        int intEdited = (int)System.Convert.ChangeType(value, typeof(int), System.Globalization.CultureInfo.CurrentCulture);

                        // Creates a clbItem that stores the name, the int value and the tooltip
                        EnumEditorItem item = new EnumEditorItem(enumVal.ToString(), intVal, tooltip);

                        // Get the checkstate from the value being edited
                        //bool checkedItem = (intEdited & intVal) > 0;
                        bool checkedItem = (intEdited & intVal) == intVal;

                        // Add the item with the right check state
                        clb.Items.Add(item, checkedItem);
                    }

                    // Show our CheckedListbox as a DropDownControl.
                    // This methods returns only when the dropdowncontrol is closed
                    edSvc.DropDownControl(clb);

                    // Get the sum of all checked flags
                    int result = 0;
                    foreach (EnumEditorItem obj in clb.CheckedItems)
                    {
                        //result += obj.Value;
                        result |= obj.Value;
                    }

                    // return the right enum value corresponding to the result
                    return System.Enum.ToObject(context.PropertyDescriptor.PropertyType, result);
                }
            }

            return value;
        }
Esempio n. 25
0
        public override object EditValue(ITypeDescriptorContext ctx, IServiceProvider provider, object value)
        {
            Index idx = ctx.Instance as Index;
              Trigger trig = ctx.Instance as Trigger;
              ViewTableBase parent = null;

              if (idx != null) parent = idx.Table;
              else if (trig != null) parent = trig.ViewTableBase;

              // initialize editor service
              _edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
              if (_edSvc == null)
            return value;

              if (value == null) value = String.Empty;
              if (String.IsNullOrEmpty(value.ToString()) == true) value = String.Empty;

              string[] values = value.ToString().Split(',');

              // populate the list
              _list.Items.Clear();

              if (parent is Table)
              {
            foreach (Column c in ((Table)parent).Columns)
            {
              CheckState check = CheckState.Unchecked;
              for (int n = 0; n < values.Length; n++)
              {
            if (values[n].Trim() == String.Format("[{0}]", c.ColumnName))
            {
              check = CheckState.Checked;
              break;
            }
              }
              _list.Items.Add(c.ColumnName, check);
            }
              }
              else
              {
            try
            {
              using (DbCommand cmd = trig.GetConnection().CreateCommand())
              {
            cmd.CommandText = ((View)parent).SqlText;
            using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly))
            using (DataTable tbl = reader.GetSchemaTable())
            {
              foreach (DataRow row in tbl.Rows)
              {
                CheckState check = CheckState.Unchecked;
                for (int n = 0; n < values.Length; n++)
                {
                  if (values[n].Trim() == String.Format("[{0}]", row[SchemaTableColumn.ColumnName]))
                  {
                    check = CheckState.Checked;
                    break;
                  }
                }
                _list.Items.Add(row[SchemaTableColumn.ColumnName].ToString(), check);
              }
            }
              }
            }
            catch
            {
            }
              }
              _list.Height = Math.Min(300, (_list.Items.Count + 1) * _list.Font.Height);

              // show the list
              _cancel = false;
              _edSvc.DropDownControl(_list);

              // build return value from checked items on the list
              if (!_cancel)
              {
            // build a comma-delimited string with the checked items
            StringBuilder sb = new StringBuilder();
            foreach (object item in _list.CheckedItems)
            {
              if (sb.Length > 0) sb.Append(", ");
              sb.AppendFormat("[{0}]", item.ToString());
            }

            return sb.ToString();
              }

              // done
              return value;
        }
Esempio n. 26
0
        /// <summary>
        /// Overrides the method used to provide basic behaviour for selecting editor.
        /// Shows our custom control for editing the value.
        /// </summary>
        /// <param name="context">The context of the editing control</param>
        /// <param name="provider">A valid service provider</param>
        /// <param name="value">The current value of the object to edit</param>
        /// <returns>The new value of the object</returns>
        public override object EditValue(ITypeDescriptorContext context,
            IServiceProvider provider,object value)
        {
            if (context!=null&&context.Instance!=null&&provider!=null)
              {
            edSvc=(System.Windows.Forms.Design.IWindowsFormsEditorService)
              provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
            if (edSvc!=null)
            {
              lb=new System.Windows.Forms.ListBox();
              lb.BorderStyle=System.Windows.Forms.BorderStyle.None;
              lb.SelectedIndexChanged+=new EventHandler(lb_SelectedIndexChanged);
              foreach(Control ctrl in ((Control)context.Instance).Page.Controls)
              {
            if (ctrl.GetType().IsSubclassOf(typeShow)||
              ctrl.GetType().FullName==typeShow.FullName) lb.Items.Add(ctrl.ID);
              }
              edSvc.DropDownControl(lb);
              if (lb.SelectedIndex==-1) return value;
              return lb.SelectedItem;
            }
              }

              return value;
        }
Esempio n. 27
0
        /// <summary>
        /// Overrides the method used to provide basic behaviour for selecting editor.
        /// Shows our custom control for editing the value.
        /// </summary>
        /// <param name="context">The context of the editing control</param>
        /// <param name="provider">A valid service provider</param>
        /// <param name="value">The current value of the object to edit</param>
        /// <returns>The new value of the object</returns>
        public override object EditValue(ITypeDescriptorContext context,
            IServiceProvider provider,object value)
        {
            if (context!=null&&context.Instance!=null&&provider!=null)
              {
            edSvc=(System.Windows.Forms.Design.IWindowsFormsEditorService)
              provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
            if (edSvc!=null)
            {
              lb=new System.Windows.Forms.ListBox();
              lb.BorderStyle=System.Windows.Forms.BorderStyle.None;
              lb.SelectedIndexChanged+=new EventHandler(lb_SelectedIndexChanged);
              lb.Items.Add("onclick");
              lb.Items.Add("ondblclick");
              lb.Items.Add("onmouseover");
              lb.Items.Add("onfocus");
              lb.Items.Add("oncontextmenu");
              edSvc.DropDownControl(lb);
              if (lb.SelectedIndex==-1) return value;
              return lb.SelectedItem;
            }
              }

              return value;
        }
        /// <summary>
        /// Overrides the method used to provide basic behaviour for selecting editor.
        /// Shows our custom control for editing the value.
        /// </summary>
        /// <param name="context">The context of the editing control</param>
        /// <param name="provider">A valid service provider</param>
        /// <param name="value">The current value of the object to edit</param>
        /// <returns>The new value of the object</returns>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            if (context == null || context.Instance == null || provider == null)
            {
                return base.EditValue(context, provider, value);
            }
            if ((m_EdSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService))) == null)
            {
                return value;
            }
            // Create a CheckedListBox and populate it with all the propertylist values
            m_List = new System.Windows.Forms.ListBox();
            m_List.BorderStyle = System.Windows.Forms.BorderStyle.None;
            GXDataIOSource source = (GXDataIOSource)context.Instance;
            GXDataIOSourceAttribute att = TypeDescriptor.GetAttributes(source.Parent)[typeof(GXDataIOSourceAttribute)] as GXDataIOSourceAttribute;
            List<Enum> tmp = new List<Enum>();
            Array SourceTypes = Enum.GetValues(value.GetType());
            Array TargetTypes = null;
            if (att.SupportedProperties != null)
            {
                long values = (long)att.SupportedProperties;
                foreach (object it in Enum.GetValues(att.SupportedProperties.GetType()))
                {
                    long val = Convert.ToInt64(it);
                    if ((val & values) == val && val != 0)
                    {
                        tmp.Add((Enum)it);
                    }
                }
                TargetTypes = tmp.ToArray();
            }

            foreach (object it in SourceTypes)
            {
                if (TargetTypes == null)
                {
                    long val = Convert.ToInt64(it);
                    if (val > 0)
                    {
                        m_List.Items.Add(Enum.GetName(value.GetType(), it));
                    }
                }
                else
                {
                    foreach (Enum it2 in TargetTypes)
                    {
                        if (string.Compare(Enum.GetName(value.GetType(), it), it2.ToString()) == 0)
                        {
                            m_List.Items.Add(Enum.GetName(value.GetType(), it));
                            break;
                        }
                    }
                }
            }
            if (value != null)
            {
                m_List.SelectedIndex = m_List.Items.IndexOf(value.ToString());
            }
            m_List.SelectedIndexChanged += new System.EventHandler(this.OnSelectedIndexChanged);
            // Show Listbox as a DropDownControl. This methods returns only when the dropdowncontrol is closed
            m_EdSvc.DropDownControl(m_List);
            if (m_List.SelectedItem != null)
            {
                return Enum.Parse(value.GetType(), m_List.SelectedItem.ToString());
            }
            return value;
        }
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			Reference retval = null;
			try
			{
				edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

				ModelRoot root = null;
				if (context.Instance is Relation)
					root = (ModelRoot)((Relation)context.Instance).Root;
				else if (context.Instance is Table)
					root = (ModelRoot)((Table)context.Instance).Root;

				var tableCollection = root.Database.Tables;

				//Create the list box 
				var newBox = new System.Windows.Forms.ListBox();
				newBox.Click += new EventHandler(newBox_Click);
				newBox.IntegralHeight = false;

				var sortedList = new SortedList();
				foreach (Table table in tableCollection)
				{
					//Ensure key is unique to avoid error
					var text = table.Name.ToLower();
					var key = text;
					var ii = 0;
					while (sortedList.ContainsKey(key))
					{
						key = text + ii.ToString();
						ii++;
					}
					sortedList.Add(key, table);
				}

				//Re-add them in order
				foreach (DictionaryEntry di in sortedList)
					newBox.Items.Add((Table)di.Value);

				edSvc.DropDownControl(newBox);
				if ((newBox.SelectedIndex > -1) && (newBox.SelectedItem != null))
					retval = ((Table)newBox.SelectedItem).CreateRef();

			}
			catch (Exception ex) { }
			return retval;
		}
Esempio n. 30
0
		public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
		{
			try
			{
				edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

				var selectedItemKey = string.Empty;
				var root = (ModelRoot)((Table)context.Instance).Root;
				var sourceTable = (Table)context.Instance;
				var retval = sourceTable.ParentTable;
				selectedItemKey = sourceTable.ParentTableKey;

				var tableCollection = new List<Table>();
				foreach (Table t in root.Database.Tables)
				{
					tableCollection.Add(t);
				}

				//Remove the current table
				tableCollection.Remove(sourceTable);

				//Remove all parent tables
				var tList = sourceTable.GetTableHierarchy();
				foreach (var t in tList)
				{
					if (tableCollection.Contains(t))
						tableCollection.Remove(t);
				}

				//Remove all child tables
				tList = sourceTable.GetTablesInheritedFromHierarchy();
				foreach (var t in tList)
				{
					if (tableCollection.Contains(t))
						tableCollection.Remove(t);
				}

				//Add the current parent if one exists
				if (sourceTable.ParentTable != null)
					tableCollection.Add(sourceTable.ParentTable);

				//Create the list box 
				var newBox = new System.Windows.Forms.ListBox();
				newBox.Click += new EventHandler(newBox_Click);
				newBox.IntegralHeight = false;

				var sortedList = new SortedList();
				foreach (var table in tableCollection)
				{
					//Ensure key is unique to avoid error
					var text = table.Name.ToLower();
					var key = text;
					var ii = 0;
					while (sortedList.ContainsKey(key))
					{
						key = text + ii.ToString();
						ii++;
					}
					sortedList.Add(key, table);
				}

				//Re-add them in order
				newBox.Items.Add("(None)");
				newBox.SelectedIndex = 0;
				foreach (DictionaryEntry di in sortedList)
				{
					var t = (Table)di.Value;
					newBox.Items.Add(t);
					if (t.Key == selectedItemKey)
						newBox.SelectedIndex = newBox.Items.Count - 1;
				}

				edSvc.DropDownControl(newBox);
				if ((newBox.SelectedIndex > 0) && (newBox.SelectedItem != null))
					retval = ((Table)newBox.SelectedItem);
				else if (newBox.SelectedIndex == 0)
					retval = null;

				return retval;
			}
			catch (Exception ex) { }
			return null;
		}
        /// <summary>
        /// Overrides the method used to provide basic behaviour for selecting editor.
        /// Shows our custom control for editing the value.
        /// </summary>
        /// <param name="context">The context of the editing control</param>
        /// <param name="provider">A valid service provider</param>
        /// <param name="value">The current value of the object to edit</param>
        /// <returns>The new value of the object</returns>
        public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value)
        {
            if (context != null &&
                context.Instance != null &&
                provider != null)
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                if (edSvc != null)
                {
                    // Create a CheckedListBox and populate it with all the enum values
                    clb              = new System.Windows.Forms.CheckedListBox();
                    clb.BorderStyle  = System.Windows.Forms.BorderStyle.FixedSingle;
                    clb.CheckOnClick = true;
                    clb.MouseDown   += new System.Windows.Forms.MouseEventHandler(this.OnMouseDown);
                    clb.MouseMove   += new System.Windows.Forms.MouseEventHandler(this.OnMouseMoved);

                    tooltipControl            = new System.Windows.Forms.ToolTip();
                    tooltipControl.ShowAlways = true;

                    foreach (string name in System.Enum.GetNames(context.PropertyDescriptor.PropertyType))
                    {
                        // Get the enum value
                        object enumVal = System.Enum.Parse(context.PropertyDescriptor.PropertyType, name);
                        // Get the int value
                        int intVal = (int)System.Convert.ChangeType(enumVal, typeof(int), System.Globalization.CultureInfo.CurrentCulture);

                        // Get the description attribute for this field
                        System.Reflection.FieldInfo fi = context.PropertyDescriptor.PropertyType.GetField(name);
                        System.ComponentModel.DescriptionAttribute[] attrs = (System.ComponentModel.DescriptionAttribute[])fi.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);

                        // Store the the description
                        string tooltip = attrs.Length > 0 ? attrs[0].Description : string.Empty;

                        // Get the int value of the current enum value (the one being edited)
                        int intEdited = (int)System.Convert.ChangeType(value, typeof(int), System.Globalization.CultureInfo.CurrentCulture);

                        // Creates a clbItem that stores the name, the int value and the tooltip
                        EnumEditorItem item = new EnumEditorItem(enumVal.ToString(), intVal, tooltip);

                        // Get the checkstate from the value being edited
                        //bool checkedItem = (intEdited & intVal) > 0;
                        bool checkedItem = (intEdited & intVal) == intVal;

                        // Add the item with the right check state
                        clb.Items.Add(item, checkedItem);
                    }

                    // Show our CheckedListbox as a DropDownControl.
                    // This methods returns only when the dropdowncontrol is closed
                    edSvc.DropDownControl(clb);

                    // Get the sum of all checked flags
                    int result = 0;
                    foreach (EnumEditorItem obj in clb.CheckedItems)
                    {
                        //result += obj.Value;
                        result |= obj.Value;
                    }

                    // return the right enum value corresponding to the result
                    return(System.Enum.ToObject(context.PropertyDescriptor.PropertyType, result));
                }
            }

            return(value);
        }
Esempio n. 32
0
        override public object EditValue(ITypeDescriptorContext ctx, IServiceProvider provider, object value)
        {
            Index         idx    = ctx.Instance as Index;
            Trigger       trig   = ctx.Instance as Trigger;
            ViewTableBase parent = null;

            if (idx != null)
            {
                parent = idx.Table;
            }
            else if (trig != null)
            {
                parent = trig.ViewTableBase;
            }

            // initialize editor service
            _edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));
            if (_edSvc == null)
            {
                return(value);
            }

            if (value == null)
            {
                value = String.Empty;
            }
            if (String.IsNullOrEmpty(value.ToString()) == true)
            {
                value = String.Empty;
            }

            string[] values = value.ToString().Split(',');

            // populate the list
            _list.Items.Clear();

            if (parent is Table)
            {
                foreach (Column c in ((Table)parent).Columns)
                {
                    CheckState check = CheckState.Unchecked;
                    for (int n = 0; n < values.Length; n++)
                    {
                        if (values[n].Trim() == String.Format(CultureInfo.InvariantCulture, "[{0}]", c.ColumnName))
                        {
                            check = CheckState.Checked;
                            break;
                        }
                    }
                    _list.Items.Add(c.ColumnName, check);
                }
            }
            else
            {
                try
                {
                    using (DbCommand cmd = trig.GetConnection().CreateCommand())
                    {
                        cmd.CommandText = ((View)parent).SqlText;
                        using (DbDataReader reader = cmd.ExecuteReader(CommandBehavior.SchemaOnly))
                            using (DataTable tbl = reader.GetSchemaTable())
                            {
                                foreach (DataRow row in tbl.Rows)
                                {
                                    CheckState check = CheckState.Unchecked;
                                    for (int n = 0; n < values.Length; n++)
                                    {
                                        if (values[n].Trim() == String.Format(CultureInfo.InvariantCulture, "[{0}]", row[SchemaTableColumn.ColumnName]))
                                        {
                                            check = CheckState.Checked;
                                            break;
                                        }
                                    }
                                    _list.Items.Add(row[SchemaTableColumn.ColumnName].ToString(), check);
                                }
                            }
                    }
                }
                catch
                {
                }
            }
            _list.Height = Math.Min(300, (_list.Items.Count + 1) * _list.Font.Height);

            // show the list
            _cancel = false;
            _edSvc.DropDownControl(_list);

            // build return value from checked items on the list
            if (!_cancel)
            {
                // build a comma-delimited string with the checked items
                StringBuilder sb = new StringBuilder();
                foreach (object item in _list.CheckedItems)
                {
                    if (sb.Length > 0)
                    {
                        sb.Append(", ");
                    }
                    sb.AppendFormat("[{0}]", item.ToString());
                }

                return(sb.ToString());
            }

            // done
            return(value);
        }
Esempio n. 33
0
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            try
            {
                edSvc = (System.Windows.Forms.Design.IWindowsFormsEditorService)provider.GetService(typeof(System.Windows.Forms.Design.IWindowsFormsEditorService));

                var selectedItemKey = string.Empty;
                var root            = (ModelRoot)((Table)context.Instance).Root;
                var sourceTable     = (Table)context.Instance;
                var retval          = sourceTable.ParentTable;
                selectedItemKey = sourceTable.ParentTableKey;

                var tableCollection = new List <Table>();
                foreach (Table t in root.Database.Tables)
                {
                    tableCollection.Add(t);
                }

                //Remove the current table
                tableCollection.Remove(sourceTable);

                //Remove all parent tables
                var tList = sourceTable.GetTableHierarchy();
                foreach (var t in tList)
                {
                    if (tableCollection.Contains(t))
                    {
                        tableCollection.Remove(t);
                    }
                }

                //Remove all child tables
                tList = sourceTable.GetTablesInheritedFromHierarchy();
                foreach (var t in tList)
                {
                    if (tableCollection.Contains(t))
                    {
                        tableCollection.Remove(t);
                    }
                }

                //Add the current parent if one exists
                if (sourceTable.ParentTable != null)
                {
                    tableCollection.Add(sourceTable.ParentTable);
                }

                //Create the list box
                var newBox = new System.Windows.Forms.ListBox();
                newBox.Click         += new EventHandler(newBox_Click);
                newBox.IntegralHeight = false;

                var sortedList = new SortedList();
                foreach (var table in tableCollection)
                {
                    //Ensure key is unique to avoid error
                    var text = table.Name.ToLower();
                    var key  = text;
                    var ii   = 0;
                    while (sortedList.ContainsKey(key))
                    {
                        key = text + ii.ToString();
                        ii++;
                    }
                    sortedList.Add(key, table);
                }

                //Re-add them in order
                newBox.Items.Add("(None)");
                newBox.SelectedIndex = 0;
                foreach (DictionaryEntry di in sortedList)
                {
                    var t = (Table)di.Value;
                    newBox.Items.Add(t);
                    if (t.Key == selectedItemKey)
                    {
                        newBox.SelectedIndex = newBox.Items.Count - 1;
                    }
                }

                edSvc.DropDownControl(newBox);
                if ((newBox.SelectedIndex > 0) && (newBox.SelectedItem != null))
                {
                    retval = ((Table)newBox.SelectedItem);
                }
                else if (newBox.SelectedIndex == 0)
                {
                    retval = null;
                }

                return(retval);
            }
            catch (Exception ex) { }
            return(null);
        }