12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115 |
- // 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;
-
- 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);
- #if 1 // 导入精修片时返回给增量备份使用的相片路径数组 [5/4/2015 Jeff]
- pThis->m_AryOfImagePath.Add(pThis->m_pDesArray->ElementAt(i));
- #endif
- 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);
- #if 1 // 导入原片时返回给增量备份使用的相片路径数组 [5/4/2015 Jeff]
- pThis->m_AryOfImagePath.Add(filename2);
- #endif
- }
- 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
- {
- filename2 = pThis->m_savepath+filename.Right (filename.GetLength ()-filename.ReverseFind ('\\')-1);
- pThis->MyCopyFile (filename, filename2, pThis->m_bOverWrite==0);
- #if 1 // 导入初修片时返回给增量备份使用的相片路径数组 [5/4/2015 Jeff]
- pThis->m_AryOfImagePath.Add(filename2);
- #endif
- }
- }
- }
- 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 = m_AryOfImagePath.GetSize();
- for (int i = 0; i < nSize; i++)
- {
- CString strPath = m_AryOfImagePath.ElementAt(i);
-
- if (!PathFileExists(strPath)) continue;
-
- nIndex = strPath.ReverseFind(_T('\\'));
- if (nIndex != -1)
- {
- // 获取相片名;
- strPath = strPath.Mid(nIndex + 1);
- nIndex = strPath.ReverseFind(_T('.'));
- if (nIndex != -1)
- {
- strPath = strPath.Left(nIndex);
- AryOfName += strPath;
- AryOfName += _T("|");
- }
- }
- }
-
- // IncrementalBackup插入;
- strSQLInsert.Format(INSERT_INCREMENT, 0, g_domain, CTime::GetCurrentTime().Format("%Y-%m-%d %H:%M:%S"), m_id, m_nphototype + 1, AryOfName, g_user.account, g_user.name);
- //WriteTextLog(_T("写入增量:") + strSQLInsert);
- // 上传规则,不应该有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;
- }
|