private void txt_PauseTime_Validating(object sender, CancelEventArgs e) { //如果是越野时间验证 if (MatchConfigID == 7) { string pattern = @"^\d{1,2}'\d{2}''$"; TextBox tb = (TextBox)sender; if (tb.Text.ToString().Length != 0 && !RegexDao.IsMatch(pattern, tb.Text.ToString())) { e.Cancel = true; } } //如果是场地障碍时间验证 else { string pattern = @"^\d{1,3}\.?\d{0,3}$"; TextBox tb = (TextBox)sender; if (tb.Text.ToString().Length != 0 && !RegexDao.IsMatch(pattern, tb.Text.ToString())) { e.Cancel = true; } } }
private void dgvMatchConfig_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { if (dgvMatchConfig.Columns[e.ColumnIndex].Name == "F_RiderInterval" && e.FormattedValue != null) {//DateTime DateTime dtOut; if (e.FormattedValue.ToString().Length != 0 && !DateTime.TryParse(e.FormattedValue.ToString(), out dtOut)) { e.Cancel = true; } } else if (dgvMatchConfig.Columns[e.ColumnIndex].Name == "F_Judge" && e.FormattedValue != null) {//E,H,C,M,B } else if (dgvMatchConfig.Columns[e.ColumnIndex].Name == "F_Type" && e.FormattedValue != null) {//text } else if (dgvMatchConfig.Columns[e.ColumnIndex].Name == "F_Penalties" && e.FormattedValue != null) {//float float fOut = 0; if (e.FormattedValue.ToString().Length != 0 && !float.TryParse(e.FormattedValue.ToString(), out fOut)) { e.Cancel = true; } } //else if ((dgvMatchConfig.Columns[e.ColumnIndex].Name == "F_AddResult" // || dgvMatchConfig.Columns[e.ColumnIndex].Name == "F_AddResultTeam") // && e.FormattedValue != null) //{//只包含数字,且数字间使用","隔开的字符串 // string pattern = @"^([1-9]\d*,)*[1-9]\d*$"; // if (e.FormattedValue.ToString().Length != 0 && // !RegexDao.IsMatch(pattern, e.FormattedValue.ToString())) // e.Cancel = true; //} else if (dgvMatchConfig.Columns[e.ColumnIndex].Name == "F_TimeAllowed" && e.FormattedValue != null && m_iMatchConfigID == 7) { string pattern = @"^\d{1,2}'\d{2}''$"; if (e.FormattedValue.ToString().Length != 0 && !RegexDao.IsMatch(pattern, e.FormattedValue.ToString())) { e.Cancel = true; } } else {//int int nOut; if (e.FormattedValue.ToString().Length != 0 && !int.TryParse(e.FormattedValue.ToString(), out nOut)) { e.Cancel = true; } } }