ConvertAnyStringToColor, etc...

This commit is contained in:
Loretta 2025-09-26 16:10:50 +02:00
parent 7c320a939e
commit 14f0b65ef8
1 changed files with 12 additions and 7 deletions

View File

@ -130,19 +130,18 @@
@{
var tranferItem = (Transfer)context.DataItem;
var driverBgStyle = "border-radius: 10px; float: left; width: 20px; height: 20px; margin: 4px;";
var firstTransferDriver = tranferItem.TransferToDrivers.FirstOrDefault();
var firstDriverName = firstTransferDriver?.UserProductMapping?.User?.Profile?.Name;
if (!firstDriverName.IsNullOrWhiteSpace())
{
driverBgStyle += $" background-color: #{firstDriverName.GetHashCode():X8} !important";
}
var driverBgStyle = $"border-radius: 10px; float: left; width: 20px; height: 20px; margin: 4px; background-color: {ConvertAnyStringToColor(firstDriverName)} !important";
<div>
<div style="@driverBgStyle"></div>
<div style="position: relative; float: left; width: calc(100% - 28px)">@(string.Join(", ", tranferItem.TransferToDrivers.Select(x => x.UserProductMapping?.User?.Profile?.Name)))</div>
</div>
<div>
<div style="@driverBgStyle"></div>
<div style="position: relative; float: left; width: calc(100% - 28px)">@(string.Join(", ", tranferItem.TransferToDrivers.Select(x => x.UserProductMapping?.User?.Profile?.Name)))</div>
</div>
}
}
</CellDisplayTemplate>
@ -653,4 +652,10 @@
_gridTransfer.Reload();
}
private static string ConvertAnyStringToColor(string anyString)
{
var computeHash = SHA256.Create().ComputeHash(Encoding.UTF8.GetBytes(anyString));
return $"#{BitConverter.ToUInt32(computeHash, 0) % 1000000:X8}";
}
}