Skip to content

Commit

Permalink
Commit 26092020
Browse files Browse the repository at this point in the history
  • Loading branch information
Minh Đức Trương committed Sep 25, 2020
1 parent f67b9ac commit e4e4a5b
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 57 deletions.
8 changes: 0 additions & 8 deletions QuanLyChiTieu/adduser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ AddUser::AddUser(QWidget *parent) :

this->setWindowTitle(QString::fromUtf8("Đăng ký"));

//DataBase
QSqlDatabase myDB = QSqlDatabase::addDatabase("QODBC");

myDB.setDatabaseName("DRIVER={SQL Server Native Client 11.0};SERVER=DEREKPC;DATABASE=DO_AN_CHI_TIEU;UID=sa;PWD=derek123;WSID=.;Trusted_connection=yes");

bool connected = myDB.open();

if(!connected) QMessageBox::warning(this,"Chú ý",QString::fromUtf8("Lỗi! Không kết nối được CSDL!!"));
}

AddUser::~AddUser()
Expand Down
2 changes: 2 additions & 0 deletions QuanLyChiTieu/chitieu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ ChiTieu::ChiTieu(QString DanhMuc, QString username,QWidget *parent ) :
ui(new Ui::ChiTieu)
{
ui->setupUi(this);

this->setWindowTitle(QString::fromUtf8("Chi tiêu"));
//

this->Username = username;
Expand Down
73 changes: 56 additions & 17 deletions QuanLyChiTieu/expensetracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -591,18 +591,7 @@ void ExpenseTracker::on_btn_page4_ThemTK_TK_clicked()
/// Insert bảng TietKiem
int MTK = TaiKhoanQL.LayMaTaiKhoan(TenDangNhap, TenTaiKhoan);

qry.prepare("INSERT INTO TietKiem ( TenTietKiem, SoDu, MucTieu, MaTaiKhoan, TenChu )" "VALUES ( :TenTietKiem, :SoDu, :MucTieu, :MaTaiKhoan, :TenChu )");

qry.bindValue(":TenTietKiem", TenTaiKhoan);
qry.bindValue(":SoDu", SoDu);
qry.bindValue(":MucTieu", MucTieu);
qry.bindValue(":MaTaiKhoan", MTK);
qry.bindValue(":TenChu", TenDangNhap);

if( !qry.exec() ){
QMessageBox::warning(this,"Chú ý",QString::fromUtf8("Không thể thêm tài khoản!!"));
return;
}
TietKiemQL.ThemTietKiem(TenDangNhap, TenTaiKhoan, SoDu, MucTieu, MTK);

QMessageBox::information(this, QString::fromUtf8("Thông báo"), QString::fromUtf8("Bạn đã thêm tài khoản thành công!!"));

Expand Down Expand Up @@ -758,7 +747,7 @@ void ExpenseTracker::on_btn_page4_XoaTaiKhoan_clicked()
}

QMessageBox::StandardButton reply;
reply = QMessageBox::question(this, "Cảnh báo", "Bạn có chắc muốn xoá tài khoản "+TenTaiKhoan+" không", QMessageBox::Yes|QMessageBox::No);
reply = QMessageBox::question(this, "Cảnh báo", "Bạn có chắc muốn xoá tài khoản "+TenTaiKhoan+"? Mọi chi tiêu, thu nhập liên quan đến tài khoản này sẽ vẫn còn được giữ lại!", QMessageBox::Yes|QMessageBox::No);

if( reply == QMessageBox::Yes ){
QSqlQuery qry;
Expand Down Expand Up @@ -797,6 +786,49 @@ void ExpenseTracker::on_btn_page4_XoaTaiKhoan_clicked()
else return;


}

void ExpenseTracker::on_btn_page4_CapNhat_XemBang_clicked()
{
QString LoaiTaiKhoan;

LoaiTaiKhoan = ui->comboBox_p4_LoaiTaiKhoan_XemBang->currentText();

if( LoaiTaiKhoan == "Thường xuyên(Thẻ, tiền mặt,...)" ){
qryModel = new QSqlQueryModel();
qryModel->setQuery("SELECT Ten AS N'Tên thẻ', SoDu AS N'Số dư' , MoTa AS N'Mô tả' FROM TaiKhoan WHERE TenChu = '"+TenDangNhap+"' AND Loai = N'Thường xuyên(Thẻ, tiền mặt,...)'");
//Chỉnh độ rộng
ui->tableView_page4->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableView_page4->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);

ui->tableView_page4->setModel(qryModel);
ui->tableView_page4->show();
}

