コード例 #1
0
        private DataTable LoadDataGrid()
        {
            DataTable dt = new DataTable();
            DataTableFiltered = new DataTable();
            RedEmpleoOffLineEntities db = new RedEmpleoOffLineEntities();

            dt.Columns.Add("Estado", typeof(string));
            dt.Columns.Add("Editar", typeof(string));
            dt.Columns.Add("Ver", typeof(string));
            dt.Columns.Add("Nombre Completo", typeof(string));
            dt.Columns.Add("Identificación", typeof(string));
            dt.Columns.Add("Departamento", typeof(string));
            dt.Columns.Add("Municipio", typeof(string));
            dt.Columns.Add("Vereda", typeof(string));
            dt.Columns.Add("Teléfono", typeof(string));
            dt.Columns.Add("Celular", typeof(string));


            var personas = from p in db.Personas.OrderByDescending(x=>x.Fecha_Modificacion )
                           select new { Estado= p.Estado , NombreCompleto = p.PrimerNombre + " " + p.SegundoNombre + " " + p.PrimerApellido + " " + p.SegundoApellido, Identificacion = p.TipoDocumento + p.NoDocumento, Dep = p.Municipio.Departamento.nombre , ciud = p.Municipio.nombre, vere = p.Vereda, Tel= p.Telefono, Cel= p.Celular, Edit= p.AllowEdit };
                           

            foreach (var p in personas)
            {
                string Vereda = (from v in db.Veredas where v.IdCodigo.Contains(p.vere) select v.nombre).FirstOrDefault();
                dt.Rows.Add(p.Estado.ToString(), p.Edit.ToString(), "true", p.NombreCompleto, p.Identificacion, p.Dep, p.ciud, Vereda, p.Tel, p.Cel);
            }
 
            DataTableFiltered.Columns.Add("Estado", typeof(string));
            DataTableFiltered.Columns.Add("Editar", typeof(string));
            DataTableFiltered.Columns.Add("Ver", typeof(string));
            DataTableFiltered.Columns.Add("Nombre Completo", typeof(string));
            DataTableFiltered.Columns.Add("Identificación", typeof(string));
            DataTableFiltered.Columns.Add("Departamento", typeof(string));
            DataTableFiltered.Columns.Add("Municipio", typeof(string));
            DataTableFiltered.Columns.Add("Vereda", typeof(string));
            DataTableFiltered.Columns.Add("Teléfono", typeof(string));
            DataTableFiltered.Columns.Add("Celular", typeof(string));

            
            List<List<string>> alist = new List<List<string>>();
            foreach (var p in personas)
            {
                string Vereda = (from v in db.Veredas where v.IdCodigo.Contains(p.vere) select v.nombre).FirstOrDefault();
                List<string> list1 = new List<string>() { p.Estado.ToString(), p.Edit.ToString(), "true", p.NombreCompleto, p.Identificacion, p.Dep, p.ciud, Vereda, p.Tel, p.Cel };
                alist.Add(list1);
            }

            IList results = (IList)alist;

            CollectionViewList = new ListCollectionView(results);

            return dt;
        }
