在调试代码时,出现错误#NULL is not a valid value for Int32
。
private void satelliteComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
Helper.SetWaitCursor();
if (satelliteComboBox.SelectedValue != null)
{
var satelliteId = Convert.ToInt32(satelliteComboBox.SelectedValue);
satelliteStatusUserControl.DataSource =
_satelliteStatusBusinessService.GetSingleSatellite(
new Dictionary<string, object> { { "SatelliteID", satelliteId } }, true);
//2012.07.07 get colors for all machine status
satelliteStatusUserControl.DataSource.DefectColors =
_satelliteStatusBusinessService.GetDefectColors().ToList();
foreach (var defectColor in
satelliteStatusUserControl.DataSource.DefectColors)
{
MachineStatusCtrl.AddMachineStatusColors(
defectColor.DefectTypeID,
defectColor.DefectType,
defectColor.OEEColor);
}
//2012.07.07
satelliteStatusUserControl.DataBind();
}
Helper.SetDefaultCursor();
}
我在foreach
循环中收到此错误
更新:这是实现AddMachineStatusColors
public static void AddMachineStatusColors(int statusColorId, string StatusName, string oeeColor)
{
MacStatusColors macStatusColor;
//add dummy colors with unknow till the next defectId so that it will be easy to get color later while painting.
for(int Index = StatusColors.Count; Index < statusColorId ; Index++)
{
macStatusColor = new MacStatusColors();
StatusColors.Add(macStatusColor);
}
macStatusColor = new MacStatusColors();
macStatusColor.DefectTypeID = statusColorId;
macStatusColor.DefectType = StatusName;
macStatusColor.OEEColor1 = ControlPaint.Dark(getColorFromString(oeeColor));
macStatusColor.OEEColor2 = ControlPaint.Light(getColorFromString(oeeColor));
StatusColors.Add(macStatusColor);
}
public static Color getColorFromString(string oeeColor)
{
if (oeeColor[0] != '#') { oeeColor = '#' + oeeColor; }
return System.Drawing.ColorTranslator.FromHtml(oeeColor);
}