/// <summary> /// Sets colors according to the channel status entity. /// </summary> public void SetColors(CnlStatus cnlStatus) { if (cnlStatus == null) { SetColorsToDefault(); } else { Colors = new string[] { cnlStatus.MainColor ?? "", cnlStatus.SecondColor ?? "", cnlStatus.BackColor ?? "" }; } }
/// <summary> /// Formats the channel data according to the specified data type and format. /// </summary> public CnlDataFormatted FormatCnlData(CnlData cnlData, int dataTypeID, int formatID, int unitID) { CnlDataFormatted cnlDataFormatted = new CnlDataFormatted(); Format format = formatID > 0 ? configDataset.FormatTable.GetItem(formatID) : null; Unit unit = unitID > 0 ? configDataset.UnitTable.GetItem(unitID) : null; EnumFormat enumFormat = null; if (format != null && format.IsEnum) { enums.TryGetValue(format.FormatID, out enumFormat); } // displayed value try { if (cnlData.IsUndefined) { cnlDataFormatted.DispVal = CommonPhrases.UndefinedSign; } else if (format == null) { cnlDataFormatted.DispVal = FormatByDataType(cnlData.Val, dataTypeID); } else if (format.IsNumber) { cnlDataFormatted.DispVal = FormatNumber(cnlData.Val, dataTypeID, format.Frmt); } else if (format.IsEnum) { cnlDataFormatted.DispVal = FormatEnum(cnlData.Val, dataTypeID, enumFormat); } else if (format.IsDate) { cnlDataFormatted.DispVal = FormatDate(cnlData.Val, dataTypeID, format.Frmt); } else // format.IsString or not specified { cnlDataFormatted.DispVal = FormatByDataType(cnlData.Val, dataTypeID); } if (!string.IsNullOrEmpty(unit?.Name)) { cnlDataFormatted.DispVal += " " + unit.Name; } } catch { cnlDataFormatted.DispVal = FormatError; } // color try { // color determined by status CnlStatus cnlStatus = configDataset.CnlStatusTable.GetItem(cnlData.Stat); cnlDataFormatted.SetColors(cnlStatus); // color determined by value if (enumFormat != null && cnlData.Stat == CnlStatusID.Defined && 0 <= cnlData.Val && cnlData.Val < enumFormat.Colors.Length && enumFormat.Colors[(int)cnlData.Val] is string color && color != "") { cnlDataFormatted.SetFirstColor(color); } } catch { cnlDataFormatted.SetColorsToDefault(); } return(cnlDataFormatted); }