コード例 #2
0
        private void Sincronizar(object sender, RoutedEventArgs e)
        {
            RedEmpleoOffLineEntities db = new RedEmpleoOffLineEntities();
            string Usuario = LebelUsuario.Content.ToString();
            string UsurioUtente = (from u in db.UsuariosPuntos
                              where u.Usuario.ToString().ToLower().Equals(Usuario.ToLower(), StringComparison.OrdinalIgnoreCase)
                              select u.Redempleo_UTENTE).First().ToString();

            var Allpersonas = (from p in db.Personas where p.Estado.Equals(null)
                              select new { Id = p.Id, PrimerNombre = p.PrimerNombre, SegundoNombre = p.SegundoNombre, PrimerApellido = p.PrimerApellido, SegundoApellido = p.SegundoApellido, Sexo = p.Sexo, TipoDocumento = p.TipoDocumento, NoDocumento = p.NoDocumento, FechaNacimiento = p.FechaNacimiento, Usuario = p.Usuario, Contrasena = p.Contrasena, Departamento = p.Departamento, Ciudad = p.Ciudad, Direccion = p.Direccion, Barrio = p.Barrio, Telefono = p.Telefono, Celular = p.Celular, CorreoElectronico = p.CorreoElectronico, CentroEmpleo = p.CentroEmpleo,Fecha_Creacion = p.Fecha_Creacion, Redempleo_UTENTE = UsurioUtente }).ToList();
            List<Listado> Listlistado = new List<Listado>();
            foreach (var per in Allpersonas)
            {
                Listado listado = new Listado();
                listado.Id = Convert.ToInt64(per.Id);
                listado.PrimerNombre = per.PrimerNombre;
                listado.SegundoNombre = per.SegundoNombre;
                listado.PrimerApellido = per.PrimerApellido;
                listado.SegundoApellido = per.SegundoApellido;
                listado.Sexo = per.Sexo;
                listado.TipoDocumento = per.TipoDocumento;
                listado.NoDocumento = per.NoDocumento;
                listado.FechaNacimiento = per.FechaNacimiento.ToString("yyyy-MM-dd hh:mm:ss");
                listado.Usuario = per.Usuario;
                listado.Contrasena = per.Contrasena;
                listado.Departamento = per.Departamento;
                listado.Ciudad = per.Ciudad;
                listado.Direccion = per.Direccion;
                listado.Barrio = per.Barrio;
                listado.Telefono = per.Telefono;
                listado.Celular = per.Celular;
                listado.CorreoElectronico = per.CorreoElectronico;
                listado.CentroEmpleo = per.CentroEmpleo;
                listado.Fecha_Creacion = per.Fecha_Creacion.ToString("yyyy-MM-dd hh:mm:ss");
                listado.Redempleo_UTENTE = per.Redempleo_UTENTE;
                Listlistado.Add(listado);
            }

            UsuariosPuntos Auth = (from u in db.UsuariosPuntos
                                   where u.Usuario.ToString().ToLower().Equals(Usuario.ToLower(), StringComparison.OrdinalIgnoreCase)
                                   select u).FirstOrDefault();
            DataSync dataSync = new DataSync();
            dataSync.listado = Listlistado;
            dataSync.usuariosPuntos = Auth;

            string jsonContent = JsonConvert.SerializeObject(dataSync);

            jsonContent = Regex.Replace(jsonContent, "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1");
            //string url = "http://serviciodeempleo.gov.co:9095/api/redempleo/save/postPersonas";
            //string url = "http://ivandarioperill/RedEmpleoII/api/redempleo/save/postPersonas";
            string url = "http://*****:*****@"application/json";
            Mensage relustado = null;
            bool conexion= false;
            try
            {
                using (Stream dataStream = request.GetRequestStream()) {
                    dataStream.Write(byteArray, 0, byteArray.Length);
                }
                using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) {
                    //relustado = response.ToString();
                    if (response.StatusCode != HttpStatusCode.OK)
                        throw new Exception(String.Format(
                        "Server error (HTTP {0}: {1}).",
                        response.StatusCode,
                        response.StatusDescription));
                    using (Stream data = response.GetResponseStream())
                    using (var reader = new StreamReader(data))
                    {
                        string text = reader.ReadToEnd();
                       // var jobj = (JObject)JsonConvert.DeserializeObject(text);
                        relustado = JsonConvert.DeserializeObject<Mensage>(text);
                        conexion = true;
                    }
                }
            }
            catch (WebException ex) {
                MessageBox.Show("No hay conexion con el servidor: " + ex.Status +" ");
            }
            if (conexion)
            {
                if (relustado != null)
                {
                    foreach (ResultadoCollection resultadoCollection in relustado.resultadoCollection)
                    {
                        Personas persona = db.Personas.Find(resultadoCollection.PersonasOffline_Id);
                        persona.Fecha_Sincronizacion = DateTime.ParseExact(resultadoCollection.FechaSincronizacion, "yyyy-MM-dd hh:mm:ss", CultureInfo.InvariantCulture);
                        //sincronisacion exitosa
                        if (resultadoCollection.SyncOK)
                        {
                            persona.AllowEdit = false;
                            persona.Estado = true;
                        }
                        // Error Al  guardar
                        if (resultadoCollection.ErrorGuardar)
                        {
                            persona.Estado = false;
                            persona.AllowEdit = true;
                        }
                        //Persona Existe
                        if (resultadoCollection.personaexiste)
                        {
                            persona.Estado = false;
                            persona.AllowEdit = true;
                        }
                        //Conbinacion TipoDoc NoDocumento Existe
                        if (resultadoCollection.TipoDocDocumentoexiste)
                        {
                            persona.Estado = false;
                            persona.AllowEdit = true;
                        }
                        //Usuario Existe
                        if (resultadoCollection.usuarioexiste)
                        {
                            persona.Estado = false;
                            persona.AllowEdit = true;
                            persona.UsuarioValido = true;
                        }
                        persona.Respuesta = resultadoCollection.Respuesta;
                        persona.RedEmpleoID = resultadoCollection.Redempleo_Id;
                        try
                        {
                            db.Entry(persona).State = EntityState.Modified;
                            db.SaveChanges();
                        }
                        catch (DbEntityValidationException ex)
                        {
                            // Retrieve the error messages as a list of strings.
                            var errorMessages = ex.EntityValidationErrors
                            .SelectMany(x => x.ValidationErrors)
                            .Select(x => x.ErrorMessage);

                            // Join the list to a single string.
                            var fullErrorMessage = string.Join("; ", errorMessages);

                            // Combine the original exception message with the new one.
                            var exceptionMessage = string.Concat(ex.Message, " The validation errors are: ", fullErrorMessage);
                            MessageBox.Show(exceptionMessage);
                        }
                    }
                    int oferentesSincronizados = (from o in relustado.resultadoCollection where o.SyncOK.Equals(true) select o.PersonasOffline_Id).ToList().Count();
                    int oferentesEsistentes = (from o in relustado.resultadoCollection where o.personaexiste.Equals(true) || o.TipoDocDocumentoexiste.Equals(true) select o.PersonasOffline_Id).ToList().Count();
                    int oferentesUsuarioExistente = (from o in relustado.resultadoCollection where o.usuarioexiste.Equals(true) select o.PersonasOffline_Id).ToList().Count();
                    MessageBox.Show("Sincronizacíon completa:\nTotal oferentes enviados => " + Listlistado.Count().ToString()
                        + "\nTotal oferentes procesados => " + relustado.resultadoCollection.Count().ToString()
                        + "\nTotal oferentes sincronizados => " + oferentesSincronizados.ToString()
                        + "\nTotal oferentes ya registrados => " + oferentesEsistentes.ToString()
                        + "\nTotal oferentes con usuario  existente => " + oferentesUsuarioExistente.ToString());
                    RefrescarDatagrid();
                }
                else
                {
                    MessageBox.Show("El no hay registros para sincronizar");
                }
            }
            else
            {
              //  MessageBox.Show("El no hay  registros para sincronizar");
            }
        }
