protected void btnReg_Click(object sender, EventArgs e) { bool trackAll = true; string ID = txtEmpID.Text; MatchCollection matchena = Regex.Matches(ID, @"\[.*?\]"); string[] gettestID = matchena.Cast<Match>() .Select(m => m.Groups[0].Value.Trim(new char[] { '[', ']' })) .ToArray(); string emp_ID = gettestID[0]; string dueDate = null; try { dueDate = Convert.ToDateTime(txtDDate.Text.Trim()).ToShortDateString(); if (dueDate.Trim() != "" && dueDate.Trim() != null) { lblduedate.Visible = false; DDate = dueDate; trackAll &= true; } } catch (FormatException) { lblduedate.Visible = true; lblduedate.Text = "Please enter due date in the format 'MM/dd/YYYY' and then try again."; trackAll &= false; } //CATCH ANY OTHER EXCEPTION, dont let user see any kind of unexpected error catch (Exception ex) { trackAll &= false; //Write this exception to file for investigation of the issue later. LoggerManager.LogError(ex.ToString(), logger); } string startDate = null; try { startDate = Convert.ToDateTime(txtSDate.Text.Trim()).ToShortDateString(); if (startDate.Trim() != "" && startDate.Trim() != null) { lblstartDate.Visible = false; SDate = startDate; trackAll &= true; } } catch (FormatException) { lblstartDate.Visible = true; lblstartDate.Text = "Please enter start date in the format 'MM/dd/YYYY' and then try again."; trackAll &= false; } //CATCH ANY OTHER EXCEPTION, dont let user see any kind of unexpected error catch (Exception ex) { trackAll &= false; //Write this exception to file for investigation of the issue later. LoggerManager.LogError(ex.ToString(), logger); } string endDate = null; try { endDate = Convert.ToDateTime(txtEDate.Text.Trim()).ToShortDateString(); if (endDate.Trim() != "" && endDate.Trim() != null) { lblstartDate.Visible = false; EDate = endDate; trackAll &= true; } } catch (FormatException) { lblendDate.Visible = true; lblendDate.Text = "Please enter end date in the format 'MM/dd/YYYY' and then try again."; trackAll &= false; } //CATCH ANY OTHER EXCEPTION, dont let user see any kind of unexpected error catch (Exception ex) { trackAll &= false; //Write this exception to file for investigation of the issue later. LoggerManager.LogError(ex.ToString(), logger); } bool temp = areTrainingDatesValid(Convert.ToDateTime(DDate), Convert.ToDateTime(SDate), Convert.ToDateTime(EDate)); if (!temp) { return; } string Traingid = null; if (TraingDDown.SelectedValue != "-1") { Traingid = TraingDDown.SelectedValue; } else { lblInformationMsg.Text = "Training must be selected."; trackAll &= false; } if (!trackAll) { return; } EmployeeManager manage = new EmployeeManager(); TransactionResponse response = manage.AddEmployeeInTrainingRoom(emp_ID.Trim(), DDate, SDate, EDate, Traingid); //if store to DB is successful if (response.isSuccessful()) { txtEmpID.Text = ""; txtFName.Text = ""; txtDDate.Text = ""; txtSDate.Text = ""; txtEDate.Text = ""; txtJTittle.Text = ""; btnReg.Enabled = false; UserDetialPanel.Visible = false; clearLabel(); msgPanel.Visible = true; SucessDIV.Visible = true; lblSuccessMessage.Text = "Successfully Registered!"; } // show error message to a user. else { clearLabel(); msgPanel.Visible = true; WarnDIV.Visible = true; lblErrorMsg.Text = "Registraction was not sucessful!"; } }