首页 > 代码库 > ASPxGridView改变列颜色
ASPxGridView改变列颜色
protected void ASPxGridView1_HtmlDataCellPrepared(object sender, ASPxGridViewTableDataCellEventArgs e)
{
string tJhso = e.GetValue("PLAN_SO").ToString();
string tJhdm = e.GetValue("PLAN_CODE").ToString();
string sql = " SELECT PLAN_CODE,PLAN_SO,CREATE_DATE,REMARK frOM DATA_PLANLOG where PLAN_SO=‘" + tJhso + "‘ and PLAN_CODE=‘" + tJhdm
+ "‘ AND ROUNTING_SITE IN (SELECT PLINE_CODE FROM VW_USER_ROLE_PROGRAM WHERE USER_ID = ‘ "
+ theUserId + "‘ AND PROGRAM_CODE = ‘" + theProgramCode + "‘ AND COMPANY_CODE = ‘" + theCompanyCode + "‘) "
+ " ORDER BY CREATE_DATE,PLAN_CODE ";
dc.setTheSql(sql);
DataTable dt = dc.GetTable();
if (dt.Rows.Count > 0)
{
//一些不需设置颜色的列
if (e.DataColumn.Caption.ToString() == "计划确认标识") return;
if (e.DataColumn.Caption.ToString() == "BOM转换") return;
if (e.DataColumn.Caption.ToString() == "库房确认标识") return;
if (e.DataColumn.Caption.ToString() == "是否分配流水号") return;
if (e.DataColumn.Caption.ToString() == "三方要料") return;
if (e.DataColumn.Caption.ToString() == "库房要料") return;
if (e.DataColumn.Caption.ToString() == "三方物料接收状态") return;
if (e.DataColumn.Caption.ToString() == "库房发料接收状态") return;
if (e.DataColumn.Caption.ToString() == "生产确认标识") return;
if (e.DataColumn.Caption.ToString() == "柳汽标识") return;
if (e.DataColumn.Caption.ToString() == "改制返修是否转BOM") return;
//也可以根据FieldName进行判断
//if (e.DataColumn.FieldName.ToString() == "ORDER_CODE") return;
//给需要设置颜色的列设置颜色
e.Cell.BackColor = System.Drawing.Color.Cyan;
}
string status = e.GetValue("RUN_FLAG").ToString();
if (status == "N")
{
//一些不需设置颜色的列
if (e.DataColumn.Caption.ToString() == "计划确认标识") return;
if (e.DataColumn.Caption.ToString() == "BOM转换") return;
if (e.DataColumn.Caption.ToString() == "库房确认标识") return;
if (e.DataColumn.Caption.ToString() == "是否分配流水号") return;
if (e.DataColumn.Caption.ToString() == "三方要料") return;
if (e.DataColumn.Caption.ToString() == "库房要料") return;
if (e.DataColumn.Caption.ToString() == "三方物料接收状态") return;
if (e.DataColumn.Caption.ToString() == "库房发料接收状态") return;
if (e.DataColumn.Caption.ToString() == "生产确认标识") return;
if (e.DataColumn.Caption.ToString() == "柳汽标识") return;
if (e.DataColumn.Caption.ToString() == "改制返修是否转BOM") return;
//给需要设置颜色的列设置颜色
e.Cell.BackColor = System.Drawing.Color.Red;
}
status = e.GetValue("CONFIRM_FLAG").ToString();
if (status == "N")
{
//一些不需设置颜色的列
if (e.DataColumn.Caption.ToString() == "计划确认标识") return;
if (e.DataColumn.Caption.ToString() == "BOM转换") return;
if (e.DataColumn.Caption.ToString() == "库房确认标识") return;
if (e.DataColumn.Caption.ToString() == "是否分配流水号") return;
if (e.DataColumn.Caption.ToString() == "三方要料") return;
if (e.DataColumn.Caption.ToString() == "库房要料") return;
if (e.DataColumn.Caption.ToString() == "三方物料接收状态") return;
if (e.DataColumn.Caption.ToString() == "库房发料接收状态") return;
if (e.DataColumn.Caption.ToString() == "生产确认标识") return;
if (e.DataColumn.Caption.ToString() == "柳汽标识") return;
if (e.DataColumn.Caption.ToString() == "改制返修是否转BOM") return;
//给需要设置颜色的列设置颜色
e.Cell.BackColor = System.Drawing.Color.Yellow;
}
status = e.GetValue("BOM_FLAG").ToString();
if (status == "N")
{
//一些不需设置颜色的列
if (e.DataColumn.Caption.ToString() == "计划确认标识") return;
if (e.DataColumn.Caption.ToString() == "BOM转换") return;
if (e.DataColumn.Caption.ToString() == "库房确认标识") return;
if (e.DataColumn.Caption.ToString() == "是否分配流水号") return;
if (e.DataColumn.Caption.ToString() == "三方要料") return;
if (e.DataColumn.Caption.ToString() == "库房要料") return;
if (e.DataColumn.Caption.ToString() == "三方物料接收状态") return;
if (e.DataColumn.Caption.ToString() == "库房发料接收状态") return;
if (e.DataColumn.Caption.ToString() == "生产确认标识") return;
if (e.DataColumn.Caption.ToString() == "柳汽标识") return;
if (e.DataColumn.Caption.ToString() == "改制返修是否转BOM") return;
//给需要设置颜色的列设置颜色
e.Cell.BackColor = System.Drawing.Color.Green;
}
sql = " select plan_code from ms_sfjit_plan_log where gzdd IN (SELECT PLINE_CODE FROM VW_USER_ROLE_PROGRAM WHERE USER_ID = ‘ "
+ theUserId + "‘ AND PROGRAM_CODE = ‘" + theProgramCode + "‘ AND COMPANY_CODE = ‘" + theCompanyCode + "‘) "
+ " and plan_code=‘" + tJhdm + "‘ ";
dc.setTheSql(sql);
dt = dc.GetTable();
if (dt.Rows.Count > 0)
{
//给需要设置颜色的列设置颜色
if (e.DataColumn.FieldName.ToString() == "PLAN_CODE")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(128, 128, 64);
}
}
sql = " select plan_code from ms_kfjit_plan_log where gzdd IN (SELECT PLINE_CODE FROM VW_USER_ROLE_PROGRAM WHERE USER_ID = ‘ "
+ theUserId + "‘ AND PROGRAM_CODE = ‘" + theProgramCode + "‘ AND COMPANY_CODE = ‘" + theCompanyCode + "‘) "
+ " and plan_code=‘" + tJhdm + "‘ ";
dc.setTheSql(sql);
dt = dc.GetTable();
if (dt.Rows.Count > 0)
{
//给需要设置颜色的列设置颜色
if (e.DataColumn.FieldName.ToString() == "PLAN_SO")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(255, 0, 255);
}
}
sql = " select SO from atpusofjb where so=‘" + tJhso + "‘ ";
dc.setTheSql(sql);
dt = dc.GetTable();
if (dt.Rows.Count < 0)
{
//给需要设置颜色的列设置颜色
if (e.DataColumn.FieldName.ToString() == "PRODUCT_MODEL")
{
e.Cell.BackColor = System.Drawing.Color.FromArgb(0, 123, 123);
}
}
//string status = e.GetValue("RUN_FLAG").ToString();
//if (status == "N")
//{
// //第0列RMES_ID
// object c0 = e.DataColumn.Caption;
// //e.Cell.BackColor = System.Drawing.Color.Red;
// //第1列Command列
// //object c1 = e.Row.Cells[1];
// ////第2列 计划序
// //object c2 = e.Row.Cells[2];
// ////第3列 计划代码
// //object c3 = e.Row.Cells[3];
// ////第4列 生产线代码
// //object c4 = e.Row.Cells[4];
// //e.Row.Cells[0].BackColor = System.Drawing.Color.Red;
// //e.Row.Cells[1].BackColor = System.Drawing.Color.Red;
// //e.Row.Cells[2].BackColor = System.Drawing.Color.Red;
// //e.Row.Cells[3].BackColor = System.Drawing.Color.Red;
// //e.Row.Cells[4].BackColor = System.Drawing.Color.Red;
// if (e.DataColumn.Caption.ToString() == "计划代码")
// {
// e.Cell.BackColor = System.Drawing.Color.Red;
// }
//}
}
ASPxGridView改变列颜色