/* ******************************** FUNCIONES ************************************** ******************************************************************************* */ /* ******************************** EVENTOS ************************************** ******************************************************************************* */ //SELECCIONAR VISTA private void cajaVerPor_SelectedIndexChanged(object sender, EventArgs e) { ClaseClientes conad = new ClaseClientes(); switch (cajaVerPor.Text) { case "POR DEFECTO": conad.MostrarDatosClientes(MostrarDatosClientes, 1); break; case "NOMBRE CLIENTE, A -> Z": conad.MostrarDatosClientes(MostrarDatosClientes, 2); break; case "NOMBRE CLIENTE, Z -> A": conad.MostrarDatosClientes(MostrarDatosClientes, 3); break; case "CRÉDITO DISPONIBLE, 0 -> 3000000": conad.MostrarDatosClientes(MostrarDatosClientes, 4); break; case "CRÉDITO DISPONIBLE, 3000000 -> 0": conad.MostrarDatosClientes(MostrarDatosClientes, 5); break; default: conad.MostrarDatosClientes(MostrarDatosClientes, 1); break; } }
//FUNCIÓN OBTENER DIRECCIONES public void recuperarDirecciones() { ClaseClientes cl = new ClaseClientes(); ArrayList dire = new ArrayList(); dire = cl.ObtenerDireccionesCliente(auxcodi); int con = dire.Count; //ARRAY AUXILIARES ArrayList cod = new ArrayList(); ArrayList direc = new ArrayList(); ArrayList ciud = new ArrayList(); //GUARDO TODOS LOS VALORES DE DIRECCIONES for (int i = 0; i < con; i = i + 3) { cod.Add(dire[i].ToString()); direc.Add(dire[i + 1].ToString()); ciud.Add(dire[i + 2].ToString()); } //AGREGO AL COMBOBOX int auxcon = cod.Count; for (int i = 0; i < auxcon; i++) { cajaDirecciones.Items.Add(cod[i].ToString() + "-" + ciud[i].ToString() + "-" + direc[i].ToString()); } cajaDireccion.Text = dire[1].ToString(); cajaCiudad.Text = dire[2].ToString(); }
//GUARDAR CAMBIOS EFECTUADOS TANTO EN EL CLIENTE COMO EN LA DIRECCIÓN MISMA private void botonGuardar_Click(object sender, EventArgs e) { ClaseClientes cl = new ClaseClientes(); if (cajaApellidos.Text == "" || cajaCelular.Text == "" || cajaCiudad.Text == "" || cajaCredito.Text == "" || cajaDescuento.Text == "" || cajaDireccion.Text == "" || cajaNombre.Text == "" || cajaRun.Text == "" || cajaDirecciones.Text == "") { MessageBox.Show("Por favor, rellene las casillas antes de modificar los datos del cliente."); } else { if (cl.ModificarDatosCliente(auxcodi, cajaCelular.Text, Convert.ToInt32(cajaCredito.Text), Convert.ToInt32(cajaDescuento.Text))) { //SE MODIFICO EL CLIENTE, AHORA VAMOS CON LA DIRECCION ACTUAL if (cl.ModificarDireccionCliente(auxCodDireccionModificar, cajaDireccion.Text, cajaCiudad.Text)) { MessageBox.Show("Se han actualizado correctamente los datos del cliente."); recuperarDatosCliente(); cajaDirecciones.Items.Clear(); recuperarDirecciones(); } else { MessageBox.Show("Ha ocurrido un error al actualizar los datos del cliente (Dirección). Intente nuevamente por favor."); } } else { MessageBox.Show("Ha ocurrido un error al actualizar los datos del cliente. Intente nuevamente por favor."); } } }
/* ******************************** BOTONES ************************************** ******************************************************************************* */ //BOTÓN SELECCIONAR UN CLIENTE private void botonCliente_Click(object sender, EventArgs e) { PrincipalPedidosSeleccionarCliente prin = new PrincipalPedidosSeleccionarCliente(); if (prin.ShowDialog() == DialogResult.OK) { codiCliente = 0; codiCliente = prin.codCli; if (codiCliente == 0) { MessageBox.Show("Error no especificado."); } else { limpiar(); ClaseClientes cla = new ClaseClientes(); ArrayList list = new ArrayList(); list = cla.ObtenerDatosCliente(codiCliente); cajaNombre.Text = list[0].ToString() + " " + list[1].ToString(); cajaRun.Text = list[2].ToString(); cajaCelular.Text = list[3].ToString(); creditoCliente = Convert.ToInt32(list[4]); descuentoCliente = Convert.ToInt32(list[5]); ArrayList dire = new ArrayList(); dire = cla.ObtenerDireccionesCliente(codiCliente); int con = dire.Count; //ARRAY AUXILIARES ArrayList cod = new ArrayList(); ArrayList direc = new ArrayList(); ArrayList ciud = new ArrayList(); //GUARDO TODOS LOS VALORES DE DIRECCIONES for (int i = 0; i < con; i = i + 3) { cod.Add(dire[i].ToString()); direc.Add(dire[i + 1].ToString()); ciud.Add(dire[i + 2].ToString()); } //AGREGO AL COMBOBOX int auxcon = cod.Count; for (int i = 0; i < auxcon; i++) { cajaDirecciones.Items.Add(cod[i].ToString() + "-" + ciud[i].ToString() + "-" + direc[i].ToString()); } cajaDireccion.Text = dire[1].ToString(); cajaCiudad.Text = dire[2].ToString(); textoDescuento.Text = textoDescuento.Text + " " + descuentoCliente + "%"; cajaCréditoDisponible.Text = creditoCliente.ToString(); botonAgregar.Enabled = true; botonGuardar.Enabled = true; cajaFormaPago.Enabled = true; cajaDirecciones.Enabled = true; } } }
/* ******************************** FUNCIONES ************************************** ******************************************************************************* */ /* ******************************** ENVENTOS ************************************** ******************************************************************************* */ //SELECCIONAR FILA private void MostrarDatosClientes_CellContentClick(object sender, DataGridViewCellEventArgs e) { int codiCliente = 0; DataGridViewRow fila = MostrarDatosClientes.CurrentRow; // obtengo la fila actualmente seleccionada en el dataGridView codiCliente = Convert.ToInt32(fila.Cells[0].Value); //obtengo el valor de la primer columna //SI EL CODIGO ESTA VACIO, ARROJAR ERROR if (codiCliente == 0) { MessageBox.Show("Error no controlado."); } else { //COMPRUEBO QUE EL CLIENTE EXISTA Y NO ESTÉ ELIMINADO ClaseClientes cl = new ClaseClientes(); if (cl.VerificarExisteClienteEstado(codiCliente)) { PrincipalClientesVerModificar prin = new PrincipalClientesVerModificar(codiCliente); prin.ShowDialog(); ClaseClientes conad = new ClaseClientes(); conad.MostrarDatosClientes(MostrarDatosClientes, 1); } else { ClaseClientes conad = new ClaseClientes(); //SI NO EXISTE EL CLIENTE, SE PODRÁ REACTIVAR String texto = Microsoft.VisualBasic.Interaction.InputBox( "¿Desea reactivar al usuario seleccionado?" + "\n\r" + "\n\r" + " *(1) SI " + "\n\r" + " *(2) NO", "Reactivación Cliente", ""); //DEPENDIENDO DE LA RESPUESTA INGRESADA switch (texto) { case "1": if (conad.ReactivarCliente(codiCliente)) { MessageBox.Show("Cliente reactivado nuevamente."); conad.MostrarDatosClientes(MostrarDatosClientes, 1); } else { MessageBox.Show("Ha ocurrido un error al intentar reactivar el cliente actual. Intente nuevamente por favor."); } break; case "2": break; default: MessageBox.Show("No hubo respuesta o no se respetaron las instrucciones."); break; } } } }
//LOAD private void PrincipalPedidosSeleccionarCliente_Load(object sender, EventArgs e) { //OPCIONES DE VISUALIZACIÓN DE CLIENTES cajaVerPor.Items.Add("POR DEFECTO"); cajaVerPor.Items.Add("NOMBRE CLIENTE, A -> Z"); cajaVerPor.Items.Add("NOMBRE CLIENTE, Z -> A"); cajaVerPor.Items.Add("CRÉDITO DISPONIBLE, 0 -> 3000000"); cajaVerPor.Items.Add("CRÉDITO DISPONIBLE, 3000000 -> 0"); cajaVerPor.Items.Add("CLIENTES ELIMINADOS"); ClaseClientes conad = new ClaseClientes(); conad.MostrarDatosClientes(MostrarDatosClientes, 1); }
//FUNCIÓN OBTENER DATOS DEL CLIENTE public void recuperarDatosCliente() { ClaseClientes cl; cl = new ClaseClientes(); ArrayList list = new ArrayList(); list = cl.ObtenerDatosCliente(auxcodi); cajaNombre.Text = list[0].ToString(); cajaApellidos.Text = list[1].ToString(); cajaRun.Text = list[2].ToString(); cajaCelular.Text = list[3].ToString(); cajaCredito.Text = list[4].ToString(); cajaDescuento.Text = list[5].ToString(); }
/* ******************************** BOTONES ************************************** ******************************************************************************* */ //BOTON REGISTRAR private void botonGuardar_Click(object sender, EventArgs e) { ClaseClientes cla = new ClaseClientes(); if (cajaApellidos.Text == "" || cajaCelular.Text == "" || cajaCredito.Text == "" || cajaDireccion.Text == "" || cajaNombre.Text == "" || cajaRun.Text == "" || cajaDescuento.Text == "" || cajaCredito.Text == "" || cajaCiudad.Text == "") { MessageBox.Show("Rellene las casillas antes de registrar un cliente."); } else { //COMPRUEBO QUE NO EXISTA UN CLIENTE CON DICHO RUNS if (cla.VerificarExisteRunCliente(cajaRun.Text)) { MessageBox.Show("El run ya está registrado. Intente nuevamente por favor."); } else { //REALIZO EL INGRESO DEL CLIENTE Y OBTENGO SU ID String auxCod = cla.RegistrarCliente(cajaNombre.Text, cajaApellidos.Text, cajaRun.Text, cajaCelular.Text, Convert.ToInt32(cajaCredito.Text), Convert.ToInt32(cajaDescuento.Text)); if (auxCod == "") { //SI EL CODIGO ES "", ALGO OCURRIO MessageBox.Show("Ha ocurrido un error al intentar registrar un cliente. Intente nuevamente por favor."); } else { //SE REALIZO CON ÉXITO EL CLIENTE. if (cla.AnexarDireccion(Convert.ToInt32(auxCod), cajaDireccion.Text, cajaCiudad.Text)) { //SE REALIZÓ CON ÉXITO EL ANEXO DE LA DIRECCIÓN Y EL CLIENTE MessageBox.Show("Se ha registro con éxito el cliente."); } else { //ALGO OCURRIÓ MessageBox.Show("Ha ocurrido un error al anexar la dirección al cliente. Intente nuevamente por favor."); } } } limpiarCasillas(); } }
/* ******************************** BOTONES ************************************** ******************************************************************************* */ //BOTÓN ELIMINAR EL CLIENTE ACTUAL private void botonEliminar_Click(object sender, EventArgs e) { /* * INPUT BOX PARA IMPORTAR, IR A REFERENCES DEL PROYECTO, BUSCAR Microsoft.VisualBasic Y AGREGAR. PLANTILLA: * string texto = Microsoft.VisualBasic.Interaction.InputBox( * "Texto de la pregunta", * "Titulo del diálogo", * "Respuesta por defecto"); */ ClaseClientes cl = new ClaseClientes(); String texto = Microsoft.VisualBasic.Interaction.InputBox( "¿Desea eliminar el usuario actual?" + "\n\r" + "\n\r" + " *(1) SI " + "\n\r" + " *(2) NO", "Eliminación registro cliente", ""); //DEPENDIENDO DE LA RESPUESTA INGRESADA switch (texto) { case "1": if (cl.EliminarCliente(auxcodi)) { MessageBox.Show("Se ha eliminado satisfactoriamente el cliente."); this.Close(); } else { MessageBox.Show("Ha ocurrido un error al intentar eliminar el cliente actual. Intente nuevamente por favor."); } break; case "2": break; default: MessageBox.Show("No hubo respuesta o no se respetaron las instrucciones."); break; } }
//BOTÓN REGISTRAR NUEVA DIRECCIÓN private void botonRegistrar_Click(object sender, EventArgs e) { ClaseClientes cl = new ClaseClientes(); if (cajaCiudad.Text == "" || cajaDireccion.Text == "") { MessageBox.Show("Rellene las casillas antes de registrar una nueva dirección."); } else { if (cl.AnexarDireccion(auxCod, cajaDireccion.Text, cajaCiudad.Text)) { //SE REALIZÓ CON ÉXITO EL ANEXO DE LA DIRECCIÓN MessageBox.Show("Se ha registro con éxito una nueva dirección al cliente."); } else { //ALGO OCURRIÓ MessageBox.Show("Ha ocurrido un error al anexar la dirección al cliente. Intente nuevamente por favor."); } } limpiarCasillas(); }
//BUSCAR CLIENTE VIA TECLADO private void cajaBuscar_KeyUp(object sender, KeyEventArgs e) { ClaseClientes conad = new ClaseClientes(); conad.MostrarDatosClientesBusqueda(MostrarDatosClientes, cajaBuscar.Text); }