if( LoaiTaiKhoan == "Tiết kiệm" ){
qryModel = new QSqlQueryModel();
qryModel->setQuery("SELECT tk1.TenTietKiem AS N'Tên tiết kiệm', tk1.SoDu AS N'Số Dư', tk1.MucTieu AS N'Mục tiêu', tk2.MoTa AS N'Mô Tả' FROM TietKiem tk1 INNER JOIN dbo.TaiKhoan tk2 ON tk1.MaTaiKhoan = tk2.MaTaiKhoan AND tk1.TenChu = '"+TenDangNhap+"' AND tk2.TenChu = '"+TenDangNhap+"' ");
//Chỉnh độ rộng
ui->tableView_page4->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableView_page4->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);

ui->tableView_page4->setModel(qryModel);
ui->tableView_page4->show();
}

if( LoaiTaiKhoan == "Nợ" ){
qryModel = new QSqlQueryModel();
qryModel->setQuery("SELECT tk1.TenNo AS N'Tên khoản nợ', tk1.TienNo AS N'Tiền nợ', tk1.LaiSuat AS N'Lãi suất', format(tk1.KyHan,'dd/MM/yyyy') AS N'Kỳ hạn', tk2.MoTa AS N'Mô tả' FROM Loan tk1 INNER JOIN dbo.TaiKhoan tk2 ON tk1.MaTaiKhoan = tk2.MaTaiKhoan AND tk1.TenChu = '"+TenDangNhap+"' AND tk2.TenChu = '"+TenDangNhap+"' ");
//Chỉnh độ rộng
ui->tableView_page4->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
ui->tableView_page4->verticalHeader()->setSectionResizeMode(QHeaderView::Stretch);

ui->tableView_page4->setModel(qryModel);
ui->tableView_page4->show();
}



}

void ExpenseTracker::on_btn_GiaDinhPic_clicked()
Expand Down Expand Up @@ -1056,19 +1088,19 @@ void ExpenseTracker::on_btn_p2_TimKiemChung_clicked()
QSqlQuery qry;

if( TenDanhMuc == "Tất Cả" && TenTaiKhoan == "Tất Cả" ){
qry.prepare("SELECT TOP 10 SoTien AS N'Số tiền', GhiChu AS N'Mô tả', format(NgayChiTieu,'dd/MM/yyyy') AS N'Thời gian', TenTaiKhoan AS N'Tên tài khoản' FROM KhoanChi WHERE TenChu = '"+TenDangNhap+"' AND GhiChu LIKE N'%"+Key+"%' ORDER BY Year(NgayChiTieu) DESC, Month(NgayChiTieu) DESC, Day(NgayChiTieu) DESC ");
qry.prepare("SELECT TOP 15 SoTien AS N'Số tiền', GhiChu AS N'Mô tả', format(NgayChiTieu,'dd/MM/yyyy') AS N'Thời gian', TenTaiKhoan AS N'Tên tài khoản' FROM KhoanChi WHERE TenChu = '"+TenDangNhap+"' AND GhiChu LIKE N'%"+Key+"%' ORDER BY Year(NgayChiTieu) DESC, Month(NgayChiTieu) DESC, Day(NgayChiTieu) DESC ");
}

