Browse Source

完成:导入/导出图片接口;

sat23 4 years ago
parent
commit
4580977595
2 changed files with 92 additions and 7 deletions
  1. 87 5
      CTSManager/CTSManager/Database.cpp
  2. 5 2
      CTSManager/CTSManager/Database.h

+ 87 - 5
CTSManager/CTSManager/Database.cpp

@@ -588,20 +588,53 @@ BOOL CDatabase::QueryBrand(std::vector<STBranch>& vtBrand)
 	return TRUE;
 }
 
-BOOL CDatabase::ImportLogo(std::string brand, std::string file, BOOL bQuarter/*=FALSE*/)
+BOOL CDatabase::ImportBrandLogo(std::string brand, std::string file)
 {
 	if (!PathFileExists(file.c_str()))
 		return FALSE;
 
-	
-	return 0;
+	// ¶Á³öͼƬ;
+	CFile cfile;
+	if (!cfile.Open(file.c_str(), CFile::modeRead, NULL))
+		return FALSE;
+
+	ULONGLONG ulLength = cfile.GetLength();
+	char* pData = new char[ulLength];
+	cfile.Read(pData, ulLength);
+	cfile.Close();
+
+	TCHAR szSql[MAX_PATH] = {0};
+	_stprintf_s(szSql, _T("update brand set logo = ? where `name` = '%s'"), brand.c_str());
+
+	BOOL bResult = SetBinaryField(szSql, pData, ulLength);
+	if (pData)
+		delete[]pData;
+	pData = NULL;
+
+	return bResult;
 }
 
-BOOL CDatabase::ExportLogo(std::string brand, std::string file, BOOL bQuarter/*=FALSE*/)
+BOOL CDatabase::ExportBrandLogo(std::string brand, std::string file)
 {
+	char* pData = NULL;
+	unsigned long ulLength = 0;
+	TCHAR szSql[MAX_PATH] = {0};
+	_stprintf_s(szSql, _T("select logo from brand where `name`='%s';"), brand.c_str());
+	BOOL bResult = GetBinaryField(szSql, (void**)&pData, ulLength);
+	if (bResult && pData)
+	{
+		CFile cfile;
+		if (cfile.Open(file.c_str(), CFile::modeCreate | CFile::modeWrite))
+		{
+			cfile.Write(pData, ulLength);
+			cfile.Close();
+		}
 
+		delete[]pData;
+		pData = NULL;
+	}
 
-	return 0;
+	return bResult;
 }
 
 BOOL CDatabase::InsertQuarter(const STQuarter& quarter)
@@ -1199,6 +1232,55 @@ BOOL CDatabase::QueryQBrand(std::vector<STQbrand>& vtQBrand)
 	return TRUE;
 }
 
+BOOL CDatabase::ImportQBrandLogo(std::string file, std::string brand, std::string soc, std::string quarter)
+{
+	if (!PathFileExists(file.c_str()))
+		return FALSE;
+
+	// ¶Á³öͼƬ;
+	CFile cfile;
+	if (!cfile.Open(file.c_str(), CFile::modeRead, NULL))
+		return FALSE;
+
+	ULONGLONG ulLength = cfile.GetLength();
+	char* pData = new char[ulLength];
+	cfile.Read(pData, ulLength);
+	cfile.Close();
+
+	TCHAR szSql[MAX_PATH] = { 0 };
+	_stprintf_s(szSql, _T("update qbrand set logo = ? where `soc` = '%s' and `quarter`='%s' and `brand`='%s';"), soc.c_str(), quarter.c_str(), brand.c_str());
+
+	BOOL bResult = SetBinaryField(szSql, pData, ulLength);
+	if (pData)
+		delete[]pData;
+	pData = NULL;
+
+	return bResult;
+}
+
+BOOL CDatabase::ExportQBrandLogo(std::string file, std::string brand, std::string soc, std::string quarter)
+{
+	char* pData = NULL;
+	unsigned long ulLength = 0;
+	TCHAR szSql[MAX_PATH] = { 0 };
+	_stprintf_s(szSql, _T("select logo from qbrand where `soc` = '%s' and `quarter`='%s' and `brand`='%s';"), soc.c_str(), quarter.c_str(), brand.c_str());
+	BOOL bResult = GetBinaryField(szSql, (void**)&pData, ulLength);
+	if (bResult && pData)
+	{
+		CFile cfile;
+		if (cfile.Open(file.c_str(), CFile::modeCreate | CFile::modeWrite))
+		{
+			cfile.Write(pData, ulLength);
+			cfile.Close();
+		}
+
+		delete[]pData;
+		pData = NULL;
+	}
+
+	return bResult;
+}
+
 // ʾÀý;
 void test(MYSQL* mysql)
 {

+ 5 - 2
CTSManager/CTSManager/Database.h

@@ -87,8 +87,8 @@ public:
 	BOOL UpdateBrand(std::string name, const STBranch& brand);
 	BOOL QueryBrand(std::vector<STBranch>& vtBrand);
 	// 导入/导出品牌logo;
-	BOOL ImportLogo(std::string brand, std::string file, BOOL bQuarter=FALSE);
-	BOOL ExportLogo(std::string brand, std::string file, BOOL bQuarter=FALSE);
+	BOOL ImportBrandLogo(std::string brand, std::string file);
+	BOOL ExportBrandLogo(std::string brand, std::string file);
 
 	// 季度表;
 	BOOL InsertQuarter(const STQuarter& quarter);
@@ -123,6 +123,9 @@ public:
 	BOOL UpdateQBrand(std::string brand, STQbrand& QBrand);
 	BOOL UpdateQBrand(std::string soc, std::string quarter, std::string brand, STQbrand &QBrand);
 	BOOL QueryQBrand(std::vector<STQbrand>& vtQBrand);
+	// 导入/导出品牌logo;
+	BOOL ImportQBrandLogo(std::string file, std::string brand, std::string soc, std::string quarter);
+	BOOL ExportQBrandLogo(std::string file, std::string brand, std::string soc, std::string quarter);
 };