在Trac(1.2)中,我想创建一个报告,其中所有故障单按修改时间排序,颜色应指示组件(或是否已关闭)。
我认为按__color__
设置component
可以解决这个问题,但是报告跟踪报告会将所有活动门票显示为白色:
SELECT
DISTINCT
component AS __color__,
(CASE status
WHEN 'closed' THEN 'color: #777; background: #ddd; border-color: #ccc;'
END) AS __style__,
id AS ticket, summary, component, milestone, status, resolution,
t.time AS created, changetime AS modified,
priority AS _priority, reporter AS _reporter, cc AS _cc
FROM ticket t
LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
LEFT JOIN ticket_change tc ON id = tc.ticket
ORDER BY
changetime DESC
如何根据故障单引用的组件更改颜色?
答案 0 :(得分:1)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using System.Net.Cache;
namespace DateTime
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
System.DateTime dt = GetNistTime();
}
public static System.DateTime GetNistTime()
{
System.DateTime dateTime = System.DateTime.MinValue;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://nist.time.gov/actualtime.cgi?lzbc=siqm9b");
request.Method = "GET";
request.Accept = "text/html, application/xhtml+xml, */*";
request.UserAgent = "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)";
request.ContentType = "application/x-www-form-urlencoded";
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore); //No caching
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
StreamReader stream = new StreamReader(response.GetResponseStream());
string html = stream.ReadToEnd();//<timestamp time=\"1395772696469995\" delay=\"1395772696469995\"/>
string time = Regex.Match(html, @"(?<=\btime="")[^""]*").Value;
double milliseconds = Convert.ToInt64(time) / 1000.0;
dateTime = new System.DateTime(1970, 1, 1).AddMilliseconds(milliseconds).ToLocalTime();
}
return dateTime;
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
只能用于值为1到5的枚举,请参阅documentation。你可以这样做:
__color__
答案 1 :(得分:1)
受到@RjOllos答案的启发,我选择使用案例陈述来设置__color__
:
(CASE component
WHEN 'COMPONENT1' THEN 1
WHEN 'COMPONENT2' THEN 2
WHEN 'COMPONENT3a' THEN 4
WHEN 'COMPONENT3b' THEN 4
WHEN 'COMPONENT4' THEN 5
ELSE 3
END) AS __color__,
这样做的好处是行保持交替的颜色。