if( TenDanhMuc != "Tất Cả" && TenTaiKhoan == "Tất Cả" ){
qry.prepare("SELECT TOP 10 SoTien AS N'Số tiền', GhiChu AS N'Mô tả', format(NgayChiTieu,'dd/MM/yyyy') AS N'Thời gian', TenTaiKhoan AS N'Tên tài khoản' FROM KhoanChi WHERE TenChu = '"+TenDangNhap+"' AND MaDanhMuc = '"+MaDanhMuc+"' AND GhiChu LIKE N'%"+Key+"%' ORDER BY Year(NgayChiTieu) DESC, Month(NgayChiTieu) DESC, Day(NgayChiTieu) DESC ");
qry.prepare("SELECT TOP 15 SoTien AS N'Số tiền', GhiChu AS N'Mô tả', format(NgayChiTieu,'dd/MM/yyyy') AS N'Thời gian', TenTaiKhoan AS N'Tên tài khoản' FROM KhoanChi WHERE TenChu = '"+TenDangNhap+"' AND MaDanhMuc = '"+MaDanhMuc+"' AND GhiChu LIKE N'%"+Key+"%' ORDER BY Year(NgayChiTieu) DESC, Month(NgayChiTieu) DESC, Day(NgayChiTieu) DESC ");
}

if( TenDanhMuc == "Tất Cả" && TenTaiKhoan != "Tất Cả" ){
qry.prepare("SELECT TOP 10 SoTien AS N'Số tiền', GhiChu AS N'Mô tả', format(NgayChiTieu,'dd/MM/yyyy') AS N'Thời gian', TenTaiKhoan AS N'Tên tài khoản' FROM KhoanChi WHERE TenChu = '"+TenDangNhap+"' AND TenTaiKhoan = N'"+TenTaiKhoan+"' AND GhiChu LIKE N'%"+Key+"%' ORDER BY Year(NgayChiTieu) DESC, Month(NgayChiTieu) DESC, Day(NgayChiTieu) DESC ");
qry.prepare("SELECT TOP 15 SoTien AS N'Số tiền', GhiChu AS N'Mô tả', format(NgayChiTieu,'dd/MM/yyyy') AS N'Thời gian', TenTaiKhoan AS N'Tên tài khoản' FROM KhoanChi WHERE TenChu = '"+TenDangNhap+"' AND TenTaiKhoan = N'"+TenTaiKhoan+"' AND GhiChu LIKE N'%"+Key+"%' ORDER BY Year(NgayChiTieu) DESC, Month(NgayChiTieu) DESC, Day(NgayChiTieu) DESC ");
}

if( TenDanhMuc != "Tất Cả" && TenTaiKhoan != "Tất Cả" ){
qry.prepare("SELECT TOP 10 SoTien AS N'Số tiền', GhiChu AS N'Mô tả', format(NgayChiTieu,'dd/MM/yyyy') AS N'Thời gian', TenTaiKhoan AS N'Tên tài khoản' FROM KhoanChi WHERE TenChu = '"+TenDangNhap+"' AND MaDanhMuc = '"+MaDanhMuc+"' AND TenTaiKhoan = N'"+TenTaiKhoan+"' AND GhiChu LIKE N'%"+Key+"%' ORDER BY Year(NgayChiTieu) DESC, Month(NgayChiTieu) DESC, Day(NgayChiTieu) DESC ");
qry.prepare("SELECT TOP 15 SoTien AS N'Số tiền', GhiChu AS N'Mô tả', format(NgayChiTieu,'dd/MM/yyyy') AS N'Thời gian', TenTaiKhoan AS N'Tên tài khoản' FROM KhoanChi WHERE TenChu = '"+TenDangNhap+"' AND MaDanhMuc = '"+MaDanhMuc+"' AND TenTaiKhoan = N'"+TenTaiKhoan+"' AND GhiChu LIKE N'%"+Key+"%' ORDER BY Year(NgayChiTieu) DESC, Month(NgayChiTieu) DESC, Day(NgayChiTieu) DESC ");
}

if( qry.exec() ){
Expand Down Expand Up @@ -1173,7 +1205,12 @@ void ExpenseTracker::on_btn_p3_XacNhan_clicked()
//Thêm trong bảng TietKiem nếu có
if( TaiKhoanQL.LayLoaiTaiKhoan(TenDangNhap, TenTaiKhoan) == "Tiết kiệm" ){
TietKiemQL.CapNhatSoDu(TenDangNhap, MTK, SoDuTK);

if( TietKiemQL.KiemTraMucTieu(TenDangNhap, MTK) >= 0 ){
QMessageBox::information(this,"Chúc mừng",QString::fromUtf8("Bạn đã đạt mục tiêu tiết kiệm !!"));
}
}

//done

/// Cộng tiền vào tài khoản
Expand Down Expand Up @@ -1240,3 +1277,5 @@ void ExpenseTracker::on_btn_p3_XacNhan_tab2_clicked()

}