コード例 #3
0
        private void Edit_Click(object sender, RoutedEventArgs e)
        {
            RedEmpleoOffLineEntities db = new RedEmpleoOffLineEntities();
            var button = (FrameworkElement)sender;
            var row = (DataGridRow)button.Tag;
            var content = ((System.Data.DataRowView)(row.Item)).Row.ItemArray[4];
            string tipodoc = content.ToString().Substring(0, 2);
            string NoIdentificacion = content.ToString().Replace("CC", "").Replace("TI", "").Replace("CE", "").Replace("PA", "");
            var AllowEdit = (from p in db.Personas where p.NoDocumento.Equals(NoIdentificacion) && p.TipoDocumento.Equals(tipodoc) select p.AllowEdit).FirstOrDefault();
            if (!AllowEdit == false)
            {
                var UsuarioExistente = (from p in db.Personas where p.NoDocumento.Equals(NoIdentificacion) select p.UsuarioValido).FirstOrDefault();

                string Usuario = LebelUsuario.Content.ToString();
                Thread thread = new Thread(() =>
                {
                    var win = new EditPersona(content.ToString(), Usuario) { DataContext = new ViewModelEditPersona(NoIdentificacion) };
                    win.Show();
                    win.Closed += (sender1, e1) => win.Dispatcher.InvokeShutdown();
                    System.Windows.Threading.Dispatcher.Run();
                    RefrescarDatagrid();
                });
                thread.SetApartmentState(ApartmentState.STA);
                thread.IsBackground = true;
                thread.Start();

                this.Visibility = Visibility.Collapsed;
            }
            else {
              MessageBox.Show("Oferente Sincronizado");
             }
        }