Converter error was fixed

This commit is contained in:
Evgeny Redikultsev
2022-11-27 20:46:15 +05:00
parent 96b331f14c
commit e820f3522d
17 changed files with 250 additions and 38 deletions

View File

@@ -13,8 +13,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Area : UnitBase
{
public override UnitTypes unitType { get => UnitTypes.Area; }
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "mm2"); }
public override string unitName { get => "Area"; }
public override UnitTypes UnitType { get => UnitTypes.Area; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "mm2"); }
public override string UnitName { get => "Area"; }
}
}

View File

@@ -10,8 +10,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Curvature : UnitBase
{
public override UnitTypes unitType { get => UnitTypes.Curvature; }
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "1/mm"); }
public override string unitName { get => "Curvature"; }
public override UnitTypes UnitType { get => UnitTypes.Curvature; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "1/mm"); }
public override string UnitName { get => "Curvature"; }
}
}

View File

@@ -12,8 +12,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Force : UnitBase
{
public override UnitTypes unitType { get => UnitTypes.Force; }
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "kN"); }
public override string unitName { get => "Force"; }
public override UnitTypes UnitType { get => UnitTypes.Force; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "kN"); }
public override string UnitName { get => "Force"; }
}
}

View File

@@ -15,8 +15,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Length : UnitBase
{
public override UnitTypes unitType { get => UnitTypes.Length; }
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "mm"); }
public override string unitName { get => "Length"; }
public override UnitTypes UnitType { get => UnitTypes.Length; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "mm"); }
public override string UnitName { get => "Length"; }
}
}

View File

@@ -10,8 +10,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Moment : UnitBase
{
public override UnitTypes unitType { get => UnitTypes.Moment; }
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "kNm"); }
public override string unitName { get => "Moment"; }
public override UnitTypes UnitType { get => UnitTypes.Moment; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "kNm"); }
public override string UnitName { get => "Moment"; }
}
}

View File

@@ -12,8 +12,8 @@ namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal class Stress : UnitBase
{
public override UnitTypes unitType { get => UnitTypes.Stress; }
public override IUnit currentUnit { get => CommonOperation.GetUnit(unitType, "MPa"); }
public override string unitName { get => "Stress"; }
public override UnitTypes UnitType { get => UnitTypes.Stress; }
public override IUnit CurrentUnit { get => CommonOperation.GetUnit(UnitType, "MPa"); }
public override string UnitName { get => "Stress"; }
}
}

View File

@@ -7,22 +7,33 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace StructureHelper.Infrastructure.UI.Converters.Units
{
internal abstract class UnitBase : IValueConverter
{
public abstract UnitTypes unitType { get; }
public abstract IUnit currentUnit { get; }
public abstract string unitName { get;}
public abstract UnitTypes UnitType { get; }
public abstract IUnit CurrentUnit { get; }
public abstract string UnitName { get;}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return CommonOperation.Convert(currentUnit, unitName, value);
return CommonOperation.Convert(CurrentUnit, UnitName, value);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return CommonOperation.ConvertBack(unitType, currentUnit, value);
try
{
return CommonOperation.ConvertBack(UnitType, CurrentUnit, value);
}
catch (Exception)
{
MessageBox.Show($"Value of {UnitName}={(string)value} is not correct", "Error of conversion", MessageBoxButtons.OK);
return 0;
}
}
}
}