Lab review fixes
This commit is contained in:
parent
37fe5deca9
commit
a6a79d0213
@ -79,7 +79,7 @@ namespace AbazovAppView
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DateTime date = abazovDatePicker.Value;
|
DateTime? date = abazovDatePicker.Value;
|
||||||
MessageBox.Show(date.ToString(), "Через свойство");
|
MessageBox.Show(date.ToString(), "Через свойство");
|
||||||
}
|
}
|
||||||
catch (DateBoundsNotSetException ex)
|
catch (DateBoundsNotSetException ex)
|
||||||
|
@ -25,7 +25,7 @@ namespace AbazovViewComponents.Components
|
|||||||
}
|
}
|
||||||
set
|
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)
|
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 lowBoundrySet = false;
|
||||||
private bool highBoundrySet = false;
|
private bool highBoundrySet = false;
|
||||||
|
|
||||||
|
public bool BoundriesSet { get { return lowBoundrySet && highBoundrySet; } }
|
||||||
|
|
||||||
public DateTime? dateFrom
|
public DateTime? dateFrom
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@ -51,23 +53,22 @@ namespace AbazovViewComponents.Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime Value
|
public DateTime? Value
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if (dateFrom is null && dateTo is null) throw new DateBoundsNotSetException("Не заданы диапазоны компонента!");
|
if (!lowBoundrySet || !highBoundrySet || dateTimePicker.Value < dateFrom || dateTimePicker.Value > dateTo) return null;
|
||||||
if (this.dateTimePicker.Value < dateFrom || this.dateTimePicker.Value > dateTo) throw new DateOutOfBoundsException("Дата вне диапазона!");
|
return dateTimePicker.Value;
|
||||||
return this.dateTimePicker.Value;
|
|
||||||
}
|
}
|
||||||
set
|
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)
|
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);
|
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;
|
TreeNode? node = treeView.SelectedNode;
|
||||||
|
|
||||||
var type = typeof(T);
|
var type = typeof(T);
|
||||||
var fields = type.GetFields();
|
var fields = type.GetFields();
|
||||||
List<Type> types = new List<Type>();
|
|
||||||
|
var item = Activator.CreateInstance(type);
|
||||||
|
|
||||||
while (node != null)
|
while (node != null)
|
||||||
{
|
{
|
||||||
var field = fields.FirstOrDefault(x => x.Name == node.Name);
|
var field = fields.FirstOrDefault(x => x.Name == node.Name);
|
||||||
if (field != null)
|
if (field != null)
|
||||||
{
|
{
|
||||||
Type typeOfField = field.FieldType;
|
field.SetValue(item, node.Text);
|
||||||
types.Add(typeOfField);
|
|
||||||
values.Add(Convert.ChangeType(node.Text, typeOfField));
|
|
||||||
fieldNames.Add(field.Name);
|
|
||||||
}
|
}
|
||||||
node = node.Parent;
|
node = node.Parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
var constructor = type.GetConstructor(types.ToArray());
|
return item != null ? (T) item : default(T);
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setHierarchy(List<(string, bool)> fields)
|
public void setHierarchy(List<(string, bool)> fields)
|
||||||
|
Loading…
Reference in New Issue
Block a user