1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084 |
- // ImportPhoto.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ylgl.h"
- #include "ImportPhoto.h"
- #include "MyLock.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- ImportPhoto::ImportPhoto(CWnd* pParent ): CDialog(ImportPhoto::IDD, pParent)
- {
- m_mode = 0;
- m_pArray2 = NULL;
- m_pDesArray = NULL;
- m_exitcode = 0;
- m_bOverWrite = 1;
- m_bBeautifySkinFrom = 0;
- m_bOrigin = 0;
- m_bSaveUploadTask = 0;
- m_bCopyToLocal = 0;
- m_nOutputSize = 0;
- m_bOfmat = 0;
- m_nphototype = -1;
- m_bAddname = 0;
- beginno = -1;
- m_bautono = 1;
- }
- void ImportPhoto::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_PROGRESS1, m_progress);
- }
- BEGIN_MESSAGE_MAP(ImportPhoto, CDialog)
- ON_WM_CLOSE()
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- void ImportPhoto::OnOK()
- {
- // TODO: Add extra validation here
- }
- void ImportPhoto::OnCancel()
- {
- // TODO: Add extra cleanup here
- }
- //----------------------------------------------------
- // remark by Jeff 2014.12.11 pm
- // 函数:GetFileNo
- // 描述:从订单文件夹中获取相片文件的最大编号值;
- // 参数:dir 订单文件夹;
- // 返回:返回订单文件夹中文件编号最大的值+1;
- //
- // 如果使用相片名来保存,就不需要这一步了;
- //----------------------------------------------------
- int ImportPhoto::GetFileNo(CString strOrderFolder)
- {
- if (m_bautono == 0)
- {
- int a = beginno;
- beginno++;
- return a;
- }
- CString path;
- CString path2;
- CString path3;
- CString path4;
- int begin = 1;
- CString temp;
- CStringArray array;
- // 1.查找订单文件夹下的所有文件夹,包括子文件夹下的文件夹;
- using namespace helper_coffs;
- ffsco o;
- o.dirs(1); // 子文件夹也查找;
- o.find(LPCSTR(strOrderFolder), 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(&array, temp) == -1)
- array.Add(temp);
- }
- // 2.查找出订单文件夹下最大编号值的相片名;
- BOOL bFind = 1;
- while (bFind)
- {
- bFind = 0;
- for (int i = 0; i < array.GetSize(); i++)
- {
- strOrderFolder = array.ElementAt(i);
- path.Format("%s%03d.jpg", strOrderFolder, begin);
- path2.Format("%s%03d.raw", strOrderFolder, begin);
- path3.Format("%s%03d.cr2", strOrderFolder, begin);
- path4.Format("%s%03d.NEF", strOrderFolder, begin);
- //while (PathFileExists(path) || PathFileExists(path2) || PathFileExists(path3) || PathFileExists(path4))PathFileExists
- while (PathFileExists(path) || PathFileExists(path2) || PathFileExists(path3) || PathFileExists(path4))
- {
- begin++;
- path.Format("%s%03d.jpg", strOrderFolder, begin);
- path2.Format("%s%03d.raw", strOrderFolder, begin);
- path3.Format("%s%03d.cr2", strOrderFolder, begin);
- path4.Format("%s%03d.NEF", strOrderFolder, begin);
- bFind = 1;
- }
- }
- }
- // 3.返回找到的最大编号值+1;
- beginno = begin + 1;
- return begin;
- }
- void FilterFileName(CString &str)
- {
- //printf("Jeff:保存目录old:%s\n\n",str);
- ///\:*?"<>|
- str.Replace("/", "");
- str.Replace("\\", "");
- str.Replace(":", "");
- str.Replace("*", "");
- str.Replace("?", "");
- str.Replace("\"", "");
- str.Replace("<", "");
- str.Replace(">", "");
- str.Replace("|", "");
- //printf("Jeff:保存目录last:%s\n\n",str);
- }
- UINT ImportPhotoThread(LPVOID lpParameter)
- {
- ImportPhoto *pThis = (ImportPhoto*)lpParameter;
- pThis->m_progress.SetRange(0, pThis->m_pArray->GetSize());
-
- CString filename, filename2;
- CString temp;
- int pos;
- BOOL bNeedGet;
- CString temp2;
- int fileno;
- INT nIndex = -1;
- if (pThis->m_pArray2) // m_pArray2:产品名;
- {
- if (pThis->m_bAddname) // 相片名包含产品名:不生成产品文件夹;
- {
- for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
- {
- filename = pThis->m_pArray->ElementAt(i);
- temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- pos = temp.Find(".");
- temp = temp.Left(pos);
- temp += "(" + pThis->m_name + ",";
- temp2 = pThis->m_pArray2->ElementAt(i) + ").jpg";
- FilterFileName(temp2);
- // Jeff.add:拷贝文件失败,未做处理,最起码要日志记录失败原因;
- ::CopyFile(filename, pThis->m_savepath + temp + temp2, pThis->m_bOverWrite == 0);
- pThis->m_progress.SetPos(i + 1);
- }
- }
- else // 相片名不包含产品,另外生成产品文件夹。
- {
- for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
- {
- filename = pThis->m_pArray->ElementAt(i); //相片文件
- if(filename == _T(""))
- continue;
- filename2 = pThis->m_pArray2->ElementAt(i); //要导出的商品集
- pos = filename2.Find(";");
- while (pos != -1)
- {
- temp = filename2.Left(pos);
- FilterFileName(temp);
- filename2 = filename2.Right(filename2.GetLength() - pos - 1);
- pos = filename2.Find(";");
- // Jeff:生成产品文件夹,然后将与之关联的所有相片都复制一份.
- ::CreateDirectory(pThis->m_savepath + temp, NULL);
- pThis->MyCopyFile(filename, pThis->m_savepath + temp + filename.Right(filename.GetLength() - filename.ReverseFind('\\')), pThis->m_bOverWrite == 0);
- temp2 = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- int pos2 = temp2.Find(".");
- if (pos2 != -1)
- {
- temp2 = temp2.Left(pos2);
- CString filename2;
- }
- }
- temp = filename2;
- FilterFileName(temp);
- ::CreateDirectory(pThis->m_savepath + temp, NULL);
- pThis->MyCopyFile(filename, pThis->m_savepath + temp + filename.Right(filename.GetLength() - filename.ReverseFind('\\')), pThis->m_bOverWrite == 0);
- temp2 = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- pos = temp2.Find(".");
- if (pos != -1)
- {
- temp2 = temp2.Left(pos);
- }
- pThis->m_progress.SetPos(i + 1);
- }
- }
- }
- else if (pThis->m_pDesArray)
- {
- for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
- {
- filename = pThis->m_pArray->ElementAt(i);
- if (pThis->m_mode == 2)
- {
- temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- pos = temp.Find(".");
- bNeedGet = 1;
- if (bNeedGet)// && (g_serverbak!="localserver"))
- filename2.Format("%s%03d.jpg", pThis->m_savepath, pThis->GetFileNo(pThis->m_calnopath));
- else
- filename2.Format("%s%s.jpg", pThis->m_savepath, temp);
- pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
- }
- else
- pThis->MyCopyFile(filename, pThis->m_pDesArray->ElementAt(i), pThis->m_bOverWrite == 0);
- pThis->m_progress.SetPos(i + 1);
- }
- }
- //-----------------------------------------------------------------
- //-----------------------------------------------------------------
- // 1.拍照导入原片;
- // 2.初修导出原片;
- // 3.初修导入修好的修片;
- // 4.初修导出修好的片;
- // 5.选片缓存到本机;
- else
- {
- for (int i = 0; i < pThis->m_pArray->GetSize(); i++)
- {
- // filename源文件的文件名;
- filename = pThis->m_pArray->ElementAt(i);
- // 在导入原片时,该值m_mode=2;
- // 在初修导出原片时,该值m_mode=1;
- // 选片缓存到梧桐时,m_mode=1;
- if (pThis->m_mode == 2)
- {
- // 得到相片的后缀名ext;
- CString ext = filename.Right(filename.GetLength() - filename.ReverseFind('.') - 1);
- if (0)//g_serverbak=="localserver")
- {
- temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- filename2.Format("%s%s", pThis->m_savepath, temp);
- }
- else
- {
- // 在导入原片时,m_calnopath其实就是订单文件夹;
- // 从订单文件夹里获取最大的相片名编号值+1;
- // 这一步过于蛋痛!
- fileno = pThis->GetFileNo(pThis->m_calnopath);
- // 用最大编号+1重新命名新导入的相片名;
- filename2.Format("%s%03d.%s", pThis->m_savepath, fileno, ext);
- }
- // 新文件名:filename2,原文件名filename;boverwrite==0表示新文件名存在就覆盖;
- pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
- }
- else
- {
- if (pThis->m_bBeautifySkinFrom)//修片导入
- {
- temp = pThis->m_savepath + filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- pos = temp.ReverseFind('.');
- if (pos == -1)continue;
- temp = temp.Left(pos);
- pos = 0;
- filename2.Format("%s.jpg", temp);
- pos = 2;
- while (::PathFileExists(filename2))
- {
- filename2.Format("%s-%d.jpg", temp, pos);
- pos++;
- }
- pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == 0);
- }
- else
- {
- if (pThis->m_bOrigin)//原片导出
- {
- temp = filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1);
- pos = temp.Find(".");
- if (pos == -1)continue;
- temp = temp.Left(pos);
- pThis->MyCopyFile(filename, pThis->m_savepath + filename.Right(filename.GetLength() - filename.ReverseFind('\\') - 1), pThis->m_bOverWrite == 0);
- }
- else
- {
- if ( -1 != (nIndex = filename.ReverseFind('\\')) )
- {
- filename2 = pThis->m_savepath + filename.Mid(nIndex+1);
- pThis->MyCopyFile(filename, filename2, pThis->m_bOverWrite == FALSE);
- }
- }
- }
- }
- pThis->m_progress.SetPos(i + 1);
- }
- }
- pThis->PostMessage(WM_CLOSE, 0, 0);
- return 1;
- }
- BOOL ImportPhoto::OnInitDialog()
- {
- CDialog::OnInitDialog();
- #if JEFF_TEST_OFF
- // Jeff:判断目标路径是否合法;
- if ( IsDirectoryLegitimate(m_name) == FALSE)
- {
- AfxMessageBox("目标路径包含创建目录时的非法目录字符'/ \\ : * ? \" < > |',请修改后重新操作!");
- return FALSE;
- }
- #endif
- if (m_bCopyToLocal)
- SetDlgItemText(IDC_STATIC1, "客照缓存中, 请稍候...");
- else if (m_mode == 1)
- SetDlgItemText(IDC_STATIC1, "正在导出客照, 请稍候...");
- #if JEFF_TEST_OFF
- HANDLE hThread = (HANDLE)_beginthreadex(NULL, 0, ImprotOrExportImageThread, (LPVOID)this, 0, NULL);
- CloseHandle(hThread);
- #endif
- if (beginno != -1 && beginno != 0)
- {
- m_bautono = 0;
- }
- AfxBeginThread((AFX_THREADPROC)ImportPhotoThread, (LPVOID)this);
- return TRUE;
- }
- void SaveTaskPath(CString pathname)
- {
- return;
- CString path = g_path1 + "\\taskpath.dat";
- CStringArray array;
- CFile fp;
- if (::PathFileExists(path))
- {
- try
- {
- int trycount = 5;
- while (1)
- {
- if (fp.Open(path, CFile::modeRead | CFile::shareExclusive))break;
- fp.Close();
- trycount--;
- if (trycount == 0)break;
- ::Sleep(1000);
- }
- if (trycount == 0)
- {
- if (::PathFileExists(path))return;
- }
- CArchive ar(&fp, CArchive::load);
- array.Serialize(ar);
- fp.Close();
- }
- catch (...)
- {
- fp.Close();
- // AfxMessageBox("读异常");
- }
- }
- array.Add(pathname);
- try
- {
- int trycount = 5;
- while (1)
- {
- if (fp.Open(path, CFile::modeCreate | CFile::modeWrite | CFile::shareExclusive))break;
- fp.Close();
- trycount--;
- if (trycount == 0)break;
- ::Sleep(1000);
- }
- if (trycount == 0)
- {
- // AfxMessageBox("打开失败2");
- return;
- }
- CArchive ar(&fp, CArchive::store);
- array.Serialize(ar);
- ar.Close();
- fp.Close();
- }
- catch (...)
- {
- // AfxMessageBox("写异常");
- fp.Close();
- }
- }
- void ImportPhoto::OnClose()
- {
- #if USE_SHARE_FLORD
- // 导入成功后,要写入IncrementalBackup;
- // 1.获取相片名,不带后缀;
- CString strSQLInsert;
- if ( m_nphototype != -1) // 如果是导入相片;
- {
- int nIndex = 0;
- CString AryOfName;
- int nSize = 0;
- // 上传规则,不应该有dbconfig.dat指向的店铺(假设为分店My) 分店My->分店My;所以这一步应该在界面操作中禁止生成规则;
- // 首次插入的必须是dbconfig.dat中指向的数据库地址,不管是否多店汇总或连接分店;
- if ( g_bAllBranch ) // 如果是多店汇总;
- {
- // 保存原值;
- BOOL bCurBranchModify = g_bBranchModify;
- g_bBranchModify = FALSE;
- // 断开之前的连接(有可能之前使用的连接是多店汇总或者连接分店,所以必须断开);
- g_pMainWnd->OnDisconnect();
- g_branchname = m_branch;
- g_branchip = GetIP(m_branch);
- // 更新数据到本店数据库中;
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert); // 有可能发送失败;
- if ( !g_bSendOK )
- {
- //AfxMessageBox(_T("连接服务器失败"));
- printf("Jeff:A#多店汇总时连接本店服务器失败\n");
- //WriteTextLog(_T("多店汇总时,写增量时连接服务器失败"));
- }
- g_bBranchModify = bCurBranchModify;
- g_branchname = g_branchip = _T("");
- }
- else if ( g_branchname != _T("") && g_branchip != _T("") ) // 连接分店;
- {
- // 保存原值;
- CString strBranch = g_branchname;
- CString strBranchIP = g_branchip;
- g_branchname = g_branchip = _T("");
- g_bBranchModify = FALSE;
- // 断开之前的连接(有可能之前使用的连接是多店汇总或者连接分店,所以必须断开);
- g_pMainWnd->OnDisconnect();
- // 更新数据到本店数据库中;
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert); // 有可能发送失败;
- if (!g_bSendOK)
- {
- //AfxMessageBox(_T("连接服务器失败"));
- printf("Jeff:B#连接分店时导入相片失败\n");
- WriteTextLog(_T("连接分店时,写增量时连接服务器失败"));
- }
- g_pMainWnd->OnDisconnect();
- g_bBranchModify = TRUE;
- g_branchname = strBranch;
- g_branchip = strBranchIP;
- }
- else // 连接的是本店;
- {
- // 更新数据到本店数据库中;
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert);
- if (!g_bSendOK)
- {
- //AfxMessageBox(_T("连接服务器失败"));
- printf("Jeff:C#连接本店时导入相片失败\n");
- WriteTextLog(_T("本店连接时,写增量时连接服务器失败"));
- }
- }
- }
- #endif
- // m_nphototype相片类型:0原片,1初修片,2精修片,3设计片;
- if (m_nphototype < 0 || m_nphototype>3)
- {
- CDialog::OnOK();
- return;
- }
- // m_uploadtaskarray的元素数量不会小于10的;
- if (m_uploadtaskarray.GetSize() <= 10)
- {
- CDialog::OnOK();
- return;
- }
- #ifdef ENTERPRISE_VERSION
- // 集团版,是否开启上传功能;
- if (m_bSaveUploadTask)
- {
- // 上传相片的规则,在[version]表中的[uploadrule]字段;
- /*
- 示例:
- "type3@:铁西店->万泰店(总店)%$铁西店->219店%$219店->219店%$金色店->金色店%$万泰店(总店)->万泰店(总店)%$万泰店(总店)->219店%$\
- type0@:铁西店->219店%$铁西店->万泰店(总店)%$219店->219店%$金色店->金色店%$万泰店(总店)->万泰店(总店)%$万泰店(总店)->219店%$\
- type2@:铁西店->219店%$铁西店->万泰店(总店)%$铁西店->金色店%$219店->219店%$万泰店(总店)->万泰店(总店)%$金色店->金色店%$"
- */
- CString m_rule = g_cominfoarraylocal.ElementAt(0).ElementAt(116);
- CString m_header, m_left, m_right, m_currule;
- CStringArray rulearray;
- if (m_nphototype == 0)
- {
- m_header = "type0@:";
- }
- else if (m_nphototype == 1)
- {
- m_header = "type1@:";
- }
- else if (m_nphototype == 2)
- {
- m_header = "type2@:";
- }
- else if (m_nphototype == 3)
- {
- m_header = "type3@:";
- }
- int pos = m_rule.Find(m_header);
- if (pos != -1)
- {
- m_left = m_rule.Left(pos);
- m_rule = m_rule.Right(m_rule.GetLength() - pos);
- m_rule.Delete(0, m_header.GetLength());
- pos = m_rule.Find("@:");
- if (pos != -1)
- {
- m_right = m_rule.Right(m_rule.GetLength() - pos + 5);
- m_rule = m_rule.Left(pos - 5);
- }
- // m_rule的最终结果如:
- // 铁西店->万泰店(总店)%$铁西店->219店%$219店->219店%$金色店->金色店%$万泰店(总店)->万泰店(总店)%$万泰店(总店)->219店%$
- m_currule = m_rule;
- m_rule.Empty();
- m_currule.TrimLeft("%$");
- m_currule.TrimRight("%$");
- // 铁西店->万泰店(总店)%$铁西店->219店%$219店->219店%$金色店->金色店%$万泰店(总店)->万泰店(总店)%$万泰店(总店)->219店
- if (m_currule.Find("%$") != -1)
- {
- pos = m_currule.Find("%$");
- while (pos != -1)
- {
- if (m_currule.Left(pos) != "")rulearray.Add(m_currule.Left(pos));
- m_currule = m_currule.Right(m_currule.GetLength() - pos - 2);
- pos = m_currule.Find("%$");
- }
- }
- if (m_currule != "")rulearray.Add(m_currule);
- }
- for (int i = 0; i < rulearray.GetSize(); i++)
- {
- m_currule = rulearray.ElementAt(i);
- pos = m_currule.Find("->");
- if (pos == -1)continue;
- m_left = m_currule.Left(pos);
- m_right = m_currule.Right(m_currule.GetLength() - pos - 2);
- CString curdomain, curdomain2;
- // m_branch分店名称,如果"铁西店",表明在使用"多店汇总"菜单;
- if (m_branch != "")
- {
- curdomain = GetDomainFromBranch(m_branch);
- curdomain2 = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
- }
- else if (g_branchname != "")// 表示在使用"连接铁西分店"菜单;
- {
- curdomain = GetDomainFromBranch(g_branchname);
- curdomain2 = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
- }
- else// 表示连接的是本店;
- {
- curdomain = GetDomainFromBranch(g_brancharray.ElementAt(g_brancharray.GetSize() - 1).ElementAt(0));
- curdomain2 = curdomain;
- }
- // 源域名;
- CString domainleft = GetDomainFromBranch(m_left);
- if (curdomain != domainleft)
- {
- continue;
- }
- // 目标域名;
- CString domainright = GetDomainFromBranch(m_right);
- if (domainleft.Find(".ly.com") == -1 || domainright.Find(".ly.com") == -1)
- {
- continue;
- }
- if (curdomain2 == domainright)
- {
- continue;
- }
- MyLock lock("uploadtaskaccess");
- // m_uploadtaskarray 元素0 = 订单号+顾客名称;
- m_uploadtaskarray.SetAt(1, domainright); // 目标域名;
- m_uploadtaskarray.SetAt(2, domainleft); // 源域名;
- m_uploadtaskarray.SetAt(3, m_sel); // 压缩像素的值;
- CFile fp;
- CString pathdir = m_savepath + "uploadtask";
- //printf("Jeff:pathdir: %s\n", pathdir);
- if (m_id != "")
- {
- int pos = pathdir.Find(m_id);
- pos += m_id.GetLength();
- int pos2 = pathdir.ReverseFind('\\');
- pathdir = pathdir.Left(pos) + pathdir.Right(pathdir.GetLength() - pos2);
- }
- CString path;
- int taskpos = 1;
- path.Format("%s%d.dat", pathdir, taskpos);
- CString dir = path.Left(path.ReverseFind('\\') + 1);
- pathdir = g_path1 + "\\上传任务\\";
- //printf("Jeff:pathdir: %s\n", pathdir);
- ::CreateDirectory(pathdir, NULL);
- path.Format("%s%d.dat", pathdir, taskpos);
- while (PathFileExists(path))
- {
- taskpos++;
- path.Format("%s%d.dat", pathdir, taskpos);
- printf("Jeff:path: %s\n", path);
- }
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- CArchive ar(&fp, CArchive::store);
- //printf("Jeff:dir: %s\n", dir);
- m_uploadtaskarray.SetAt(4, dir); // 相片所在的路径;
- m_uploadtaskarray.Serialize(ar); // 最后将m_uploadtaskarray序列化;
- ar.Close();
- fp.Close();
- // SaveTaskPath(path);
- #if USE_SHARE_FLORD
- // 2015-07-02 根据上传分店规则,为每个要上传的任务写IncrementalBackup到分店中;
- // 分店A,分店B,总店S.
- // 在分店A中导入分店B的订单B001,分店A的上传规则:分店A->分店S,分店B->分店B,分店B->总店S.
- // 那么本次订单B001同时要上传至分店B和总店S中;
- // 1.在这里切换多个分店服务端的连接;2.在FTP客户端中连接多家分店数据库;
- // 如果用户不使用FTP来上传相片,那么远程分店是无法按增量来备份的;
- //WriteTextLog(_T("写入分店增量:") + strSQLInsert);
- if ( g_bAllBranch && m_branch != "" ) // 多店汇总;
- {
- // 断开之前的连接;
- g_pMainWnd->OnDisconnect();
- // 更新要连接的服务端;
- g_branchname = m_right;
- g_branchip = GetIP(m_right);
- g_bBranchModify = TRUE;
- // 更新数据;
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert);
- if ( !g_bSendOK )
- {
- //strSQLInsert.Format(_T("连接分店[%s]时失败~"),m_right);
- //WriteTextLog(strSQLInsert);
- }
- // 断开连接;
- g_pMainWnd->OnDisconnect();
- // 恢复无分店连接状态;
- g_bBranchModify = FALSE;
- g_branchip = "";
- g_branchname = "";
- }
- else if ( g_branchname != "" ) // 连接分店;
- {
- if ( !g_branchname.CompareNoCase(m_right) && !g_branchip.CompareNoCase(GetIP(m_right)) )
- {
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert);
- }
- else
- {
- CString strCurBranch = g_branchname;
- CString strCurBranchIP = g_branchip;
- BOOL bCurBranchModify = g_bBranchModify;
- // 断开之前的连接;
- g_pMainWnd->OnDisconnect();
- // 更新要连接的服务端;
- g_branchname = m_right;
- g_branchip = GetIP(m_right);
- g_bBranchModify = TRUE;
- // 更新数据;
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert);
- if ( !g_bSendOK )
- {
- //strSQLInsert.Format(_T("连接分店[%s]时失败~"),m_right);
- //WriteTextLog(strSQLInsert);
- }
- // 断开连接;
- g_pMainWnd->OnDisconnect();
- // 恢复原分店连接;
- g_bBranchModify = bCurBranchModify;
- g_branchip = strCurBranchIP;
- g_branchname = strCurBranch;
- }
- }
- else // 连接本店;
- {
- // 断开之前的连接;
- g_pMainWnd->OnDisconnect();
- // 更新要连接的服务端;
- g_branchname = m_right;
- g_branchip = GetIP(m_right);
- g_bBranchModify = TRUE;
- // 更新数据;
- g_sendhead.bsql = 1;
- g_pMainWnd->ProcessChatMessageRequest2(strSQLInsert);
- if ( !g_bSendOK )
- {
- //strSQLInsert.Format(_T("连接分店[%s]时失败~"),m_right);
- //WriteTextLog(strSQLInsert);
- }
- // 断开连接;
- g_pMainWnd->OnDisconnect();
- // 恢复本店连接;
- g_bBranchModify = FALSE;
- g_branchip = "";
- g_branchname = "";
- }
- #endif
- }
- }
- #endif
- // CString ss;
- //ss.Format ("cc:%d", g_filecount);MessageBox(ss);m_fp.Close ();
- CDialog::OnOK();
- }
- extern void SaveImageToFile(Image *img, CString path);
- void ImportPhoto::MyCopyFile(CString file1, CString file2, BOOL bOverWrite)
- {
- if (::PathFileExists(file1) == 0)
- {
- return;
- }
- if (m_bOfmat)
- {
- CString file1bak = file1;
- CString file2bak = file2;
- file1bak = file1bak.Left(file1bak.GetLength() - 3);
- file2bak = file2bak.Left(file2bak.GetLength() - 3);
- file1bak += "jpg";
- file2bak += "jpg";
- CString src = file1bak;
- CString des = file2bak;
- src.Replace(".jpg", ".raw");
- des.Replace(".jpg", ".raw");
- ::CopyFile(src, des, bOverWrite);
- src = file1bak;
- des = file2bak;
- src.Replace(".jpg", ".nef");
- des.Replace(".jpg", ".nef");
- ::CopyFile(src, des, bOverWrite);
- src = file1bak;
- des = file2bak;
- src.Replace(".jpg", ".cr2");
- des.Replace(".jpg", ".cr2");
- ::CopyFile(src, des, bOverWrite);
- }
- if (m_nphototype == 0 || m_nphototype == 1 || m_nphototype == 2 || m_nphototype == 3)
- {
- CString str = file2;
- CString spath = str.Left(str.ReverseFind('\\') + 1);
- CString mpath = spath;
- spath += "s";
- spath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
- mpath += "m";
- mpath += str.Right(str.GetLength() - str.ReverseFind('\\') - 1);
- ::DeleteFile(spath); // 删除s小图;
- ::DeleteFile(mpath); // 删除m小图;
- }
- if (m_nOutputSize)
- {
- file1.MakeLower();
- if (file1.Right(3) == "jpg")
- {
- Image *img = NULL;
- ::LoadImageFromBuf(&img, file1);
- if (img == NULL)
- {
- if (::CopyFile(file1, file2, bOverWrite) == 0)
- {
- CString str;
- str = file1;
- int pos = str.ReverseFind('\\');
- if (pos != -1)
- str = str.Right(str.GetLength() - pos - 1);
- AfxMessageBox("拷贝失败" + str + "请重新导入此文件!");
- }
- }
- else if (img->GetWidth() == 0)
- {
- if (::CopyFile(file1, file2, bOverWrite) == 0)
- {
- CString str;
- str = file1;
- int pos = str.ReverseFind('\\');
- if (pos != -1)
- str = str.Right(str.GetLength() - pos - 1);
- AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!");
- }
- }
- else
- {
- int newsize = m_nOutputSize;
- if (img->GetWidth() > newsize || img->GetHeight() > newsize)
- {
- CRect rc(0, 0, newsize, newsize);
- RectFitDes(img->GetWidth(), img->GetHeight(), rc);
- Image *simg = img->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
- Graphics graphic(simg);//防止GetThumbnailImage影响质量
- graphic.DrawImage(img, 0, 0, simg->GetWidth(), simg->GetHeight());
- delete img;
- ::SaveImageToFile(simg, file2);
- delete simg;
- }
- else
- {
- if (::CopyFile(file1, file2, bOverWrite) == 0)
- {
- CString str;
- str = file1;
- int pos = str.ReverseFind('\\');
- if (pos != -1)
- str = str.Right(str.GetLength() - pos - 1);
- AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!");
- }
- }
- }
- }
- else
- {
- if (::CopyFile(file1, file2, bOverWrite) == 0)
- {
- CString str;
- str = file1;
- int pos = str.ReverseFind('\\');
- if (pos != -1)
- str = str.Right(str.GetLength() - pos - 1);
- AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!!");
- }
- }
- }
- else
- {
- if (::CopyFile(file1, file2, bOverWrite) == 0)
- {
- CString str;
- str = file1;
- int pos = str.ReverseFind('\\');
- if (pos != -1)
- str = str.Right(str.GetLength() - pos - 1);
- AfxMessageBox("拷贝失败" + str + "请重新导入此文件!!!!!");
- }
- //
- if (m_bCopyToLocal)//选片缓存
- {
- CString path = file2;
- CString spath = path.Left(path.ReverseFind('\\') + 1);
- spath += "s";
- // CString temp=path.Right (path.GetLength ()-path.ReverseFind ('\\')-1);
- spath += path.Right(path.GetLength() - path.ReverseFind('\\') - 1);
- //if(!PathFileExists (spath))
- {
- Image *pImg = NULL;
- ::LoadImageFromBuf(&pImg, path);
- if (pImg == NULL)return;
- if (pImg->GetWidth() == 0)return;
- CRect rc(0, 0, 100, 90);
- RectFitDes(pImg->GetWidth(), pImg->GetHeight(), rc);
- Image *simg = pImg->GetThumbnailImage(rc.Width(), rc.Height(), NULL, NULL);
- if (simg == NULL)return;
- Graphics graphic(simg);//防止GetThumbnailImage影响质量
- graphic.Clear(Color(255, 255, 255, 255));
- graphic.DrawImage(pImg, 0, 0, simg->GetWidth(), simg->GetHeight());
- ///////////////////////////////
- UINT totalBufferSize;
- UINT numProperties;
- pImg->GetPropertySize(&totalBufferSize, &numProperties);
- // Allocate the buffer that will receive the property items.
- PropertyItem* pAllItems = (PropertyItem*)malloc(totalBufferSize);
- // Fill the buffer.
- pImg->GetAllPropertyItems(totalBufferSize, numProperties, pAllItems);
- // Print the id data member of each property item.
- for (UINT j = 0; j < numProperties; ++j)
- {
- if (PropertyTagOrientation == pAllItems[j].id)
- {
- short* ptrLong = (short*)(pAllItems[j].value);
- int ret = (int)*ptrLong;
- // CString str;
- // str.Format ("%d", ret);
- // AfxMessageBox(str);
- if (ret == 8)
- {
- simg->RotateFlip(Rotate270FlipNone);
- }
- else if (ret == 6)
- {
- simg->RotateFlip(Rotate90FlipNone);
- }
- break;
- }
- }
- free(pAllItems);
- ///////////////////////////////
- ::SaveImageToFile(simg, spath);
- delete simg;
- delete pImg;
- }
- }//选片缓存
- }
- file2.MakeLower();
- if (m_mode != 1 && file2.Right(3) == "jpg")
- {
- CString path = file2.Left(file2.ReverseFind('\\'));
- path.TrimRight("\\"); path += "\\";
- path += "modifytime";
- CStdioFile fp;
- if (::PathFileExists(path))
- {
- fp.Open(path, CFile::modeWrite);
- fp.WriteString(g_date);
- fp.Close();
- }
- else
- {
- fp.Open(path, CFile::modeCreate | CFile::modeWrite);
- fp.WriteString(g_date);
- fp.Close();
- }
- }
- #ifdef ENTERPRISE_VERSION
- if (m_bSaveUploadTask)
- {
- if (m_id != "")
- {
- if (file2.Right(3) == "jpg")
- {
- int pos = file2.Find(m_id);
- pos += m_id.GetLength();
- int pos2 = file2.ReverseFind('\\');
- // Jeff:获取景点;
- CString jd;
- if (pos2 > pos)
- {
- jd = file2.Mid(pos + 1, pos2 - pos - 1);
- }
- CString task;
- if (jd != "")
- task = jd + "\\" + file2.Right(file2.GetLength() - pos2 - 1);
- else
- task = file2.Right(file2.GetLength() - pos2 - 1);
- m_uploadtaskarray.Add(task);
- m_uploadtaskarray.Add("");
- }
- }
- else
- {
- if (file2.Right(3) == "jpg")
- {
- m_uploadtaskarray.Add(file2.Right(file2.GetLength() - m_savepath.GetLength()));
- m_uploadtaskarray.Add("");
- }
- }
- }
- #endif
- }
- //*
- unsigned int WINAPI ImportPhoto::ImprotOrExportImageThread(LPVOID lp)
- {
- ImportPhoto *pThis = (ImportPhoto*)lp;
- if ( pThis->m_bImportImage )
- {
- // 初始化工作,并将导入标识写入数据库中;
- switch ( pThis->m_ImportOfImageType )
- {
- case ImageType_Original:
- break;
- case ImageType_Early:
- break;
- case ImageType_Further:
- break;
- case ImageType_Design:
- break;
- default:
- break;
- }
- // 实参校验;
- if ( pThis->m_pArray->GetSize() > 0 && lyfzCreateDirectory(pThis->m_savepath))
- lyfzImportImage(pThis->m_savepath, *(pThis->m_pArray));
- }
- else
- {
- // 初始化工作;
- switch (pThis->m_ExportOfImageType)
- {
- case ImageType_Original:
- break;
- case ImageType_Early:
- break;
- case ImageType_Further:
- break;
- case ImageType_Design:
- default:
- break;
- }
- }
- return 0;
- }
|