コード例 #1
0
        //convert image to bytearray

        private void btnGuardar_Click(object sender, EventArgs e)
        {
            byte[] bitDataFoto;

            if (TxtCelular1.Text == "")
            {
                MessageBox.Show("Ingrese al menos un numero de telefono", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (TxtIdentidad.Text != "" && TxtNombres.Text != "" && TxtApellidos.Text != "" && TxtDireccion.Text != "" && TxtCelular1.Text != "")
            {
                if (!bandera_Estado) // Para identificar si se va ingresar
                {
                    //Preguntar si tiene una foto  cargada
                    if (nameFoto == "")
                    {
                        Image img = PictureFoto.Image;
                        bitDataFoto = Funcion.imgToByteArray(img);
                    }
                    else
                    {
                        bitDataFoto = Funcion.ConvertImg_Bytes(nameFoto);
                    }
                    Empleado ObjEmpleado = new Empleado(cmbTipoDocumento.Text, TxtIdentidad.Text, TxtNombres.Text, TxtApellidos.Text,
                                                        ckbActivo.Checked, TxtDireccion.Text, bitDataFoto, Convert.ToInt32(CmbParroquia.SelectedValue), TxtEmail.Text,
                                                        DtpFechaNacimiento.Value, CmbTipoLicencia.Text, CmbTipoSangre.Text, TxtLibretaMilitar.Text, CkbDiscapacidad.Checked,
                                                        Convert.ToInt32(NupDiscapacidad.Value), Convert.ToSingle(TxtMovimientoQuincenal.Text), CmbGenero.Text, CmbEstadoCivil.Text, Convert.ToSingle(TxtSueldoMensual.Text),
                                                        Convert.ToSingle(TxtSueldoExtra.Text), TxtCelular1.Text, TxtCelular2.Text);

                    String resultado = ObjEmpleado.InsertarEmpleado(ObjEmpleado); // retorna true si esta correcto todo
                    if (resultado == "Datos Guardados")
                    {
                        MessageBox.Show("Cliente Registrado Correctamente ", "Exito", MessageBoxButtons.OK);
                        cargarDatos("1");
                        rbtActivosEmpleado.Checked = true;
                        inicializarDatos();
                    }
                    else if (resultado == "Error al Registrar")
                    {
                        MessageBox.Show("Error al guardar", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else if (resultado == "Existe")
                    {
                        MessageBox.Show("Ya Existe el Empleado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else if (bandera_Estado) // Para identificar si se va modificar
                {
                    if (nameFoto != "")  // si esta cargada alguna foto guarde la imagen en el arreglo
                    {
                        bitDataFoto = Funcion.ConvertImg_Bytes(nameFoto);
                    }
                    else if (imgenDefault) // Para que se guarde la imgen por defecto si desea cancelar la imagen
                    {
                        imgenDefault = false;
                        bitDataFoto  = MyDataImagen;
                    }
                    else // si no modifica la imagen, que quede la misma
                    {
                        bitDataFoto = MyDataImagen;
                    }

                    Empleado ObjEmpleado = new Empleado(cmbTipoDocumento.Text, TxtIdentidad.Text, TxtNombres.Text, TxtApellidos.Text,
                                                        ckbActivo.Checked, TxtDireccion.Text, bitDataFoto, Convert.ToInt32(CmbParroquia.SelectedValue), TxtEmail.Text,
                                                        DtpFechaNacimiento.Value, CmbTipoLicencia.Text, CmbTipoSangre.Text, TxtLibretaMilitar.Text, CkbDiscapacidad.Checked,
                                                        Convert.ToInt32(NupDiscapacidad.Value), Convert.ToSingle(TxtMovimientoQuincenal.Text), CmbGenero.Text, CmbEstadoCivil.Text, Convert.ToSingle(TxtSueldoMensual.Text),
                                                        Convert.ToSingle(TxtSueldoExtra.Text), TxtCelular1.Text, TxtCelular2.Text);

                    String Resultado = ObjEmpleado.ModificarEmpleado(identificacion, bitDataFoto); // retorna true si esta correcto todo
                    if (Resultado == "Correcto")
                    {
                        MessageBox.Show("Empleado Actualizado", "Exito");
                        cargarDatos("1");
                        rbtActivosEmpleado.Checked = true;
                        identificacion             = "";
                    }
                    else
                    {
                        MessageBox.Show("Error al actualizar Empleado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    inicializarDatos();
                    bandera_Estado  = false;
                    btnGuardar.Text = "&Guardar";
                    MyDataImagen    = null;
                }
            }
            else
            {
                MessageBox.Show("Ingrese los datos del Empleado", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }