#include "StdAfx.h" #include "ChoosePhotoBase.h" #include "YLGL.h" #include "./helper/ffsco.h" using namespace helper_coffs; unsigned __stdcall LoadThumbNail3(LPVOID lpParam); ChoosePhotoBase::ChoosePhotoBase() { m_SelectCategory = INDX_ALL; m_bSaveFail = 0; m_liapath = _T(""); m_path = _T(""); // 选片或看设计的片种目录; m_strOrderNumber = _T(""); m_status8 = _T(""); m_name = _T(""); m_seltxname = _T(""); taoxiname = _T(""); m_taoxijiage = _T(""); m_waiter1 = _T(""); m_waiter2 = _T(""); m_clothescount = _T(""); ren = _T(""); m_time5old = _T(""); m_time6old = _T(""); m_checkstatus = _T(""); // 未看 或者 OK; m_size = _T(""); m_oldmoney3 = _T(""); m_name1 = _T(""); m_name2 = _T(""); m_phone1 = _T(""); m_phone2 = _T(""); m_time4 = _T(""); m_waiter3 = _T(""); // 选片人员(g_user.name当前登陆系统人员) m_takezs = _T(""); m_taoxizs = _T(""); m_choosezs = _T(""); m_money3 = _T(""); m_urgent = _T(""); m_bz3 = _T(""); m_bz4 = _T(""); m_bz2 = _T(""); m_time5 = _T(""); m_time6 = _T(""); m_bSave = 0; m_bModify = 0; m_showpichwd = NULL; m_pHideImg = NULL; //相片icon m_pBk = NULL; m_Runingmode = 0; // 作用:选片模式==0、看设计模式==1, 默认为0; m_bRunning = false; // 线程运行标志 m_bTerminate = false; // 线程终止的标志 m_dwThreadID = 0; // Thread ID m_hThread = NULL; m_hEvent = NULL; // Thread and Event handle m_bSort = 0; m_bCanSave = 1; m_ticks = 0; m_timer = 0; m_nChoosePhotoType = 0; m_sChooseFilter = _T(""); m_bGrowthTX = 0; m_bHide = FALSE; //是否显示小图 m_bFromLocal = 0; //是否通过本地获取相图路径 } ChoosePhotoBase::ChoosePhotoBase(DWORD id, CWnd *pParent) : CDialog(id, pParent) { m_SelectCategory = INDX_ALL; m_bSaveFail = 0; m_liapath = _T(""); m_path = _T(""); // 选片或看设计的片种目录; m_strOrderNumber = _T(""); m_status8 = _T(""); m_name = _T(""); m_seltxname = _T(""); taoxiname = _T(""); m_taoxijiage = _T(""); m_waiter1 = _T(""); m_waiter2 = _T(""); m_clothescount = _T(""); ren = _T(""); m_time5old = _T(""); m_time6old = _T(""); m_checkstatus = _T(""); // 未看 或者 OK; m_size = _T(""); m_oldmoney3 = _T(""); m_name1 = _T(""); m_name2 = _T(""); m_phone1 = _T(""); m_phone2 = _T(""); m_time4 = _T(""); m_waiter3 = _T(""); // 选片人员(g_user.name当前登陆系统人员) m_takezs = _T(""); m_taoxizs = _T(""); m_choosezs = _T(""); m_money3 = _T(""); m_urgent = _T(""); m_bz3 = _T(""); m_bz4 = _T(""); m_bz2 = _T(""); m_time5 = _T(""); m_time6 = _T(""); m_bSave = 0; m_bModify = 0; m_showpichwd = NULL; m_pHideImg = NULL; //相片icon m_pBk = NULL; m_bRunning = false; // 线程运行标志 m_bTerminate = false; // 线程终止的标志 m_dwThreadID = 0; // Thread ID m_hThread = NULL; m_hEvent = NULL; // Thread and Event handle m_Runingmode = 0; // 作用:选片模式==0、看设计模式==1, 默认为0; m_bSort = 0; m_bCanSave = 1; m_ticks = 0; m_timer = 0; m_nChoosePhotoType = 0; m_sChooseFilter = _T(""); m_bGrowthTX = 0; m_bHide = TRUE; //是否显示小图 m_bFromLocal = 0; //是否通过本地获取相图路径 } ChoosePhotoBase::~ChoosePhotoBase() { } BOOL ChoosePhotoBase::OnInitDialog() { CDialog::OnInitDialog(); return TRUE; } CStringArray* ChoosePhotoBase::GetCurArray(const int nIndx, SFolderInfo* m_pForder) { return NULL; } BOOL ChoosePhotoBase::OnDel() { return TRUE; } //点击右键事件 void ChoosePhotoBase::OnRclickList1() { } CString ChoosePhotoBase::GetZSInfo(int iItem){return _T("");} BOOL ChoosePhotoBase::ReLoad(){return TRUE;} BOOL ChoosePhotoBase::GetData(){return TRUE;} void ChoosePhotoBase::UpdateChooseZS(){} void ChoosePhotoBase::LoadPhotos(){} //通过文件夹获取所有文件 void ChoosePhotoBase::GetAllFileFromFolder(const int nType, CString& strFileNames){} /************************************************************************/ /* 函数: ReLoadImageFromRes 描述: 重新从资源里加载图片 参数: Image** pImageOut, 图片资源指针 const CString& strFile, 图片路径 BOOL& bNulling 返回: 1成功,0失败 */ /************************************************************************/ int ChoosePhotoBase::ReLoadImageFromRes(Image** pImageOut, const CString& strFile, BOOL& bNulling) { CString str = strFile; CString spath = str.Left(str.ReverseFind('\\') + 1); spath += "s"; spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1); if (PathFileExists(spath)) ::LoadImageFromBuf(pImageOut, spath); else if (PathFileExists(str)) ::LoadImageFromBuf(pImageOut, str); else bNulling = TRUE; if ((*pImageOut) == NULL || (*pImageOut)->GetWidth() == 0) return 0; int orientation = GetOrientation((*pImageOut)); if (orientation == 8) (*pImageOut)->RotateFlip(Rotate270FlipNone); //旋转、翻转或者同时旋转和翻转 else if (orientation == 6) (*pImageOut)->RotateFlip(Rotate90FlipNone); return 1; } /************************************************************************/ /* 函数: GetDelPhotos 描述: 获取删除的所有相片名 参数: OUT CString& strDelPhotos 返回相片名集合 返回: */ /************************************************************************/ void ChoosePhotoBase::GetDelPhotos(OUT CString& strDelPhotos) { for (int i = 0; i < m_DelPhotoPath.GetSize(); i++) { if (strDelPhotos.GetLength() > 4096) break; CString no = m_DelPhotoPath.ElementAt(i); //在选片时被删除的相片名的全路径集合; no = no.Right(no.GetLength() - no.ReverseFind('\\') - 1); no = no.Left(no.Find('.')); strDelPhotos += no; #ifdef USE_SEP_VEB strDelPhotos += SEPS_VEB; #else strDelPhotos += SEPS_SCN; #endif //#ifdef USE_SEP_VEB } // strDelPhotos:解析为只有相片名,以分号为分隔符的字符串; if (!strDelPhotos.IsEmpty()) { #ifdef USE_SEP_VEB strDelPhotos.TrimLeft(SEPS_VEB); #else strDelPhotos.TrimLeft(SEPS_SCN); #endif //#ifdef USE_SEP_VEB } } void ChoosePhotoBase::GetNoSelPhoto(){} //获取所有文件夹名 void ChoosePhotoBase::GetAllFolderNames(CString& strNames){} void ChoosePhotoBase::SetLiaPath(CString path) { m_liapath = path; } void ChoosePhotoBase::DrawInterface(){} /************************************************************************/ /* 函数: ZoomImage 描述: 缩放图片大小 参数: 返回: */ /************************************************************************/ void ChoosePhotoBase::ZoomImage(Image* pImage, Rect& desRt) { int XDest(0), YDest(0), nDestWidth(0), nDestHeight(0); const float fRatio = (float)THUMBNAIL_HEIGHT / THUMBNAIL_WIDTH; const float fImgRatio = (float)pImage->GetHeight() / pImage->GetWidth(); if (fImgRatio > fRatio) { nDestWidth = THUMBNAIL_HEIGHT / fImgRatio; XDest = (THUMBNAIL_WIDTH - nDestWidth) / 2; YDest = 0; nDestHeight = THUMBNAIL_HEIGHT; } else { XDest = 0; nDestWidth = THUMBNAIL_WIDTH; nDestHeight = THUMBNAIL_WIDTH*fImgRatio; YDest = (THUMBNAIL_HEIGHT - nDestHeight) / 2; } desRt.X = XDest; desRt.Y = YDest; desRt.Width = nDestWidth; desRt.Height = nDestHeight; } CString ChoosePhotoBase::GetModifyTime2(CString path) { HANDLE hFile; WIN32_FIND_DATA wfd; SYSTEMTIME systime; FILETIME localtime; CString stime; //输出时间 memset(&wfd, 0, sizeof(wfd)); if ((hFile = FindFirstFile(path, &wfd)) == INVALID_HANDLE_VALUE) return _T(""); //ok,转换时间 FileTimeToLocalFileTime(&wfd.ftLastWriteTime, &localtime); FileTimeToSystemTime(&localtime, &systime); stime.Format("%4d%02d%02d", systime.wYear, systime.wMonth, systime.wDay); return stime; } /************************************************************************/ /* 函数: GetPathFromNo2 描述: 通过No2获取路径 参数: CString dir, 目标目录 CString no, 图片名 CStringArray *pArray 目标路径集合 返回: 返回获取的路径 */ /************************************************************************/ CString ChoosePhotoBase::GetPathFromNo2(CString dir, CString no, CStringArray *pArray) { CString path = _T(""); for (int i = 0; i < pArray->GetSize(); i++) { path = pArray->ElementAt(i); path = path.Right(path.GetLength() - path.ReverseFind('\\') - 1); if (path.Find(_T(".")) != -1) path = path.Left(path.Find(_T("."))); if ( no.CompareNoCase(path) == 0 ) return pArray->ElementAt(i); } return _T(""); } /************************************************************************/ /* 函数:GetZS 描述:返回dindansp表中no或no2字段中关于选中相片名的相片数量; 参数: str:dindansp表no或no2字段值,使用逗号分隔开所有相片名; 返回: 返回no或no2字段中,所包含的相片名数量; */ /************************************************************************/ int ChoosePhotoBase::GetZS(CString str) { #ifdef USE_SEP_VEB str.TrimLeft(SEPS_VEB); str.TrimRight(SEPS_VEB); if (str.IsEmpty()) return 0; int pos = str.Find(SEPS_VEB); int count = 1; while (pos != -1) { str.Delete(pos); pos = str.Find(SEPS_VEB); count++; } #else str.TrimLeft(SEPS_CMA); str.TrimRight(SEPS_CMA); if (str.IsEmpty()) return 0; int pos = str.Find(SEPC_CMA); int count = 1; while (pos != -1) { str.Delete(pos); pos = str.Find(SEPC_CMA); count++; } #endif //#ifdef USE_SEP_VEB return count; } /************************************************************************/ /* 函数:GetSelCountFromName 描述:返回相片数量; 参数: IN CString name, OUT CString &scount 返回: */ /************************************************************************/ void ChoosePhotoBase::GetSelCountFromName(CString name, CString &scount) { #ifdef USE_SEP_VEB name.TrimLeft(SEPS_VEB); name.TrimRight(SEPS_VEB); #else name.TrimLeft(SEPS_CMA); name.TrimRight(SEPS_CMA); #endif //#ifdef USE_SEP_VEB if (name.GetLength() == 0) { scount = "0"; return; } int ncount = 0; #ifdef USE_SEP_VEB int npos = name.Find(SEPS_VEB); #else int npos = name.Find(SEPS_CMA); #endif //#ifdef USE_SEP_VEB while (npos != -1) { ncount++; name = name.Right(name.GetLength() - npos - 1); #ifdef USE_SEP_VEB npos = name.Find(SEPS_VEB); #else npos = name.Find(SEPS_CMA); #endif //#ifdef USE_SEP_VEB } ncount++; scount.Format("%d", ncount); } /************************************************************************/ /* 函数: GetPathFromNo 描述: 通过图片名获取路径 参数: CString dir, 目标目录 CString no, 图片名 CStringArray *pArray 目标路径集合 返回: 返回获取的路径 */ /************************************************************************/ CString ChoosePhotoBase::GetPathFromNo(CString dir, CString no, CStringArray *pArray) { CStringArray dirarray; CString sRet = _T(""); CString temp = _T(""); dir.TrimRight('\\'); dir += _T("\\"); if (pArray->GetSize() == 0) { ffsco o; o.dirs(1); o.find(LPCSTR(dir), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_dir(); for (it = coo.begin(); coo.end() != it; it++) { temp = (*it).c_str(); if (::FindArray(&dirarray, temp) == -1 && temp != dir) dirarray.Add(temp); } } else dirarray.Copy(*pArray); for (int i = 0; i < dirarray.GetSize(); i++) { temp = dirarray.ElementAt(i); sRet.Format(_T("%s%s.jpg"), temp, no); if (::PathFileExists(sRet)) return sRet; } return dir + no + _T(".jpg"); } void ChoosePhotoBase::SortArray2(CArray&datearray) { int strtemp; int last = datearray.GetSize() - 1; bool sorted = true; do { sorted = true; for (int i = 0; i < last; i++) { if (datearray[i] < datearray[i + 1]) { strtemp = datearray[i]; datearray[i] = datearray[i + 1]; datearray[i + 1] = strtemp; sorted = false; } } last--; } while (!sorted); } /*-------------------------------------------------- // 函数: DelPhotoFromName // 描述: 通过名字删除 // 参数: CStringArray& arr, 文件列表 const CString& strName 文件名 // 返回: 成功1,失败0; //--------------------------------------------------*/ int ChoosePhotoBase::DelPhotoFromName(CStringArray& arr, const CString& strName) { if(strName == _T("") || arr.GetSize() == 0) return 0; CString strName2 = _T(""); for (int i = 0; i < arr.GetSize(); i++) { strName2 = arr.ElementAt(i); strName2 = strName2.Right(strName2.GetLength() - strName2.ReverseFind('\\') - 1); strName2 = strName2.Left(strName2.Find('.')); if (strName == strName2) { arr.RemoveAt(i); return 1; } } return 0; } /************************************************************************/ /* 函数: GetAllPhotoPath 描述: 获取全部相片路径 参数: CSting &strDirPath 目录路径 返回: */ /************************************************************************/ void ChoosePhotoBase::GetAllPhotoPath(CString& strDirPath, CStringArray& arr) { // 查找m_path下所有文件o.find(...); CString filename = _T(""); CString path(_T("")), path2(_T("")); ffsco o; o.dirs(1); o.find(LPCSTR(strDirPath), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_file(); for (it = coo.begin(); coo.end() != it; it++) // 遍历文件夹; { path = (*it).c_str(); if (path.GetAt(path.ReverseFind('\\') + 1) != 's' && path.GetAt(path.ReverseFind('\\') + 1) != 'm') { path.MakeLower(); filename = path.Right(path.GetLength() - path.ReverseFind('\\') - 1); if (filename.Find(_T(".")) != -1) filename = filename.Left(filename.Find(_T("."))); if (!myisdigit(filename))continue; if (m_nChoosePhotoType == 1) // m_AllPhotoPath只添加修片文件夹; { #if JEFF_TEST_ON if(PathFileExists(path)) arr.Add(path); #endif //#if JEFF_TEST_ON } else if (m_nChoosePhotoType == 0 || m_nChoosePhotoType == 2)//else // m_nChoosePhotoType=0,2 { path2 = path; if (m_nChoosePhotoType == 0) // 原片+修片; { path2.Replace(_T("客户原片"), _T("修好的片")); //printf("Jeff:原片+修片 path2=%s\n\n",path2); // Jeff Printf; } if (m_bGrowthTX == 0) { int pos = path2.Find(m_strOrderNumber); pos += m_strOrderNumber.GetLength(); int pos2 = path2.ReverseFind('\\'); path2 = path2.Left(pos) + path2.Right(path2.GetLength() - pos2); } if (m_nChoosePhotoType == 0 && PathFileExists(path2)) // 原片+修片; { arr.Add(path2); } else // 不仅原片 { path2.Replace(_T(".raw"), _T(".jpg")); if (PathFileExists(path2)) { arr.Add(path2); continue; } path2.Replace(_T(".nef"), _T(".jpg")); if (PathFileExists(path2)) { arr.Add(path2); continue; } path2.Replace(_T(".cr2"), _T(".jpg")); if (PathFileExists(path2)) { arr.Add(path2); continue; } else { if (path.Right(3) != _T("jpg")) continue; #if JEFF_TEST_ON if (PathFileExists(path)) arr.Add(path); #else arr.Add(path); #endif //#if JEFF_TEST_ON } } } } } } /************************************************************************/ /* 函数:GetTXName[4/17/2016 IT]; /* 描述:若是儿童成长套系,获取成长套系内容; /* 参数:; /* [IN] pStrOrder:订单号; /* [IN] nModle:选片或选设计, nModel == 0 表示选片, nMode == 1 表示选设计; /* [OUT] bGrowthTx:若查询是儿童成长套系,返回TRUE; /* [OUT] strTxName:若查询是儿童成长套系,返回要选片的成长套系名; /* 返回:void; /* 注意:; /* 示例:; /* /* 修改:; /* 日期:; /* 内容:; /************************************************************************/ void ChoosePhotoBase::GetTXName(IN const CString* pStrOrder, IN const int nModle, OUT BOOL& bGrowthTx, OUT CString& strTxName) { if(pStrOrder == NULL || (*pStrOrder) == _T("")) return; IsGrowthTx growthtxdlg; growthtxdlg.m_mode = nModle; growthtxdlg.m_strOrderNumber = (*pStrOrder); growthtxdlg.DoModal(); bGrowthTx = growthtxdlg.m_bGrowthTx; strTxName = growthtxdlg.m_seltxname; } /************************************************************************/ /* 函数: GetPhotos 描述: 得看设计 参数: 返回: */ /************************************************************************/ void ChoosePhotoBase::GetPhotos() { int i = 0; int j = 0; m_AllPhotoPath.RemoveAll(); m_path.MakeLower(); CStringArray dirarray; CString str; if (1) { ffsco o; o.dirs(1); o.find(LPCSTR(m_path), LPCSTR(_T("*.*"))); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_dir(); for (it = coo.begin(); coo.end() != it; it++) { str = (*it).c_str(); str.TrimRight(_T("\\")); CString dirname = str.Right(str.GetLength() - str.ReverseFind('\\') - 1); if (dirname.Find("DelgaBook") != -1) { if (FindArray(&m_AllPhotoPath, str) == -1) m_AllPhotoPath.Add(str); } if (FindArray(&dirarray, str) == -1) dirarray.Add(str); } } if (1) { for ( i = 0; i < dirarray.GetSize(); i++) { ffsco o; o.dirs(0); o.find(LPCSTR(dirarray.ElementAt(i)), LPCSTR("*.jpg")); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_file(); for (it = coo.begin(); coo.end() != it; it++) { str = (*it).c_str(); if (str.GetAt(str.ReverseFind('\\') + 1) == 's')continue; if (str.GetAt(str.ReverseFind('\\') + 1) == 'm')continue; str.MakeLower(); m_AllPhotoPath.Add(str); } } } CStringArray *pArray[1] = { &m_AllPhotoPath }; for ( i = 0; i < 1; i++) { m_combo1.ResetContent(); CString Temp; for ( j = 0; j < pArray[i]->GetSize(); j++) m_combo1.AddString(pArray[i]->ElementAt(j)); for (j = 0; j < pArray[i]->GetSize(); j++) { m_combo1.GetLBText(j, Temp); pArray[i]->SetAt(j, Temp); } } } /************************************************************************/ /* 函数:[3/4/2016 CheckOK]; 描述:判断字符串是否是数字组成; 参数: name 要判断的字符串; 返回:如果是数字组成返回1,否则返回0; */ /************************************************************************/ BOOL ChoosePhotoBase::CheckOK(CString name) { if (name.GetLength() > 4)return 0; for (int i = 0; i < name.GetLength(); i++) { if (name.GetAt(i) < '0' || name.GetAt(i) > '9')return 0; } return 1; } /************************************************************************/ /* 函数: GetSelName 描述: 获取文件名 参数: CString name 相片名 返回: 注意: */ /************************************************************************/ CString ChoosePhotoBase::GetSelName(CString name) { CString ret; int i = 0; #ifdef USE_SEP_VEB name = SEPS_VEB + name + SEPS_VEB; #else name = SEPS_CMA + name + SEPS_CMA; #endif //#ifdef USE_SEP_VEB for ( i = 0; i < m_List2.GetItemCount(); i++) { if (m_noarray.ElementAt(i).Find(name) != -1) {// 获取数量; ret += m_List2.GetItemText(i, 2); ret += _T("\r\n"); } } for (i = 0; i < m_List3.GetItemCount(); i++) { if (m_no2array.ElementAt(i).Find(name) != -1) {// 获取商品名称; ret += m_List3.GetItemText(i, 2); ret += _T("\r\n"); } } if (!ret.IsEmpty()) { ret = _T("\r\n") + ret; ret.TrimRight("\r\n"); } return ret; } /************************************************************************/ /* 函数: ClearResData 描述: 清除资源的路径 参数: 返回: */ /************************************************************************/ void ChoosePhotoBase::ClearResData() { vector::iterator it = m_vResData.begin(); for(;it != m_vResData.end();) { SResData* p = (*it); if(p != NULL) delete p; ++it; } m_vResData.clear(); } /************************************************************************/ /* 函数: RecordDeletedPhotos 描述: 记录已删除的相片 参数: CString* pStrDel, 要删除的相片 CStringArray& arr 要删除的相片保存到array 返回: 注意: */ /************************************************************************/ void ChoosePhotoBase::RecordDeletedPhotos(CString* pStrDel, CStringArray& arr) { if(pStrDel == NULL || (*pStrDel) == _T("")) return; //添加删除相片; #ifdef USE_SEP_VEB m_delphotos.TrimLeft(SEPC_VEB); m_delphotos.TrimRight(SEPC_VEB); m_delphotos = SEPC_VEB + m_delphotos; m_delphotos += SEPC_VEB; #else m_delphotos.TrimLeft(SEPC_SCN); m_delphotos.TrimRight(SEPC_SCN); m_delphotos = SEPC_SCN + m_delphotos; m_delphotos += SEPC_SCN; #endif //#ifdef USE_SEP_VEB for (int i = m_AllPhotoPath.GetSize() - 1; i >= 0; i--) { CString no; no = m_AllPhotoPath.ElementAt(i); no = no.Right(no.GetLength() - no.ReverseFind('\\') - 1); no = no.Left(no.Find('.')); #ifdef USE_SEP_VEB no = SEPC_VEB + no; no += SEPC_VEB; #else no = SEPC_SCN + no; no += SEPC_SCN; #endif //#ifdef USE_SEP_VEB if (m_delphotos.Find(no) != -1) { no = m_AllPhotoPath.ElementAt(i); m_AllPhotoPath.RemoveAt(i); #if JEFF_TEST_ON if(PathFileExists(no)) arr.Add(no); #else arr.Add(no); #endif //JEFF_TEST_ON } } } /************************************************************************/ /* 函数: AddPhotoFromDir 描述: 添加选中相片 参数: CStringArray* pSelArr 选中相片集合 const CString& strDir, 目标目录 CString& str 文件名: ",004," const int nPos 字符','在文件名的位置 返回: 1成功, 0失败 */ /*************************************************************************/ int ChoosePhotoBase::AddPhotoFromDir(CStringArray* pSelArr, const CString& strDir, CString& str) { if(pSelArr == NULL || strDir.IsEmpty() || str == _T("")) return 0; CString path(_T("")); #ifdef USE_SEP_VEB int pos = str.Find(SEPS_VEB); #else int pos = str.Find(SEPS_CMA); #endif //#ifdef USE_SEP_VEB while (pos != -1) { path = strDir + str.Left(pos) + _T(".jpg"); if (FindArray(pSelArr, path) == -1) { #if JEFF_TEST_ON if (PathFileExists(path)) pSelArr->Add(path); #else pSelArr->Add(path); #endif //#if JEFF_TEST_ON } str = str.Right(str.GetLength() - pos - 1); #ifdef USE_SEP_VEB pos = str.Find(SEPS_VEB); #else pos = str.Find(SEPC_CMA); #endif //#ifdef USE_SEP_VEB } path = strDir + str + _T(".jpg"); if (FindArray(pSelArr, path) == -1) { #if JEFF_TEST_ON if (PathFileExists(path)) pSelArr->Add(path); #else pSelArr->Add(path);//MessageBox(path); #endif //#if JEFF_TEST_ON } return 1; } void ChoosePhotoBase::CalChooseZS(CStringArray* pSelArr, CStringArray* pAllArr) { if(pSelArr == NULL || pAllArr == NULL) return; int i = 0; CString str = _T(""); pSelArr->RemoveAll(); for ( i = 0; i < m_noarray.GetSize(); i++) { str = m_noarray.ElementAt(i); GetPathAddToSel(pSelArr, str, pAllArr); } for (i = 0; i < m_no2array.GetSize(); i++) { str = m_no2array.ElementAt(i); GetPathAddToSel(pSelArr, str, pAllArr); } } //-------------------------------------------------- // remark by Jeff 2014.12.15 // 函数:CheckName // 描述:类似CheckOK,判断字符串是否是数字组成(除去"$" "."两符号以及后缀名); // 参数:name 要判断的字符串; // 返回:如果是数字组成返回1,否则返回0; //-------------------------------------------------- BOOL ChoosePhotoBase::CheckName(CString name) {//$001.002.003 int pos = name.Find("$"); if (pos != 0)return 0; name.Delete(0, 1); pos = name.Find("."); while (pos != -1) { if (CheckOK(name.Left(pos)) == 0)return 0; name = name.Right(name.GetLength() - pos - 1); pos = name.Find("."); } return CheckOK(name); } /************************************************************************/ /* 函数:GetPathAddToSel[4/17/2016 IT]; /* 描述:获取路径添加到选中相片; /* 参数:; /* [IN] pSelArr:dindapsp.no或dindansp.no2的相片路径结果集; /* [IN] strName:dindansp表中每个商品记录中的no字段对应的相片串; /* [IN] pAllArr:strName的相片路径来源; /* 返回:1成功,0失败; /* 注意:; /* 示例:; /* /* 修改:; /* 日期:; /* 内容:; /************************************************************************/ int ChoosePhotoBase::GetPathAddToSel(CStringArray* pSelArr, const CString& strName, CStringArray* pAllArr) { if(pSelArr == NULL || strName == _T("") || pAllArr == NULL) return 0; CString str = strName; if (m_bFromLocal) { // 本地(缓存)加载选片 #ifdef USE_SEP_VEB str.TrimLeft(SEPS_VEB); str.TrimRight(SEPS_VEB); #else str.TrimLeft(SEPS_CMA); str.TrimRight(SEPS_CMA); #endif //#ifdef USE_SEP_VEB if (str.IsEmpty()) return 0; CString path(_T("")), path2(_T("")); #ifdef _UNICODE WCHAR spath[MAX_PATH] = {0}; #else char spath[MAX_PATH] = {0}; #endif //#ifdef _UNICODE ::GetSystemDirectory(spath, MAX_PATH); CString sysdir = spath; sysdir += _T("\\lyfz"); sysdir += _T("\\"); sysdir += m_strOrderNumber; sysdir += _T("\\"); AddPhotoFromDir(pSelArr, sysdir, str); } else { #ifdef USE_SEP_VEB str.TrimLeft(SEPS_VEB); str.TrimRight(SEPS_VEB); #else str.TrimLeft(SEPS_CMA); str.TrimRight(SEPS_CMA); #endif //#ifdef USE_SEP_VEB if (str.IsEmpty()) return 0; #ifdef USE_SEP_VEB int pos = str.Find(SEPS_VEB); #else int pos = str.Find(SEPS_CMA); #endif //#ifdef USE_SEP_VEB CString path(_T("")), path2(_T("")); while (pos != -1) { path = GetPathFromNo2(m_path, str.Left(pos), pAllArr); path2 = path; if (path != _T("") && FindArray(pSelArr, path) == -1) { if (PathFileExists(path)) pSelArr->Add(path); } str = str.Right(str.GetLength() - pos - 1); #ifdef USE_SEP_VEB pos = str.Find(SEPS_VEB); #else pos = str.Find(SEPS_CMA); #endif //#ifdef USE_SEP_VEB } path = GetPathFromNo2(m_path, str, pAllArr);//+".jpg"; path2 = path; if(path == _T("")) return 0; if (FindArray(pSelArr, path) == -1) { if (PathFileExists(path)) pSelArr->Add(path); } } return 1; } /************************************************************************/ /* 函数: LoadThumbImages 描述: 创建线程加载函数LoadThumbNail3 参数: 返回: 注意: */ /************************************************************************/ void ChoosePhotoBase::LoadThumbImages() { TerminateThread(); m_hThread = (HANDLE)_beginthreadex(NULL, 0, LoadThumbNail3, (LPVOID)this, 0/* CREATE_SUSPENDED*/, &m_dwThreadID); m_bRunning = true; } BOOL ChoosePhotoBase::TerminateThread() { if (!m_bRunning) return TRUE; m_bTerminate = true; for (;;) { if (::WaitForSingleObject(m_hThread, 0) == WAIT_OBJECT_0) break; MSG msg; while (::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { if (!AfxGetApp()->PumpMessage()) break; } } ::CloseHandle(m_hThread); m_hThread = NULL; return TRUE; } //extern void LoadImageFromFile(Image **img, CString path); unsigned __stdcall LoadThumbNail3(LPVOID lpParam) { ChoosePhotoBase* pDlg = (ChoosePhotoBase*)lpParam; pDlg->DrawImageWork(); return 0; } void ChoosePhotoBase::Save(IN LPCTSTR lpPath, IN LPCTSTR lpFileName) { int i = 0; int j = 0; CString sql; CArraysparray; sparray.SetSize(m_List2.GetItemCount() + m_no2array.GetSize()); for ( i = 0; i < m_List2.GetItemCount(); i++) { sparray.ElementAt(i).Add(m_strOrderNumber); sparray.ElementAt(i).Add(m_List2.GetItemText(i, 0)); sparray.ElementAt(i).Add(m_List2.GetItemText(i, 1)); sparray.ElementAt(i).Add(m_List2.GetItemText(i, 2)); sparray.ElementAt(i).Add(m_List2.GetItemText(i, 3)); sparray.ElementAt(i).Add(m_List2.GetItemText(i, 4)); } for ( j = 0; j < m_no2array.GetSize(); j++) { sparray.ElementAt(i).Add(m_strOrderNumber); sparray.ElementAt(i).Add(m_List3.GetItemText(j, 0)); sparray.ElementAt(i).Add(m_List3.GetItemText(j, 1)); sparray.ElementAt(i).Add(m_List3.GetItemText(j, 2)); sparray.ElementAt(i).Add(m_List3.GetItemText(j, 3)); sparray.ElementAt(i).Add(m_List3.GetItemText(j, 4)); sparray.ElementAt(i).Add(m_List3.GetItemText(j, 5)); #ifdef LKAY_VERSION sparray.ElementAt (i).Add ( m_List3.GetItemText (j, 6) ); sparray.ElementAt (i).Add ( m_List3.GetItemText (j, 7) ); #endif //#ifdef LKAY_VERSION sparray.ElementAt(i).Add("4"); i++; } if (sparray.GetSize() == 0) { sparray.SetSize(1); sparray.ElementAt(0).Add(m_strOrderNumber); } CMemFile memfile; CArchive ar(&memfile, CArchive::store); for (int ii = 0; ii < sparray.GetSize(); ii++) { sparray.ElementAt(ii).Serialize(ar); } ar.Close(); int length = memfile.GetLength(); BYTE *pData = memfile.Detach(); int size = sparray.GetSize(); BYTE *pData2 = new BYTE[length + sizeof(int)]; memcpy(pData2, pData, length); memcpy(pData2 + length, &size, sizeof(int)); delete[]pData; length += sizeof(int); CString savepath = _T(""); //savepath.Format("%s\\%s.dat", g_mainpath, lpFileName/*m_strOrderNumber*/);选片 //savepath.Format("%s\\%s-2.dat", g_mainpath, lpFileName/*m_strOrderNumber*/);选版 savepath.Format("%s\\%s.dat", lpPath, lpFileName); if (1) { CFile fp; fp.Open(savepath, CFile::modeCreate | CFile::modeWrite); fp.Write(pData2, length); fp.Close(); } delete[]pData2; } /************************************************************************/ /* 函数: IsFileExist 描述: 文件是否存在 参数: 返回: */ /************************************************************************/ BOOL ChoosePhotoBase::IsFileExistInDir(CString* pPath) { BOOL bExist = FALSE; if(pPath == NULL || (*pPath) == _T("")) return bExist; ffsco o; o.dirs(0); o.find(pPath->GetBuffer(pPath->GetLength()), LPCSTR("*.jpg")); int nsize = o.co_file().size(); if (nsize > 0) bExist = TRUE; return bExist; } /************************************************************************/ /* 函数:IsSelPhoto[4/18/2016 IT]; /* 描述:是否选取相片; /* 参数:; /* [IN] strPhotoName:如:"|004|"; /* [OUT] :; /* [IN/OUT] :; /* 返回:void; /* 注意:; /* 示例:; /* /* 修改:; /* 日期:; /* 内容:; /************************************************************************/ BOOL ChoosePhotoBase::IsSelPhoto(CString strPhotoName) { int nPos = 0; int i = 0; for (i = 0; i < m_no2array.GetSize(); i++) { // m_no2array.ElementAt(i) 前后都有 SEPS_VEB; if ( m_no2array.ElementAt(i).Find(strPhotoName) != -1 ) { return TRUE; } } for (i = 0; i < m_noarray.GetSize(); i++) { // m_noarray.ElementAt(i) 前后都有 SEPS_VEB; if ( m_noarray.ElementAt(i).Find(strPhotoName) != -1 ) { return TRUE; } } return FALSE; } /************************************************************************/ /* 函数: IsPhoto2Exist 描述: 参数: 返回: 0,>1 */ /************************************************************************/ BOOL ChoosePhotoBase::IsPhoto2Exist() { CString path2; CString path = _T(""); path = g_path2 + _T("\\"); path += m_strOrderNumber; path += _T("\\"); CStringArray StrSubFoloderArray; ffsco o; o.dirs(1); // Jeff.1:查找子目录; o.find(LPCSTR(path), LPCSTR("*.*")); // 可能存在m和s开头的缩略图,需要过滤掉; if (o.count() == 0) return 0; // 获取子目录数; ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_dir(); for (it = coo.begin(); it != coo.end(); it++) { if (::FindArray(&StrSubFoloderArray, (*it).c_str()) == -1) StrSubFoloderArray.Add((*it).c_str()); } // 获取子目录下的文件数; CStringArray StrPhotoArray; for (int n = 0; n < StrSubFoloderArray.GetSize(); n++) { ffsco op; op.dirs(0); // printf("path=%s\n", StrSubFoloderArray.ElementAt(n)); op.find(LPCSTR(StrSubFoloderArray.ElementAt(n)), LPCSTR("*.*")); ffsco::typeT coo; ffsco::typeT::iterator itp; coo = op.co_file(); for (itp = coo.begin(); itp != coo.end(); itp++) { StrPhotoArray.Add((*itp).c_str()); } } CString strTempFile; int nIndex = 0; int nSizeOfFile = 0; // 记录相片文件数; int nCount = StrPhotoArray.GetSize(); for (int i = 0; i < nCount; i++) { strTempFile = StrPhotoArray.ElementAt(i); nIndex = strTempFile.ReverseFind('\\'); strTempFile = strTempFile.Right(strTempFile.GetLength() - nIndex - 1); // printf("file=%s\n", strTempFile); if (strTempFile.Left(1) == _T("m") || strTempFile.Left(1) == _T("s")) { continue; } strTempFile = strTempFile.Right(4); strTempFile.MakeLower(); if (strTempFile == _T(".jpg")) { nSizeOfFile++; } else if (strTempFile == _T(".raw")) { nSizeOfFile++; } else if (strTempFile == _T(".cr2")) { nSizeOfFile++; } else if (strTempFile == _T(".nef")) { nSizeOfFile++; } } return nSizeOfFile; } void ChoosePhotoBase::OnPaint2(CWnd *pWnd) { try { CPaintDC dc(pWnd); // device context for painting // TODO: Add your message handler code here CRect rc; GetClientRect(rc); if (m_pBk == NULL) { return; } int width = m_pBk->GetWidth(); int height = m_pBk->GetHeight(); Graphics graph(dc.GetSafeHdc()); Rect destinationRect(0, 0, rc.Width(), rc.Height()); graph.SetSmoothingMode(SmoothingModeHighQuality); graph.DrawImage(m_pBk, destinationRect, 0, 0, width, height, UnitPixel); } catch (...) { } } /************************************************************************/ /* 函数: IsThereACacheImg 描述: 检查本机上是否有缓存的相片 参数: 返回: */ /************************************************************************/ BOOL ChoosePhotoBase::IsThereACacheImg() { CString str = _T(""); char path[MAX_PATH] = {0}; ::GetSystemDirectory(path, MAX_PATH); CString sysdir = path; sysdir += _T("\\lyfz"); ::CreateDirectory(sysdir, NULL); sysdir += _T("\\"); sysdir += m_strOrderNumber; ffsco o; o.dirs(1); o.find(LPCSTR(sysdir), LPCSTR(_T("*.jpg"))); ffsco::typeT coo; ffsco::typeT::iterator it; coo = o.co_file(); if (coo.size()) { if (AfxMessageBox("提醒, 此客人有本机缓存片,是否使用缓存片?", MB_YESNO | MB_ICONINFORMATION) == IDYES) { for (it = coo.begin(); coo.end() != it; it++) { str = (*it).c_str(); if (str.GetAt(str.ReverseFind('\\') + 1) != 's' && str.GetAt(str.ReverseFind('\\') + 1) != 'm') m_AllPhotoPath.Add(str); } return 1; } } return 0; } /************************************************************************/ /* 函数: GetNoSelPhotoCount 描述: 获取未选相片数量 参数: CStringArray* pAllPhotoPath, CStringArray* pSelPhotoPath 返回: 注意: 返回数量 */ /************************************************************************/ int ChoosePhotoBase::GetNoSelPhotoCount(CStringArray* pAllPhotoPath, CStringArray* pSelPhotoPath) { if(pAllPhotoPath == NULL || pSelPhotoPath == NULL) return 0; int nRet = 0; CString str1, str2; for (int i = 0; i < pAllPhotoPath->GetSize(); i++) { BOOL bFind = 0; for (int j = 0; j < pSelPhotoPath->GetSize(); j++) { str1 = pAllPhotoPath->ElementAt(i); str2 = pSelPhotoPath->ElementAt(j); if (str1.CollateNoCase(str2) == 0) { bFind = 1; break; } } if (bFind == 0) nRet++; } return nRet; } /************************************************************************/ /* 函数: IsFolderExist 描述: 判断共享目录是否存在 参数: const CString& strDomain 域名 std::vector& vPath 共享目录集 返回: TRUE成功,FALSE失败 */ /************************************************************************/ BOOL ChoosePhotoBase::IsShareFolderExist(CString& strSharePath) { if(strSharePath == _T("")) return FALSE; char szPath[MAX_PATH] = { 0 }; #ifdef VC60 strcpy(szPath, strSharePath.GetBuffer(strSharePath.GetLength())); #else _tcscpy_s(szPath, MAX_PATH, strSharePath.GetString()); #endif if(IsExistFolder(szPath) == -1) return FALSE; return TRUE; }