Esempio n. 1
0
        public int Grabar(object unItem)
        {
            contable        item    = (contable)unItem;
            int             i       = 0;
            fraccionperiodo periodo = PeriodoPr.Instancia.RegistroPorId((short)item.fecha.Year, (short)item.fecha.Month);

            if (periodo == null)
            {
                throw new Exception("Periodo no registrado");
            }
            if (!periodo.cerrado)
            {
                using (ispDB db = new ispDB())
                {
                    try
                    {
                        item.fkfraccionperiodo = periodo;
                        item.IntegrarAsociados();

                        db.BeginTransaction();
                        if (item.numero == 0)
                        {
                            item.numero = db.contables.Where(x => x.idperiodo == item.idperiodo && x.idtipocontable == item.idtipocontable)
                                          .GroupBy(x => Sql.GroupBy.None, (idx, g) => g.Max(y => y.numero)).Single();
                            item.numero++;
                        }

                        i = db.InsertOrReplace(item);

                        db.detallescontables.Where(x => x.idperiodo == item.idperiodo && x.idtipocontable == item.idtipocontable && x.numerocontable == item.numero).Delete();

                        for (int ix = 0; ix < item.fkdetallescontables.Count(); ix++)
                        {
                            detallecontable detalle = item.fkdetallescontables.ElementAt(ix);
                            detalle.idperiodo      = item.idperiodo;
                            detalle.idtipocontable = item.idtipocontable;
                            detalle.numerocontable = item.numero;
                            detalle.registro       = (short)ix;

                            db.InsertOrReplace(detalle);
                        }

                        db.CommitTransaction();
                    }
                    catch (Exception)
                    {
                        db.RollbackTransaction();
                        throw;
                    }
                }
            }


            return(i);
        }
Esempio n. 2
0
        public int Grabar(cliente item)
        {
            int i = 0;

            PersonaPr.Instancia.Grabar(item.fkpersona);
            using (ispDB db = new ispDB())
            {
                try
                {
                    db.BeginTransaction();
                    if (item.idpersona == 0)
                    {
                        item.idpersona = item.fkpersona.id;
                    }
                    db.InsertOrReplace(item);
                    db.CommitTransaction();
                }
                catch (Exception)
                {
                    db.RollbackTransaction();
                    throw;
                }
                return(i);
            }
        }
Esempio n. 3
0
        public int Borrar(object unItem)
        {
            contable item = (contable)unItem;
            int      i    = 0;

            //VERIFICAMOS PERIODO
            if (PeriodoPr.PeriodoCerrado((short)item.fecha.Year, (short)item.fecha.Month))
            {
                throw new Exception("Periodo cerrado no se puede continuar");
            }

            //CONTRA ASIENTO PARA ANULAR CONTABLE
            using (ispDB db = new ispDB())
            {
                try
                {
                    db.BeginTransaction();
                    item.esanulado = true;
                    i = db.InsertOrReplace(item);
                    db.CommitTransaction();
                }
                catch (Exception)
                {
                    db.RollbackTransaction();
                    throw;
                }
            }
            return(i);
        }
Esempio n. 4
0
        public int Grabar(IEnumerable <menu> items)
        {
            int i = 0; short id = 0;

            using (ispDB db = new ispDB())
            {
                try
                {
                    id = db.menus.Max(x => (short?)x.id) ?? (short)0;
                    foreach (menu item in items.Where(x => x.Modificado))
                    {
                        //GRABAMOS MENU
                        if (item.id == 0)
                        {
                            item.id = ++id;
                        }
                        i = db.InsertOrReplace(item);
                        //GRABAMOS DETALLES
                        db.columnasgrids.Where(x => x.idmenu == item.id).Delete();
                        foreach (columnasgrid item1 in item.fkcolumnasgrid)
                        {
                            if (item1.idmenu == 0)
                            {
                                item1.idmenu = item.id;
                            }
                            i = db.InsertOrReplace(item1);
                        }
                    }
                }
                catch (Exception)
                {
                    throw;
                }
            }

            if (i == 0)
            {
                throw new Exception("Error de concurrencia, por favor vuelva a realizar la transaccion.");
            }
            return(i);
        }
Esempio n. 5
0
        public int Grabar(venta item)
        {
            int i = 0;

            using (ispDB db = new ispDB())
            {
                try
                {
                    db.BeginTransaction();
                    PagoPr.Instancia.Grabar(item.fkidentificadorespago.fkconveniospago);
                    if (item.id == 0)
                    {
                        item.id = db.ventas.Max(x => x.id);
                        item.id++;
                    }
                    i = db.InsertOrReplace(item);

                    db.detallesventas.Where(x => x.idventa == item.id).Delete();

                    for (int ix = 0; ix < item.fkdetallesventa.Count(); ix++)
                    {
                        detalleventa detalle = item.fkdetallesventa.ElementAt(ix);
                        if (detalle.idventa == 0)
                        {
                            detalle.idventa = item.id;
                        }
                        db.InsertOrReplace(detalle);
                    }
                    db.CommitTransaction();
                }
                catch (Exception)
                {
                    db.RollbackTransaction();
                    throw;
                }
            }
            return(i);
        }
