2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-06-24 13:41:48 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Drawing;
|
2023-01-06 15:09:35 +01:00
|
|
|
|
using System.Linq;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
|
|
|
|
using XenAdmin.Actions;
|
|
|
|
|
using XenAdmin.CustomFields;
|
|
|
|
|
using XenAdmin.Dialogs;
|
|
|
|
|
using XenAPI;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace XenAdmin.SettingsPanels
|
|
|
|
|
{
|
|
|
|
|
public partial class CustomFieldsDisplayPage : UserControl, IEditPage
|
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// This is not ideal, but we need something in the last row of the tableLayoutPanel
|
|
|
|
|
/// that fills all the way to the bottom of the page; if we leave the controls in the
|
|
|
|
|
/// last row, they align vertically in its middle because they don't have vertical
|
|
|
|
|
/// anchoring (because they have different heights and it's a pain to get the vertical
|
|
|
|
|
/// alignment right by fiddling with the margins)
|
|
|
|
|
/// </summary>
|
|
|
|
|
private readonly Panel _panelDummy;
|
|
|
|
|
private IXenObject _xenObject;
|
|
|
|
|
private readonly List<CustomFieldRow> _fieldRows = new List<CustomFieldRow>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public CustomFieldsDisplayPage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2023-01-06 15:09:35 +01:00
|
|
|
|
_panelDummy = new Panel { Size = new Size(0, 0), Margin = new Padding(0) };
|
2013-06-24 13:41:48 +02:00
|
|
|
|
Text = Messages.CUSTOM_FIELDS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#region IEditPage Members
|
|
|
|
|
|
|
|
|
|
public AsyncAction SaveSettings()
|
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
var customFields = new List<CustomField>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
foreach (var row in _fieldRows)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
object currentValue = CustomFieldsManager.GetCustomFieldValue(_xenObject, row.CustomFieldDefinition);
|
|
|
|
|
object newValue = row.GetValue();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
if (currentValue == null && newValue == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
customFields.Add(new CustomField(row.CustomFieldDefinition, newValue));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
return new SaveCustomFieldsAction(_xenObject, customFields, true);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetXenObjects(IXenObject orig, IXenObject clone)
|
|
|
|
|
{
|
|
|
|
|
CustomFieldsManager.CustomFieldsChanged -= CustomFields_CustomFieldsChanged;
|
2023-01-06 15:09:35 +01:00
|
|
|
|
_xenObject = clone;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
if (_xenObject != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
CustomFieldsManager.CustomFieldsChanged += CustomFields_CustomFieldsChanged;
|
|
|
|
|
Rebuild(true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
public bool ValidToSave => true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
public void ShowLocalValidationMessages()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-23 11:34:46 +02:00
|
|
|
|
public void HideLocalValidationMessages()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
public void Cleanup()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool HasChanged
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
foreach (var row in _fieldRows)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
object currentValue = CustomFieldsManager.GetCustomFieldValue(_xenObject, row.CustomFieldDefinition);
|
|
|
|
|
object newValue = row.GetValue();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
if (currentValue == null && newValue == null)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (currentValue == null || newValue == null)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (newValue.Equals(currentValue))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2018-03-20 18:02:45 +01:00
|
|
|
|
#region IVerticalTab Members
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
public string SubText
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
List<string> fields = new List<string>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
foreach (var row in _fieldRows)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
object newValue = row.GetValue();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
if (newValue == null || newValue.ToString() == string.Empty)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
continue;
|
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
fields.Add(row.CustomFieldDefinition.Name + Messages.GENERAL_PAGE_KVP_SEPARATOR + newValue);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fields.Count == 0)
|
|
|
|
|
return Messages.NONE;
|
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
return string.Join(", ", fields);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-18 02:20:29 +02:00
|
|
|
|
public Image Image => Images.StaticImages._000_Fields_h32bit_16;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
2016-10-13 23:59:06 +02:00
|
|
|
|
private void CustomFields_CustomFieldsChanged()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Rebuild(false);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private void Rebuild(bool resetValues)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
var customFieldDefinitions = CustomFieldsManager.GetCustomFields(_xenObject.Connection).ToArray();
|
|
|
|
|
|
|
|
|
|
tableLayoutPanel.SuspendLayout();
|
|
|
|
|
tableLayoutPanel.Controls.Remove(_panelDummy);
|
|
|
|
|
|
|
|
|
|
// Add new custom fields
|
|
|
|
|
foreach (var definition in customFieldDefinitions)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
object value = CustomFieldsManager.GetCustomFieldValue(_xenObject, definition);
|
|
|
|
|
var row = _fieldRows.FirstOrDefault(r => r.CustomFieldDefinition.Equals(definition));
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
if (row == null)
|
|
|
|
|
{
|
|
|
|
|
row = new CustomFieldRow(definition, value);
|
|
|
|
|
row.DeleteCustomFieldClicked += DeleteCustomFieldClicked_Click;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
_fieldRows.Add(row);
|
|
|
|
|
tableLayoutPanel.Controls.AddRange(row.Controls);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
if (1 < row.Controls.Length && row.Controls.Length < tableLayoutPanel.ColumnCount)
|
|
|
|
|
tableLayoutPanel.SetColumnSpan(row.Controls[1], 2); //this is the textbox
|
|
|
|
|
}
|
|
|
|
|
else if (resetValues)
|
|
|
|
|
{
|
|
|
|
|
row.SetValue(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tableLayoutPanel.Controls.Add(_panelDummy);
|
|
|
|
|
|
|
|
|
|
var extraRows = _fieldRows.Where(r => !customFieldDefinitions.Contains(r.CustomFieldDefinition)).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var row in extraRows)
|
|
|
|
|
{
|
|
|
|
|
row.DeleteCustomFieldClicked -= DeleteCustomFieldClicked_Click;
|
|
|
|
|
_fieldRows.Remove(row);
|
|
|
|
|
|
|
|
|
|
foreach (var control in row.Controls)
|
|
|
|
|
{
|
|
|
|
|
tableLayoutPanel.Controls.Remove(control);
|
|
|
|
|
control.Dispose();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2023-01-06 15:09:35 +01:00
|
|
|
|
|
|
|
|
|
tableLayoutPanel.ResumeLayout();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private void buttonNewCustomField_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
using (var dialog = new NewCustomFieldDialog(_xenObject.Connection))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
if (dialog.ShowDialog() == DialogResult.OK)
|
|
|
|
|
new AddCustomFieldAction(_xenObject.Connection, dialog.Definition).RunAsync();
|
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private void DeleteCustomFieldClicked_Click(CustomFieldRow row)
|
|
|
|
|
{
|
|
|
|
|
string name = row.CustomFieldDefinition.Name.Ellipsise(50);
|
|
|
|
|
|
|
|
|
|
if (!Program.RunInAutomatedTestMode)
|
|
|
|
|
{
|
|
|
|
|
using (var dialog = new WarningDialog(string.Format(Messages.MESSAGEBOX_DELETE_CUSTOM_FIELD, name),
|
|
|
|
|
ThreeButtonDialog.ButtonYes, ThreeButtonDialog.ButtonNo))
|
|
|
|
|
{
|
|
|
|
|
if (dialog.ShowDialog(Program.MainWindow) != DialogResult.Yes)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
2023-01-06 15:09:35 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
if (_xenObject.Connection != null && _xenObject.Connection.IsConnected)
|
|
|
|
|
{
|
|
|
|
|
new RemoveCustomFieldAction(_xenObject.Connection, row.CustomFieldDefinition).RunAsync();
|
|
|
|
|
}
|
|
|
|
|
else if (!Program.RunInAutomatedTestMode)
|
|
|
|
|
{
|
|
|
|
|
using (var dlg = new ErrorDialog(Messages.DISCONNECTED_BEFORE_ACTION_STARTED))
|
|
|
|
|
dlg.ShowDialog(this);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
|
|
|
|
|
private class CustomFieldRow
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private readonly TextBox _textBox;
|
|
|
|
|
private readonly DateTimePicker _datePicker;
|
|
|
|
|
private readonly DateTimePicker _timePicker;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
public event Action<CustomFieldRow> DeleteCustomFieldClicked;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
public CustomFieldRow(CustomFieldDefinition definition, object value)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
CustomFieldDefinition = definition;
|
|
|
|
|
|
|
|
|
|
var controls = new List<Control>();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
var label = CreateNewLabel(definition);
|
|
|
|
|
controls.Add(label);
|
|
|
|
|
|
|
|
|
|
switch (definition.Type)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
case CustomFieldDefinition.Types.String:
|
|
|
|
|
_textBox = CreateNewTextBox(value as string);
|
|
|
|
|
controls.Add(_textBox);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case CustomFieldDefinition.Types.Date:
|
|
|
|
|
_datePicker = CreateNewDatePicker(value as DateTime?);
|
|
|
|
|
_timePicker = CreateNewTimePicker(value as DateTime?);
|
|
|
|
|
controls.Add(_datePicker);
|
|
|
|
|
controls.Add(_timePicker);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
throw new InvalidEnumArgumentException(nameof(definition));
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
var deleteButton = CreateNewDeleteButton();
|
|
|
|
|
controls.Add(deleteButton);
|
|
|
|
|
Controls = controls.ToArray();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
UpdateDateTImePickerState();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
public CustomFieldDefinition CustomFieldDefinition { get; }
|
|
|
|
|
|
|
|
|
|
public Control[] Controls { get; }
|
|
|
|
|
|
|
|
|
|
public object GetValue()
|
|
|
|
|
{
|
|
|
|
|
if (_textBox != null && !string.IsNullOrEmpty(_textBox.Text))
|
|
|
|
|
return _textBox.Text;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
if (_datePicker != null && _timePicker != null && _datePicker.Checked)
|
|
|
|
|
{
|
|
|
|
|
DateTime date = _datePicker.Value;
|
|
|
|
|
DateTime time = _timePicker.Value;
|
|
|
|
|
return new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2023-01-06 15:09:35 +01:00
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetValue(object value)
|
|
|
|
|
{
|
|
|
|
|
if (_textBox != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
_textBox.Text = value as string;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
if (_datePicker != null && _timePicker != null)
|
|
|
|
|
{
|
|
|
|
|
if (value != null)
|
|
|
|
|
{
|
|
|
|
|
_datePicker.Checked = true;
|
|
|
|
|
_datePicker.Value = (DateTime)value;
|
|
|
|
|
_timePicker.Value = (DateTime)value;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
_datePicker.Checked = false;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private Label CreateNewLabel(CustomFieldDefinition customFieldDefinition)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
return new Label
|
|
|
|
|
{
|
|
|
|
|
Anchor = AnchorStyles.Left | AnchorStyles.Right,
|
2023-08-15 11:55:14 +02:00
|
|
|
|
Text = customFieldDefinition.Name.EscapeAmpersands().Ellipsise(45),
|
2023-01-06 15:09:35 +01:00
|
|
|
|
Font = Program.DefaultFont,
|
|
|
|
|
AutoSize = true,
|
|
|
|
|
AutoEllipsis = false
|
|
|
|
|
};
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private TextBox CreateNewTextBox(string text)
|
|
|
|
|
{
|
|
|
|
|
return new TextBox
|
|
|
|
|
{
|
|
|
|
|
Anchor = AnchorStyles.Left | AnchorStyles.Right,
|
|
|
|
|
Text = text ?? string.Empty
|
|
|
|
|
};
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private DateTimePicker CreateNewDatePicker(DateTime? value)
|
|
|
|
|
{
|
|
|
|
|
var date = new DateTimePicker
|
|
|
|
|
{
|
|
|
|
|
Anchor = AnchorStyles.Left | AnchorStyles.Right,
|
|
|
|
|
MinDate = DateTime.MinValue,
|
|
|
|
|
MaxDate = DateTime.MaxValue,
|
|
|
|
|
ShowCheckBox = true,
|
|
|
|
|
Format = DateTimePickerFormat.Long,
|
|
|
|
|
Checked = value.HasValue
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (value.HasValue)
|
|
|
|
|
date.Value = (DateTime)value;
|
|
|
|
|
|
|
|
|
|
date.ValueChanged += Date_ValueChanged;
|
|
|
|
|
return date;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private DateTimePicker CreateNewTimePicker(DateTime? value)
|
|
|
|
|
{
|
|
|
|
|
var time = new DateTimePicker
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2023-01-06 15:09:35 +01:00
|
|
|
|
Anchor = AnchorStyles.Left | AnchorStyles.Right,
|
|
|
|
|
MinDate = DateTime.MinValue,
|
|
|
|
|
MaxDate = DateTime.MaxValue,
|
|
|
|
|
Format = DateTimePickerFormat.Time,
|
|
|
|
|
ShowUpDown = true,
|
|
|
|
|
Enabled = value.HasValue
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (value.HasValue)
|
|
|
|
|
time.Value = (DateTime)value;
|
|
|
|
|
|
|
|
|
|
return time;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private Button CreateNewDeleteButton()
|
|
|
|
|
{
|
|
|
|
|
var buttonDelete = new Button
|
|
|
|
|
{
|
|
|
|
|
Anchor = AnchorStyles.Left,
|
|
|
|
|
BackColor = Color.Transparent,
|
|
|
|
|
FlatStyle = FlatStyle.Flat,
|
|
|
|
|
Image = Images.StaticImages._000_Abort_h32bit_16,
|
|
|
|
|
Size = new Size(22, 22),
|
|
|
|
|
Text = string.Empty,
|
|
|
|
|
};
|
|
|
|
|
buttonDelete.FlatAppearance.BorderSize = 0;
|
|
|
|
|
buttonDelete.Click += buttonDelete_Click;
|
|
|
|
|
return buttonDelete;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private void UpdateDateTImePickerState()
|
|
|
|
|
{
|
|
|
|
|
if (_datePicker != null && _timePicker != null)
|
|
|
|
|
_timePicker.Enabled = _datePicker.Checked;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private void Date_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
UpdateDateTImePickerState();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2023-01-06 15:09:35 +01:00
|
|
|
|
private void buttonDelete_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
DeleteCustomFieldClicked?.Invoke(this);
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|