我怎么能看到缺席和呈现独特的颜色? [英] How could I view absent and present with unique color?
本文介绍了我怎么能看到缺席和呈现独特的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表(PayRoll_AttendanceStatus),其中包含4列,例如
I have a table(PayRoll_AttendanceStatus) that contains 4 columns like
======================================
StatusID | Status | ShortName | color
======================================
01 | Present| P | Yellow
02 | Absent | A | Red
=======================================
来自上面提到的表格我用来标记日常出勤到另一张桌子(PayRollMarkAttendance),它包含的价值如
from above mentioned table I used to mark day wise attendance into another table (PayRollMarkAttendance)and it contains values like
====================================================
MarkId | Employee_Code | StatusID | DateTime
====================================================
1 | 001 | 01 | 2016-06-11
2 | 002 | 02 | 2016-06-11
====================================================
对于视图我使用的是数据透视表,数据透视表的代码是
For view I am using Pivot table and the code for pivot table is
SELECT * FROM (SELECT [EMPLOYEENAME] ,[EMPLOYEE_CODE] ,[ShortName], DATENAME(M, [DateTime])as [Month] ,DAY([DateTime]) as [DayValue] FROM [View_PayRollMarkAttendance]) as Composite PIVOT (MAX([ShortName]) FOR [DayValue] IN ([1], [2], [3], [4],[5], [6], [7], [8], [9],[10], [11], [12], [13], [14],[15], [16], [17], [18], [19],[20], [21], [22], [23], [24],[25], [26], [27], [28], [29],[30],[31])) AS PivotTable
通过此数据表我可以很好地查看我的状态。但我希望通过其独特的代码颜色来查看不存在和存在。缺少红色和黄色礼物。
请帮助任何人。
谢谢
Through this pivottable I can view my status quite good. But I want to view ABSENT AND PRESENT through its unique code color. Absent for Red and Present for Yellow.
Please help any one.
Thanks
推荐答案
更新解决方案:
updated solution:
private void Form1_Load(object sender, EventArgs e)
{
DataTable dtStatusColor = new DataTable();
dtStatusColor.Columns.Add("ShortName");
dtStatusColor.Columns.Add("color");
dtStatusColor.Rows.Add("P", "Yellow");
dtStatusColor.Rows.Add("A", "Red");
Dictionary<string, string> dictColors = new Dictionary<string, string>();
foreach (DataRow row in dtStatusColor.Rows)
dictColors.Add(row["ShortName"].ToString(), row["color"].ToString());
DataTable dtStatus = new DataTable();
dtStatus.Columns.Add("EMPLOYEENAME");
dtStatus.Columns.Add("EMPLOYEE_CODE");
dtStatus.Columns.Add("ShortName");
dtStatus.Columns.Add("Month");
dtStatus.Columns.Add("DayValue");
dtStatus.Rows.Add("karthik", "E01", "P", "Jan", 25);
dtStatus.Rows.Add("parthip", "E02", "P", "Feb", 25);
dtStatus.Rows.Add("kavya", "E03", "A", "Mar", 25);
dataGridView1.DataSource = dtStatus;
int columnIndex = 2; // index value for the status column ( zero based index )
foreach (DataGridViewRow row in dataGridView1.Rows)
{
if (row.Index > -1 && row.Index < dataGridView1.Rows.Count - 1)
{
string status = row.Cells[columnIndex].Value.ToString();
row.Cells[columnIndex].Style.BackColor = System.Drawing.Color.FromName(dictColors[status]);
}
}
}
这篇关于我怎么能看到缺席和呈现独特的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文