Ejemplo n.º 1
0
 //BOTON ACEPTAR (CRUD)
 private void btnAceptar_Click(object sender, EventArgs e)
 {
     if (cbEscuelaTaller.Text != "Seleccionar Escuela" && txtNombreTaller.Text != "" && txtCostoTaller.Text != "" && txtDescripcionTaller.Text != "" && dtFechaIniTaller.Text != "" && dtFechaFinTaller.Text != "" && cbNivelTaller.Text != "" && cbGradoTaller.Text != "" && cbProfeTaller.Text != "Seleccionar Profesor" && txtHabilidadesTaller.Text != "" && txtJustificacionCostoTaller.Text != "" && txtHerramientasTaller.Text != "")
     {
         webservices3435.WSPHP wsPHP = new webservices3435.WSPHP();
         ClassTaller           ta    = new ClassTaller();
         ta.ta_id_escuela                = txtIdEscuela.Text;
         ta.ta_nombre_taller             = txtNombreTaller.Text;
         ta.ta_costo_taller              = Convert.ToDouble(txtCostoTaller.Text);
         ta.ta_descripcion_taller        = txtDescripcionTaller.Text;
         ta.ta_nivel_educativo_taller    = cbNivelTaller.Text;
         ta.ta_grados_taller             = cbGradoTaller.Text;
         ta.ta_fecha_ini_taller          = txtFechaInicio.Text;
         ta.ta_fecha_fin_taller          = txtFechaFin.Text;
         ta.ta_id_profesor               = txtIdProfesorTaller.Text;
         ta.ta_habilidades_taller        = txtHabilidadesTaller.Text;
         ta.ta_justificacioncosto_taller = txtJustificacionCostoTaller.Text;
         ta.ta_herramientas_taller       = txtHerramientasTaller.Text;
         if (MessageBox.Show("¿Estas seguro de realizar esta accion?", "¿Seguro de hacer estos cambios?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
         {
             if (opcionBotones == 0)
             {
                 if (validarFechas(1, 1, 'a') == 1)
                 {
                     generarID();
                     ta.ta_id_taller = label16.Text;
                     try
                     {
                         string mensaje = wsPHP.agregarTaller(ta.ta_id_escuela, ta.ta_id_taller, ta.ta_nombre_taller, ta.ta_costo_taller, ta.ta_descripcion_taller, ta.ta_fecha_ini_taller, ta.ta_fecha_fin_taller, ta.ta_nivel_educativo_taller, ta.ta_grados_taller, ta.ta_id_profesor, ta.ta_habilidades_taller, ta.ta_justificacioncosto_taller, ta.ta_herramientas_taller);
                         MessageBox.Show(mensaje, "¡Taller Agregado!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                         dgvTaller.Enabled = true;
                         cargarDatosTabla();
                         vaciarEntradas();
                         entradasDisponibles(2);
                     }
                     catch
                     {
                         MessageBox.Show("No se pudo agregar este taller", "¡Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                     }
                 }
             }
             else if (opcionBotones == 1)
             {
                 if (txtIdTaller.Text == "")
                 {
                     MessageBox.Show("Debes seleccionar antes un registro para editar", "ERROR");
                 }
                 else
                 {
                     ta.ta_id_taller = txtIdTaller.Text;
                     if (dtFechaIniTaller.Value.Date != fechaIDGV && dtFechaFinTaller.Value.Date != fechaFDGV)
                     {
                         val = validarFechas(1, 1, 'm');
                     }
                     else if (dtFechaIniTaller.Value.Date != fechaIDGV && dtFechaFinTaller.Value.Date == fechaFDGV)
                     {
                         val = validarFechas(1, 0, 'm');
                     }
                     else if (dtFechaIniTaller.Value.Date == fechaIDGV && dtFechaFinTaller.Value.Date != fechaFDGV)
                     {
                         val = validarFechas(0, 1, 'm');
                     }
                     else
                     {
                         val = 1;
                     }
                     if (val != 0)
                     {
                         try
                         {
                             string mensaje = wsPHP.modificarTaller(ta.ta_id_escuela, ta.ta_id_taller, ta.ta_nombre_taller, ta.ta_costo_taller, ta.ta_descripcion_taller, ta.ta_fecha_ini_taller, ta.ta_fecha_fin_taller, ta.ta_nivel_educativo_taller, ta.ta_grados_taller, ta.ta_id_profesor, ta.ta_habilidades_taller, ta.ta_justificacioncosto_taller, ta.ta_herramientas_taller);
                             MessageBox.Show(mensaje, "¡Taller Modificado!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                             cargarDatosTabla();
                             vaciarEntradas();
                             entradasDisponibles(2);
                         }
                         catch
                         {
                             MessageBox.Show("No se pudo modificar los datos de este taller", "¡Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                         }
                     }
                 }
             }
             else if (opcionBotones == 2)
             {
                 if (txtIdTaller.Text == "")
                 {
                     MessageBox.Show("Debes seleccionar antes un registro para Eliminar", "ERROR");
                 }
                 else
                 {
                     ta.ta_id_taller  = txtIdTaller.Text;
                     ta.ta_id_escuela = txtIdEscuela.Text;
                     string mensaje = wsPHP.eliminarTaller(ta.ta_id_taller, ta.ta_id_escuela);
                     MessageBox.Show(mensaje, "¡Taller Eliminado!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     cargarDatosTabla();
                     vaciarEntradas();
                     entradasDisponibles(2);
                 }
             }
         }
     }
     else
     {
         MessageBox.Show("Es necesario que llenes todos los campos", "¡ALERTA!");
     }
 }