///************************************************************************************* ///NOMBRE DE LA FUNCIÓN : Modificar_Descuento ///DESCRIPCIÓN : Modifica la información de un descuento ///PARÁMETROS : ///CREO : Luis Eugenio Razo Mendiola ///FECHA_CREO : 18 Octubre 2013 ///MODIFICO : ///FECHA_MODIFICO : ///CAUSA_MODIFICACIÓN : ///************************************************************************************* private Boolean Modificar_Descuentos() { Cls_Cat_Descuentos_Negocio P_Descuentos = new Cls_Cat_Descuentos_Negocio(); Boolean Modificar = false; try { if (Validar_Alta()) { P_Descuentos.P_Descuento_ID = Txt_ID_Descuento.Text; P_Descuentos.P_Vigencia_Desde = Dtp_Fecha_Desde.Value; P_Descuentos.P_Vigencia_Hasta = Dtp_Fecha_Hasta.Value; P_Descuentos.P_Porcentaje_Descuento = Txt_Porcentaje_Descuento.Text; P_Descuentos.P_Monto_Descuento = Txt_Monto_Descuento.Text; P_Descuentos.P_Motivo = Txt_Motivo.Text; P_Descuentos.P_Leyenda = Txt_Leyenda.Text; P_Descuentos.P_Usuario_Modifico = MDI_Frm_Apl_Principal.Nombre_Usuario; P_Descuentos.P_Fecha_Modifico = DateTime.Now; P_Descuentos.Modificar_Descuentos(); Modificar = true; MessageBox.Show("El Descuento '" + Txt_ID_Descuento.Text + "' ha sido modificado", "Descuentos", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception e) { MessageBox.Show(e.Message, "Descuentos", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(Modificar); }
///******************************************************************************* ///NOMBRE DE LA FUNCIÓN : Consultar_Descuentos ///DESCRIPCIÓN : Consulta informacion de los descuentos de la base de datos ///PARÁMETROS : P_Descuentos que contiene los filtros de los descuentos a buscar ///CREÓ : Luis Eugenio Razo Mendiola ///FECHA_CREO : 18 Octubre 2013 ///MODIFICÓ : ///FECHA_MODIFICO : ///CAUSA_MODIFICACIÓN : ///******************************************************************************* public static System.Data.DataTable Consultar_Descuentos(Cls_Cat_Descuentos_Negocio P_Descuentos) { StringBuilder Mi_SQL = new StringBuilder(); try { Conexion.Iniciar_Helper(); Conexion.HelperGenerico.Conexion_y_Apertura(); Mi_SQL.Append("SELECT * FROM " + Cat_Descuentos.Tabla_Cat_Descuentos + " WHERE 1 = 1 "); if (!String.IsNullOrEmpty(P_Descuentos.P_Descuento_ID)) { Mi_SQL.Append("AND " + Cat_Descuentos.Campo_Descuento_ID + " = '" + P_Descuentos.P_Descuento_ID + "'"); } if (!String.IsNullOrEmpty(P_Descuentos.P_Descripcion)) { Mi_SQL.Append("AND " + Cat_Descuentos.Campo_Descripcion + " LIKE '" + P_Descuentos.P_Descripcion + "%'"); } return(Conexion.HelperGenerico.Obtener_Data_Table(Mi_SQL.ToString())); } catch (Exception e) { throw new Exception("Consultar Descuentos : " + e.Message); } finally { Conexion.HelperGenerico.Cerrar_Conexion(); } }
///******************************************************************************* ///NOMBRE DE LA FUNCIÓN : Eliminar_Descuentos ///DESCRIPCIÓN : Elimina la informacion de un descuento de la base de datos ///PARÁMETROS : P_Descuentos que contiene el id del descuento a eliminar ///CREÓ : Luis Eugenio Razo Mendiola ///FECHA_CREO : 18 Octubre 2013 ///MODIFICÓ : ///FECHA_MODIFICO : ///CAUSA_MODIFICACIÓN : ///******************************************************************************* public static void Eliminar_Descuentos(Cls_Cat_Descuentos_Negocio P_Descuentos) { StringBuilder Mi_SQL = new StringBuilder(); Conexion.Iniciar_Helper(); Conexion.HelperGenerico.Conexion_y_Apertura(); Mi_SQL.Append("DELETE FROM " + Cat_Descuentos.Tabla_Cat_Descuentos); Mi_SQL.Append(" WHERE " + Cat_Descuentos.Campo_Descuento_ID + " = '" + P_Descuentos.P_Descuento_ID + "'"); Conexion.HelperGenerico.Ejecutar_NonQuery(Mi_SQL.ToString()); Conexion.HelperGenerico.Cerrar_Conexion(); }
///************************************************************************************* ///NOMBRE DE LA FUNCIÓN : Cargar_Descuentos ///DESCRIPCIÓN : Método que carga todos los descuentos registrados en el sistema ///PARÁMETROS : ///CREO : Luis Eugenio Razo Mendiola ///FECHA_CREO : 18 Octubre 2013 ///MODIFICO : ///FECHA_MODIFICO : ///CAUSA_MODIFICACIÓN : ///************************************************************************************* private void Cargar_Descuentos() { Cls_Cat_Descuentos_Negocio P_Descuentos = new Cls_Cat_Descuentos_Negocio(); try { Grid_Descuentos.DataSource = P_Descuentos.Consultar_Descuentos(); } catch (Exception e) { MessageBox.Show(e.Message, "Descuentos", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
///******************************************************************************* ///NOMBRE DE LA FUNCIÓN : Modificar_Descuentos ///DESCRIPCIÓN : Modifica la información de un descuento en la base de datos ///PARÁMETROS : P_Descuentos que contiene la información de un descuento a modificar ///CREÓ : Luis Eugenio Razo Mendiola ///FECHA_CREO : 18 Octubre 2013 ///MODIFICÓ : ///FECHA_MODIFICO : ///CAUSA_MODIFICACIÓN : ///******************************************************************************* public static void Modificar_Descuentos(Cls_Cat_Descuentos_Negocio P_Descuentos) { StringBuilder Mi_SQL = new StringBuilder(); try { Conexion.Iniciar_Helper(); Conexion.HelperGenerico.Conexion_y_Apertura(); Mi_SQL.Append("UPDATE " + Cat_Descuentos.Tabla_Cat_Descuentos + " SET "); if (!String.IsNullOrEmpty(P_Descuentos.P_Descripcion)) { Mi_SQL.Append(Cat_Descuentos.Campo_Descripcion + " = '" + P_Descuentos.P_Descripcion + "',"); } if (!String.IsNullOrEmpty(P_Descuentos.P_Vigencia_Desde.ToString())) { Mi_SQL.Append(Cat_Descuentos.Campo_Vigencia_Desde + " = " + Cls_Ayudante_Sintaxis.Insertar_Fecha_Hora(P_Descuentos.P_Vigencia_Desde) + ","); } if (!String.IsNullOrEmpty(P_Descuentos.P_Vigencia_Hasta.ToString())) { Mi_SQL.Append(Cat_Descuentos.Campo_Vigencia_Hasta + " = " + Cls_Ayudante_Sintaxis.Insertar_Fecha_Hora(P_Descuentos.P_Vigencia_Hasta) + ","); } if (!String.IsNullOrEmpty(P_Descuentos.P_Porcentaje_Descuento)) { Mi_SQL.Append(Cat_Descuentos.Campo_Porcentaje_Descuento + " = '" + P_Descuentos.P_Porcentaje_Descuento + "',"); } if (!String.IsNullOrEmpty(P_Descuentos.P_Monto_Descuento)) { Mi_SQL.Append(Cat_Descuentos.Campo_Monto_Descuento + " = '" + P_Descuentos.P_Monto_Descuento + "',"); } if (!String.IsNullOrEmpty(P_Descuentos.P_Motivo)) { Mi_SQL.Append(Cat_Descuentos.Campo_Motivo + " = '" + P_Descuentos.P_Motivo + "',"); } if (!String.IsNullOrEmpty(P_Descuentos.P_Leyenda)) { Mi_SQL.Append(Cat_Descuentos.Campo_Leyenda + " = '" + P_Descuentos.P_Leyenda + "',"); } Mi_SQL.Append(Cat_Descuentos.Campo_Usuario_Modifico + " = '" + P_Descuentos.P_Usuario_Modifico + "',"); Mi_SQL.Append(Cat_Descuentos.Campo_Fecha_Modifico + " = " + Cls_Ayudante_Sintaxis.Insertar_Fecha_Hora(P_Descuentos.P_Fecha_Modifico) + " "); Mi_SQL.Append("WHERE " + Cat_Descuentos.Campo_Descuento_ID + " = '" + P_Descuentos.P_Descuento_ID + "'"); Conexion.HelperGenerico.Ejecutar_NonQuery(Mi_SQL.ToString()); } catch (Exception e) { throw new Exception("Modificar Descuentos : " + e.Message); } finally { Conexion.HelperGenerico.Cerrar_Conexion(); } }
///************************************************************************************* ///NOMBRE DE LA FUNCIÓN : Btn_Eliminar_Click ///DESCRIPCIÓN : Elimina un descuento de la base de datos ///PARÁMETROS : ///CREÓ : Luis Eugenio Razo Mendiola ///FECHA_CREO : 18 Octubre 2013 ///MODIFICÓ : ///FECHA_MODIFICO : ///CAUSA_MODIFICACIÓN : ///************************************************************************************* private void Btn_Eliminar_Click(object sender, EventArgs e) { Cls_Cat_Descuentos_Negocio Descuentos_Eliminar = new Cls_Cat_Descuentos_Negocio(); try { if (Txt_ID_Descuento.Text != String.Empty) { if (MessageBox.Show(this, "¿Quiere realmente eliminar el descuento '" + Txt_ID_Descuento.Text + "' ?", "Advertencia", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { Descuentos_Eliminar.P_Descuento_ID = Txt_ID_Descuento.Text; Descuentos_Eliminar.Eliminar_Descuentos(); MessageBox.Show("El Descuento '" + Txt_ID_Descuento.Text + "' ha sido eliminado", "Descuentos", MessageBoxButtons.OK, MessageBoxIcon.Information); Cls_Metodos_Generales.Limpia_Controles(Fra_Datos_Generales); Cargar_Descuentos(); } } else { MessageBox.Show("Para eliminar un Descuento, debe seleccionar una de la lista", "Descuentos", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } catch (Exception exc) { if (exc.Data.Contains("HelpLink.EvtID")) { if (exc.Data["HelpLink.EvtID"].ToString() == "547") { MessageBox.Show("No se puede eliminar el registro debido a que tiene relación con otras tablas", "Descuentos", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show(exc.GetHashCode().ToString() + " " + exc.Message); } } }
///************************************************************************************* ///NOMBRE DE LA FUNCIÓN : Consultar_Descuentos ///DESCRIPCIÓN : Realiza la consulta de los descuentos en la base de datos ///PARÁMETROS : ///CREO : Luis Eugenio Razo Mendiola ///FECHA_CREO : 18 Octubre 2013 ///MODIFICO : ///FECHA_MODIFICO : ///CAUSA_MODIFICACIÓN : ///************************************************************************************* private void Consultar_Descuentos() { Cls_Cat_Descuentos_Negocio Descuentos_Consultar = new Cls_Cat_Descuentos_Negocio(); try { switch (Cmb_Busqueda_Tipo.Text) { case "ID Descuento": Descuentos_Consultar.P_Descuento_ID = Txt_Descripcion_Busqueda.Text; Grid_Descuentos.DataSource = Descuentos_Consultar.Consultar_Descuentos(); break; case "Descripción": Descuentos_Consultar.P_Descripcion = Txt_Descripcion_Busqueda.Text; Grid_Descuentos.DataSource = Descuentos_Consultar.Consultar_Descuentos(); break; } } catch (Exception e) { MessageBox.Show(e.Message, "Descuentos", MessageBoxButtons.OK, MessageBoxIcon.Error);; } }
///******************************************************************************* ///NOMBRE DE LA FUNCIÓN : Alta_Descuentos ///DESCRIPCIÓN : Registra un nuevo descuento en la base de datos ///PARÁMETROS : P_Descuento que contiene la información del nuevo descuento a registrar ///CREÓ : Luis Eugenio Razo Mendiola ///FECHA_CREO : 18 Octubre 2013 ///MODIFICÓ : ///FECHA_MODIFICO : ///CAUSA_MODIFICACIÓN : ///******************************************************************************* public static Boolean Alta_Descuentos(Cls_Cat_Descuentos_Negocio P_Descuentos) { StringBuilder Mi_SQL = new StringBuilder(); Boolean Alta = false; String Descuentos_ID; try { Descuentos_ID = Cls_Metodos_Generales.Obtener_ID_Consecutivo(Cat_Descuentos.Tabla_Cat_Descuentos, Cat_Descuentos.Campo_Descuento_ID, "", 5); Conexion.Iniciar_Helper(); Conexion.HelperGenerico.Conexion_y_Apertura(); Mi_SQL.Append("INSERT INTO " + Cat_Descuentos.Tabla_Cat_Descuentos + "("); Mi_SQL.Append(Cat_Descuentos.Campo_Descuento_ID + ","); Mi_SQL.Append(Cat_Descuentos.Campo_Descripcion + ","); Mi_SQL.Append(Cat_Descuentos.Campo_Vigencia_Desde + ","); Mi_SQL.Append(Cat_Descuentos.Campo_Vigencia_Hasta + ","); if (!String.IsNullOrEmpty(P_Descuentos.P_Porcentaje_Descuento)) { Mi_SQL.Append(Cat_Descuentos.Campo_Porcentaje_Descuento + ","); } if (!String.IsNullOrEmpty(P_Descuentos.P_Monto_Descuento)) { Mi_SQL.Append(Cat_Descuentos.Campo_Monto_Descuento + ","); } if (!String.IsNullOrEmpty(P_Descuentos.P_Motivo)) { Mi_SQL.Append(Cat_Descuentos.Campo_Motivo + ","); } if (!String.IsNullOrEmpty(P_Descuentos.P_Leyenda)) { Mi_SQL.Append(Cat_Descuentos.Campo_Leyenda + ","); } Mi_SQL.Append(Cat_Descuentos.Campo_Usuario_Creo + ","); Mi_SQL.Append(Cat_Descuentos.Campo_Fecha_Creo); Mi_SQL.Append(") VALUES ("); Mi_SQL.Append("'" + Descuentos_ID + "',"); Mi_SQL.Append("'" + P_Descuentos.P_Descripcion + "',"); Mi_SQL.Append(Cls_Ayudante_Sintaxis.Insertar_Fecha_Hora(P_Descuentos.P_Vigencia_Desde) + ","); Mi_SQL.Append(Cls_Ayudante_Sintaxis.Insertar_Fecha_Hora(P_Descuentos.P_Vigencia_Hasta) + ","); if (!String.IsNullOrEmpty(P_Descuentos.P_Porcentaje_Descuento)) { Mi_SQL.Append("'" + P_Descuentos.P_Porcentaje_Descuento + "',"); } if (!String.IsNullOrEmpty(P_Descuentos.P_Monto_Descuento)) { Mi_SQL.Append("'" + P_Descuentos.P_Monto_Descuento + "',"); } if (!String.IsNullOrEmpty(P_Descuentos.P_Motivo)) { Mi_SQL.Append("'" + P_Descuentos.P_Motivo + "',"); } if (!String.IsNullOrEmpty(P_Descuentos.P_Leyenda)) { Mi_SQL.Append("'" + P_Descuentos.P_Leyenda + "',"); } Mi_SQL.Append("'" + P_Descuentos.P_Usuario_Creo + "',"); Mi_SQL.Append(Cls_Ayudante_Sintaxis.Insertar_Fecha_Hora(P_Descuentos.P_Fecha_Creo) + ")"); Conexion.HelperGenerico.Ejecutar_NonQuery(Mi_SQL.ToString()); Alta = true; } catch (Exception e) { throw new Exception("Alta Descuentos : " + e.Message); } finally { Conexion.HelperGenerico.Cerrar_Conexion(); } return(Alta); }