private void saveButton_Click(object sender, EventArgs e) { SaveFileDialog saveFileDialog = new SaveFileDialog(); saveFileDialog.CheckPathExists = true; saveFileDialog.Filter = languageSupportManager.GetStringValue("Main_SaveButton_Filter_estm") + "|*.estm"; saveFileDialog.FileName = languageSupportManager.GetStringValue("Main_SaveButton_DefaultFileNameTemplate") + $".{DateTime.Now.ToString("yyyyMMdd")}"; saveFileDialog.Title = languageSupportManager.GetStringValue("SaveDialogTitle"); saveFileDialog.InitialDirectory = Environment.CurrentDirectory; if (saveFileDialog.ShowDialog(this) == DialogResult.OK) { Template usedTemplate = new Template(); usedTemplate.Base = template.Base; usedTemplate.PriceHour = template.PriceHour; usedTemplate.CustomControls = new List <CustomControl>(); foreach (ICustomControl usedControl in controlContainer.Controls) { CustomControl customControl = new CustomControl(); customControl.Category = usedControl.Category; customControl.Description = usedControl.Description; customControl.ControlType = usedControl.ControlType; customControl.Effort = usedControl.Effort; customControl.Weight = usedControl.Weight; if (usedControl.GetType() == typeof(NumberControl)) { NumberControl numberControl = (NumberControl)usedControl; customControl.DefaultValue = numberControl.SelectedNumber.ToString(); } else if (usedControl.GetType() == typeof(OptionBoolControl)) { OptionBoolControl optionBoolControl = (OptionBoolControl)usedControl; customControl.DefaultValue = optionBoolControl.SelectedOption.ToString(); } else if (usedControl.GetType() == typeof(PercentControl)) { PercentControl percentControl = (PercentControl)usedControl; int percent = Convert.ToInt32(percentControl.EstimatedWeight * 100); customControl.DefaultValue = percent.ToString(); } usedTemplate.CustomControls.Add(customControl); } templateBO.SaveTemplate(usedTemplate, saveFileDialog.FileName); } }
/// <summary> /// Creates a value block for presenting percent values. /// </summary> /// <param name="propertyName">The name of the property to be bound to the value.</param> /// <returns>A visual element that will display the bound value as a percent.</returns> public static FrameworkElement CreatePercentMetadataValue(String propertyName) { // This will create a presenter for the percent metadata values and bind it to the given property. PercentControl percentControl = new PercentControl() { Foreground = DetailBar.valueBrush, FontSize = 12.0, HorizontalContentAlignment = HorizontalAlignment.Left }; BindingOperations.SetBinding(percentControl, PercentControl.PercentProperty, new Binding() { Path = new PropertyPath(propertyName) }); return(percentControl); }
/// <summary> /// Edits the specified object's value using the editor style indicated by the <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"/> method. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be used to gain additional context information.</param> /// <param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to obtain services.</param> /// <param name="value">The object to edit.</param> /// <returns> /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed. /// </returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (value.GetType() != typeof(float)) return value; var editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (editorService != null) { PercentControl control = new PercentControl((float)value, editorService); editorService.DropDownControl(control); return control.Value; } return value; }
private void RefreshTemplate(string path) { template = templateBO.LoadTemplate(path); int y = 0; controlContainer.Controls.Clear(); foreach (CustomControl customControl in template.CustomControls) { if (customControl.ControlType.ToUpper().Trim() == "NUMBER") { NumberControl numberControl = new NumberControl(); numberControl.EstimatedWeigthChanged += CustomControl_EstimatedWeigthChanged; numberControl.Top = y; MapControl(customControl, numberControl); controlContainer.Controls.Add(numberControl); y += numberControl.Height + numberControl.Margin.Bottom; } else if (customControl.ControlType.ToUpper().Trim() == "PERCENT") { PercentControl percentControl = new PercentControl(); percentControl.EstimatedWeigthChanged += CustomControl_EstimatedWeigthChanged; percentControl.Top = y; MapControl(customControl, percentControl); controlContainer.Controls.Add(percentControl); y += percentControl.Height + percentControl.Margin.Bottom; } else if (customControl.ControlType.ToUpper().Trim() == "OPTIONBOOL") { OptionBoolControl optionControl = new OptionBoolControl(); optionControl.EstimatedWeigthChanged += CustomControl_EstimatedWeigthChanged; optionControl.Top = y; MapControl(customControl, optionControl); controlContainer.Controls.Add(optionControl); y += optionControl.Height + optionControl.Margin.Bottom; } } CustomControl_EstimatedWeigthChanged(); }
/// <summary> /// Edits the specified object's value using the editor style indicated by the <see cref="M:System.Drawing.Design.UITypeEditor.GetEditStyle"/> method. /// </summary> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that can be used to gain additional context information.</param> /// <param name="provider">An <see cref="T:System.IServiceProvider"/> that this editor can use to obtain services.</param> /// <param name="value">The object to edit.</param> /// <returns> /// The new value of the object. If the value of the object has not changed, this should return the same object it was passed. /// </returns> public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (value.GetType() != typeof(float)) { return(value); } var editorService = provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService; if (editorService != null) { PercentControl control = new PercentControl((float)value, editorService); editorService.DropDownControl(control); return(control.Value); } return(value); }