private async void GuardarNUC()
 {
     if (Ingreso != null && SelectedInterconexion != null)
     {
         var nuc = new NUC();
         nuc.ID_CENTRO   = Ingreso.ID_CENTRO;
         nuc.ID_ANIO     = Ingreso.ID_ANIO;
         nuc.ID_IMPUTADO = Ingreso.ID_IMPUTADO;
         nuc.ID_INGRESO  = Ingreso.ID_INGRESO;
         nuc.ID_NUC      = SelectedInterconexion.EXPEDIENTEID.ToString();
         nuc.DESCR       = string.Empty;
         new cNuc().Insertar(nuc);
     }
 }
Exemplo n.º 2
0
 private void ActualizarNUC()
 {
     if (SelectedCausaPenal != null)
     {
         if (SelectedCausaPenal.NUC != null)//EDITAR
         {
             if (!string.IsNullOrEmpty(NUC))
             {
                 var n = new NUC()
                       {
                           ID_CENTRO = SelectedCausaPenal.ID_CENTRO,
                           ID_ANIO = SelectedCausaPenal.ID_ANIO,
                           ID_IMPUTADO = SelectedCausaPenal.ID_IMPUTADO,
                           ID_INGRESO = SelectedCausaPenal.ID_INGRESO,
                           ID_CAUSA_PENAL = SelectedCausaPenal.ID_CAUSA_PENAL,
                           ID_NUC = NUC.Replace("NUC:",string.Empty)
                       };
                 if (new cNuc().Actualizar(n))
                     SelectedCausaPenal.NUC = n;
                     
                       
             }
             else//ELIMINAR
             {
                 if (new cNuc().Eliminar(SelectedCausaPenal.ID_CENTRO, SelectedCausaPenal.ID_ANIO, SelectedCausaPenal.ID_IMPUTADO, SelectedCausaPenal.ID_INGRESO, SelectedCausaPenal.ID_CAUSA_PENAL))
                     SelectedCausaPenal.NUC = null;
             }
         }
         else //INSERTAR
         {
             var n = new NUC()
                        {
                            ID_CENTRO = SelectedCausaPenal.ID_CENTRO,
                            ID_ANIO = SelectedCausaPenal.ID_ANIO,
                            ID_IMPUTADO = SelectedCausaPenal.ID_IMPUTADO,
                            ID_INGRESO = SelectedCausaPenal.ID_INGRESO,
                            ID_CAUSA_PENAL = SelectedCausaPenal.ID_CAUSA_PENAL,
                            ID_NUC =  !string.IsNullOrEmpty(NUC) ? NUC.Replace("NUC:", string.Empty) : string.Empty
                        };
             if (new cNuc().Insertar(n))
                 SelectedCausaPenal.NUC = n;
                 
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// metodo que se conecta a la base de datos para actualizar un registro
        /// </summary>
        /// <param name="Entity">objeto de tipo "CAUSA_PENAL" con valores a actualizar</param>
        public bool Actualizar(CAUSA_PENAL Entity, List <CAUSA_PENAL_DELITO> Delito, NUC Nuc)//string NUC)
        {
            try
            {
                using (TransactionScope transaccion = new TransactionScope(TransactionScopeOption.RequiresNew, new TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted
                }))
                {
                    Context.Entry(Entity).State = System.Data.EntityState.Modified;
                    #region Delitos
                    var delitos = Context.CAUSA_PENAL_DELITO.Where(w => w.ID_CENTRO == Entity.ID_CENTRO && w.ID_ANIO == Entity.ID_ANIO && w.ID_IMPUTADO == Entity.ID_IMPUTADO && w.ID_INGRESO == Entity.ID_INGRESO && w.ID_CAUSA_PENAL == Entity.ID_CAUSA_PENAL);
                    if (delitos != null)
                    {
                        foreach (var d in delitos)
                        {
                            Context.Entry(d).State = System.Data.EntityState.Deleted;
                        }
                    }
                    foreach (var d in Delito)
                    {
                        Context.CAUSA_PENAL_DELITO.Add(d);
                    }
                    #endregion

                    #region NUC
                    var nuc = Context.NUC.Where(w => w.ID_CENTRO == Entity.ID_CENTRO && w.ID_ANIO == Entity.ID_ANIO && w.ID_IMPUTADO == Entity.ID_IMPUTADO && w.ID_INGRESO == Entity.ID_INGRESO && w.ID_CAUSA_PENAL == Entity.ID_CAUSA_PENAL).SingleOrDefault();

                    //if (string.IsNullOrEmpty(NUC) && nuc != null)
                    if (Nuc == null && nuc != null)
                    {
                        Context.Entry(nuc).State = System.Data.EntityState.Deleted;
                    }
                    else
                    //if (!string.IsNullOrEmpty(NUC) && nuc == null)
                    if (Nuc != null && nuc == null)
                    {
                        //Context.NUC.Add(new NUC() { ID_CENTRO = Entity.ID_CENTRO, ID_ANIO = Entity.ID_ANIO, ID_IMPUTADO = Entity.ID_IMPUTADO, ID_INGRESO = Entity.ID_INGRESO, ID_CAUSA_PENAL = Entity.ID_CAUSA_PENAL, ID_NUC = NUC });
                        Context.NUC.Add(new NUC()
                        {
                            ID_CENTRO = Entity.ID_CENTRO, ID_ANIO = Entity.ID_ANIO, ID_IMPUTADO = Entity.ID_IMPUTADO, ID_INGRESO = Entity.ID_INGRESO, ID_CAUSA_PENAL = Entity.ID_CAUSA_PENAL, ID_NUC = Nuc.ID_NUC, ID_PERSONA_PG = Nuc.ID_PERSONA_PG
                        });
                    }
                    else
                    //if (!string.IsNullOrEmpty(NUC) && nuc != null)
                    if (Nuc != null && nuc != null)
                    {
                        //nuc.ID_NUC = NUC;
                        nuc.ID_NUC                  = Nuc.ID_NUC;
                        nuc.ID_PERSONA_PG           = Nuc.ID_PERSONA_PG;
                        Context.Entry(Entity).State = System.Data.EntityState.Modified;
                    }
                    #endregion

                    #region Cambio de Estatus Administrativo
                    var causasPenales = Context.CAUSA_PENAL.Where(w => w.ID_CENTRO == Entity.ID_CENTRO && w.ID_ANIO == Entity.ID_ANIO && w.ID_IMPUTADO == Entity.ID_IMPUTADO && w.ID_INGRESO == Entity.ID_INGRESO);
                    if (causasPenales != null)
                    {
                        var ingreso = new INGRESO();
                        ingreso.ID_CENTRO   = Entity.ID_CENTRO;
                        ingreso.ID_ANIO     = Entity.ID_ANIO;
                        ingreso.ID_IMPUTADO = Entity.ID_IMPUTADO;
                        ingreso.ID_INGRESO  = Entity.ID_INGRESO;
                        if (causasPenales.Count(w => w.ID_ESTATUS_CP == 1) > 0) //sentenciado
                        {
                            ingreso.ID_CLASIFICACION_JURIDICA = "3";            //SENTENCIADO
                        }
                        else
                        {
                            ingreso.ID_CLASIFICACION_JURIDICA = "2";//PROCESADO
                        }
                        Context.INGRESO.Attach(ingreso);
                        Context.Entry(ingreso).Property(x => x.ID_CLASIFICACION_JURIDICA).IsModified = true;
                    }
                    #endregion

                    Context.SaveChanges();
                    transaccion.Complete();
                    return(true);
                }
                //if (Update(Entity))
                //    return true;
                //else
                //    return false;
            }
            catch (Exception ex)
            {
                //if (ex.Message.Contains("part of the object's key information"))
                //    throw new ApplicationException("La llave principal no se puede cambiar");
                //else
                throw new ApplicationException(ex.Message);
            }
            return(false);
        }
Exemplo n.º 4
0
        private bool GuardarCausaPenal()
        {
            try
            {
                if (!base.HasErrors)
                {
                    var cp = new CAUSA_PENAL();
                    
                    #region Averiguacion Previa
                    if (SelectedAgencia.ID_AGENCIA != -1)
                        cp.ID_AGENCIA = SelectedAgencia.ID_AGENCIA;
                    if (SelectedAgencia.ID_ENTIDAD != -1)
                        cp.ID_ENTIDAD = SelectedAgencia.ID_ENTIDAD;
                    if (SelectedAgencia.ID_MUNICIPIO != -1)
                        cp.ID_MUNICIPIO = SelectedAgencia.ID_MUNICIPIO;
                    cp.AP_ANIO = AnioAP;
                    cp.AP_FOLIO = FolioAP;
                    cp.AP_FORANEA = AveriguacionPreviaAP;
                    cp.AP_FEC_INICIO = FecAveriguacionAP;
                    cp.AP_FEC_CONSIGNACION = FecConsignacionAP;
                    #endregion

                    #region Causa Penal
                    cp.CP_ANIO = AnioCP;
                    cp.CP_FOLIO = FolioCP;
                    cp.CP_BIS = BisCP;
                    cp.CP_FORANEO = ForaneoCP;
                    if (TipoOrdenCP != -1)
                        cp.CP_TIPO_ORDEN = TipoOrdenCP;
                    if (PaisJuzgadoCP != -1)
                        cp.CP_PAIS_JUZGADO = PaisJuzgadoCP;
                    if (EstadoJuzgadoCP != -1)
                        cp.CP_ESTADO_JUZGADO = EstadoJuzgadoCP;
                    if (MunicipioJuzgadoCP != -1)
                        cp.CP_MUNICIPIO_JUZGADO = MunicipioJuzgadoCP;
                    if (!string.IsNullOrEmpty(FueroCP))
                        cp.CP_FUERO = FueroCP;
                    if (JuzgadoCP != -1)
                        cp.CP_JUZGADO = JuzgadoCP;
                    cp.CP_FEC_RADICACION = FecRadicacionCP;
                    if (!string.IsNullOrEmpty(AmpliacionCP))
                        cp.CP_AMPLIACION = AmpliacionCP;
                    if (TerminoCP != -1)
                        cp.CP_TERMINO = TerminoCP;
                    if (EstatusCP != -1)
                        cp.ID_ESTATUS_CP = EstatusCP;
                    cp.CP_FEC_VENCIMIENTO_TERMINO = FecVencimientoTerinoCP;
                    cp.OBSERV = ObservacionesCP;
                    #endregion
                    
                    //#region Baja
                    //cp.BAJA_FEC = BFecha;
                    //cp.ID_MOTIVO_BAJA = BMotivoBaja != null ? BMotivoBaja : null;
                    //cp.ID_AUTO_BAJA = BAutoridadBaja != null ? BAutoridadBaja : null;
                    //#endregion

                    if (SelectedCausaPenal == null)//INSERT
                    {
                        cp.ID_CENTRO = SelectedIngreso.ID_CENTRO;
                        cp.ID_ANIO = SelectedIngreso.ID_ANIO;
                        cp.ID_IMPUTADO = SelectedIngreso.ID_IMPUTADO;
                        cp.ID_INGRESO = SelectedIngreso.ID_INGRESO;
                        
                        #region Delitos
                        var delitos = new List<CAUSA_PENAL_DELITO>(LstCausaPenalDelitos == null ? null : LstCausaPenalDelitos.Select((w, i) => new CAUSA_PENAL_DELITO()
                        {
                            ID_CENTRO = SelectedIngreso.ID_CENTRO,
                            ID_ANIO = SelectedIngreso.ID_ANIO,
                            ID_IMPUTADO = SelectedIngreso.ID_IMPUTADO,
                            ID_INGRESO = SelectedIngreso.ID_INGRESO,
                            ID_CAUSA_PENAL = 0,
                            ID_DELITO = w.ID_DELITO,
                            ID_FUERO = w.ID_FUERO,
                            ID_MODALIDAD = w.ID_MODALIDAD,
                            ID_TIPO_DELITO = w.ID_TIPO_DELITO,
                            CANTIDAD = w.CANTIDAD,
                            OBJETO = w.OBJETO,
                            DESCR_DELITO = w.DESCR_DELITO,
                            ID_CONS = Convert.ToInt16(i + 1)
                        }));
                        cp.CAUSA_PENAL_DELITO = delitos;
                        #endregion

                        #region NUC
                        //if (!string.IsNullOrEmpty(NUC))
                        //    cp.NUC = new NUC() { ID_NUC = NUC.Replace("NUC:", string.Empty) };
                        if (SelectedInterconexion != null)
                        {
                            cp.NUC = new NUC() { ID_NUC = SelectedInterconexion.EXPEDIENTEID.ToString(), ID_PERSONA_PG = SelectedInterconexion.PERSONAFISICAID };
                        }
                        #endregion

                        cp.ID_CAUSA_PENAL = new cCausaPenal().Insertar(cp);
                        if (cp.ID_CAUSA_PENAL > 0)
                        {
                            SelectedCausaPenal = cp;
                            //if (GuardarDelitoCausaPenal(cp.ID_CAUSA_PENAL))
                            //{
                                if (LstCausaPenalDelitos != null)
                                {
                                    //CARGAMOS LA LISTA DE DELITOS CON LOS DELITOS DE LA CAUSA PENAL EN LA SENTENCIA
                                    if (LstSentenciaDelitos == null)
                                        LstSentenciaDelitos = new ObservableCollection<SENTENCIA_DELITO>();
                                    foreach (var d in LstCausaPenalDelitos)
                                    {
                                        LstSentenciaDelitos.Add(
                                            new SENTENCIA_DELITO()
                                            {
                                                ID_DELITO = d.ID_DELITO,
                                                ID_FUERO = d.ID_FUERO,
                                                ID_MODALIDAD = d.ID_MODALIDAD,
                                                ID_TIPO_DELITO = d.ID_TIPO_DELITO,
                                                DESCR_DELITO = d.DESCR_DELITO,
                                                CANTIDAD = d.CANTIDAD,
                                                OBJETO = d.OBJETO,
                                                MODALIDAD_DELITO = d.MODALIDAD_DELITO,
                                                TIPO_DELITO = d.TIPO_DELITO
                                            });
                                    }
                                    if (LstSentenciaDelitos.Count > 0)
                                        SentenciaDelitoEmpty = false;
                                    else
                                        SentenciaDelitoEmpty = true;
                                }
                                
                                return true;
                        }
                        else
                            return false;
                    }
                    else//UPDATE
                    {
                        cp.ID_CENTRO = SelectedCausaPenal.ID_CENTRO;
                        cp.ID_ANIO = SelectedCausaPenal.ID_ANIO;
                        cp.ID_IMPUTADO = SelectedCausaPenal.ID_IMPUTADO;
                        cp.ID_INGRESO = SelectedCausaPenal.ID_INGRESO;
                        cp.ID_CAUSA_PENAL = SelectedCausaPenal.ID_CAUSA_PENAL;

                        #region Delitos
                        var delitos = new List<CAUSA_PENAL_DELITO>(LstCausaPenalDelitos == null ? null : LstCausaPenalDelitos.Select((w, i) => new CAUSA_PENAL_DELITO()
                        {
                            ID_CENTRO = SelectedCausaPenal.ID_CENTRO,
                            ID_ANIO = SelectedCausaPenal.ID_ANIO,
                            ID_IMPUTADO = SelectedCausaPenal.ID_IMPUTADO,
                            ID_INGRESO = SelectedCausaPenal.ID_INGRESO,
                            ID_CAUSA_PENAL = SelectedCausaPenal.ID_CAUSA_PENAL,
                            ID_DELITO = w.ID_DELITO,
                            ID_FUERO = w.ID_FUERO,
                            ID_MODALIDAD = w.ID_MODALIDAD,
                            ID_TIPO_DELITO = w.ID_TIPO_DELITO,
                            CANTIDAD = w.CANTIDAD,
                            OBJETO = w.OBJETO,
                            DESCR_DELITO = w.DESCR_DELITO,
                            ID_CONS = Convert.ToInt16(i + 1)
                        }));
                        #endregion 

                        #region NUC
                        //string sNUC = string.Empty;
                        //if (!string.IsNullOrEmpty(NUC))
                        //    sNUC = NUC.Replace("NUC:", string.Empty);
                        NUC nuc = null;
                        if(SelectedInterconexion != null)
                        {
                            nuc = new NUC() { ID_NUC = SelectedInterconexion.EXPEDIENTEID.ToString(), ID_PERSONA_PG = SelectedInterconexion.PERSONAFISICAID };
                        }
                        
                        #endregion

                        if (new cCausaPenal().Actualizar(cp,delitos,nuc))//sNUC))
                        {
                            //if (GuardarDelitoCausaPenal(cp.ID_CAUSA_PENAL))
                            //{
                                if (SelectedCausaPenal != null)
                                    if (SelectedCausaPenal.SENTENCIA != null)
                                    {
                                        if (SelectedCausaPenal.SENTENCIA.Count == 0)
                                        {
                                            if (LstCausaPenalDelitos != null)
                                            {
                                                //CARGAMOS LA LISTA DE DELITOS CON LOS DELITOS DE LA CAUSA PENAL EN LA SENTENCIA
                                                if (LstSentenciaDelitos == null)
                                                    LstSentenciaDelitos = new ObservableCollection<SENTENCIA_DELITO>();
                                                foreach (var d in LstCausaPenalDelitos)
                                                {
                                                    LstSentenciaDelitos.Add(
                                                        new SENTENCIA_DELITO()
                                                        {
                                                            ID_DELITO = d.ID_DELITO,
                                                            ID_FUERO = d.ID_FUERO,
                                                            ID_MODALIDAD = d.ID_MODALIDAD,
                                                            ID_TIPO_DELITO = d.ID_TIPO_DELITO,
                                                            DESCR_DELITO = d.DESCR_DELITO,
                                                            CANTIDAD = d.CANTIDAD,
                                                            OBJETO = d.OBJETO,
                                                            MODALIDAD_DELITO = d.MODALIDAD_DELITO,
                                                            TIPO_DELITO = d.TIPO_DELITO
                                                        });
                                                }
                                                if (LstSentenciaDelitos.Count > 0)
                                                    SentenciaDelitoEmpty = false;
                                                else
                                                    SentenciaDelitoEmpty = true;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        if (LstCausaPenalDelitos != null)
                                        {
                                            //CARGAMOS LA LISTA DE DELITOS CON LOS DELITOS DE LA CAUSA PENAL EN LA SENTENCIA
                                            if (LstSentenciaDelitos == null)
                                                LstSentenciaDelitos = new ObservableCollection<SENTENCIA_DELITO>();
                                            foreach (var d in LstCausaPenalDelitos)
                                            {
                                                LstSentenciaDelitos.Add(
                                                    new SENTENCIA_DELITO()
                                                    {
                                                        ID_DELITO = d.ID_DELITO,
                                                        ID_FUERO = d.ID_FUERO,
                                                        ID_MODALIDAD = d.ID_MODALIDAD,
                                                        ID_TIPO_DELITO = d.ID_TIPO_DELITO,
                                                        DESCR_DELITO = d.DESCR_DELITO,
                                                        CANTIDAD = d.CANTIDAD,
                                                        OBJETO = d.OBJETO,
                                                        MODALIDAD_DELITO = d.MODALIDAD_DELITO,
                                                        TIPO_DELITO = d.TIPO_DELITO
                                                    });
                                            }
                                            if (LstSentenciaDelitos.Count > 0)
                                                SentenciaDelitoEmpty = false;
                                            else
                                                SentenciaDelitoEmpty = true;
                                        }
                                    }
                                //ActualizarNUC();
                                return true;
                            //}
                            //else
                            //    return false;
                        }
                        else
                            return false;
                    }
                }
                else
                    return false;
            }
            catch (Exception ex)
            {
                StaticSourcesViewModel.ShowMessageError("Algo pasó...", "Ocurrió un error al guardar causa penal", ex);
                return false;
            }
        }