public void PruebaAgregarServicio() { //Intanciando las clases //Negocio N_Servicio n_Servicio = new N_Servicio(); //Entidad E_Servicio e_Servicio = new E_Servicio(); e_Servicio.servicio = "Limpiar"; e_Servicio.descripcion = "Un Equipo de limpieza"; e_Servicio.id_Salon = 20; Assert.AreNotEqual(0, n_Servicio.AgregarServicio(e_Servicio)); }
/// <summary> /// Evento click sobre el boton crear que gestionara la funcion de creacion /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SBCrearSalon_Click(object sender, EventArgs e) { //Obtener fecha de entrada String Fecha_Entrada = Convert.ToString(DateTime.Now); try { //Verifica los controles si tienen data if (TENombre.EditValue == "" || CBUbicacion.SelectedItem == null || TECapacidad.EditValue == "" || CBEstado.SelectedItem == null) { //Mensaje de informacion para el usuario de que todos los datos deben ser completados XtraMessageBox.Show("Todos los datos deben ser completados", "informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); } //Si los controles estan completos se inicia el proceso de creacion del salon else { #region Asignando Datos a la entidad de salon //se asignan los datos a una entidad salon e_Salon.nombre = Convert.ToString(TENombre.EditValue); DataRowView CBView = CBUbicacion.SelectedValue as DataRowView; e_Salon.ubicacion = Convert.ToString(CBView["Ubicacion"]); e_Salon.capacidad = Convert.ToInt32(TECapacidad.EditValue); e_Salon.estado = Convert.ToString(CBEstado.SelectedItem); #endregion //Se crea un salon y se recupera un ID del mismo e_Salon.id_Salon = n_salon.CrearSalon(e_Salon); //Se verifica el resultado if (e_Salon.id_Salon == null) { //Mensaje de error MessageBox.Show("Nose pudo guardar el salon", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Se inicia el proceso de agregar "Inventarios" y "Servicios" else { bool guardado = false; int FilasAfectadas = 1; #region Guardando los servicios del Salon //Verificacion si el checklist de servicios tiene algun items if (CKDListServicios.Items.Count > 0) { //Foreach que guardara cada items seleccionado en la base de datos foreach (DataRowView rowView in CKDListServicios.CheckedItems) { //Completando la entidad de servicios e_Servicio.id_Salon = e_Salon.id_Salon; e_Servicio.servicio = Convert.ToString(rowView["Servicio"]); //Ejecutando el metodo FilasAfectadas = n_Servicio.AgregarServicio(e_Servicio); //Verificacion de filas afectadas if (FilasAfectadas == 0) { guardado = false; } else { guardado = true; } } } #endregion #region Guardando los inventarios del salon //Verifiacion si hay algun elemento en el checklist de inventarios if (CKDListInventario.Items.Count > 0) { //Guardando cada inventario seleccionado en la base de datos foreach (DataRowView rowView in CKDListInventario.CheckedItems) { //Completando la entidad de inventarios e_Inventario.id_Salon = e_Salon.id_Salon; e_Inventario.inventario = Convert.ToString(rowView["Inventario"]); //Ejecutando el metodo de filas afectadas FilasAfectadas = n_Inventario.AgregarInventario(e_Inventario); //Verificacion if (FilasAfectadas == 0) { guardado = false; } else { guardado = true; } } } //Mostrando mensajes al usuario segun los resultados devueltos if (FilasAfectadas == 0) { //Negativo MessageBox.Show("Nose pudo guardar las informacion de servicios y inventarios del salon", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { //Positivo MessageBox.Show("Salon guardado exitosamente", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } #endregion } } } catch (Exception E) { //Mostrando la excepcion al usuario MessageBox.Show(Convert.ToString(E), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //Guardando el error en El XMl de destinado con los parametros correcpondientes X_m.GuardarEnXMl(Fecha_Entrada, Convert.ToString(e_UsuarioAU.id_Usuario), "Salones", "Crear", Convert.ToString(E)); } }
/// <summary> /// Evento Click sobre el boton actualizar el cual gestionara la funcion actualizar /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SBActualizar_Click(object sender, EventArgs e) { //<summary> // Actualizar Caracteristicas principales de un salon //</summary> //Asignando coleccion de datos a la entidad //----------// //Variable que recoge las filas afectadas int FilasAfectadas = 0; //Se verifica si los controles estan llenos o contienen data if (TENombreS.EditValue == "" || CBUbicacion.SelectedItem == null || TECapacidad.EditValue == "" || CBEstado.SelectedItem == null) { //Mensaje de informacion de que los controles deben estar debidadmente completados MessageBox.Show("Todos los datos deben ser completados", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } // De lo contrario else { #region Asignando Datos a la entidad de salon // Se asigan los datos a la entidad de salones et_Salon.nombre = Convert.ToString(TENombreS.EditValue); DataRowView CBView = CBUbicacion.SelectedValue as DataRowView; et_Salon.ubicacion = Convert.ToString(CBView["Ubicacion"]); et_Salon.capacidad = Convert.ToInt32(TECapacidad.EditValue); et_Salon.estado = Convert.ToString(CBEstado.SelectedItem); #endregion // Se ejecuta la actualizacion del salon FilasAfectadas = n_Salon.ActualizarSalon(et_Salon); //Se verifica las filas afectadas if (FilasAfectadas != 1) { //Mensaje de error en la actualizacion MessageBox.Show("Nose pudo guardar el salon", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } //De lo contrario else { #region Actualizando los Servicios y inventarios del Salon #region Servicios try { CheckState Estado; int ID; int n = 0; int Resultado = 0; //Verificacion si el checklist de servicios tiene algun items if (CKDListServicios.Items.Count > 0) { //Foreach que guardara cada items seleccionado en la base de datos foreach (DataRowView rowView in CKDListServicios.Items) { //Completando la entidad de servicios e_Servicio.id_Salon = et_Salon.id_Salon; e_Servicio.servicio = Convert.ToString(rowView["Servicio"]); Estado = CKDListServicios.GetItemCheckState(n); if (Estado == CheckState.Unchecked) { Resultado = n_Servicio.VerificarExistenciaDeServicio(e_Servicio); if (Resultado != 0) { n_Servicio.EliminarSercvicioXS_ID(e_Servicio); } } else { Resultado = n_Servicio.VerificarExistenciaDeServicio(e_Servicio); if (Resultado != 0) { //No hacer nada // } else { n_Servicio.AgregarServicio(e_Servicio); } } //Ejecutando el metodo n++; } } #endregion #region Inventarios ID = 0; n = 0; Resultado = 0; //Verificacion si el checklist de servicios tiene algun items if (CKDListInventario.Items.Count > 0) { //Foreach que guardara cada items seleccionado en la base de datos foreach (DataRowView rowView in CKDListInventario.Items) { //Completando la entidad de Inventario e_Inventario.id_Salon = et_Salon.id_Salon; e_Inventario.inventario = Convert.ToString(rowView["Inventario"]); Estado = CKDListInventario.GetItemCheckState(n); if (Estado == CheckState.Unchecked) { Resultado = n_Inventario.VerificarExistenciaDeInventario(e_Inventario); if (Resultado != 0) { n_Inventario.EliminarInventarioXS_ID(e_Inventario); } } else { Resultado = n_Inventario.VerificarExistenciaDeInventario(e_Inventario); if (Resultado != 0) { //No hacer nada // } else { n_Inventario.AgregarInventario(e_Inventario); } } //Ejecutando el metodo n++; } } #endregion #endregion //Mensaje Positivo MessageBox.Show("Salon actualizado satisfactoriamente", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception EX) { MessageBox.Show(EX.Message); } } } }