protected void btnSave_Click(object sender, EventArgs e)
        {
            eventsalarm auxNewEventAlarm = new eventsalarm();
            eventsalarmBus oEventsAlarm = new eventsalarmBus();

            eventsalarm_intrusionevents_mapping auxIntrusionEventMapping = new eventsalarm_intrusionevents_mapping();
            eventsalarm_intrusionevents_mappingBus oIntrusionEventsMapping = new eventsalarm_intrusionevents_mappingBus();

            bool needRequiredFields = false;
            int saveType = 0;

            if (btnNew.Enabled) saveType = 2;
            if (!btnNew.Enabled) saveType = 1;

            if (String.IsNullOrEmpty(txtCheckFrequency.Text)) needRequiredFields = true;
            if (String.IsNullOrEmpty(txtEventsAlarmTittle.Text)) needRequiredFields = true;

            if (!needRequiredFields)
            {
                auxNewEventAlarm.Severity = Convert.ToInt32(ddlSeverity.SelectedValue);
                auxNewEventAlarm.EventsAlarmTittle = txtEventsAlarmTittle.Text;
                auxNewEventAlarm.CheckFrecuency = Convert.ToInt32(txtCheckFrequency.Text);
                auxNewEventAlarm.Active = Convert.ToSByte(chkActive.Checked);
                auxNewEventAlarm.AffectConfidence = Convert.ToSByte(chkBIA.Items[0].Selected);
                auxNewEventAlarm.AffectIntegrity  = Convert.ToSByte(chkBIA.Items[1].Selected);
                auxNewEventAlarm.AffectAvailability = Convert.ToSByte(chkBIA.Items[2].Selected);
                auxNewEventAlarm.IdsId = Convert.ToInt32(ddlIDPS.SelectedValue);
                auxNewEventAlarm.IdsSignatureCategoryId = Convert.ToInt32(ddlIDPSSignatures.SelectedValue);

                switch (saveType)
                {
                    case 1: //save
                        if (oEventsAlarm.eventsalarmAdd(auxNewEventAlarm) > 0)
                        {
                            if (gvIntrusionEventsAssigned.Rows.Count > 0)
                            {
                                foreach (GridViewRow rowIntrusion in gvIntrusionEventsAssigned.Rows)
                                {
                                    auxIntrusionEventMapping.EventsAlarmId = Convert.ToInt32(txtEventAlarmId.Text);
                                    auxIntrusionEventMapping.IntrusionEventId = Convert.ToInt32(((Label)rowIntrusion.FindControl("intrusionEventsId")).Text);

                                    if (oIntrusionEventsMapping.eventsalarm_intrusionevents_mappingAdd(auxIntrusionEventMapping) <= 0)
                                    {
                                        lblMessage.Text = "Error al guardar Referencias del Evento [Evento de Intrusion] " + ((Label)rowIntrusion.FindControl("intrusionEventsId")).Text;
                                    }
                                }
                            }

                            lblMessage.Text = "Datos guardados correctamente!";
                            clearFields();
                            activateFields(false, true);
                            btnNew.Enabled = true;
                            getEventsAlarmData();
                        }
                        else
                            lblMessage.Text = "Error al guardar los datos!";
                        break;
                    case 2: //update
                        auxNewEventAlarm.EventsAlarmId = Convert.ToInt32(txtEventAlarmId.Text);
                        if (oEventsAlarm.eventsalarmUpdate(auxNewEventAlarm))
                        {
                            if (gvIntrusionEventsAssigned.Rows.Count > 0)
                            {
                                foreach (GridViewRow rowIntrusion in gvIntrusionEventsAssigned.Rows)
                                {
                                    auxIntrusionEventMapping.EventsAlarmId = Convert.ToInt32(txtEventAlarmId.Text);
                                    auxIntrusionEventMapping.IntrusionEventId = Convert.ToInt32(((Label)rowIntrusion.FindControl("intrusionEventsId")).Text);

                                    if (oIntrusionEventsMapping.eventsalarm_intrusionevents_mappingAdd(auxIntrusionEventMapping) <= 0)
                                    {
                                        lblMessage.Text = "Error al guardar Referencias del Evento [Evento de Intrusion] " + ((Label)rowIntrusion.FindControl("intrusionEventsId")).Text;
                                    }
                                }
                            }

                            lblMessage.Text = "Datos actualizados correctamente!";
                            clearFields();
                            activateFields(false, true);
                            btnSave.Enabled = false;
                            getEventsAlarmData();
                        }
                        else
                            lblMessage.Text = "Error al guardar los datos!";
                        break;
                }
            }
            else
            {
                lblMessage.Text = "Error, existen campos sin completar!";
            }
        }
        protected void gvAlarms_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = gvAlarms.SelectedRow;

            eventsalarm auxEventsAlarm = new eventsalarm();
            eventsalarmBus oEventsAlarm = new eventsalarmBus();

            intrusionevents auxIntrusionEvent = new intrusionevents();
            List<intrusionevents> lstIntrusionEventsAssigned = new List<intrusionevents>();
            intrusioneventsBus oIntrusionEvents = new intrusioneventsBus();

            List<eventsalarm_intrusionevents_mapping> lstEventsMapping = new List<eventsalarm_intrusionevents_mapping>();
            eventsalarm_intrusionevents_mappingBus oEventsMapping = new eventsalarm_intrusionevents_mappingBus();

            try
            {
                ddlSeverity.SelectedValue = ((Label)row.FindControl("severity")).Text;
            }
            catch
            {

            }

            if ((Label)row.FindControl("eventsAlarmId") != null) { txtEventAlarmId.Text = ((Label)row.FindControl("eventsAlarmId")).Text; } else { txtEventAlarmId.Text = ""; }
            if ((Label)row.FindControl("eventsAlarmTittle") != null) { txtEventsAlarmTittle.Text = ((Label)row.FindControl("eventsAlarmTittle")).Text; } else { txtEventsAlarmTittle.Text = ""; }
            if ((Label)row.FindControl("checkFrecuency") != null) { txtCheckFrequency.Text = ((Label)row.FindControl("checkFrecuency")).Text; } else { txtCheckFrequency.Text = ""; }
            if ((CheckBox)row.FindControl("active") != null) { chkActive.Checked = ((CheckBox)row.FindControl("active")).Checked; } else { chkActive.Checked = false; }

            auxEventsAlarm = oEventsAlarm.eventsalarmGetById(Convert.ToInt32(txtEventAlarmId.Text));
            lstEventsMapping = oEventsMapping.eventsalarm_intrusionevents_mappingGetByEventsAlarmId(Convert.ToInt32(txtEventAlarmId.Text));

            if (lstEventsMapping.Count > 0)
            {
                foreach (eventsalarm_intrusionevents_mapping rowMapping in lstEventsMapping)
                {
                    auxIntrusionEvent = oIntrusionEvents.intrusioneventsGetById(rowMapping.IntrusionEventId);
                    lstIntrusionEventsAssigned.Add(auxIntrusionEvent);
                }

                gvIntrusionEventsAssigned.DataSource = lstIntrusionEventsAssigned;
                gvIntrusionEventsAssigned.DataBind();
            }

            ddlIDPS.SelectedValue = auxEventsAlarm.IdsId.ToString();
            chkBIA.Items[0].Selected = Convert.ToBoolean(auxEventsAlarm.AffectConfidence);
            chkBIA.Items[1].Selected = Convert.ToBoolean(auxEventsAlarm.AffectIntegrity);
            chkBIA.Items[2].Selected = Convert.ToBoolean(auxEventsAlarm.AffectAvailability);
            getSignatureData(auxEventsAlarm.IdsId);
            ddlIDPSSignatures.SelectedValue = auxEventsAlarm.IdsSignatureCategoryId.ToString();

            activateFields(true, false);
            btnSave.Enabled = true;
        }