我有一个具有最小值和最大值硬编码的方法我怎么能从实体模型类中获取值?我想要查找最小值和最大值,以便它们不在代码中。我已经包含了我的代码和实体类以及sql表。
感谢
代码:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
//Is it a GridDataItem
if (e.Item is GridDataItem)
{
//Get the instance of the right type
GridDataItem dataBoundItem = e.Item as GridDataItem;
//Check the formatting condition
if (dataBoundItem["sample_hour"].Text == "4hr YP")
{
SetFormatting(dataBoundItem["ph"], 5.72f, 4.75f);
SetFormatting(dataBoundItem["brix"], 17.35f, 22.36f);
SetFormatting(dataBoundItem["temp"],89.08f, 90.97f);
SetFormatting(dataBoundItem["bud"], 3.12f, 40.76f);
SetFormatting(dataBoundItem["cell_count"], 41.24f, 177.70f);
SetFormatting(dataBoundItem["viability"], 69.18f, 103.08f);
SetFormatting(dataBoundItem["dp4"], 2.55f, 10.89f);
SetFormatting(dataBoundItem["dp3"], 1.41f, 6.05f);
SetFormatting(dataBoundItem["maltose"], 0.41f, 8.28f);
SetFormatting(dataBoundItem["glucose"], -0.26f, 6.69f);
SetFormatting(dataBoundItem["lactic_acid"], 0.01f, 0.12f);
SetFormatting(dataBoundItem["glycerol"], 0.33f, 0.57f);
SetFormatting(dataBoundItem["acetic_acid"], 0.07f, 0.17f);
SetFormatting(dataBoundItem["ethanol"], .005f, 1.15f);
}
}
}
private void SetFormatting(TableCell cell, float minValue, float maxValue)
{
float value = float.Parse(cell.Text);
if (value < minValue || value > maxValue)
{
cell.BackColor = Color.Yellow;
cell.ForeColor = Color.Black;
cell.Font.Bold = true;
}
}
实体模型类:
public partial class tbl_ferm_validation
{
public int validation_id { get; set; }
public string sample_type { get; set; }
public Nullable<decimal> val_hi { get; set; }
public Nullable<decimal> val_hihi { get; set; }
public Nullable<decimal> val_lo { get; set; }
public Nullable<decimal> val_lolo { get; set; }
}
}
Sql表:
1 ph 5.7200 NULL 4.7500 NULL
2 brix 17.3500 NULL 22.3600 NULL
3 temp 89.0800 NULL 90.9700 NULL
4 level 94.8100 NULL 88.1000 NULL
5 bud 3.1200 NULL 40.7600 NULL
6 cell count 41.2400 NULL 177.7000 NULL
7 viability 69.1800 NULL 103.0800 NULL
8 dp4 2.5500 NULL 10.8900 NULL
9 dp3 1.4100 NULL 6.0500 NULL
10 maltose 0.4100 NULL 8.2800 NULL
11 glucose -0.2600 NULL 6.6900 NULL
12 lactic acid 0.0100 NULL 0.1200 NULL
13 glycerol 0.3300 NULL 0.5700 NULL
14 acetic acid 0.0700 NULL 0.1700 NULL
15 ethanol 0.0050 NULL 1.1500 NULL