Skip to content

Commit

Permalink
Merge branch 'refs/heads/tirar_antiga_vendas'
Browse files Browse the repository at this point in the history
  • Loading branch information
GabR36 committed Jan 2, 2024
2 parents 8fbbd7b + e1d55b8 commit 2c7f461
Show file tree
Hide file tree
Showing 9 changed files with 4 additions and 303 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
qt_add_executable(QEstoqueLoja
MANUAL_FINALIZATION
${PROJECT_SOURCES}
produto.h produto.cpp

alterarproduto.h alterarproduto.cpp alterarproduto.ui
vender.h vender.cpp vender.ui

vendas.h vendas.cpp vendas.ui
venda.h venda.cpp venda.ui
)
Expand Down
107 changes: 0 additions & 107 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
#include <QFile>
#include <QTextStream>
#include <QMessageBox>
#include "produto.h"
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlQuery>
#include <QSqlQueryModel>
#include "alterarproduto.h"
#include "QItemSelectionModel"
#include "vender.h"
#include <qsqltablemodel.h>
#include "vendas.h"
#include <QDoubleValidator>

QSqlTableModel *vendasModel;
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
Expand All @@ -34,12 +31,6 @@ MainWindow::MainWindow(QWidget *parent)
} else {
qDebug() << "Erro ao criar tabela: ";
}
query.exec("CREATE TABLE vendas (id INTEGER PRIMARY KEY AUTOINCREMENT, produto_id INTEGER, quantidade INTEGER, data_hora DATETIME DEFAULT CURRENT_TIMESTAMP)");
if (query.isActive()) {
qDebug() << "Tabela de vendas criada com sucesso!";
} else {
qDebug() << "Erro ao criar tabela de vendas: ";
}
query.exec("CREATE TABLE vendas2 (id INTEGER PRIMARY KEY AUTOINCREMENT, cliente TEXT, data_hora DATETIME DEFAULT CURRENT_TIMESTAMP, total DECIMAL(10,2))");
if (query.isActive()) {
qDebug() << "Tabela de vendas2 criada com sucesso!";
Expand Down Expand Up @@ -67,16 +58,6 @@ MainWindow::MainWindow(QWidget *parent)
QModelIndex firstIndex = model->index(0, 0);
ui->Tview_Produtos->selectionModel()->select(firstIndex, QItemSelectionModel::Select);

QSqlTableModel *vendasModel;
vendasModel = new QSqlTableModel(this);
vendasModel->setTable("vendas");
vendasModel->select(); // Carrega os dados da tabela de vendas

// Configure o QTableView para exibir as vendas
ui->tableViewVendas->setModel(vendasModel);
ui->tableViewVendas->setEditTriggers(QAbstractItemView::NoEditTriggers); // Impede a edição das células
ui->tableViewVendas->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); // Expande colunas para ajustar a largura

// ajustar tamanho colunas
// coluna descricao
ui->Tview_Produtos->setColumnWidth(2, 200);
Expand All @@ -102,10 +83,6 @@ void MainWindow::atualizarTableview(){
model->setQuery("SELECT * FROM produtos");
ui->Tview_Produtos->setModel(model);
db.close();


// model->setQuery("SELECT * FROM vendas");
// ui->tableViewVendas->setModel(model);
}

void MainWindow::on_Btn_Enviar_clicked()
Expand Down Expand Up @@ -218,90 +195,6 @@ void MainWindow::on_Btn_Pesquisa_clicked()
}


void MainWindow::on_Btn_Vender_clicked()
{
QString idVenda = ui->Ledit_VendaId->text();
QString quantVenda = ui->Ledit_VendaQuant->text();
compravenda(idVenda, quantVenda, false);

ui->tableViewVendas->setModel(vendasModel);






}


void MainWindow::on_Btn_Comprar_clicked()
{
QString idVenda = ui->Ledit_VendaId->text();
QString quantVenda = ui->Ledit_VendaQuant->text();
compravenda(idVenda, quantVenda, true);


}