12 changes: 6 additions & 6 deletions QuanLyChiTieu/expensetracker.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@ class ExpenseTracker : public QDialog
void FormatDate(QString& date);
bool CheckMoneyInput(QString money);

void RefreshP1();
void RefreshP2();
void RefreshP3();
void RefreshP4();


void UpdateTableP4();

//void GetUserName(LoginAPP login);
Expand All @@ -61,6 +55,10 @@ class ExpenseTracker : public QDialog
QString TenDangNhap;

private slots:
void RefreshP1();
void RefreshP2();
void RefreshP3();
void RefreshP4();

void indexChanged(int index);

Expand Down Expand Up @@ -90,6 +88,8 @@ private slots:

void on_btn_page4_XoaTaiKhoan_clicked();

void on_btn_page4_CapNhat_XemBang_clicked();

void on_btn_GiaDinhPic_clicked();

void on_btn_SucKhoePic_clicked();
Expand Down
52 changes: 26 additions & 26 deletions QuanLyChiTieu/expensetracker.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>1321</width>
<height>1143</height>
<height>1104</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -38,7 +38,7 @@ QToolTip {
}
QTabWidget::pane {
border-top: 2px solid #C2C7CB;
border-bottom: 2px solid #C2C7CB;
border-bottom: 0px solid #C2C7CB;
}
QTabWidget#tabWidget_3::pane {
border-top: 0px solid #C2C7CB;
Expand Down Expand Up @@ -152,7 +152,7 @@ QComboBox::down-arrow:on { /* shift the arrow when popup is open */
<number>0</number>
</property>
<property name="currentIndex">
<number>3</number>
<number>1</number>
</property>
<widget class="QWidget" name="page_TrangChinh">
<property name="styleSheet">
Expand Down Expand Up @@ -891,9 +891,9 @@ background-image: url(:/Images/Pictures/reload-icon.png);</string>
<property name="geometry">
<rect>
<x>550</x>
<y>70</y>
<y>50</y>
<width>631</width>
<height>551</height>
<height>631</height>
</rect>
</property>
<property name="styleSheet">
Expand All @@ -918,9 +918,9 @@ border-radius: 8px;</string>
<property name="geometry">
<rect>
<x>630</x>
<y>20</y>
<y>0</y>
<width>471</width>
<height>51</height>
<height>41</height>
</rect>
</property>
<property name="styleSheet">
Expand Down Expand Up @@ -957,8 +957,8 @@ background-color: #F0E6EF;</string>
<widget class="QPushButton" name="btn_p2_TimKiemChung">
<property name="geometry">
<rect>
<x>270</x>
<y>310</y>
<x>230</x>
<y>300</y>
<width>121</width>
<height>41</height>
</rect>
Expand All @@ -976,9 +976,9 @@ font: 75 15pt &quot;MS Shell Dlg 2&quot;;</string>
<widget class="QWidget" name="layoutWidget_3">
<property name="geometry">
<rect>
<x>0</x>
<y>30</y>
<width>261</width>
<x>10</x>
<y>20</y>
<width>211</width>
<height>231</height>
</rect>
</property>
Expand Down Expand Up @@ -1018,8 +1018,8 @@ font: 75 15pt &quot;MS Shell Dlg 2&quot;;</string>
<widget class="QComboBox" name="comboBox_p2_TenDanhMuc">
<property name="geometry">
<rect>
<x>270</x>
<y>50</y>
<x>230</x>
<y>40</y>
<width>261</width>
<height>41</height>
</rect>
Expand Down Expand Up @@ -1094,8 +1094,8 @@ font: 75 14pt &quot;Segoe UI&quot;;</string>
<widget class="QComboBox" name="comboBox_p2_TenTaiKhoan">
<property name="geometry">
<rect>
<x>270</x>
<y>130</y>
<x>230</x>
<y>120</y>
<width>261</width>
<height>41</height>
</rect>
Expand All @@ -1110,8 +1110,8 @@ font: 75 14pt &quot;Segoe UI&quot;;</string>
<widget class="QLineEdit" name="lineEdit_p2_MoTa">
<property name="geometry">
<rect>
<x>270</x>
<y>200</y>
<x>230</x>
<y>190</y>
<width>261</width>
<height>51</height>
</rect>
Expand Down Expand Up @@ -1600,7 +1600,7 @@ background-color: rgb(255, 255, 255);</string>
<x>550</x>
<y>60</y>
<width>641</width>
<height>581</height>
<height>611</height>
</rect>
</property>
<property name="styleSheet">
Expand Down Expand Up @@ -1635,7 +1635,7 @@ color: rgb(0, 0, 0);</string>
<x>620</x>
<y>10</y>
<width>471</width>
<height>51</height>
<height>41</height>
</rect>
</property>
<property name="styleSheet">
Expand Down Expand Up @@ -1663,7 +1663,7 @@ color: rgb(0, 0, 0);</string>
background-color: rgb(226, 222, 212);</string>
</property>
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
Expand Down Expand Up @@ -2163,7 +2163,7 @@ background-color: rgb(255, 255, 255);</string>
</widget>
</widget>
</widget>
<widget class="QWidget" name="">
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>30</x>
Expand Down Expand Up @@ -2452,12 +2452,12 @@ font: 75 14pt &quot;Segoe UI&quot;;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;right&quot;&gt;Chọn loại tài khoản:&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
<widget class="QPushButton" name="btn_page4_ThemSoDu_XemBang">
<widget class="QPushButton" name="btn_page4_CapNhat_XemBang">
<property name="geometry">
<rect>
<x>180</x>
<y>220</y>
<width>161</width>
<x>220</x>
<y>130</y>
<width>131</width>
<height>41</height>
</rect>
</property>
Expand Down
36 changes: 36 additions & 0 deletions QuanLyChiTieu/tietkiem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,39 @@ void TietKiem::XoaTietKiem(QString Username, int MaTaiKhoan){
}

}

