| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763 |
- #include "../pch/pch.h"
- #include "CSqlite3.h"
- CSqlite3::CSqlite3()
- {
- try
- {
- sqlite3_config(SQLITE_CONFIG_MULTITHREAD);
- std::wstring folderPath = CSystem::GetProgramDir() + L"\\db";
- if (!CSystem::IsDirExist(folderPath))
- {
- LOG_INFO("folderPath:" << folderPath.c_str() << ",没有找到对应的目录,即将创建");
- bool flag = CreateDirectory(folderPath.c_str(), NULL);
- if (flag == false)
- {
- LOG_INFO("新建 db 目录失败!");
- }
- LOG_INFO("新建 db 目录成功!");
- }
- //如果没有这个文件,这里会创建这个文件
- std::wstring path = CSystem::GetProgramDir() + L"\\db\\pos.db";
- std::string s_path = CLewaimaiString::UnicodeToUTF8(path);
- //LOG_INFO("s_path:" << s_path.c_str());
- m_rc = sqlite3_open(s_path.c_str(), &m_db);
- if (m_rc != SQLITE_OK)
- {
- LOG_INFO("Can't open database: " << sqlite3_errmsg(m_db));
- return;
- }
- //LOG_INFO("Opened database successfully");
- }
- catch (const std::exception& e)
- {
- std::string aa = std::string(e.what());
- LOG_INFO(("创建数据库文件失败: " + std::string(e.what())).c_str());
- return ;
- }
- }
- CSqlite3::~CSqlite3()
- {
- if(m_db != NULL)
- {
- sqlite3_close(m_db);
- }
- }
- /**
- * 对数据库表进行一些初始化和检查,这个函数每次程序启动的时候执行1次,就不会再执行了
- */
- bool CSqlite3::InitDB()
- {
- //先处理pos_config表
- bool ret = this->InitPosConfig();
- if (!ret)
- {
- return false;
- }
- //再处理pos_chufang_printer表
- ret = this->InitPosChufangPrinter();
- if (!ret)
- {
- return false;
- }
- //再处理pos_user表
- ret = this->InitPosUser();
- if (!ret)
- {
- return false;
- }
- //再处理pos_food表
- ret = this->InitPosFood();
- if (!ret)
- {
- return false;
- }
- //再处理pos_foodtype表
- ret = this->InitPosFoodType();
- if (!ret)
- {
- return false;
- }
- //再处理pos_foodpackage表
- ret = this->InitPosFoodPackage();
- if (!ret)
- {
- return false;
- }
- return true;
- }
- bool CSqlite3::InitPosConfig()
- {
- //检查有没有pos_config这个表,如果没有就创建
- std::string sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'pos_config';";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
- int count = sqlite3_column_int(stmt, 0);
- if (count == 0)
- {
- //说明没找到这个表,那么这个时候新建这个表,先释放前面的stmt
- sqlite3_finalize(stmt);
- stmt = NULL;
- sql = "CREATE TABLE pos_config(" \
- "name CHAR(100) UNIQUE NOT NULL," \
- "value CHAR(2000) NOT NULL);";
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- //执行该语句
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
- LOG_ERROR("create table fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- //走到这里就是表创建成功了
- //LOG_INFO("create table success");
- sqlite3_finalize(stmt);
- }
- else
- {
- LOG_ERROR("create table prepare fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //说明已经有这个表了,就不用再创建了
- sqlite3_finalize(stmt);
- }
- std::string sql = "SELECT * FROM pos_config;";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- std::string name = (char*)sqlite3_column_text(stmt, 0);
- std::string value = (char*)sqlite3_column_text(stmt, 1);
- CSetting::GetInstance()->SetParam(name, value, false);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- return true;
- }
- bool CSqlite3::InitPosChufangPrinter()
- {
- std::string sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'pos_chufang_printer';";
- sqlite3_stmt * stmt = NULL;
- //读取厨房打印机的参数
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
- int count = sqlite3_column_int(stmt, 0);
- if (count == 0)
- {
- //说明没找到这个表,那么这个时候新建这个表,先释放前面的stmt
- sqlite3_finalize(stmt);
- stmt = NULL;
- sql = "CREATE TABLE pos_chufang_printer(" \
- "id INTEGER PRIMARY KEY AUTOINCREMENT,"\
- "date CHAR(100) NOT NULL," \
- "name CHAR(100) NOT NULL," \
- "ip CHAR(100) NOT NULL," \
- "guige CHAR(100) NOT NULL," \
- "fendan CHAR(100) NOT NULL," \
- "fenlei CHAR(100) NOT NULL," \
- "fenlei_ids CHAR(2000) );";
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- //执行该语句
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
- std::string err = sqlite3_errmsg(m_db);
- LOG_INFO("create table fail: " << err.c_str());
- sqlite3_finalize(stmt);
- return false;
- }
- //走到这里就是表创建成功了
- sqlite3_finalize(stmt);
- }
- else
- {
- LOG_INFO("create table prepare fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //说明已经有这个表了,就不用再创建了
- sqlite3_finalize(stmt);
- }
- //兼容性检查,判断字段是否存在
- std::string sql_pandduan = "select COUNT(*) from sqlite_master where type = 'table' and tbl_name = 'pos_chufang_printer' and sql like '%fenlei%';";
- stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql_pandduan.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
- int count = sqlite3_column_int(stmt, 0);
- if (count == 0)
- {
- //说明没找到这个字段,准备添加字段
- sqlite3_finalize(stmt);
- stmt = NULL;
- sql = "ALTER TABLE pos_chufang_printer " \
- "add fenlei CHAR(100) NOT NULL DEFAULT '0';";
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- //执行该语句
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
- std::string err = sqlite3_errmsg(m_db);
- LOG_INFO("alter table fail: " << err.c_str());
- sqlite3_finalize(stmt);
- return false;
- }
- //走到这里就是表创建成功了
- LOG_INFO("alter table success");
- sqlite3_finalize(stmt);
- }
- else
- {
- LOG_INFO("alter table prepare fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //说明已经有这2个字段了
- sqlite3_finalize(stmt);
- }
- }
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- sql_pandduan = "select COUNT(*) from sqlite_master where type = 'table' and tbl_name = 'pos_chufang_printer' and sql like '%fenlei_ids%';";
- stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql_pandduan.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
- int count = sqlite3_column_int(stmt, 0);
- if (count == 0)
- {
- //说明没找到这个字段,准备添加字段
- sqlite3_finalize(stmt);
- stmt = NULL;
- sql = "ALTER TABLE pos_chufang_printer " \
- "add fenlei_ids CHAR(2000) NOT NULL DEFAULT '';";
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- //执行该语句
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
- std::string err = sqlite3_errmsg(m_db);
- LOG_INFO("alter table fail: " << err.c_str());
- sqlite3_finalize(stmt);
- return false;
- }
- //走到这里就是表创建成功了
- sqlite3_finalize(stmt);
- }
- else
- {
- LOG_INFO("alter table prepare fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;;
- }
- }
- else
- {
- //说明已经有这2个字段了
- sqlite3_finalize(stmt);
- }
- }
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- std::string sql = "SELECT * FROM pos_chufang_printer;";
- stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- std::string date = (char*)sqlite3_column_text(stmt, 1);
- std::string name = (char*)sqlite3_column_text(stmt, 2);
- std::string ip = (char*)sqlite3_column_text(stmt, 3);
- std::string guige = (char*)sqlite3_column_text(stmt, 4);
- std::string fendan = (char*)sqlite3_column_text(stmt, 5);
- std::string fenlei = (char*)sqlite3_column_text(stmt, 6);
- std::string fenlei_ids = (char*)sqlite3_column_text(stmt, 7);
- //这里仅仅是把数据库内容读到内存,所以之类用false
- CSetting::GetInstance()->AddChufangPrinter(date, name, ip, guige, fendan, fenlei, fenlei_ids, false);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- }
- }
- return true;
- }
- bool CSqlite3::InitPosUser()
- {
- std::string sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'pos_user';";
- sqlite3_stmt * stmt = NULL;
- //读取厨房打印机的参数
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
- int count = sqlite3_column_int(stmt, 0);
- if (count == 0)
- {
- //说明没找到这个表,那么这个时候新建这个表,先释放前面的stmt
- sqlite3_finalize(stmt);
- stmt = NULL;
- sql = "CREATE TABLE pos_user(" \
- "id INTEGER PRIMARY KEY AUTOINCREMENT,"\
- "username CHAR(100) NOT NULL," \
- "password CHAR(100) NOT NULL);";
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- //执行该语句
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
- std::string err = sqlite3_errmsg(m_db);
- LOG_INFO("create table fail: " << err.c_str());
- sqlite3_finalize(stmt);
- return false;
- }
- //走到这里就是表创建成功了
- //LOG_INFO("create table success");
- sqlite3_finalize(stmt);
- }
- else
- {
- LOG_INFO("create table prepare fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //说明已经有这个表了,就不用再创建了
- sqlite3_finalize(stmt);
- }
- std::string sql = "SELECT * FROM pos_user;";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- std::string username = (char*)sqlite3_column_text(stmt, 1);
- std::string password = (char*)sqlite3_column_text(stmt, 2);
- //这里仅仅是把数据库内容读到内存,所以之类用false
- CSetting::GetInstance()->SetUser(username, password);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- }
- }
- return true;
- }
- bool CSqlite3::InitPosFood()
- {
- //检查有没有pos_food这个表,如果没有就创建
- std::string sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'pos_food';";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
- int count = sqlite3_column_int(stmt, 0);
- if (count == 0)
- {
- //说明没找到这个表,那么这个时候新建这个表,先释放前面的stmt
- sqlite3_finalize(stmt);
- stmt = NULL;
- sql = "CREATE TABLE pos_food(" \
- "id CHAR(20) UNIQUE NOT NULL,"\
- "shop_id CHAR(200) NOT NULL," \
- "name CHAR(100) NOT NULL," \
- "price CHAR(100) NOT NULL," \
- "tag CHAR(100) NOT NULL," \
- "status CHAR(100) NOT NULL," \
- "type_id CHAR(20) NOT NULL," \
- "is_dabao CHAR(20) NOT NULL," \
- "dabao_money CHAR(100) NOT NULL," \
- "is_nature CHAR(20) NOT NULL," \
- "nature CHAR(10000) NOT NULL," \
- "autostocknum CHAR(100) NOT NULL," \
- "goods_img CHAR(100) NOT NULL," \
- "unit CHAR(100) NOT NULL," \
- "barcode CHAR(100) NOT NULL," \
- "member_price_used CHAR(100) NOT NULL," \
- "member_price CHAR(100) NOT NULL," \
- "buying_price CHAR(100) NOT NULL," \
- "stock CHAR(100) NOT NULL," \
- "stockvalid CHAR(100) NOT NULL," \
- "stock_warning CHAR(100) NOT NULL," \
- "is_shouyinji_show CHAR(20) NOT NULL," \
- "is_waimai_show CHAR(20) NOT NULL," \
- "is_tangshi_show CHAR(20) NOT NULL," \
- "is_zhengcan_show CHAR(20) NOT NULL," \
- "expiration_date CHAR(100) NOT NULL," \
- "is_weight CHAR(20) NOT NULL," \
- "weight_plu_code CHAR(20) NOT NULL," \
- "weight_food_code CHAR(20) NOT NULL," \
- "jiagong_type CHAR(20) NOT NULL," \
- "cost_mode CHAR(20) NOT NULL," \
- "member_price_json CHAR(100) NOT NULL);";
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- //执行该语句
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
- LOG_ERROR("create table fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- //走到这里就是表创建成功了
- //LOG_INFO("create table success");
- sqlite3_finalize(stmt);
- }
- else
- {
- LOG_ERROR("create table prepare fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //说明已经有这个表了,就不用再创建了
- sqlite3_finalize(stmt);
- }
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- return true;
- }
- bool CSqlite3::InitPosFoodType()
- {
- //检查有没有pos_foodtype这个表,如果没有就创建
- std::string sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'pos_foodtype';";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
- int count = sqlite3_column_int(stmt, 0);
- if (count == 0)
- {
- //说明没找到这个表,那么这个时候新建这个表,先释放前面的stmt
- sqlite3_finalize(stmt);
- stmt = NULL;
- sql = "CREATE TABLE pos_foodtype(" \
- "id CHAR(20) UNIQUE NOT NULL,"\
- "name CHAR(200) NOT NULL," \
- "is_shouyinji_show CHAR(100) NOT NULL," \
- "tag CHAR(100) NOT NULL);";
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- //执行该语句
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
- LOG_ERROR("create table fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- //走到这里就是表创建成功了
- //LOG_INFO("create table success");
- sqlite3_finalize(stmt);
- }
- else
- {
- LOG_ERROR("create table prepare fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //说明已经有这个表了,就不用再创建了
- sqlite3_finalize(stmt);
- }
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- return true;
- }
- bool CSqlite3::InitPosFoodPackage()
- {
- //检查有没有pos_foodpackage这个表,如果没有就创建
- std::string sql = "SELECT COUNT(*) FROM sqlite_master where type = 'table' and name = 'pos_foodpackage';";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
- int count = sqlite3_column_int(stmt, 0);
- if (count == 0)
- {
- //说明没找到这个表,那么这个时候新建这个表,先释放前面的stmt
- sqlite3_finalize(stmt);
- stmt = NULL;
- sql = "CREATE TABLE pos_foodpackage(" \
- "id CHAR(20) UNIQUE NOT NULL,"\
- "shop_id CHAR(200) NOT NULL," \
- "name CHAR(100) NOT NULL," \
- "price CHAR(100) NOT NULL," \
- "tag CHAR(100) NOT NULL," \
- "status CHAR(100) NOT NULL," \
- "is_dabao CHAR(20) NOT NULL," \
- "dabao_money CHAR(100) NOT NULL," \
- "nature CHAR(10000) NOT NULL," \
- "goods_img CHAR(100) NOT NULL," \
- "unit CHAR(100) NOT NULL," \
- "supporttype CHAR(100) NOT NULL," \
- "is_shouyinji_show CHAR(100) NOT NULL," \
- "barcode CHAR(100) NOT NULL);";
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- //执行该语句
- if (sqlite3_step(stmt) != SQLITE_DONE)
- {
- LOG_ERROR("create table fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- //走到这里就是表创建成功了
- //LOG_INFO("create table success");
- sqlite3_finalize(stmt);
- }
- else
- {
- LOG_ERROR("create table prepare fail: " << sqlite3_errmsg(m_db));
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //说明已经有这个表了,就不用再创建了
- sqlite3_finalize(stmt);
- }
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- return false;
- }
- return true;
- }
- bool CSqlite3::SaveParams(std::map<std::string, std::string>& params)
- {
- int result = sqlite3_exec(m_db, "BEGIN;", 0, 0, 0);
- std::string sql = "delete from pos_config;";
- result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
- for(std::map<std::string, std::string>::iterator it = params.begin(); it != params.end(); it++)
- {
- std::string name = CLewaimaiString::SqlZhuanyi(it->first);
- std::string value = CLewaimaiString::SqlZhuanyi(it->second);
- sql = "INSERT INTO pos_config (name, value) VALUES ('" + name + "','" + value + "');";
- result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
- }
- result = sqlite3_exec(m_db, "COMMIT;", 0, 0, 0);
- if(result == SQLITE_OK)
- {
- //LOG_INFO("save params success");
- return true;
- }
- LOG_INFO("save params fail:"<< sqlite3_errmsg(m_db));
- return false;
- }
- bool CSqlite3::SaveChufangPrinter(std::vector<ChufangPrinter>& printers)
- {
- int result = sqlite3_exec(m_db, "BEGIN;", 0, 0, 0);
- std::string sql = "delete from pos_chufang_printer;";
- result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
- for (std::vector<ChufangPrinter>::iterator it = printers.begin(); it != printers.end(); it++)
- {
- std::string date = CLewaimaiString::SqlZhuanyi((*it).date);
- std::string name = CLewaimaiString::SqlZhuanyi((*it).name);
- std::string ip = CLewaimaiString::SqlZhuanyi((*it).ip);
- std::string guige = CLewaimaiString::SqlZhuanyi((*it).guige);
- std::string fendan = CLewaimaiString::SqlZhuanyi((*it).fendan);
- std::string fenlei = CLewaimaiString::SqlZhuanyi((*it).fenlei);
- std::string fenlei_ids = CLewaimaiString::SqlZhuanyi((*it).fenlei_ids);
- sql = "INSERT INTO pos_chufang_printer (date, name, ip, guige, fendan, fenlei, fenlei_ids) VALUES ('" + date + "' ,'" + name + "','" + ip + "','" + guige + "','" + fendan + "','" + fenlei + "','" + fenlei_ids + "')";
- result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
- }
- result = sqlite3_exec(m_db, "COMMIT;", 0, 0, 0);
- if (result == SQLITE_OK)
- {
- LOG_INFO("save params success");
- return true;
- }
- LOG_INFO("save params fail");
- return false;
- }
- bool CSqlite3::SaveUsers(std::map<std::string, std::string> users)
- {
- int result = sqlite3_exec(m_db, "BEGIN;", 0, 0, 0);
- std::string sql = "delete from pos_user;";
- result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
- for(std::map<std::string, std::string>::iterator it = users.begin(); it != users.end(); it++)
- {
- std::string name = CLewaimaiString::SqlZhuanyi(it->first);
- std::string password = CLewaimaiString::SqlZhuanyi(it->second);
- sql = "INSERT INTO pos_user (username, password) VALUES ('" + name + "' ,'" + password + "')";
- result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
- }
- result = sqlite3_exec(m_db, "COMMIT;", 0, 0, 0);
- if(result == SQLITE_OK)
- {
- //LOG_INFO("save params success");
- return true;
- }
- //LOG_INFO("save params fail");
- return false;
- }
- bool CSqlite3::InitFoodData(rapidjson::Value& foodrows)
- {
- this->ExeSQl("begin;");
- //先清空之前的旧数据,重新完整写入新数据
- std::string sql_delete = "delete from pos_food;";
- this->ExeSQl(sql_delete);
- for (rapidjson::SizeType i = 0; i < foodrows.Size(); ++i)
- {
- rapidjson::Value& foodinfo = foodrows[i];
- std::string id = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["id"]));
- std::string shop_id = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["shop_id"]));
- std::string name = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["name"]));
- std::string price = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["price"]));
- std::string tag = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["tag"]));
- std::string status = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["status"]));
- std::string type_id = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["type_id"]));
- std::string is_dabao = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_dabao"]));
- std::string dabao_money = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["dabao_money"]));
- std::string is_nature = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_nature"]));
- std::string nature = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::JsonToString(foodinfo["nature"]));
- std::string autostocknum = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["autostocknum"]));
- std::string goods_img = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["goods_img"]));
- std::string unit = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["unit"]));
- std::string barcode = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["barcode"]));
- std::string member_price_used = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["member_price_used"]));
- std::string member_price = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["member_price"]));
- std::string buying_price = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["buying_price"]));
- std::string stock = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["stock"]));
- std::string stockvalid = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["stockvalid"]));
- std::string stock_warning = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["stock_warning"]));
- std::string is_shouyinji_show = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_shouyinji_show"]));
- std::string expiration_date = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["expiration_date"]));
- std::string is_weight = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_weight"]));
- std::string member_price_json = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["member_price_json"]));
- std::string is_waimai_show = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_waimai_show"]));
- std::string is_tangshi_show = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_tangshi_show"]));
- std::string is_zhengcan_show = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_zhengcan_show"]));
- std::string jiagong_type = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["jiagong_type"]));
- std::string cost_mode = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["cost_mode"]));
- std::string weight_plu_code;
- if (foodinfo["weight_plu_code"].IsString())
- {
- weight_plu_code = CLewaimaiString::SqlZhuanyi(foodinfo["weight_plu_code"].GetString());
- }
- else
- {
- weight_plu_code = "";
- }
- std::string weight_food_code;
- if (foodinfo["weight_food_code"].IsString())
- {
- weight_food_code = CLewaimaiString::SqlZhuanyi(foodinfo["weight_food_code"].GetString());
- }
- else
- {
- weight_food_code = "";
- }
- //插入一个商品数据
- std::string sql = "INSERT INTO pos_food (id,shop_id,name,price,tag,status,type_id,is_dabao,dabao_money,is_nature,nature,autostocknum,goods_img,unit,barcode,member_price_used,member_price, \
- buying_price,stock,stockvalid,stock_warning,is_shouyinji_show,is_waimai_show,is_tangshi_show,is_zhengcan_show,expiration_date,is_weight,member_price_json,weight_plu_code,weight_food_code,jiagong_type,cost_mode) VALUES ('" + id + "' ,'" + shop_id + "','" \
- + name + "', '" + price + "', '" + tag + "', '" + status + "', '" + type_id + "', '" + is_dabao + "', '" + dabao_money + "', '" + is_nature + "', '" + nature + "', '" \
- + autostocknum + "', '" + goods_img + "', '" + unit + "', '" + barcode + "', '" + member_price_used + "', '" + member_price + "', '" + buying_price + "', '" + stock + "', '" \
- + stockvalid + "', '" + stock_warning + "', '" + is_shouyinji_show + "', '" + is_waimai_show + "', '" + is_tangshi_show + "', '" + is_zhengcan_show + "', '" + expiration_date + "','" + is_weight + "','" + member_price_json + "','" + weight_plu_code + "','" + weight_food_code + "','" + jiagong_type + "','" + cost_mode + "')";
- bool ret = this->ExeSQl(sql);
- if (!ret)
- {
- LOG_INFO("商品插入失败,sql:" << sql.c_str());
- return false;
- }
- }
- this->ExeSQl("commit;");
- return true;
- }
- bool CSqlite3::InitFoodtypeData(rapidjson::Value& foodtyperows)
- {
- this->ExeSQl("begin;");
- //先清空之前的旧数据,重新完整写入新数据
- std::string sql = "delete from pos_foodtype;";
- this->ExeSQl(sql);
- for (rapidjson::SizeType i = 0; i < foodtyperows.Size(); ++i)
- {
- rapidjson::Value& foodtypeinfo = foodtyperows[i];
- std::string type_id = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodtypeinfo["type_id"]));
- std::string name = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodtypeinfo["name"]));
- std::string is_shouyinji_show = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodtypeinfo["is_shouyinji_show"]));
- std::string tag = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodtypeinfo["tag"]));
- //插入一个商品数据
- std::string sql = "INSERT INTO pos_foodtype (id,name,is_shouyinji_show,tag) VALUES ('" + type_id + "' ,'" + name + "', '" + is_shouyinji_show + "', '" + tag + "')";
- bool ret = this->ExeSQl(sql);
- if (!ret)
- {
- LOG_INFO("商品分类插入失败:" << i);
- return false;
- }
- }
- this->ExeSQl("commit;");
- return true;
- }
- bool CSqlite3::InitFoodpackageData(rapidjson::Value& foodpackagerows)
- {
- //先清空之前的旧数据,重新完整写入新数据
- this->ExeSQl("begin;");
- std::string sql = "delete from pos_foodpackage;";
- this->ExeSQl(sql);
- for (rapidjson::SizeType i = 0; i < foodpackagerows.Size(); ++i)
- {
- rapidjson::Value& foodinfo = foodpackagerows[i];
- std::string id = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["id"]));
- std::string shop_id = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["shop_id"]));
- std::string name = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["name"]));
- std::string price = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["price"]));
- std::string tag = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["tag"]));
- std::string status = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["status"]));
- std::string is_dabao = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_dabao"]));
- std::string dabao_money = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["dabao_money"]));
- std::string nature = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::JsonToString(foodinfo["nature"]));
- std::string goods_img = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["goods_img"]));
- std::string unit = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["unit"]));
- std::string supporttype = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["supporttype"]));
- std::string is_shouyinji_show = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_shouyinji_show"]));
- std::string barcode = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["barcode"]));
- //插入一个商品数据
- std::string sql = "INSERT INTO pos_foodpackage (id,shop_id,name,price,tag,status,is_dabao,dabao_money,nature,goods_img,unit,supporttype,is_shouyinji_show,barcode) VALUES ('" + id + "' ,'" + shop_id + "','" \
- + name + "', '" + price + "', '" + tag + "', '" + status + "', '" + is_dabao + "', '" + dabao_money + "', '" + nature + "', '" \
- + goods_img + "', '" + unit + "', '" + supporttype + "', '" + is_shouyinji_show + "', '" + barcode + "')";
- bool ret = this->ExeSQl(sql);
- if (!ret)
- {
- LOG_INFO("商品套餐插入失败:" << i);
- return false;
- }
- }
- this->ExeSQl("commit;");
- return true;
- }
- bool CSqlite3::UpdateOneFood(rapidjson::Value& foodrows)
- {
- this->ExeSQl("begin;");
- rapidjson::Value& foodinfo = foodrows;
- std::string id = CLewaimaiString::SqlZhuanyi(foodinfo["goods_id"].GetString());
- //不管当前有没有这个商品,执行一下删除
- std::string sql_delete = "delete from pos_food where id = '" + id + "';";
- this->ExeSQl(sql_delete);
-
- std::string shop_id = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["shop_id"]));
- std::string name = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["goods_name"]));
- std::string price = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["goods_price"]));
- std::string tag = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["goods_tag"]));
- std::string status = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["goods_status"]));
- std::string type_id = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["type_lv1_id"]));
- std::string is_dabao = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_dabao"]));
- std::string dabao_money = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["dabao_money"]));
- std::string is_nature = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_nature"]));
- std::string nature;
- if (is_nature == "1")
- {
- nature = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::JsonToString(foodinfo["nature"]));
- }
- else
- {
- nature = "";
- }
- std::string autostocknum = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["autostocknum"]));
- std::string goods_img = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["goods_img"]));
- std::string unit = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["unit"]));
- std::string barcode = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["barcode"]));
- std::string member_price_used = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["member_price_used"]));
- std::string member_price = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["member_price"]));
- std::string buying_price = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["buying_price"]));
- std::string stock = CLewaimaiString::SqlZhuanyi(std::to_string(foodinfo["stock"].GetDouble()));
- std::string stockvalid;
- std::string stock_status = CLewaimaiJson::ToString(foodinfo["stock_status"]);
- if (stock_status == "OPEN")
- {
- stockvalid = "1";
- }
- else
- {
- stockvalid = "0";
- }
- std::string stock_warning = CLewaimaiString::SqlZhuanyi(std::to_string(foodinfo["stock_warning"].GetDouble()));
- std::string is_shouyinji_show = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_shouyinji_show"]));
- std::string expiration_date = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["expiration_date"]));
- std::string is_weight = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_weight"]));
- std::string member_price_json = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["member_price_json"]));
- std::string is_waimai_show = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_waimai_show"]));
- std::string is_tangshi_show = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_tangshi_show"]));
- std::string is_zhengcan_show = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["is_zhengcan_show"]));
- std::string jiagong_type = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["jiagong_type"]));
- std::string cost_mode = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["cost_mode"]));
- std::string weight_plu_code;
- if (foodinfo["weight_plu_code"].IsString())
- {
- weight_plu_code = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["weight_plu_code"]));
- }
- else
- {
- weight_plu_code = "";
- }
- std::string weight_food_code;
- if (foodinfo["weight_food_code"].IsString())
- {
- weight_food_code = CLewaimaiString::SqlZhuanyi(CLewaimaiJson::ToString(foodinfo["weight_food_code"]));
- }
- else
- {
- weight_food_code = "";
- }
- //插入一个商品数据
- std::string sql = "INSERT INTO pos_food (id,shop_id,name,price,tag,status,type_id,is_dabao,dabao_money,is_nature,nature,autostocknum,goods_img,unit,barcode,member_price_used,member_price, \
- buying_price,stock,stockvalid,stock_warning,is_shouyinji_show,is_waimai_show,is_tangshi_show,is_zhengcan_show,expiration_date,is_weight,member_price_json,weight_plu_code,weight_food_code,jiagong_type,cost_mode) VALUES ('" + id + "' ,'" + shop_id + "','" \
- + name + "', '" + price + "', '" + tag + "', '" + status + "', '" + type_id + "', '" + is_dabao + "', '" + dabao_money + "', '" + is_nature + "', '" + nature + "', '" \
- + autostocknum + "', '" + goods_img + "', '" + unit + "', '" + barcode + "', '" + member_price_used + "', '" + member_price + "', '" + buying_price + "', '" + stock + "', '" \
- + stockvalid + "', '" + stock_warning + "', '" + is_shouyinji_show + "', '" + is_waimai_show + "', '" + is_tangshi_show + "', '" + is_zhengcan_show + "', '" + expiration_date + "','" + is_weight + "','" + member_price_json + "','" + weight_plu_code + "','" + weight_food_code + "','" + jiagong_type + "','" + cost_mode + "')";
- bool ret = this->ExeSQl(sql);
- if (!ret)
- {
- return false;
- }
- this->ExeSQl("commit;");
- return true;
- }
- bool CSqlite3::DeleteOneFood(std::string food_id)
- {
- food_id = CLewaimaiString::SqlZhuanyi(food_id);
- this->ExeSQl("begin;");
- //不管当前有没有这个商品,执行一下删除
- std::string sql_delete = "delete from pos_food where id = '" + food_id + "';";
- this->ExeSQl(sql_delete);
- this->ExeSQl("commit;");
- return true;
- }
- bool CSqlite3::AddOneFoodtype(std::string type_id, std::string name, std::string is_shouyinji_show, std::string tag)
- {
- this->ExeSQl("begin;");
- type_id = CLewaimaiString::SqlZhuanyi(type_id);
- name = CLewaimaiString::SqlZhuanyi(name);
- is_shouyinji_show = CLewaimaiString::SqlZhuanyi(is_shouyinji_show);
- tag = CLewaimaiString::SqlZhuanyi(tag);
- //插入一个商品数据
- std::string sql = "INSERT INTO pos_foodtype (id,name,is_shouyinji_show,tag) VALUES ('" + type_id + "' ,'" + name + "', '" + is_shouyinji_show + "', '" + tag + "')";
- bool ret = this->ExeSQl(sql);
- if (!ret)
- {
- LOG_INFO("商品分类插入失败:");
- return false;
- }
- this->ExeSQl("commit;");
- return true;
- }
- bool CSqlite3::ExeSQl(std::string sql)
- {
- char *zErrMsg = 0;
- int rc;
- rc = sqlite3_exec(m_db, sql.c_str(), 0, 0, &zErrMsg);
- if (rc != SQLITE_OK)
- {
- LOG_ERROR("SQL error: "<<zErrMsg);
- sqlite3_free(zErrMsg);
- return false;
- }
- else
- {
- return true;
- }
- return true;
- }
- //获取套餐商品的数量
- int CSqlite3::GetFoodpackageNum()
- {
- int count = 0;
- std::string sql = "SELECT count(*) as num FROM pos_foodpackage WHERE status = 'NORMAL';";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- if (sqlite3_step(stmt) == SQLITE_ROW)
- {
- count = sqlite3_column_int(stmt, 0);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return count;
- }
- std::vector<CFoodType> CSqlite3::GetFoodtypes(bool is_shouyinji_show)
- {
- std::vector<CFoodType> data;
- std::string sql;
-
- if (is_shouyinji_show)
- {
- sql = "SELECT * FROM pos_foodtype WHERE is_shouyinji_show = '1';";
- }
- else
- {
- sql = "SELECT * FROM pos_foodtype;";
- }
-
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- std::string id = (char*)sqlite3_column_text(stmt, 0);
- std::string name = (char*)sqlite3_column_text(stmt, 1);
- std::string is_shouyinji_show = (char*)sqlite3_column_text(stmt, 2);
- std::string tag = (char*)sqlite3_column_text(stmt, 3);
- CFoodType newtype;
- newtype.id = id;
- newtype.name = name;
- newtype.is_shouyinji_show = is_shouyinji_show;
- newtype.tag = tag;
- data.push_back(newtype);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return data;
- }
- bool CSqlite3::GetFoodtypeById(std::string foodtype_id, CFoodType& newFoodType)
- {
- foodtype_id = CLewaimaiString::SqlZhuanyi(foodtype_id);
- bool is_found = false;
- std::string sql = "SELECT * FROM pos_foodtype WHERE id = '" + foodtype_id + "'";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- is_found = true;
- newFoodType.id = (char*)sqlite3_column_text(stmt, 0);
- newFoodType.name = (char*)sqlite3_column_text(stmt, 1);
- newFoodType.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 2);
- newFoodType.tag = (char*)sqlite3_column_text(stmt, 3);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return is_found;
- }
- /**
- * 如果type_id为0,表示读取所有商品,否则只读取当前type_id的商品
- */
- std::vector<CFood> CSqlite3::GetFoodByTypeid(std::string type_id, bool is_shouyinji_show)
- {
- type_id = CLewaimaiString::SqlZhuanyi(type_id);
- std::vector<CFood> data;
- std::string sql;
- if (is_shouyinji_show)
- {
- sql = "SELECT * FROM pos_food WHERE status='NORMAL' and is_shouyinji_show = '1'";
- }
- else
- {
- sql = "SELECT * FROM pos_food WHERE status='NORMAL'";
- }
- if (type_id != "0")
- {
- sql += " AND type_id = '" + type_id + "'";
- }
- sql += " ORDER BY tag ASC";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- CFood newFood;
- newFood.id = (char*)sqlite3_column_text(stmt, 0);
- newFood.shop_id = (char*)sqlite3_column_text(stmt, 1);
- newFood.name = (char*)sqlite3_column_text(stmt, 2);
- newFood.price = (char*)sqlite3_column_text(stmt, 3);
- newFood.tag = (char*)sqlite3_column_text(stmt, 4);
- newFood.status = (char*)sqlite3_column_text(stmt, 5);
- newFood.type_id = (char*)sqlite3_column_text(stmt, 6);
- newFood.is_dabao = (char*)sqlite3_column_text(stmt, 7);
- newFood.dabao_money = (char*)sqlite3_column_text(stmt, 8);
- newFood.is_nature = (char*)sqlite3_column_text(stmt, 9);
- newFood.nature = (char*)sqlite3_column_text(stmt, 10);
- newFood.autostocknum = (char*)sqlite3_column_text(stmt, 11);
- newFood.goods_img = (char*)sqlite3_column_text(stmt, 12);
- newFood.unit = (char*)sqlite3_column_text(stmt, 13);
- newFood.barcode = (char*)sqlite3_column_text(stmt, 14);
- newFood.member_price_used = (char*)sqlite3_column_text(stmt, 15);
- newFood.member_price = (char*)sqlite3_column_text(stmt, 16);
- newFood.buying_price = (char*)sqlite3_column_text(stmt, 17);
- newFood.stock = (char*)sqlite3_column_text(stmt, 18);
- newFood.stockvalid = (char*)sqlite3_column_text(stmt, 19);
- newFood.stock_warning = (char*)sqlite3_column_text(stmt, 20);
- newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
- newFood.is_waimai_show = (char*)sqlite3_column_text(stmt, 22);
- newFood.is_tangshi_show = (char*)sqlite3_column_text(stmt, 23);
- newFood.is_zhengcan_show = (char*)sqlite3_column_text(stmt, 24);
- newFood.expiration_date = (char*)sqlite3_column_text(stmt, 25);
- newFood.is_weight = (char*)sqlite3_column_text(stmt, 26);
- newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 27);
- newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 28);
- newFood.jiagong_type = (char*)sqlite3_column_text(stmt, 29);
- newFood.cost_mode = (char*)sqlite3_column_text(stmt, 30);
- newFood.member_price_json = (char*)sqlite3_column_text(stmt, 31);
- data.push_back(newFood);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return data;
- }
- std::vector<CFood> CSqlite3::GetFoodForTiaomacheng()
- {
- std::vector<CFood> data;
- std::string sql;
- sql = "SELECT * FROM pos_food WHERE is_weight = '1' AND weight_plu_code != '' AND weight_food_code != ''";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- CFood newFood;
- newFood.id = (char*)sqlite3_column_text(stmt, 0);
- newFood.shop_id = (char*)sqlite3_column_text(stmt, 1);
- newFood.name = (char*)sqlite3_column_text(stmt, 2);
- newFood.price = (char*)sqlite3_column_text(stmt, 3);
- newFood.tag = (char*)sqlite3_column_text(stmt, 4);
- newFood.status = (char*)sqlite3_column_text(stmt, 5);
- newFood.type_id = (char*)sqlite3_column_text(stmt, 6);
- newFood.is_dabao = (char*)sqlite3_column_text(stmt, 7);
- newFood.dabao_money = (char*)sqlite3_column_text(stmt, 8);
- newFood.is_nature = (char*)sqlite3_column_text(stmt, 9);
- newFood.nature = (char*)sqlite3_column_text(stmt, 10);
- newFood.autostocknum = (char*)sqlite3_column_text(stmt, 11);
- newFood.goods_img = (char*)sqlite3_column_text(stmt, 12);
- newFood.unit = (char*)sqlite3_column_text(stmt, 13);
- newFood.barcode = (char*)sqlite3_column_text(stmt, 14);
- newFood.member_price_used = (char*)sqlite3_column_text(stmt, 15);
- newFood.member_price = (char*)sqlite3_column_text(stmt, 16);
- newFood.buying_price = (char*)sqlite3_column_text(stmt, 17);
- newFood.stock = (char*)sqlite3_column_text(stmt, 18);
- newFood.stockvalid = (char*)sqlite3_column_text(stmt, 19);
- newFood.stock_warning = (char*)sqlite3_column_text(stmt, 20);
- newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
- newFood.is_waimai_show = (char*)sqlite3_column_text(stmt, 22);
- newFood.is_tangshi_show = (char*)sqlite3_column_text(stmt, 23);
- newFood.is_zhengcan_show = (char*)sqlite3_column_text(stmt, 24);
- newFood.expiration_date = (char*)sqlite3_column_text(stmt, 25);
- newFood.is_weight = (char*)sqlite3_column_text(stmt, 26);
- newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 27);
- newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 28);
- newFood.jiagong_type = (char*)sqlite3_column_text(stmt, 29);
- newFood.cost_mode = (char*)sqlite3_column_text(stmt, 30);
- newFood.member_price_json = (char*)sqlite3_column_text(stmt, 31);
- data.push_back(newFood);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return data;
- }
- std::vector<CFood> CSqlite3::GetFoodByFoodname(std::string foodname, bool is_shouyinji_show)
- {
- std::vector<CFood> data;
- std::string sql;
- foodname = CLewaimaiString::SqlZhuanyi(foodname);
- if (is_shouyinji_show)
- {
- sql = "SELECT * FROM pos_food WHERE name LIKE '%" + foodname + "%' AND status='NORMAL' AND is_shouyinji_show = '1'";
- }
- else
- {
- sql = "SELECT * FROM pos_food WHERE name LIKE '%" + foodname + "%' AND status='NORMAL'";
- }
- sql += " ORDER BY tag";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- CFood newFood;
- newFood.id = (char*)sqlite3_column_text(stmt, 0);
- newFood.shop_id = (char*)sqlite3_column_text(stmt, 1);
- newFood.name = (char*)sqlite3_column_text(stmt, 2);
- newFood.price = (char*)sqlite3_column_text(stmt, 3);
- newFood.tag = (char*)sqlite3_column_text(stmt, 4);
- newFood.status = (char*)sqlite3_column_text(stmt, 5);
- newFood.type_id = (char*)sqlite3_column_text(stmt, 6);
- newFood.is_dabao = (char*)sqlite3_column_text(stmt, 7);
- newFood.dabao_money = (char*)sqlite3_column_text(stmt, 8);
- newFood.is_nature = (char*)sqlite3_column_text(stmt, 9);
- newFood.nature = (char*)sqlite3_column_text(stmt, 10);
- newFood.autostocknum = (char*)sqlite3_column_text(stmt, 11);
- newFood.goods_img = (char*)sqlite3_column_text(stmt, 12);
- newFood.unit = (char*)sqlite3_column_text(stmt, 13);
- newFood.barcode = (char*)sqlite3_column_text(stmt, 14);
- newFood.member_price_used = (char*)sqlite3_column_text(stmt, 15);
- newFood.member_price = (char*)sqlite3_column_text(stmt, 16);
- newFood.buying_price = (char*)sqlite3_column_text(stmt, 17);
- newFood.stock = (char*)sqlite3_column_text(stmt, 18);
- newFood.stockvalid = (char*)sqlite3_column_text(stmt, 19);
- newFood.stock_warning = (char*)sqlite3_column_text(stmt, 20);
- newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
- newFood.is_waimai_show = (char*)sqlite3_column_text(stmt, 22);
- newFood.is_tangshi_show = (char*)sqlite3_column_text(stmt, 23);
- newFood.is_zhengcan_show = (char*)sqlite3_column_text(stmt, 24);
- newFood.expiration_date = (char*)sqlite3_column_text(stmt, 25);
- newFood.is_weight = (char*)sqlite3_column_text(stmt, 26);
- newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 27);
- newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 28);
- newFood.jiagong_type = (char*)sqlite3_column_text(stmt, 29);
- newFood.cost_mode = (char*)sqlite3_column_text(stmt, 30);
- newFood.member_price_json = (char*)sqlite3_column_text(stmt, 31);
- data.push_back(newFood);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return data;
- }
- std::vector<CFoodpackage> CSqlite3::GetFoodpackages(bool is_shouyinji_show)
- {
- std::vector<CFoodpackage> data;
- std::string sql;
- if (is_shouyinji_show)
- {
- sql = "SELECT * FROM pos_foodpackage WHERE status='NORMAL' AND is_shouyinji_show = '1' ORDER BY tag";
- }
- else
- {
- sql = "SELECT * FROM pos_foodpackage WHERE status='NORMAL' ORDER BY tag";
- }
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- CFoodpackage newFood;
- newFood.id = (char*)sqlite3_column_text(stmt, 0);
- newFood.shop_id = (char*)sqlite3_column_text(stmt, 1);
- newFood.name = (char*)sqlite3_column_text(stmt, 2);
- newFood.price = (char*)sqlite3_column_text(stmt, 3);
- newFood.tag = (char*)sqlite3_column_text(stmt, 4);
- newFood.status = (char*)sqlite3_column_text(stmt, 5);
- newFood.is_dabao = (char*)sqlite3_column_text(stmt, 6);
- newFood.dabao_money = (char*)sqlite3_column_text(stmt, 7);
- newFood.nature = (char*)sqlite3_column_text(stmt, 8);
- newFood.goods_img = (char*)sqlite3_column_text(stmt, 9);
- newFood.unit = (char*)sqlite3_column_text(stmt, 10);
- newFood.supporttype = (char*)sqlite3_column_text(stmt, 11);
- newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 12);
- newFood.barcode = (char*)sqlite3_column_text(stmt, 13);
- data.push_back(newFood);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return data;
- }
- bool CSqlite3::GetFoodById(std::string food_id, CFood& newFood)
- {
- food_id = CLewaimaiString::SqlZhuanyi(food_id);
- bool is_found = false;
- std::string sql = "SELECT * FROM pos_food WHERE id = '" + food_id + "'";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- is_found = true;
- newFood.id = (char*)sqlite3_column_text(stmt, 0);
- newFood.shop_id = (char*)sqlite3_column_text(stmt, 1);
- newFood.name = (char*)sqlite3_column_text(stmt, 2);
- newFood.price = (char*)sqlite3_column_text(stmt, 3);
- newFood.tag = (char*)sqlite3_column_text(stmt, 4);
- newFood.status = (char*)sqlite3_column_text(stmt, 5);
- newFood.type_id = (char*)sqlite3_column_text(stmt, 6);
- newFood.is_dabao = (char*)sqlite3_column_text(stmt, 7);
- newFood.dabao_money = (char*)sqlite3_column_text(stmt, 8);
- newFood.is_nature = (char*)sqlite3_column_text(stmt, 9);
- newFood.nature = (char*)sqlite3_column_text(stmt, 10);
- newFood.autostocknum = (char*)sqlite3_column_text(stmt, 11);
- newFood.goods_img = (char*)sqlite3_column_text(stmt, 12);
- newFood.unit = (char*)sqlite3_column_text(stmt, 13);
- newFood.barcode = (char*)sqlite3_column_text(stmt, 14);
- newFood.member_price_used = (char*)sqlite3_column_text(stmt, 15);
- newFood.member_price = (char*)sqlite3_column_text(stmt, 16);
- newFood.buying_price = (char*)sqlite3_column_text(stmt, 17);
- newFood.stock = (char*)sqlite3_column_text(stmt, 18);
- newFood.stockvalid = (char*)sqlite3_column_text(stmt, 19);
- newFood.stock_warning = (char*)sqlite3_column_text(stmt, 20);
- newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
- newFood.is_waimai_show = (char*)sqlite3_column_text(stmt, 22);
- newFood.is_tangshi_show = (char*)sqlite3_column_text(stmt, 23);
- newFood.is_zhengcan_show = (char*)sqlite3_column_text(stmt, 24);
- newFood.expiration_date = (char*)sqlite3_column_text(stmt, 25);
- newFood.is_weight = (char*)sqlite3_column_text(stmt, 26);
- newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 27);
- newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 28);
- newFood.jiagong_type = (char*)sqlite3_column_text(stmt, 29);
- newFood.cost_mode = (char*)sqlite3_column_text(stmt, 30);
- newFood.member_price_json = (char*)sqlite3_column_text(stmt, 31);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return is_found;
- }
- bool CSqlite3::GetFoodByBarcode(std::string barcode, CFood& newFood)
- {
- bool is_found = false;
- barcode = CLewaimaiString::SqlZhuanyi(barcode);
- std::string sql = "SELECT * FROM pos_food WHERE barcode = '" + barcode + "'";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- is_found = true;
- newFood.id = (char*)sqlite3_column_text(stmt, 0);
- newFood.shop_id = (char*)sqlite3_column_text(stmt, 1);
- newFood.name = (char*)sqlite3_column_text(stmt, 2);
- newFood.price = (char*)sqlite3_column_text(stmt, 3);
- newFood.tag = (char*)sqlite3_column_text(stmt, 4);
- newFood.status = (char*)sqlite3_column_text(stmt, 5);
- newFood.type_id = (char*)sqlite3_column_text(stmt, 6);
- newFood.is_dabao = (char*)sqlite3_column_text(stmt, 7);
- newFood.dabao_money = (char*)sqlite3_column_text(stmt, 8);
- newFood.is_nature = (char*)sqlite3_column_text(stmt, 9);
- newFood.nature = (char*)sqlite3_column_text(stmt, 10);
- newFood.autostocknum = (char*)sqlite3_column_text(stmt, 11);
- newFood.goods_img = (char*)sqlite3_column_text(stmt, 12);
- newFood.unit = (char*)sqlite3_column_text(stmt, 13);
- newFood.barcode = (char*)sqlite3_column_text(stmt, 14);
- newFood.member_price_used = (char*)sqlite3_column_text(stmt, 15);
- newFood.member_price = (char*)sqlite3_column_text(stmt, 16);
- newFood.buying_price = (char*)sqlite3_column_text(stmt, 17);
- newFood.stock = (char*)sqlite3_column_text(stmt, 18);
- newFood.stockvalid = (char*)sqlite3_column_text(stmt, 19);
- newFood.stock_warning = (char*)sqlite3_column_text(stmt, 20);
- newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
- newFood.is_waimai_show = (char*)sqlite3_column_text(stmt, 22);
- newFood.is_tangshi_show = (char*)sqlite3_column_text(stmt, 23);
- newFood.is_zhengcan_show = (char*)sqlite3_column_text(stmt, 24);
- newFood.expiration_date = (char*)sqlite3_column_text(stmt, 25);
- newFood.is_weight = (char*)sqlite3_column_text(stmt, 26);
- newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 27);
- newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 28);
- newFood.jiagong_type = (char*)sqlite3_column_text(stmt, 29);
- newFood.cost_mode = (char*)sqlite3_column_text(stmt, 30);
- newFood.member_price_json = (char*)sqlite3_column_text(stmt, 31);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return is_found;
- }
- bool CSqlite3::GetFoodByPluBianma(std::string barcode, CFood& newFood)
- {
- bool is_found = false;
- barcode = CLewaimaiString::SqlZhuanyi(barcode);
- std::string sql = "SELECT * FROM pos_food WHERE is_weight = '1' AND weight_food_code = '" + barcode + "'";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- is_found = true;
- newFood.id = (char*)sqlite3_column_text(stmt, 0);
- newFood.shop_id = (char*)sqlite3_column_text(stmt, 1);
- newFood.name = (char*)sqlite3_column_text(stmt, 2);
- newFood.price = (char*)sqlite3_column_text(stmt, 3);
- newFood.tag = (char*)sqlite3_column_text(stmt, 4);
- newFood.status = (char*)sqlite3_column_text(stmt, 5);
- newFood.type_id = (char*)sqlite3_column_text(stmt, 6);
- newFood.is_dabao = (char*)sqlite3_column_text(stmt, 7);
- newFood.dabao_money = (char*)sqlite3_column_text(stmt, 8);
- newFood.is_nature = (char*)sqlite3_column_text(stmt, 9);
- newFood.nature = (char*)sqlite3_column_text(stmt, 10);
- newFood.autostocknum = (char*)sqlite3_column_text(stmt, 11);
- newFood.goods_img = (char*)sqlite3_column_text(stmt, 12);
- newFood.unit = (char*)sqlite3_column_text(stmt, 13);
- newFood.barcode = (char*)sqlite3_column_text(stmt, 14);
- newFood.member_price_used = (char*)sqlite3_column_text(stmt, 15);
- newFood.member_price = (char*)sqlite3_column_text(stmt, 16);
- newFood.buying_price = (char*)sqlite3_column_text(stmt, 17);
- newFood.stock = (char*)sqlite3_column_text(stmt, 18);
- newFood.stockvalid = (char*)sqlite3_column_text(stmt, 19);
- newFood.stock_warning = (char*)sqlite3_column_text(stmt, 20);
- newFood.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 21);
- newFood.is_waimai_show = (char*)sqlite3_column_text(stmt, 22);
- newFood.is_tangshi_show = (char*)sqlite3_column_text(stmt, 23);
- newFood.is_zhengcan_show = (char*)sqlite3_column_text(stmt, 24);
- newFood.expiration_date = (char*)sqlite3_column_text(stmt, 25);
- newFood.is_weight = (char*)sqlite3_column_text(stmt, 26);
- newFood.weight_plu_code = (char*)sqlite3_column_text(stmt, 27);
- newFood.weight_food_code = (char*)sqlite3_column_text(stmt, 28);
- newFood.jiagong_type = (char*)sqlite3_column_text(stmt, 29);
- newFood.cost_mode = (char*)sqlite3_column_text(stmt, 30);
- newFood.member_price_json = (char*)sqlite3_column_text(stmt, 31);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return is_found;
- }
- bool CSqlite3::GetFoodpackageById(std::string foodpackage_id, CFoodpackage& newFoodpackage)
- {
- bool is_found = false;
- std::string sql = "SELECT * FROM pos_foodpackage WHERE id = '" + foodpackage_id + "'";
- sqlite3_stmt * stmt = NULL;
- if (sqlite3_prepare_v2(m_db, sql.c_str(), -1, &stmt, NULL) == SQLITE_OK)
- {
- while (sqlite3_step(stmt) == SQLITE_ROW)
- {
- is_found = true;
- newFoodpackage.id = (char*)sqlite3_column_text(stmt, 0);
- newFoodpackage.shop_id = (char*)sqlite3_column_text(stmt, 1);
- newFoodpackage.name = (char*)sqlite3_column_text(stmt, 2);
- newFoodpackage.price = (char*)sqlite3_column_text(stmt, 3);
- newFoodpackage.tag = (char*)sqlite3_column_text(stmt, 4);
- newFoodpackage.status = (char*)sqlite3_column_text(stmt, 5);
- newFoodpackage.is_dabao = (char*)sqlite3_column_text(stmt, 6);
- newFoodpackage.dabao_money = (char*)sqlite3_column_text(stmt, 7);
- newFoodpackage.nature = (char*)sqlite3_column_text(stmt, 8);
- newFoodpackage.goods_img = (char*)sqlite3_column_text(stmt, 9);
- newFoodpackage.unit = (char*)sqlite3_column_text(stmt, 10);
- newFoodpackage.supporttype = (char*)sqlite3_column_text(stmt, 11);
- newFoodpackage.is_shouyinji_show = (char*)sqlite3_column_text(stmt, 12);
- newFoodpackage.barcode = (char*)sqlite3_column_text(stmt, 13);
- }
- sqlite3_finalize(stmt);
- }
- else
- {
- //异常情况
- sqlite3_finalize(stmt);
- }
- return is_found;
- }
- //更新商品ID的库存
- void CSqlite3::UpdateFoodStock(std::string food_id, std::string stock)
- {
- food_id = CLewaimaiString::SqlZhuanyi(food_id);
- int result = sqlite3_exec(m_db, "BEGIN;", 0, 0, 0);
- std::string sql = "UPDATE pos_food SET stock = '" + stock + "' WHERE id = " + food_id;
- result = sqlite3_exec(m_db, sql.c_str(), 0, 0, 0);
- result = sqlite3_exec(m_db, "COMMIT;", 0, 0, 0);
- }
|