private void btnAgregar_Click(object sender, EventArgs e) { Empleado cliente = new Empleado(); EmpleadoNegocio negocio = new EmpleadoNegocio(); if (txtDni.Text.Length > 0 && txtApellido.Text.Length > 0 && txtNombre.Text.Length > 0 && txtMail.Text.Length > 0 && txtNumTel.Text.Length > 0 && txtTipoTel.Text.Length > 0 && txtCalle.Text.Length > 0 && txtNumero.Text.Length > 0 && txtCodPostal.Text.Length > 0 && txtlocalidad.Text.Length > 0 && txtCuil.Text.Length > 0) { cliente.DNI = Convert.ToInt32(txtDni.Text); cliente.Apellido = txtApellido.Text; cliente.Nombre = txtNombre.Text; cliente.Mail = txtMail.Text; cliente.CUIL = Convert.ToInt64(txtCuil.Text); if (cbbtipoempleado.SelectedItem.ToString() == "GERENTE") { cliente.Tipo = "GERENTE"; } if (cbbtipoempleado.SelectedItem.ToString() == "ENCARGADO") { cliente.Tipo = "ENCARGADO"; } if (cbbtipoempleado.SelectedItem.ToString() == "VENDEDOR") { cliente.Tipo = "VENDEDOR"; } cliente.telefono = new Telefono(); cliente.telefono.Numero = Convert.ToInt32(txtNumTel.Text); cliente.telefono.TipoDeTelefono = txtTipoTel.Text; cliente.domicilio = new Domicilio(); cliente.domicilio.Calle = txtCalle.Text; cliente.domicilio.Altura = Convert.ToInt32(txtNumero.Text); cliente.domicilio.CodigoPostal = Convert.ToInt32(txtCodPostal.Text); cliente.domicilio.Localidad = txtlocalidad.Text; negocio.AgregarEmpleado(cliente); cargarGrilla(); } else { MessageBox.Show("DEBEN ESTAR TODOS LOS CAMPOS COMPLETOS!!"); } }
protected void BtnAgregar_Click(object sender, EventArgs e) { try { bool Estado; string Extension; EmpleadoNegocio EmpleadoNegocio = new EmpleadoNegocio(); Empleado Empleado = new Empleado(); Empleado = null; Empleado = EmpleadoNegocio.BuscarEmpleado(Convert.ToInt32(txtDNI.Text)); if (Empleado == null) { Empleado = new Empleado(); Empleado.Dni = Convert.ToInt32(txtDNI.Text); Empleado.Nombre = txtNombre.Text; Empleado.Email = txtEmail.Text; if (Foto.HasFile) { Extension = Path.GetExtension(Foto.FileName).ToLower(); if (Extension == ".jpg" || Extension == ".gif" || Extension == ".jpeg") { Foto.SaveAs(Server.MapPath("~/Fotos/" + Foto.FileName)); Empleado.Foto = "~/Fotos/" + Foto.FileName; } else { lblMensaje.Text = "El formato de la imagen es incorrecto"; } } else { Empleado.Foto = ""; } if (txtDNI.Text == "" || txtNombre.Text == "" || txtEmail.Text == "") { lblMensaje.Text = "Hay campos que se encuentran vacios"; } else { Estado = EmpleadoNegocio.AgregarEmpleado(Empleado); if (Estado == true) { EmpleadoNegocio.GenerarUsuario(Empleado); EmpleadoNegocio.EnviarCorreo(Empleado); lblMensaje.Text = "Empleado agregado correctamente"; txtDNI.Text = ""; txtNombre.Text = ""; txtEmail.Text = ""; } else { lblMensaje.Text = "Error el empleado no fue agregado correctamente"; } } } else if (Empleado != null) { Empleado.Dni = Convert.ToInt32(txtDNI.Text); Empleado.Nombre = txtNombre.Text; Empleado.Email = txtEmail.Text; if (txtDNI.Text == "" || txtNombre.Text == "" || txtEmail.Text == "") { lblMensaje.Text = "Hay campos que se encuentran vacios"; } else { Estado = EmpleadoNegocio.ModificarEmpleado(Empleado); if (Estado == true) { lblMensaje.Text = "Empleado modificado correctamente"; txtDNI.Text = ""; txtNombre.Text = ""; txtEmail.Text = ""; } else { lblMensaje.Text = "Error el empleado no fue modificado correctamente"; } } } } catch (Exception) { lblMensaje.Text = "Hay campos que se encuentran vacios o verificar el formato de la imagen"; } }