//ref,out private void CheckTextboxNotEmpty(ref bool isOK, params TextBox[] textboxes) { foreach (TextBox txtBox in textboxes) { if (txtBox.Text.Length <= 0) { isOK = false; txtBox.Background = Brushes.Red; } else { txtBox.Background = null; } } } private void CheckComboBoxNotEmpty(ref bool isOK, params ComboBox[] cmbs) { foreach (ComboBox cmb in cmbs) { if (cmb.SelectedIndex < 0) { isOK = false; cmb.Effect = new DropShadowEffect { Color=Colors.Red}; } else { cmb.Effect = null; } } } CheckTextboxNotEmpty(ref isOK, txtName, txtNational, txtNativeAddr, txtAddr, txtBaseSalary, txtTelNum, txtIdNum, txtPosition, txtNumber); CheckComboBoxNotEmpty(ref isOK, cbGender, cbMarriage, cbPartyStatus, cbEducation, cbDepatment); if (!isOK)//如果没有通过数据合法性检查,则不保存 { return; }