//realizo la busqueda al seleccionar un departamento ya que son necesario los dos campos para buscar una ciudad private void cbDepartamentos_SelectedValueChanged(object sender, EventArgs e) { try { if (cbDepartamentos.SelectedIndex == 0) { dgvCiudades.Columns.Clear(); throw new Exception("Seleccione un departamento."); } string _codDep = CodigoDepto(cbDepartamentos.SelectedItem.ToString()); CargarGV(_codDep); if (txtNombreCiudad.Text == string.Empty) { throw new Exception("Para agregar una ciudad coloque su nombre y seleccione un departamento."); } Ciudad _CiudadBuscada = new ServicioObligatorio.ServicioObligatorio().BuscarCiudad(_codDep, txtNombreCiudad.Text); if (_CiudadBuscada == null) { btnAlta.Enabled = true; txtNombreCiudad.Enabled = false; cbDepartamentos.Enabled = false; _unaCiudad = new Ciudad(); _unaCiudad.CodDepto = CodigoDepto(cbDepartamentos.SelectedItem.ToString()); _unaCiudad.Nombre = txtNombreCiudad.Text; lblError.Text = "No se encontro ninguna ciudad con el nombre '" + txtNombreCiudad.Text + "', puede agregarla si lo desea."; } else { btnBaja.Enabled = true; _unaCiudad = _CiudadBuscada; txtNombreCiudad.Enabled = false; cbDepartamentos.Enabled = false; lblError.Text = "Ya existe la ciudad, si deseea puede eliminarla"; } } catch (System.Web.Services.Protocols.SoapException ex) { if (ex.Detail.InnerText == "") { lblError.Text = "¡Error en Web Service!"; } else { lblError.Text = ex.Detail.InnerText; } } catch (Exception ex) { lblError.Text = ex.Message; } }
private void txtId_Validating(object sender, CancelEventArgs e) { string _idCategoria = txtId.Text.Trim(); try { if (_idCategoria.Length != 3 || !(char.IsLetter(_idCategoria[0])) || !(char.IsLetter(_idCategoria[1])) || !(char.IsLetter(_idCategoria[2]))) { throw new Exception("El identificador de la categoria debe tener 3 letras."); } else { epCategoria.Clear(); } Categoria c = new ServicioObligatorio.ServicioObligatorio().BuscarCategoria(txtId.Text); if (c == null) { btnAlta.Enabled = true; txtId.Enabled = false; lblError.Text = "No se encontro ninguna categoria con el Id: " + _idCategoria + " (si desea puede agregarla)."; _unaCategoria = new Categoria(); _unaCategoria.Identificador = txtId.Text; } else { _unaCategoria = c; txtId.Text = c.Identificador; txtNombre.Text = c.Nombre; txtDescripcion.Text = c.Descripcion; txtId.Enabled = false; btnBaja.Enabled = true; btnModificar.Enabled = true; lblError.Text = "¡Categoria encontrada!"; } } catch (System.Web.Services.Protocols.SoapException ex) { if (ex.Detail.InnerText == "") { lblError.Text = "¡Error en Web Service!"; } else { lblError.Text = ex.Detail.InnerText; } } catch (Exception ex) { epCategoria.SetError(txtId, ex.Message); e.Cancel = true; lblError.Text = ex.Message; } }
private void txtRut_Validating(object sender, CancelEventArgs e) { try { string rut = txtRut.Text; if (rut.Length != 12) { throw new Exception("El RUT debe tener 12 caracteres"); } try { Convert.ToInt64(rut); } catch { throw new Exception("Formato de RUT no válido"); } if (Convert.ToInt64(rut) < 0) { throw new Exception("El Rut no puede ser un número negativo"); } Empresa empresa = new ServicioObligatorio.ServicioObligatorio().BuscarEmpresa(rut); if (empresa != null) { _empresa = empresa; EstadoControles(true); } else { EstadoControles(false); } //si llega hasta acá se limpia el ErrorProvider epRut.Clear(); } catch (System.Web.Services.Protocols.SoapException ex) { if (ex.Detail.InnerText == "") { lblMensaje.Text = "¡Error en Web Service!"; } else { lblMensaje.Text = ex.Detail.InnerText; } } catch (Exception ex) { epRut.SetError(txtRut, ex.Message); e.Cancel = true; lblMensaje.Text = ex.Message; } }
private void ddlDepto_SelectedIndexChanged(object sender, EventArgs e) { try { if (ddlDepto.SelectedIndex != 0) { List <Ciudad> ciudades = new ServicioObligatorio.ServicioObligatorio().ListarCiudad(ddlDepto.SelectedValue.ToString()).ToList(); if (ciudades.Count != 0) { ddlCiudad.DataSource = ciudades; ddlCiudad.DisplayMember = "Nombre"; ddlCiudad.ValueMember = "Nombre"; lblMensaje.Text = ""; } else { ddlCiudad.DataSource = null; } } else { ddlCiudad.DataSource = null; } } catch (System.Web.Services.Protocols.SoapException ex) { if (ex.Detail.InnerText == "") { lblMensaje.Text = "¡Error en Web Service!"; } else { lblMensaje.Text = ex.Detail.InnerText; } } catch (Exception ex) { lblMensaje.Text = ex.Message; } }
public void ComprobarUsuario(object sender, EventArgs e) { try { Usuario _unUsuario = new ServicioObligatorio.ServicioObligatorio().LogueoUsuario(controlLogIn1.NombreUsuario, controlLogIn1.Contraseña); if (_unUsuario == null || controlLogIn1.Contraseña.Length != 5) { lblMensaje.Text = "Error! Nombre de Usuario o Contraseña Incorrectos"; } else if (_unUsuario is Cliente) { lblMensaje.Text = "Los Clientes no tienen autorizacion para usar la aplicación."; } else { Administrador _adminLogueado = (Administrador)_unUsuario; this.Hide(); Form _unForm = new FrmPrincipal(_adminLogueado); _unForm.ShowDialog(); this.Close(); } } catch (System.Web.Services.Protocols.SoapException ex) { if (ex.Detail.InnerText == "") { lblMensaje.Text = "¡Error en Web Service!"; } else { lblMensaje.Text = ex.Detail.InnerText; } } catch (Exception ex) { lblMensaje.Text = ex.Message; } }
private void txtCI_Validating(object sender, CancelEventArgs e) { try { if (txtCI.Text.Trim() == string.Empty) { throw new Exception("Por favor ingrese una CI"); } int _ci = Convert.ToInt32(txtCI.Text.Trim()); if (_ci.ToString().Length != 8) { throw new Exception("La cedula debe tener 8 caracteres"); } if (_ci < 0) { throw new Exception("La cedula no puede ser negativa"); } epError.Clear(); lblMensaje.Text = ""; Usuario _usuario = new ServicioObligatorio.ServicioObligatorio().BuscarUsuario(_ci); if (_usuario == null) { lblMensaje.Text = "No se encontro ningun administrador con CI: " + _ci + " Desea agreagarlo?"; btnAgregar.Enabled = true; txtCI.Enabled = false; } else if (_usuario is Administrador) { txtCI.Enabled = false; if (_AdminLogueado.CI == Convert.ToInt32(txtCI.Text)) { cbListado.Enabled = false; } else { cbListado.Enabled = true; } _UsuarioBuscado = new Administrador(); _UsuarioBuscado.CI = _usuario.CI; _UsuarioBuscado.Nombre = _usuario.Nombre; _UsuarioBuscado.NombreUsuario = _usuario.NombreUsuario; _UsuarioBuscado.Contrasenia = _usuario.Contrasenia; _UsuarioBuscado.VeListado = ((Administrador)_usuario).VeListado; txtCI.Text = _usuario.CI.ToString(); txtNombre.Text = _usuario.Nombre; txtUsuario.Text = _usuario.NombreUsuario; cbListado.Checked = ((Administrador)_usuario).VeListado; ActivarBotonA(); if (_AdminLogueado.CI == Convert.ToInt32(txtCI.Text)) { btnEliminar.Enabled = false; } } else { lblMensaje.Text = "Ya existe un usuario con esa cedula asociada"; txtNombre.Enabled = false; txtUsuario.Enabled = false; txtContrasenia.Enabled = false; txtConfContrasenia.Enabled = false; cbListado.Enabled = false; } } catch (System.Web.Services.Protocols.SoapException ex) { if (ex.Detail.InnerText == "") { lblMensaje.Text = "¡Error en Web Service!"; } else { lblMensaje.Text = ex.Detail.InnerText; } } catch (Exception ex) { epError.SetError(txtCI, ex.Message); e.Cancel = true; lblMensaje.Text = ex.Message; } }
private void toolStripbtnAgregar_Click(object sender, EventArgs e) { try { string rut = txtRut.Text; string nombre = txtNombre.Text; string direccion = txtDireccion.Text; if (string.IsNullOrEmpty(nombre)) { throw new Exception("Ingresa un nombre"); } if (string.IsNullOrEmpty(direccion)) { throw new Exception("Ingresa una dirección"); } if (ddlCiudad.SelectedIndex == -1) { throw new Exception("Selecciona una ciudad"); } Categoria categoria = new ServicioObligatorio.ServicioObligatorio().BuscarCategoria(ddlcategoria.SelectedValue.ToString()); Ciudad ciudad = new ServicioObligatorio.ServicioObligatorio().BuscarCiudad(ddlDepto.SelectedValue.ToString(), ddlCiudad.SelectedValue.ToString()); List <Telefono> telefonos = new List <Telefono>(); foreach (string nro in controlTelefonos1.Telefonos) { Telefono tel = new Telefono(); tel.Numero = nro; telefonos.Add(tel); } Empresa empresa = new Empresa(); empresa.Rut = rut; empresa.Nombre = nombre; empresa.Direccion = direccion; empresa.Telefonos = telefonos.ToArray(); empresa.Ciudad = ciudad; empresa.Categoria = categoria; empresa.Visitas = new List <Visita>().ToArray(); new ServicioObligatorio.ServicioObligatorio().AltaEmpresa(empresa); Limpiar(); lblMensaje.Text = "Empresa agregada correctamente."; } catch (System.Web.Services.Protocols.SoapException ex) { if (ex.Detail.InnerText == "") { lblMensaje.Text = "¡Error en Web Service!"; } else { lblMensaje.Text = ex.Detail.InnerText; } } catch (Exception ex) { lblMensaje.Text = ex.Message; } }