void TietKiem::ThemTietKiem(QString Username, QString TenTietKiem, lli SoDu, lli MucTieu, int MaTaiKhoan){
QSqlQuery qry;

qry.prepare("INSERT INTO TietKiem ( TenTietKiem, SoDu, MucTieu, MaTaiKhoan, TenChu )" "VALUES ( :TenTietKiem, :SoDu, :MucTieu, :MaTaiKhoan, :TenChu )");

qry.bindValue(":TenTietKiem", TenTietKiem);
qry.bindValue(":SoDu", SoDu);
qry.bindValue(":MucTieu", MucTieu);
qry.bindValue(":MaTaiKhoan", MaTaiKhoan);
qry.bindValue(":TenChu", Username);

if( !qry.exec() ){
qDebug()<<"Lỗi không kết nối được CSDL!";
}

}

lli TietKiem::KiemTraMucTieu(QString Username, int MaTaiKhoan){
QSqlQuery qry;
lli res = 0;

qry.prepare("SELECT SoDu, MucTieu FROM TietKiem WHERE TenChu = :Username AND MaTaiKhoan = :MaTaiKhoan");

qry.bindValue(":Username", Username);
qry.bindValue(":MaTaiKhoan", MaTaiKhoan);

if( qry.exec() ){
while ( qry.next() ) {
res = qry.value("SoDu").toLongLong() - qry.value("MucTieu").toLongLong();
}
}

return res;

}
4 changes: 4 additions & 0 deletions QuanLyChiTieu/tietkiem.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ class TietKiem : public QuanLyTaiKhoan
void CapNhatSoDu(QString Username, int MaTaiKhoan, lli SoDuTK);

void XoaTietKiem(QString Username, int MaTaiKhoan);

void ThemTietKiem(QString Username, QString TenTietKiem, lli SoDu, lli MucTieu, int MaTaiKhoan);

lli KiemTraMucTieu(QString Username, int MaTaiKhoan);
};

#endif // TIETKIEM_H

0 comments on commit e4e4a5b

Please sign in to comment.