Example #1
0
        private BE.Prestamo PrestamoUItoBE(BE.UI.Prestamo UiPrestamo)
        {
            var bePrestamo = new BE.Prestamo();

            bePrestamo.IdPrestamo     = UiPrestamo.IdPrestamo;
            bePrestamo.Fecha          = UiPrestamo.Fecha;
            bePrestamo.CodigoEmpleado = UiPrestamo.CodigoEmpleado;
            bePrestamo.Motivo         = UiPrestamo.Motivo;
            bePrestamo.Monto          = UiPrestamo.Monto;
            bePrestamo.Pagado         = UiPrestamo.Pagado;
            bePrestamo.NumeroCuotas   = UiPrestamo.NumeroCuotas;
            return(bePrestamo);
        }
Example #2
0
        private BE.UI.Prestamo PrestamoBEtoUI(BE.Prestamo bePrestamo)
        {
            var UiPrestamo = new BE.UI.Prestamo();

            UiPrestamo.IdPrestamo     = bePrestamo.IdPrestamo;
            UiPrestamo.Fecha          = bePrestamo.Fecha;
            UiPrestamo.CodigoEmpleado = bePrestamo.CodigoEmpleado;
            UiPrestamo.Motivo         = bePrestamo.Motivo;
            UiPrestamo.Monto          = bePrestamo.Monto;
            UiPrestamo.Pagado         = bePrestamo.Pagado;
            UiPrestamo.NumeroCuotas   = bePrestamo.NumeroCuotas;
            return(UiPrestamo);
        }
