//保存时候判断不同类别的百分比必须100
private string CheckOrderData(DataTable dtTable) { string strMessage = ""; double sumPercentage = 0; string strTypeValue = ""; //检查Content的Percentage是否都为100 for (int i = 0; i < dtTable.Rows.Count; i++) { if (dtTable.Rows[i]["TypeEnglish"].ToString() != strTypeValue && i > 0) //进行类别是否相同 { if (sumPercentage != 100) { strMessage = "同一类别的百分比不能小于或大于100"; } else { sumPercentage = 0; } } sumPercentage += double.Parse(dtTable.Rows[i]["Percentage"].ToString().Trim() == "" ? "0" : dtTable.Rows[i]["Percentage"].ToString()); strTypeValue = dtTable.Rows[i]["TypeEnglish"].ToString(); //赋值给新的 } if (strMessage == "") { if (sumPercentage != 100 && dtTable.Rows.Count > 0) { strMessage = "同一类别的百分比不能小于或大于100"; } } return strMessage; }