Esempio n. 6
0
        /// <summary>
        /// Graba una lista de registros que generalmente proviene de un DataSource tipo Object
        /// </summary>
        /// <param name="lista">De tipo BindingListView contenedora de los registros</param>
        /// <returns>Numero generado para PK en Insert o registros afectados en Update</returns>
        public int Grabar(IEnumerable <sucursal> items)
        {
            int i = 0; int n = 0;

            items = items.Where(x => x.Modificado == true).ToList();
            if (items.Count() == 0)
            {
                return(0);
            }
            using (ispDB db = new ispDB())
            {
                try
                {
                    db.BeginTransaction();
                    n = db.sucursales.Max(x => (int?)x.id) ?? 1;
                    foreach (var item in items)
                    {
                        if (item.id == 0)
                        {
                            item.id = ++n;
                        }
                        i = db.InsertOrReplace(item);
                        db.telefonossucursales.Where(x => x.idsucursal == item.id).Delete();
                        foreach (var item1 in item.fktelefonossucursal)
                        {
                            if (item1.idsucursal == 0)
                            {
                                item1.idsucursal = item.id;
                            }
                            db.Insert(item1);
                        }
                    }
                    db.CommitTransaction();
                }
                catch (Exception)
                {
                    db.RollbackTransaction();
                    throw;
                }
            }
            if (i == 0)
            {
                throw new Exception("Error de concurrencia, por favor vuelva a realizar la transaccion.");
            }
            return(i);
        }
Esempio n. 7
0
 public static int GrabarListaT<T, V>(this IEnumerable<T> lista, Expression<Func<T, V>> propiedadMax) where T : Instrumental1
 {
     int i = 0; int x = 0;
     PropertyInfo campo = null;
     if (lista.Count() == 0)
         return 0;
     using (ispDB db = new ispDB())
     {
         try
         {
             object n = default(V);
             db.BeginTransaction();
             if (propiedadMax != null)
             {
                 campo = GetPropertyInfo(lista.ElementAt(0), propiedadMax);
                 n = typeof(Extenciones).GetMethod("ToNullableExpression")
                     .MakeGenericMethod(new Type[] { typeof(T), typeof(V) })
                     .Invoke(null, new object [] { propiedadMax, db.GetTable<T>() });
                 //n = db.GetTable<T>().Max(expr);
                 if (n == null)
                     n = default(V);
             }
             foreach (T item in lista)
             {
                 if (propiedadMax != null)
                 {
                     if (campo.GetValue(item, null).Equals(default(V)))
                     {
                         n = Calculator<V>.Add((V)n, (V)Convert.ChangeType(1, typeof(V)));
                         campo.SetValue(item, n, null);
                     }
                 }
                 i = db.InsertOrReplace(item);
                 if (i == 0)
                     i = x;
             }
             db.CommitTransaction();
         }
         catch (Exception)
         {
             db.RollbackTransaction();
             throw;
         }
     }
     return i;
 }
Esempio n. 8
0
        public int Borrar(cliente item)
        {
            int i = 0;

            item.fkpersona.idestadopersona = 2;
            using (ispDB db = new ispDB())
            {
                try
                {
                    db.BeginTransaction();
                    i = db.InsertOrReplace(item.fkpersona);
                    db.CommitTransaction();
                }
                catch (Exception)
                {
                    db.RollbackTransaction();
                    throw;
                }
            }
            return(i);
        }
Esempio n. 9
0
 public static int GrabarObjetoT<T, V>(this T objeto, Expression<Func<T, V>> propiedadMax) where T : Instrumental1
 {
     int i = 0;
     PropertyInfo campo = null;
     using (ispDB db = new ispDB())
     {
         try
         {
             //DEFINIMOS VALOR DEFAULT PARA 'N' (VALOR MAX DE LA TABLA SEGUN EXPRESION)
             object n = default(V);
             db.BeginTransaction();
             if (propiedadMax != null)
             {
                 //OBTENER CAMPO SEGUN EXPRESION
                 campo = GetPropertyInfo(objeto, propiedadMax);
                 //CONVERTIR EXPRESION EN EXPRESION NULL PARA OBTENER NULL EN CASOS QUE HO HAY REGISTROS
                 n = typeof(Extenciones).GetMethod("ToNullableExpression")
                     .MakeGenericMethod(new Type[] { typeof(T), typeof(V) })
                     .Invoke(null, new object[] { propiedadMax, db.GetTable<T>() });
                 //n = db.GetTable<T>().Max(propiedadMax);
                 //SI REGISTRO CONTIENE CERO EN SU CAMPO SEGUN EXPRESION SE ASIGNA EL VALOR SUMANDO 1
                 if (campo.GetValue(objeto, null).Equals(default(V)))
                 {
                     n = Calculator<V>.Add((V)n, (V)Convert.ChangeType(1, typeof(V)));
                     campo.SetValue(objeto, n, null);
                 }
             }
             //ALMACENAMOS EL REGISTRO
             i = db.InsertOrReplace(objeto);
             db.CommitTransaction();
         }
         catch (Exception)
         {
             db.RollbackTransaction();
             throw;
         }
     }
     return i;
 }