Position class Equals method override

This commit is contained in:
Sergey Chebotar 2022-03-23 17:56:46 +03:00
parent 5dcc91e4a1
commit 7fffd91c9b
2 changed files with 37 additions and 7 deletions

View File

@ -135,21 +135,25 @@ namespace RehauSku.PriceListTools
protected int? GetPositionRow(Range range, string sku, string group)
{
Range found = range.Find(sku);
string foundGroupValue;
if (found == null)
{
return null;
}
int firstFoundRow = found.Row;
int firstFoundRow = found.Row;
if (string.IsNullOrEmpty(group))
{
return found.Row;
}
while (true)
{
Range groupCell = TargetFile.Sheet.Cells[found.Row, TargetFile.GroupCell.Column];
foundGroupValue = TargetFile.Sheet.Cells[found.Row, TargetFile.GroupCell.Column].Value2.ToString();
if (string.IsNullOrEmpty(group) ||
string.IsNullOrEmpty(groupCell.Value2.ToString()) ||
group.Equals(groupCell.Value2.ToString()))
if (group.Equals(foundGroupValue))
{
return found.Row;
}

View File

@ -1,6 +1,8 @@
namespace RehauSku.PriceListTools
using System.Linq;
namespace RehauSku.PriceListTools
{
public class Position
public class Position
{
public string Group { get; private set; }
public string Sku { get; private set; }
@ -12,5 +14,29 @@
Sku = sku;
Name = name;
}
public override bool Equals(object obj)
{
if (obj as Position == null)
return false;
Position other = obj as Position;
return Group == other.Group &&
Sku == other.Sku &&
Name == other.Name;
}
public override int GetHashCode()
{
string[] properties = new[]
{
Group,
Sku,
Name
};
return properties.Where(p => p != null).Sum(p => p.GetHashCode());
}
}
}