Ejemplo n.º 1
0
 public static string add_DetallePromocion(DetallePromocion d)
 {
     return "{" +
         '"' + "IdPromocion" + '"' + ": " + d.IdPromocion.ToString() + ',' +
         '"' + "IdDetallePromocion" + '"' + ": " + d.IdDetallePromocion.ToString() + ',' +
         '"' + "Cantidad" + '"' + ": " + d.Cantidad.ToString() + ',' +
         '"' + "PrecioUnitario" + '"' + ": " + d.PrecioUnitario.ToString() + ',' +
         '"' + "IdProducto" + '"' + ": " + d.IdProducto.ToString() +
         "}";
 }
Ejemplo n.º 2
0
        public ResponseBD add_DetallePromocion(DetallePromocion d)
        {
            try
            {
                ResponseBD response = new ResponseBD();

                string ConnString = ConfigurationManager.ConnectionStrings["barabaresConnectionString"].ConnectionString;
                using (SqlConnection SqlConn = new SqlConnection(ConnString))
                {
                    try
                    {
                        SqlConn.Open();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                        response.Flujo = Constantes.FALLA;
                        response.Mensaje = "Error al abrir la conexión a BD";
                        return response;
                    }

                    SqlCommand sqlCmd = new SqlCommand("PROMOCION_DETALLE_INSERT", SqlConn);
                    sqlCmd.CommandType = CommandType.StoredProcedure;

                    SqlParameter flujo = new SqlParameter("@opsFlujo", SqlDbType.VarChar)
                    {
                        Direction = ParameterDirection.Output,
                        Size = 10

                    };

                    SqlParameter mensaje = new SqlParameter("@opsMsj", SqlDbType.VarChar)
                    {
                        Direction = ParameterDirection.Output,
                        Size = 100
                    };

                    sqlCmd.Parameters.Add("@ipnCantidad", SqlDbType.Int).Value = d.Cantidad;
                    sqlCmd.Parameters.Add("@ipnPrecioUnitario", SqlDbType.Real).Value = d.PrecioUnitario;
                    sqlCmd.Parameters.Add("@ipnIdProducto", SqlDbType.Int).Value = d.IdProducto;
                    sqlCmd.Parameters.Add("@ipnIdPromocion", SqlDbType.Int).Value = d.IdPromocion;
                    sqlCmd.Parameters.Add(flujo);
                    sqlCmd.Parameters.Add(mensaje);

                    sqlCmd.ExecuteNonQuery();

                    response.Flujo = flujo.Value.ToString();
                    response.Mensaje = mensaje.Value.ToString();

                    SqlConn.Close();

                }

                return response;
            }
            catch (Exception ex)
            {
                LogBarabares b = new LogBarabares()
                {
                    Accion = Constantes.LOG_CREAR,
                    Servicio = Constantes.Add_DetallePromocion,
                    Input = "", //TODO
                    Descripcion = ex.ToString(),
                    Clase = (d == null) ? "null" : d.GetType().Name,
                    Aplicacion = Constantes.ENTORNO_SERVICIOS,
                    Estado = Constantes.FALLA,
                    Ip = "",
                    IdUsuario = 1 //TODO: obtener usuario de la sesión

                };

                Utils.add_LogBarabares(b);

                ResponseBD response = new ResponseBD();
                response.Flujo = Constantes.FALLA;
                response.Mensaje = "Error al abrir la conexión a BD";
                return response;
            }
        }
Ejemplo n.º 3
0
        public List<DetallePromocion> selectAll_DetallePromocion()
        {
            try
            {
                List<DetallePromocion> detallePromociones = new List<DetallePromocion>();
                DetallePromocion d;

                DataTable dt = new DataTable();
                SqlDataAdapter sda = new SqlDataAdapter();
                string ConnString = ConfigurationManager.ConnectionStrings["barabaresConnectionString"].ConnectionString;
                using (SqlConnection SqlConn = new SqlConnection(ConnString))
                {
                    try
                    {
                        SqlConn.Open();
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                        return detallePromociones;
                    }

                    SqlCommand sqlCmd = new SqlCommand("PROMOCION_DETALLE_SELECT_ALL", SqlConn);
                    sqlCmd.CommandType = CommandType.StoredProcedure;
                    sda.SelectCommand = sqlCmd;
                    sda.Fill(dt);
                    SqlConn.Close();
                    sqlCmd.Dispose();
                    sda.Dispose();
                }

                DataRow[] rows = dt.Select();

                for (int i = 0; i < rows.Length; i++)
                {
                    d = Utils.detallePromocion_parse(rows[i]);
                    detallePromociones.Add(d);
                }

                return detallePromociones;
            }
            catch (Exception ex)
            {
                DetallePromocion d = new DetallePromocion();

                LogBarabares b = new LogBarabares()
                {
                    Accion = Constantes.LOG_LISTAR,
                    Servicio = Constantes.SelectAll_DetallePromocion,
                    Input = "",
                    Descripcion = ex.ToString(),
                    Clase = d.GetType().Name,
                    Aplicacion = Constantes.ENTORNO_SERVICIOS,
                    Estado = Constantes.FALLA,
                    Ip = "",
                    IdUsuario = 1 //TODO: obtener usuario de la sesión

                };

                Utils.add_LogBarabares(b);

                return new List<DetallePromocion>();
            }
        }
Ejemplo n.º 4
0
        public static DetallePromocion detallePromocion_parse(DataRow r)
        {
            DetallePromocion d = new DetallePromocion();
            d.IdPromocion = Int32.Parse(r["idPromocion"].ToString());
            d.IdDetallePromocion = Int32.Parse(r["idDetallePromocion"].ToString());
            d.Cantidad = Int32.Parse(r["cantidad"].ToString());
            d.PrecioUnitario = Double.Parse(r["precioUnitario"].ToString());
            d.IdProducto = Int32.Parse(r["idProducto"].ToString());

            return d;
        }