Beispiel #1
0
        public void Inserir(ModeloItemVendas modeloItemVendas)
        {
            MySqlConnection mySqlConnection = new MySqlConnection();

            try
            {
                mySqlConnection.ConnectionString = DadosDaConexao.StringDeConexao;
                mySqlConnection.Open();

                MySqlCommand mySqlCommand = new MySqlCommand();
                mySqlCommand.Connection  = mySqlConnection;
                mySqlCommand.CommandType = CommandType.StoredProcedure;
                mySqlCommand.CommandText = "SP_INSERIR_ITENSVENDAS";

                mySqlCommand.Parameters.AddWithValue("@cod_prod", modeloItemVendas.cod_prod);
                mySqlCommand.Parameters.AddWithValue("@cod_venda", modeloItemVendas.cod_venda);
                mySqlCommand.Parameters.AddWithValue("@quantidade", modeloItemVendas.quantidade);
                mySqlCommand.Parameters.AddWithValue("@preco_unitario", modeloItemVendas.preco_unitario);
                mySqlCommand.Parameters.AddWithValue("@valor_total", modeloItemVendas.valor_total);

                modeloItemVendas.cod_venda = Convert.ToInt32(mySqlCommand.ExecuteScalar());
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            finally
            {
                mySqlConnection.Close();
            }
        }
        public void BLLInserirItensVendas(ModeloItemVendas modeloItemVendas)
        {
            if (modeloItemVendas.cod_prod <= 0)
            {
                throw new Exception("O Código Do Produto Não Pode Ser Negativo");
            }

            if (modeloItemVendas.cod_venda <= 0)
            {
                throw new Exception("O Código Da Venda Não Pode Ser Negativo");
            }

            if (modeloItemVendas.quantidade <= 0)
            {
                throw new Exception("O Campo Quantidade Não Pode Ser Negativo");
            }

            if (modeloItemVendas.preco_unitario <= 0)
            {
                throw new Exception("O Campo Quantidade Não Pode Ser Negativo");
            }

            if (modeloItemVendas.valor_total <= 0)
            {
                throw new Exception("O Campo Valor Total Não Pode Ser Negativo");
            }

            dallModeloItensVendas.Inserir(modeloItemVendas);
        }
Beispiel #3
0
        public ModeloItemVendas CarregaModeloItemVendas( )
        {
            ModeloItemVendas modeloItemVendas = new ModeloItemVendas();

            MySqlDataReader mySqlDataReader = null;

            MySqlConnection mySqlConnection = new MySqlConnection();

            try
            {
                mySqlConnection.ConnectionString = DadosDaConexao.StringDeConexao;
                mySqlConnection.Open();

                MySqlCommand mySqlCommand = new MySqlCommand();
                mySqlCommand.Connection  = mySqlConnection;
                mySqlCommand.CommandType = CommandType.StoredProcedure;
                mySqlCommand.CommandText = "SP_ListarTodos_ItensVendas";

                mySqlDataReader = mySqlCommand.ExecuteReader();

                if (mySqlDataReader.HasRows)
                {
                    mySqlDataReader.Read();

                    modeloItemVendas.cod_prod       = Convert.ToInt32(mySqlDataReader["cod_prod"]);
                    modeloItemVendas.cod_venda      = Convert.ToInt32(mySqlDataReader["cod_venda"]);
                    modeloItemVendas.quantidade     = Convert.ToInt32(mySqlDataReader["quantidade"]);
                    modeloItemVendas.preco_unitario = Convert.ToDecimal(mySqlDataReader["preco_unitario"]);
                    modeloItemVendas.valor_total    = Convert.ToDecimal(mySqlDataReader["valor_total"]);
                }
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            finally
            {
                mySqlConnection.Close();
                mySqlDataReader.Close();
            }

            return(modeloItemVendas);
        }