Forum Discussion

dkinsley's avatar
dkinsley
Ideator I
6 years ago
Solved

Color code item current states

I have the following code that works but i would like to add an additional property so it too receives the same color coding that the new_state property receives. I am not familiar with C# coding so ...
  • Gopikrishnan's avatar
    6 years ago

    Hi Dkinsley

    Try this code and let me know if it works

    string bg_color_new = "";
    string myCss_new = "";
    string text_color_new = "#000000";
    string bg_color_aff = "";
    string myCss_aff = "";
    string text_color_aff = "#000000";
    for (int i = 0; i < this.getItemCount(); i++)
    {
    Item thisItem = this.getItemByIndex(i);
    string thisStatus = thisItem.getProperty("new_state", "");
    string thisAffStatus = thisItem.getProperty("affected_state", "");
    switch (thisStatus)
    {
    case "Preliminary":
    case "In Review":

    bg_color_new = "#FFCC00"; // yellow
    text_color_new = "#000000"; // black
    break;
    case "In Change":

    case "Inactive":
    bg_color_new = "#80EE80"; // light green
    text_color_new = "#000000"; // black
    break;

    case "Released":
    bg_color_new = "#55CC55"; // green
    text_color_new = "#000000"; // black
    break;
    case "Superseded":
    case "Obsolete":
    bg_color_new = "#FF8888"; // light red
    text_color_new = "#000000"; // black
    break;
    default:
    bg_color_new = ""; // none
    break;
    }
    switch (thisAffStatus)
    {
    case "Preliminary":
    case "In Review":

    bg_color_aff = "#FFCC00"; // yellow
    text_color_aff = "#000000"; // black
    break;
    case "In Change":

    case "Inactive":
    bg_color_aff = "#80EE80"; // light green
    text_color_aff = "#000000"; // black
    break;

    case "Released":
    bg_color_aff = "#55CC55"; // green
    text_color_aff = "#000000"; // black
    break;
    case "Superseded":
    case "Obsolete":
    bg_color_aff = "#FF8888"; // light red
    text_color_aff = "#000000"; // black
    break;
    default:
    bg_color_aff = ""; // none
    break;
    }

    if (bg_color_new != "")
    {
    myCss_new = ".new_state { background-color: " + bg_color_new + "; color: " + text_color_new + "; }";
    }
    if (bg_color_aff != "")
    {
    myCss_aff = ".affected_state { background-color: " + bg_color_aff + "; color: " + text_color_aff + "; }";
    }
    thisItem.setProperty("css", myCss_new + " " + myCss_aff);
    }
    return this;

    Thanks

    Gopikrishnan R