Esempio n. 1
0
        // creates a control of appropriate type for the parameter.
        // note: parameter values are stored as invariant strings.
        private Control GetControl(OleDbParameter p)
        {
            var value = p.Value as string;
            var type  = OleDbSchema.GetType(p.OleDbType);

            if (OleDbSchema.IsNumeric(type))
            {
                var num = new Altaxo.Gui.Common.DecimalUpDown
                {
                    Minimum = decimal.MinValue,
                    Maximum = decimal.MaxValue
                };
                decimal dec = 0;
                if (!string.IsNullOrEmpty(value))
                {
                    decimal.TryParse(value, _numberStyle, _invariant, out dec);
                }
                num.Value = dec;
                return(num);
            }
            if (type == typeof(DateTime))
            {
                var dtp = new DatePicker
                {
                    SelectedDateFormat = p.OleDbType == OleDbType.Filetime
            ? DatePickerFormat.Long
            : DatePickerFormat.Short
                };
                DateTime dt = DateTime.Now;
                if (!string.IsNullOrEmpty(value))
                {
                    DateTime.TryParse(value, _invariant, _dateStyle, out dt);
                }
                dtp.SelectedDate = dt;
                return(dtp);
            }
            if (type == typeof(bool))
            {
                var  chk = new CheckBox();
                bool b   = false;
                if (!string.IsNullOrEmpty(value))
                {
                    bool.TryParse(value as string, out b);
                }
                chk.IsChecked = b;
                return(chk);
            }

            // default: textbox
            var tb = new TextBox
            {
                Text = value
            };

            return(tb);
        }
Esempio n. 2
0
		// creates a control of appropriate type for the parameter.
		// note: parameter values are stored as invariant strings.
		private Control GetControl(OleDbParameter p)
		{
			var value = p.Value as string;
			var type = OleDbSchema.GetType(p.OleDbType);
			if (OleDbSchema.IsNumeric(type))
			{
				var num = new Altaxo.Gui.Common.DecimalUpDown();
				num.Minimum = decimal.MinValue;
				num.Maximum = decimal.MaxValue;
				decimal dec = 0;
				if (!string.IsNullOrEmpty(value))
				{
					decimal.TryParse(value, _numberStyle, _invariant, out dec);
				}
				num.Value = dec;
				return num;
			}
			if (type == typeof(DateTime))
			{
				var dtp = new DatePicker();
				dtp.SelectedDateFormat = p.OleDbType == OleDbType.Filetime
						? DatePickerFormat.Long
						: DatePickerFormat.Short;
				DateTime dt = DateTime.Now;
				if (!string.IsNullOrEmpty(value))
				{
					DateTime.TryParse(value, _invariant, _dateStyle, out dt);
				}
				dtp.SelectedDate = dt;
				return dtp;
			}
			if (type == typeof(bool))
			{
				var chk = new CheckBox();
				bool b = false;
				if (!string.IsNullOrEmpty(value))
				{
					bool.TryParse(value as string, out b);
				}
				chk.IsChecked = b;
				return chk;
			}

			// default: textbox
			var tb = new TextBox();
			tb.Text = value;
			return tb;
		}