コード例 #1
0
ファイル: SgmproImport.cs プロジェクト: jmfragueiro/sgmpro
        /// <summary>
        /// Importa las gestiones recibidas desde el Lex Doctor.
        /// Como en el archivo exportado del Lex son 6 registros por
        /// cada cuenta
        /// </summary>
        public static void ImportarGestionesLegales(ArrayList registro)
        {
            try {
                // Obtiene la segunda fila, la cual tiene el nº de expendiente
                String strReg = registro[1].ToString();
                // Extrae el nº de expediente
                String nroExp = strReg.Substring(
                    strReg.IndexOf("Exp:") + 4,
                    strReg.Length - (strReg.IndexOf("Exp:") + 4));
                // Limpia de espacios
                nroExp = nroExp.Trim();

                // Verifica si existe una cuenta con ese nº de exp.
                if (nroExp == String.Empty)
                    return;
                var unSBuilder = new StringBuilder();
                unSBuilder.Append("select c.cta_id from Cuenta c ");
                unSBuilder.Append(String.Format("where c.cta_expediente = '{0}' ", nroExp));
                object[] resulta2 = Persistencia.EjecutarSqlOneRow(
                    unSBuilder.ToString(),
                    Persistencia.Controlador.CadenaConexion);
                if (resulta2 == null)
                    return;
                string ctaId = resulta2[0].ToString();

                // Arma la lista de gestiones realizadas en el Legales
                strReg = registro[4].ToString();
                // Extrae las gestiones registradas tamaño fijo 5, separados por |
                strReg = strReg.Remove(0, 17);
                char[] delimitador = {'|'};
                string[] gestiones = strReg.Split(delimitador);
                var ultGestLeg = new Parametro();

                // Recorre el array de gestiones legales y verifica si tienen los estados
                // CON EMBARGO o CON DEPOSITO
                foreach (string t in gestiones) {
                    // Si encuentra el estado CON EMBARGO almacena en la variable ultGestLeg.
                    // a menos que ya tenga cargada el estado CON DEPOS. JUD
                    ultGestLeg = (t.Trim().Equals(_ecJuicioCEmb.Nombre) && !ultGestLeg.Equals(_ecJuicioCDep.Nombre))
                                     ? _ecJuicioCEmb
                                     : ultGestLeg;
                    // Si encuentra CON DEPOSITO JUD lo guarda.
                    ultGestLeg = (t.Trim().Equals(_ecJuicioCDep.Nombre)) ? _ecJuicioCDep : ultGestLeg;
                }

                // Si ultGestLeg no tiene nada, es porque esa cuenta no tiene gestiones
                // legales en estado CON EMBARGO o DEPOSITO JUDICIAL. En ese caso retorna.
                if (String.IsNullOrEmpty(ultGestLeg.Nombre))
                    return;

                //---- Obtiene todas las gestiones legales para la cuenta tratada ---//
                // Arma el string de consulta
                unSBuilder = new StringBuilder();
                unSBuilder.Append("select * from Gestion where ");
                unSBuilder.Append(String.Format("ges_cuenta = '{0}' ", ctaId));
                unSBuilder.Append(String.Format(" and ges_tipo = '{0}' ", _tipLegal.Id));
                unSBuilder.Append(String.Format(" and ges_resultadodesc = '{0}'", ultGestLeg.Nombre));
                // Tira la consulta
                resulta2 = Persistencia.EjecutarSqlOneRow(
                    unSBuilder.ToString(), Persistencia.Controlador.CadenaConexion);
                // Si la consulta no devuelve nada, significa que la ultima gestion
                // del Lex, todavia no fue registrada en el sgmpro. Si encuentra, significa
                // que ya esta cargada y retorna.
                if (resulta2 != null)
                    return;

                //----- Inserta la nueva gestion Legal -----//
                // Crea un nuevo ID para la gestion
                Guid gestion = Guid.NewGuid();

                // Arma el string del INSERT SQL.

                unSBuilder = new StringBuilder();
                unSBuilder.Append("BEGIN TRANSACTION ");

                unSBuilder.Append(
                    "INSERT INTO [sgmpro].[dbo].[Gestion]"
                    + "([ges_id]"
                    + ",[ges_tipo]"
                    + ",[ges_estado]"
                    + ",[ges_fechainicio]"
                    + ",[ges_resultado]"
                    //+ ",[ges_resultadofecha]"
                    + ",[ges_fechacierre]"
                    + ",[ges_resultadodesc]"
                    + ",[ges_fechaumod]"
                    + ",[ges_fechabaja]"
                    + ",[ges_cuenta]"
                    + ",[ges_usuario]) "
                    + "VALUES"
                    + String.Format("('{0}'", gestion)
                    + String.Format(",'{0}'", _tipLegal.Id)
                    + String.Format(",'{0}'", _gfinalizada.Id)
                    + String.Format(",'{0}'", Fechas.GetOkDate(DateTime.Now))
                    + String.Format(",'{0}'", _resges3.Id)
                    //+ ",'" + Fechas.GetOkDate(DateTime.Today) + "'"
                    + String.Format(",'{0}'", Fechas.GetOkDate(DateTime.Now))
                    + String.Format(",'{0}'", ultGestLeg)
                    + String.Format(",'{0}'", Fechas.GetOkDate(DateTime.Now))
                    + String.Format(",'{0}'", Fechas.GetOkDate(DateTime.MinValue))
                    + String.Format(",'{0}'", ctaId)
                    + String.Format(",'{0}') ", _usuario.Id));
                //Persistencia.EjecutarSqlDML(sqlIns, _cadena);

                //---- Actualiza el estado de la cuenta -----//
                // Arma la setencia sql
                unSBuilder.Append("Update Cuenta ");
                unSBuilder.Append(String.Format("set cta_estado = '{0}' ", ultGestLeg.Id));
                unSBuilder.Append(String.Format(" where cta_id = '{0}' ", ctaId));

                unSBuilder.Append("COMMIT TRANSACTION");
                // Ejecuta el update
                Persistencia.EjecutarSqlDML(unSBuilder.ToString(), _cadena);

                Sistema.Controlador.logear("GENERICO", ENivelMensaje.ERROR, "IMP.OK GES:" + gestion);
            } catch {
                Sistema.Controlador.logear("GENERICO", ENivelMensaje.DEBUG, "Error en la actualización de Legales");
            }
        }