Exemple #1
0
        public void InsertSaldo(Modelo.Historico obj)
        {
            SqlConnection conn = new SqlConnection(connectionString);

            conn.Open();
            SqlCommand com = conn.CreateCommand();
            SqlCommand cmd = new SqlCommand("INSERT INTO Historico (Data_Compra, Preco, Saldo, id_Cliente) VALUES(@Data, @Preco, @Saldo, @Cliente)", conn);

            cmd.Parameters.AddWithValue("@Data", obj.Data_Compra);
            cmd.Parameters.AddWithValue("@Preco", obj.Preco);
            cmd.Parameters.AddWithValue("@Saldo", obj.Saldo);
            cmd.Parameters.AddWithValue("@Cliente", obj.id_Cliente);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
Exemple #2
0
        public List <Modelo.Historico> Select(int id_cliente)
        {
            Modelo.Historico        aHistorico;
            List <Modelo.Historico> aListHistorico = new List <Modelo.Historico>();
            SqlConnection           conn           = new SqlConnection(connectionString);

            conn.Open();
            SqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = "Select * from Historico where id_cliente = @id";
            cmd.Parameters.AddWithValue("@id", id_cliente);
            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    try
                    {
                        aHistorico = new Modelo.Historico(
                            int.Parse(dr["id"].ToString()),
                            DateTime.Parse(dr["Data_Compra"].ToString()),
                            double.Parse(dr["Preco"].ToString()),
                            double.Parse(dr["Saldo"].ToString()),
                            int.Parse(dr["id_Cliente"].ToString()),
                            int.Parse(dr["id_Pacote"].ToString())
                            );
                        aListHistorico.Add(aHistorico);
                    }
                    catch
                    {
                        aHistorico = new Modelo.Historico(
                            int.Parse(dr["id"].ToString()),
                            DateTime.Parse(dr["Data_Compra"].ToString()),
                            double.Parse(dr["Preco"].ToString()),
                            double.Parse(dr["Saldo"].ToString()),
                            int.Parse(dr["id_Cliente"].ToString()),
                            0
                            );
                        aListHistorico.Add(aHistorico);
                    }
                }
            }
            dr.Close();
            conn.Close();

            return(aListHistorico);
        }