Lab review fixes
This commit is contained in:
parent
37fe5deca9
commit
a6a79d0213
@ -79,7 +79,7 @@ namespace AbazovAppView
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime date = abazovDatePicker.Value;
|
||||
DateTime? date = abazovDatePicker.Value;
|
||||
MessageBox.Show(date.ToString(), "Через свойство");
|
||||
}
|
||||
catch (DateBoundsNotSetException ex)
|
||||
|
@ -25,7 +25,7 @@ namespace AbazovViewComponents.Components
|
||||
}
|
||||
set
|
||||
{
|
||||
checkedListBox.SelectedItem = value;
|
||||
if (value != null && checkedListBox.Items.Contains(value)) checkedListBox.SelectedItem = value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ namespace AbazovViewComponents.Components
|
||||
|
||||
private void checkedListBox_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
SelectedItemChange.Invoke(checkedListBox.SelectedItem.ToString());
|
||||
SelectedItemChange?.Invoke(checkedListBox.SelectedItem.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,8 @@ namespace AbazovViewComponents.Components
|
||||
private bool lowBoundrySet = false;
|
||||
private bool highBoundrySet = false;
|
||||
|
||||
public bool BoundriesSet { get { return lowBoundrySet && highBoundrySet; } }
|
||||
|
||||
public DateTime? dateFrom
|
||||
{
|
||||
get
|
||||
@ -51,23 +53,22 @@ namespace AbazovViewComponents.Components
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime Value
|
||||
public DateTime? Value
|
||||
{
|
||||
get
|
||||
{
|
||||
if (dateFrom is null && dateTo is null) throw new DateBoundsNotSetException("Не заданы диапазоны компонента!");
|
||||
if (this.dateTimePicker.Value < dateFrom || this.dateTimePicker.Value > dateTo) throw new DateOutOfBoundsException("Дата вне диапазона!");
|
||||
return this.dateTimePicker.Value;
|
||||
if (!lowBoundrySet || !highBoundrySet || dateTimePicker.Value < dateFrom || dateTimePicker.Value > dateTo) return null;
|
||||
return dateTimePicker.Value;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (dateFrom is not null && dateTo is not null && value >= dateFrom && value <= dateTo) this.dateTimePicker.Value = value;
|
||||
if (lowBoundrySet && highBoundrySet && value.HasValue && value.Value >= dateFrom && value.Value <= dateTo) dateTimePicker.Value = value.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private void dateTimePicker_ValueChanged(object sender, EventArgs e)
|
||||
{
|
||||
DateChange.Invoke(dateTimePicker.Value);
|
||||
DateChange?.Invoke(dateTimePicker.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -35,39 +35,24 @@ namespace AbazovViewComponents.Components
|
||||
{
|
||||
if (treeView.SelectedNode == null || treeView.SelectedNode.Nodes.Count > 0) return default(T);
|
||||
|
||||
List<object> values = new List<object>();
|
||||
List<string> fieldNames = new List<string>();
|
||||
|
||||
TreeNode? node = treeView.SelectedNode;
|
||||
|
||||
var type = typeof(T);
|
||||
var fields = type.GetFields();
|
||||
List<Type> types = new List<Type>();
|
||||
|
||||
var item = Activator.CreateInstance(type);
|
||||
|
||||
while (node != null)
|
||||
{
|
||||
var field = fields.FirstOrDefault(x => x.Name == node.Name);
|
||||
if (field != null)
|
||||
{
|
||||
Type typeOfField = field.FieldType;
|
||||
types.Add(typeOfField);
|
||||
values.Add(Convert.ChangeType(node.Text, typeOfField));
|
||||
fieldNames.Add(field.Name);
|
||||
field.SetValue(item, node.Text);
|
||||
}
|
||||
node = node.Parent;
|
||||
}
|
||||
|
||||
var constructor = type.GetConstructor(types.ToArray());
|
||||
if (constructor == null) return default(T);
|
||||
var parameters = constructor.GetParameters();
|
||||
|
||||
List<object> valuesForInvoking = new List<object>();
|
||||
foreach (var param in parameters)
|
||||
{
|
||||
int index = fieldNames.IndexOf(param.Name);
|
||||
valuesForInvoking.Add(values[index]);
|
||||
}
|
||||
return (T) constructor.Invoke(valuesForInvoking.ToArray());
|
||||
return item != null ? (T) item : default(T);
|
||||
}
|
||||
|
||||
public void setHierarchy(List<(string, bool)> fields)
|
||||
|
Loading…
Reference in New Issue
Block a user