diff --git a/src/.keep b/src/.keep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/src/databass.cpp b/src/databass.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c9d749175feb4593d7603beae72c1ea91e910bde --- /dev/null +++ b/src/databass.cpp @@ -0,0 +1,238 @@ +#include "databass.h" + + +Databass::Databass() +{ + db = QSqlDatabase::addDatabase("QSQLITE"); + db.setDatabaseName("attendance.db"); + createTable(); +} + + +void Databass::createTable() +{ + /** + *此函数用于创建数据库表单 + * 根据获取的本地时间,以xxxx/xx/xx为名称创建表单, + * 当存在此表单,就不创建,不存在就创建; + * 默认存在 序号 员工工号 + */ + + //1、创建数据库对象 + QSqlQuery query; + + //2、打开数据库 + openDb(); + + //3、获取表名 + QString localTime = getTime(); + tableName ="data_" + localTime.replace(QRegExp("\\."), "_"); + + QString creatTable_sql = "create table if not exists " + + tableName + + " (serialNum integer primary key autoincrement," + "employeeId)"; + + //5、执行创建数据表单,存在则不创建 + if(!query.exec(creatTable_sql)) + { + qDebug()<setQuery(query); + int ncolumn = queryModel->columnCount(); + return ncolumn; +} + +void Databass::show() +{ + db.open(); + QSqlQuery query; + QString select_sql = "select * from " + tableName; + if(!query.exec(select_sql)) + { + qDebug()< + +#include +#include +#include +#include + +#include +#include + +#include + + +class Databass +{ +public: + Databass(); + int punch(std::string id, time_t time); + + void show(); + //获取表格列数 + int getTableColoum(); + +private: + QSqlDatabase db; + QString tableName; + + + + void createTable(); + void openDb(); + void closeDb(); + + + + + QString getTime(); +}; + +#endif // DATABASS_H