コード例 #1
0
        private async void EventModificar_Clicked(object sender, EventArgs e)
        {
            string connectionString = ConfigurationManager.AppSettings["ipServer"];

            try
            {
                var id         = IdEmpleado.Text;
                var nombreV    = Nombre.Text;
                var apellidoV  = Apellido.Text;
                var sexoV      = Sexo.SelectedIndex;
                var direccionV = Direccion.Text;
                var telefonoV  = telefono.Text;
                var cedulaV    = cedula.Text;
                var fnV        = FN.Date;



                if (string.IsNullOrEmpty(nombreV))
                {
                    await DisplayAlert("Validacion", "Ingrese el nombre de Usuario", "Aceptar");

                    Nombre.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(apellidoV))
                {
                    await DisplayAlert("Validacion", "Ingresar el apellido del empleado", "Aceptar");

                    Apellido.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(direccionV))
                {
                    await DisplayAlert("Validacion", "Ingreser la direccion del empleado", "Aceptar");

                    Direccion.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(telefonoV))
                {
                    await DisplayAlert("Validacion", "Ingresar el numero telefonico del empleado", "Aceptar");

                    telefono.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(cedulaV))
                {
                    await DisplayAlert("Validacion", "Ingreser la cedula del empleado", "Aceptar");

                    cedula.Focus();
                    return;
                }


                if (string.IsNullOrEmpty(fnV.ToString()))
                {
                    await DisplayAlert("Validacion", "Ingresar la fecha de nacimiento del usuario", "Aceptar");

                    FN.Focus();
                    return;
                }


                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(connectionString);

                var empleados = new Emple()
                {
                    EmpleadoID       = int.Parse(id),
                    Nombres          = nombreV,
                    Apellidos        = apellidoV,
                    Sexo             = (Sexo.SelectedIndex == 0) ? false : true,
                    Direccion        = direccionV,
                    Telefono         = telefonoV,
                    Fecha_Nacimiento = fnV,
                    Cedula           = cedulaV,
                    Edad             = DateTime.Now.Year - fnV.Value.Year
                };

                var           json          = JsonConvert.SerializeObject(empleados);
                StringContent stringContent = new StringContent(json, Encoding.UTF8, "application/json");

                var request = await client.PostAsync("/api/Empleados/modificar", stringContent);

                if (request.IsSuccessStatusCode)
                {
                    var responseJson = await request.Content.ReadAsStringAsync();

                    var respuesta = JsonConvert.DeserializeObject <Request>(responseJson);

                    if (respuesta.status)
                    {
                        await MaterialDialog.Instance.AlertAsync(message : "Usuario se modifico correctamente",
                                                                 title : "Registro",
                                                                 acknowledgementText : "Aceptar");
                    }
                    else
                    {
                        await MaterialDialog.Instance.AlertAsync(message : "Usuario no pudo modificarse correctamente",
                                                                 title : "Registro",
                                                                 acknowledgementText : "Aceptar");
                    }
                }
                else
                {
                    await MaterialDialog.Instance.AlertAsync(message : "Error",
                                                             title : "Error",
                                                             acknowledgementText : "Aceptar");
                }
            }
            catch (Exception ex)
            {
                await MaterialDialog.Instance.AlertAsync(message : ex.Message,
                                                         title : ex.Message,
                                                         acknowledgementText : "Aceptar");
            }
        }