void MainWindow::compravenda(QString idVenda, QString quantVenda, bool compravenda){
QString maismenos;
if (compravenda){
maismenos = "+";
} else {
maismenos = "-";
}
// alterar banco de dados
if(!db.open()){
qDebug() << "erro ao abrir banco de dados. botao comprar.";
}
QSqlQuery query;

query.prepare("UPDATE produtos SET quantidade = quantidade " + maismenos + " :valor1 WHERE id = :valor2");
query.bindValue(":valor1", quantVenda);
query.bindValue(":valor2", idVenda);
if (query.exec()) {
qDebug() << "Inserção bem-sucedida!";
} else {
qDebug() << "Erro na inserção: ";
}

query.prepare("UPDATE produtos SET quantidade = quantidade " + maismenos + " :valor1 WHERE id = :valor2");
query.bindValue(":valor1", quantVenda);
query.bindValue(":valor2", idVenda);
if (query.exec()) {
qDebug() << "Atualização de quantidade bem-sucedida!";
} else {
qDebug() << "Erro na atualização de quantidade: ";
}


query.prepare("INSERT INTO vendas (produto_id, quantidade) VALUES (:valor1, :valor2)");
query.bindValue(":valor1", idVenda);
query.bindValue(":valor2", quantVenda);
if (query.exec()) {
qDebug() << "Venda registrada com sucesso!";
} else {
qDebug() << "Erro ao registrar venda: ";
}

// Atualizar a tabela de produtos
query.prepare("UPDATE produtos SET quantidade = quantidade " + maismenos + " :valor1 WHERE id = :valor2");
query.bindValue(":valor1", quantVenda);
query.bindValue(":valor2", idVenda);
if (query.exec()) {
qDebug() << "Atualização de quantidade bem-sucedida!";
} else {
qDebug() << "Erro na atualização de quantidade: ";
}
// mostrar na tableview
atualizarTableview();
QSqlDatabase::database().close();
// limpar campos para nova inserção
ui->Ledit_VendaQuant->clear();
ui->Ledit_VendaId->clear();
//adsa
}


void MainWindow::on_Btn_Alterar_clicked()
Expand Down
8 changes: 1 addition & 7 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QMainWindow>
#include <QStandardItemModel>
#include <vector>
#include "produto.h"
#include <QSqlDatabase>
#include <QSqlQueryModel>

Expand All @@ -31,17 +30,12 @@ private slots:

void on_Btn_Pesquisa_clicked();

void on_Btn_Vender_clicked();

void on_Btn_Comprar_clicked();

void on_Btn_Alterar_clicked();

void on_Btn_Venda_clicked();

private:
Ui::MainWindow *ui;
void compravenda(QString idVenda, QString quantVenda, bool compravenda);
Ui::MainWindow *ui;



Expand Down
82 changes: 1 addition & 81 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>820</width>
<height>600</height>
<height>439</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -64,86 +64,6 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>40</x>
<y>420</y>
<width>239</width>
<height>120</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<layout class="QVBoxLayout" name="verticalLayout_8">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Quantidade: </string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="Ledit_VendaQuant"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string>ID: </string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="Ledit_VendaId"/>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="Btn_Vender">
<property name="text">
<string>Vender</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="Btn_Comprar">
<property name="text">
<string>Comprar</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>330</x>
<y>400</y>
<width>421</width>
<height>151</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_10">
<item>
<widget class="QLabel" name="label_7">
<property name="text">
<string>Ultimas Vendas:</string>
</property>
</widget>
</item>
<item>
<widget class="QTableView" name="tableViewVendas"/>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
Expand Down
9 changes: 0 additions & 9 deletions produto.cpp

This file was deleted.

16 changes: 0 additions & 16 deletions produto.h

This file was deleted.

14 changes: 0 additions & 14 deletions vender.cpp

This file was deleted.

22 changes: 0 additions & 22 deletions vender.h

This file was deleted.

45 changes: 0 additions & 45 deletions vender.ui

This file was deleted.

0 comments on commit 2c7f461

Please sign in to comment.