Example #3
0
        public List <BE.Prestamo> Listar(int anho, int mes, bool conCuotas = false)
        {
            var lstPrestamos = new List <BE.Prestamo>();

            try
            {
                string sp = "SpTbPrestamoListar";

                using (SqlConnection cnn = new SqlConnection(ConnectionManager.ConexionLocal))
                {
                    cnn.Open();

                    SqlCommand cmd = new SqlCommand(sp, cnn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@ANHO", anho));
                    cmd.Parameters.Add(new SqlParameter("@MES", mes));

                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        var bePrestamo = new BE.Prestamo();

                        bePrestamo.IdPrestamo     = int.Parse(reader["IdPrestamo"].ToString());
                        bePrestamo.Fecha          = DateTime.Parse(reader["Fecha"].ToString());
                        bePrestamo.CodigoEmpleado = reader["CodigoEmpleado"].ToString();
                        bePrestamo.Motivo         = reader["Motivo"].ToString();
                        bePrestamo.Monto          = double.Parse(reader["Monto"].ToString());
                        bePrestamo.NumeroCuotas   = int.Parse(reader["Cuotas"].ToString());
                        bePrestamo.Pagado         = bool.Parse(reader["Pagado"].ToString());

                        if (conCuotas == true)
                        {
                            bePrestamo.Cuotas = this.ListarCuotas(bePrestamo.IdPrestamo);
                        }

                        lstPrestamos.Add(bePrestamo);
                    }
                }

                return(lstPrestamos);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        public BE.Prestamo Obtener(int idPrestamo, bool conCuotas = false)
        {
            BE.Prestamo bePrestamo = null;
            try
            {
                string sp = "SpTbPrestamoObtener";

                using (SqlConnection cnn = new SqlConnection(ConnectionManager.ConexionLocal))
                {
                    cnn.Open();

                    SqlCommand cmd = new SqlCommand(sp, cnn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add(new SqlParameter("@IDPRESTAMO", idPrestamo));

                    SqlDataReader reader = cmd.ExecuteReader();
                    if (reader.Read())
                    {
                        bePrestamo = new BE.Prestamo();

                        bePrestamo.IdPrestamo     = int.Parse(reader["IdPrestamo"].ToString());
                        bePrestamo.Fecha          = DateTime.Parse(reader["Fecha"].ToString());
                        bePrestamo.CodigoEmpleado = reader["CodigoEmpleado"].ToString();
                        bePrestamo.Motivo         = reader["Motivo"].ToString();
                        bePrestamo.Monto          = double.Parse(reader["Monto"].ToString());
                        bePrestamo.Pagado         = bool.Parse(reader["Pagado"].ToString());
                        bePrestamo.NumeroCuotas   = int.Parse(reader["Cuotas"].ToString());

                        if (conCuotas == true)
                        {
                            bePrestamo.Cuotas = this.ListarCuotas(idPrestamo);
                        }
                    }
                }

                return(bePrestamo);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #5
0
        public bool Actualizar(BE.Prestamo bePrestamo,
                               List <BE.PrestamoCuota> lstBeCuotasNuevas,
                               List <BE.PrestamoCuota> lstBeCuotasEliminadas)
        {
            SqlConnection  cnn = null;
            SqlTransaction tns = null;

            try
            {
                int    rowsAffected = 0;
                string sp           = "";

                using (cnn = new SqlConnection(ConnectionManager.ConexionLocal))
                {
                    cnn.Open();

                    tns = cnn.BeginTransaction();

                    SqlCommand cmd = null;

                    #region Cabecera
                    sp = "SpTbPrestamoActualizar";

                    cmd             = new SqlCommand(sp, cnn);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Transaction = tns;

                    cmd.Parameters.Add(new SqlParameter("@IDPRESTAMO", bePrestamo.IdPrestamo));
                    cmd.Parameters.Add(new SqlParameter("@FECHA", bePrestamo.Fecha));
                    cmd.Parameters.Add(new SqlParameter("@CODIGOEMPLEADO", bePrestamo.CodigoEmpleado));
                    cmd.Parameters.Add(new SqlParameter("@MOTIVO", bePrestamo.Motivo));
                    cmd.Parameters.Add(new SqlParameter("@MONTO", bePrestamo.Monto));
                    cmd.Parameters.Add(new SqlParameter("@CUOTAS", bePrestamo.NumeroCuotas));
                    cmd.Parameters.Add(new SqlParameter("@PAGADO", bePrestamo.Pagado));

                    rowsAffected += cmd.ExecuteNonQuery();
                    #endregion

                    #region Agregar cuotas

                    sp = "SpTbPrestamoCuotaInsertar";
                    for (int i = 0; i < lstBeCuotasNuevas.Count; i++)
                    {
                        cmd             = new SqlCommand(sp, cnn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Transaction = tns;

                        cmd.Parameters.Add(new SqlParameter("@IDPRESTAMOCUOTA", lstBeCuotasNuevas[i].IdPrestamoCuota));
                        cmd.Parameters["@IDPRESTAMOCUOTA"].Direction = ParameterDirection.Output;
                        cmd.Parameters.Add(new SqlParameter("@IDPRESTAMO", bePrestamo.IdPrestamo));
                        cmd.Parameters.Add(new SqlParameter("@FECHA", lstBeCuotasNuevas[i].Fecha));
                        cmd.Parameters.Add(new SqlParameter("@MONTO", lstBeCuotasNuevas[i].Importe));
                        cmd.Parameters.Add(new SqlParameter("@PAGADO", lstBeCuotasNuevas[i].Pagado));

                        rowsAffected += cmd.ExecuteNonQuery();
                        lstBeCuotasNuevas[i].IdPrestamoCuota = int.Parse(cmd.Parameters["@IDPRESTAMOCUOTA"].Value.ToString());
                    }

                    #endregion

                    #region Eliminar cuotas

                    sp = "SpTbPrestamoCuotaEliminar";
                    for (int i = 0; i < lstBeCuotasEliminadas.Count; i++)
                    {
                        cmd             = new SqlCommand(sp, cnn);
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Transaction = tns;

                        cmd.Parameters.Add(new SqlParameter("@IDPRESTAMOCUOTA", lstBeCuotasEliminadas[i].IdPrestamoCuota));

                        rowsAffected += cmd.ExecuteNonQuery();
                    }

                    #endregion

                    if (tns != null)
                    {
                        tns.Commit();
                    }
                }

                return(rowsAffected > 0);
            }
            catch (Exception ex)
            {
                if (tns != null)
                {
                    tns.Rollback();
                }

                throw ex;
            }
        }