public bool IsFormValid( System.Windows.Forms.Control ctl, System.Windows.Forms.ErrorProvider errProv) { bool bValid = true; foreach (System.Windows.Forms.Control childCtl in ctl.Controls) { //childCtrl.Focus() if (errProv.GetError(childCtl) != "") { bValid = false; break; } if (childCtl.Controls.Count > 0) { bValid = IsFormValid(childCtl, errProv); if (!bValid) { break; } } } return(bValid); }
void BtStartMaintenanceClick(object sender, System.EventArgs e) { bool allPropertiesSet = false; if (cbDuration.SelectedIndex >= 0) { allPropertiesSet = true; } else { epDuration.SetError(cbDuration, "Must select duration!"); allPropertiesSet = false; } if (cbReason.SelectedIndex >= 0) { allPropertiesSet = true; } else { epReason.SetError(cbReason, "Must select reason!"); allPropertiesSet = false; } if (epIllegalComment.GetError(tbComment) != "" || epReason.GetError(cbReason) != "" || epDuration.GetError(cbDuration) != "") { allPropertiesSet = false; } // All inputs looks OK, write start command to event log. if (allPropertiesSet) { OpsMMEventLog opsEventlog = new OpsMMEventLog(); KeyValuePair kvpDuration = (KeyValuePair)cbDuration.SelectedItem; KeyValuePair kvpReason = (KeyValuePair)cbReason.SelectedItem; string comment = tbComment.Text; string userName = tbCurrentUser.Text; if (opsEventlog.writeStartEvent(kvpDuration.m_objectKey.ToString(), kvpReason.m_objectKey.ToString(), "", "", comment, userName)) { setStatusMessage("", STATUS_INFO); updateProgressBar(0, MM_TIMEOUT, Color.Green); tmCheckForACK.Start(); btStartMaintenance.Enabled = false; btStopMaintenance.Enabled = false; btnCancel.Text = "&Close"; } else { setStatusMessage("Failed to write event! Are you running as administrator?", STATUS_ERROR); } } }
void BtStopMaintenanceClick(object sender, System.EventArgs e) { OpsMMEventLog opsEventlog = new OpsMMEventLog(); string comment = tbComment.Text; string userName = tbCurrentUser.Text; if (epIllegalComment.GetError(tbComment) == "") { if (opsEventlog.writeStopEvent("", "", comment, userName)) { setStatusMessage("Stopping Maintenance Mode\n", STATUS_INFO); tmCheckForACK.Start(); btStartMaintenance.Enabled = false; btStopMaintenance.Enabled = false; btnCancel.Text = "&Close"; } else { setStatusMessage("Failed to write event! Are you running as administrator?", STATUS_ERROR); } } }