Position class Equals method override
This commit is contained in:
parent
5dcc91e4a1
commit
7fffd91c9b
@ -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;
|
||||
}
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user