コード例 #2
0
        private async void BtnGuardarEmpleados_Clicked(object sender, EventArgs e)
        {
            string connectionString = ConfigurationManager.AppSettings["ipServer"];

            try
            {
                var rolIDV            = (PosicionesListView)pickerPosiciones.SelectedItem;
                var areaProduccionIDV = (SubDepartamentosListView)pickerSubDepartamentos.SelectedItem;
                var codigoEmpleadoV   = codigoEmpleado.Text;
                var nombreV           = nombre.Text;
                var apellidoV         = apellido.Text;
                var sexoV             = sexo.SelectedIndex;
                var direccionV        = direccion.Text;
                var telefonoV         = telefono.Text;
                var cedulaV           = cedula.Text;
                var fnV           = FN.Date;
                var fechaIngresoV = FechaIngreso.Date;



                if (string.IsNullOrEmpty(rolIDV.ToString()))
                {
                    await DisplayAlert("Validacion", "Ingresar el puesto del empleado", "Aceptar");

                    pickerPosiciones.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(areaProduccionIDV.ToString()))
                {
                    await DisplayAlert("Validacion", "Ingresar el departamento del empleado", "Aceptar");

                    pickerSubDepartamentos.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(codigoEmpleadoV))
                {
                    await DisplayAlert("Validacion", "Ingresar el codigo del empleado", "Aceptar");

                    codigoEmpleado.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(nombreV))
                {
                    await DisplayAlert("Validacion", "Ingrese el nombre de Usuario", "Aceptar");

                    nombre.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(apellidoV))
                {
                    await DisplayAlert("Validacion", "Ingresar el apellido del empleado", "Aceptar");

                    apellido.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(direccionV))
                {
                    await DisplayAlert("Validacion", "Ingreser la direccion del empleado", "Aceptar");

                    direccion.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(telefonoV))
                {
                    await DisplayAlert("Validacion", "Ingresar el numero telefonico del empleado", "Aceptar");

                    telefono.Focus();
                    return;
                }

                if (string.IsNullOrEmpty(cedulaV))
                {
                    await DisplayAlert("Validacion", "Ingreser la cedula del empleado", "Aceptar");

                    cedula.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(fnV.ToString()))
                {
                    await DisplayAlert("Validacion", "Ingresar la fecha de nacimiento del empleado", "Aceptar");

                    FN.Focus();
                    return;
                }
                if (string.IsNullOrEmpty(fechaIngresoV.ToString()))
                {
                    await DisplayAlert("Validacion", "Ingresar la fecha de ingreso del empleado", "Aceptar");

                    FechaIngreso.Focus();
                    return;
                }

                HttpClient client = new HttpClient();
                client.BaseAddress = new Uri(connectionString);

                var empleados = new Emple()
                {
                    EmpleadoID        = 0,
                    PosicionID        = rolIDV.PosicionID,
                    SubDepartamentoID = areaProduccionIDV.SubDepartamentoID,
                    CodigoEmpleado    = codigoEmpleadoV,
                    Nombres           = nombreV,
                    Apellidos         = apellidoV,
                    Sexo             = (sexo.SelectedIndex == 0) ? false : true,
                    Direccion        = direccionV,
                    Telefono         = telefonoV,
                    Fecha_Nacimiento = fnV,
                    Cedula           = cedulaV,
                    Edad             = DateTime.Now.Year - fnV.Value.Year,
                    FechaIngreso     = fechaIngresoV
                };

                //Convetir a Json
                var           json          = JsonConvert.SerializeObject(empleados);
                StringContent stringContent = new StringContent(json, Encoding.UTF8, "application/json");

                //Ejecutar el api el introduces el metodo
                var request = await client.PostAsync("/api/Empleados/registrar", stringContent);

                if (request.IsSuccessStatusCode)
                {
                    var responseJson = await request.Content.ReadAsStringAsync();

                    var respuesta = JsonConvert.DeserializeObject <Request>(responseJson);

                    //Status
                    if (respuesta.status)
                    {
                        await MaterialDialog.Instance.AlertAsync(message : "Usuario registrado correctamente",
                                                                 title : "Registro",
                                                                 acknowledgementText : "Aceptar");
                    }
                    else
                    {
                        await MaterialDialog.Instance.AlertAsync(message : "Usuario no pudo registrarse correctamente",
                                                                 title : "Registro",
                                                                 acknowledgementText : "Aceptar");
                    }
                }
                else
                {
                    await MaterialDialog.Instance.AlertAsync(message : "Error",
                                                             title : "Error",
                                                             acknowledgementText : "Aceptar");
                }
            }
            catch (Exception ex)
            {
                await MaterialDialog.Instance.AlertAsync(message : ex.Message,
                                                         title : "Error",
                                                         acknowledgementText : "Aceptar");
            }
        }