testDlg.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. // testDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "test.h"
  5. #include "testDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #endif
  9. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  10. class CAboutDlg : public CDialog
  11. {
  12. public:
  13. CAboutDlg();
  14. // 对话框数据
  15. enum { IDD = IDD_ABOUTBOX };
  16. protected:
  17. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  18. // 实现
  19. protected:
  20. DECLARE_MESSAGE_MAP()
  21. };
  22. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  23. {
  24. }
  25. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. }
  29. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  30. END_MESSAGE_MAP()
  31. // CtestDlg 对话框
  32. CtestDlg::CtestDlg(CWnd* pParent /*=NULL*/)
  33. : CDialog(CtestDlg::IDD, pParent)
  34. , m_nImgtype(1)
  35. {
  36. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  37. m_pImgkernel = NULL;
  38. #if USE_ThumbNail
  39. m_hEvent = NULL;
  40. m_hThread = NULL;
  41. #endif
  42. }
  43. void CtestDlg::DoDataExchange(CDataExchange* pDX)
  44. {
  45. CDialog::DoDataExchange(pDX);
  46. DDX_Control(pDX, IDC_LIST1, m_list);
  47. DDX_Radio(pDX, IDC_RADIO1, m_nImgtype);
  48. DDX_Control(pDX, IDC_LIST2, m_listThumbNail);
  49. }
  50. BEGIN_MESSAGE_MAP(CtestDlg, CDialog)
  51. ON_WM_SYSCOMMAND()
  52. ON_WM_PAINT()
  53. ON_WM_QUERYDRAGICON()
  54. //}}AFX_MSG_MAP
  55. ON_BN_CLICKED(IDC_BUTTON1, &CtestDlg::OnBnClickedButton1)
  56. ON_BN_CLICKED(IDC_BUTTON2, &CtestDlg::OnBnClickedButton2)
  57. ON_BN_CLICKED(IDC_BUTTON3, &CtestDlg::OnBnClickedButton3)
  58. ON_BN_CLICKED(IDC_RADIO1, &CtestDlg::OnBnClickedRadio1)
  59. ON_BN_CLICKED(IDC_RADIO2, &CtestDlg::OnBnClickedRadio2)
  60. ON_BN_CLICKED(IDC_RADIO3, &CtestDlg::OnBnClickedRadio3)
  61. ON_BN_CLICKED(IDC_RADIO4, &CtestDlg::OnBnClickedRadio4)
  62. END_MESSAGE_MAP()
  63. // CtestDlg 消息处理程序
  64. BOOL CtestDlg::OnInitDialog()
  65. {
  66. CDialog::OnInitDialog();
  67. // 将“关于...”菜单项添加到系统菜单中。
  68. // IDM_ABOUTBOX 必须在系统命令范围内。
  69. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  70. ASSERT(IDM_ABOUTBOX < 0xF000);
  71. CMenu* pSysMenu = GetSystemMenu(FALSE);
  72. if (pSysMenu != NULL)
  73. {
  74. BOOL bNameValid;
  75. CString strAboutMenu;
  76. bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  77. ASSERT(bNameValid);
  78. if (!strAboutMenu.IsEmpty())
  79. {
  80. pSysMenu->AppendMenu(MF_SEPARATOR);
  81. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  82. }
  83. }
  84. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  85. // 执行此操作
  86. SetIcon(m_hIcon, TRUE); // 设置大图标
  87. SetIcon(m_hIcon, FALSE); // 设置小图标
  88. // TODO: 在此添加额外的初始化代码
  89. INT nFieldCount = 0;
  90. vector<TblNetShareInfo> vtRSet;
  91. INT nRet = g_AdoImpl->GetTbl_NetShareInfoRecordSet(_T("NetShareInfo"), NULL, SELECT_NetShareInfo, nFieldCount, vtRSet);
  92. if ( nRet == -1 )
  93. {
  94. OutputDebugString(_T("获取表记录失败"));
  95. return FALSE;
  96. }
  97. else if ( nRet == 0 )
  98. {
  99. CString strInsert = _T("");
  100. // 原片;
  101. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\客户原片(管理软件)$"), 5, 35, 1, 255);
  102. g_AdoImpl->Execute(strInsert);
  103. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\客户原片(管理软件)1$"), 5, 35, 1, 254);
  104. g_AdoImpl->Execute(strInsert);
  105. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\客户原片(管理软件)2$"), 5, 35, 1, 253);
  106. g_AdoImpl->Execute(strInsert);
  107. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\客户原片(管理软件)3$"), 5, 35, 1, 252);
  108. g_AdoImpl->Execute(strInsert);
  109. // 初修片;
  110. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\修好的片(管理软件)$"), 5, 35, 2, 255);
  111. g_AdoImpl->Execute(strInsert);
  112. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\修好的片(管理软件)1$"), 5, 35, 2, 254);
  113. g_AdoImpl->Execute(strInsert);
  114. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\修好的片(管理软件)2$"), 5, 35, 2, 253);
  115. g_AdoImpl->Execute(strInsert);
  116. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\修好的片(管理软件)3$"), 5, 35, 2, 252);
  117. g_AdoImpl->Execute(strInsert);
  118. // 精修片;
  119. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\精修好的片(管理软件)$"), 5, 35, 3, 255);
  120. g_AdoImpl->Execute(strInsert);
  121. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\精修好的片(管理软件)1$"), 5, 35, 3, 254);
  122. g_AdoImpl->Execute(strInsert);
  123. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\精修好的片(管理软件)2$"), 5, 35, 3, 253);
  124. g_AdoImpl->Execute(strInsert);
  125. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\精修好的片(管理软件)3$"), 5, 35, 3, 252);
  126. g_AdoImpl->Execute(strInsert);
  127. // 设计片;
  128. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\设计好的片(管理软件)$"), 5, 35, 4, 255);
  129. g_AdoImpl->Execute(strInsert);
  130. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\设计好的片(管理软件)1$"), 5, 35, 4, 254);
  131. g_AdoImpl->Execute(strInsert);
  132. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\设计好的片(管理软件)2$"), 5, 35, 4, 253);
  133. g_AdoImpl->Execute(strInsert);
  134. strInsert.Format(INSERT_NetShareInfo, 1, g_szEncryS1,_T("\\\\lyfz-server\\设计好的片(管理软件)3$"), 5, 35, 4, 252);
  135. g_AdoImpl->Execute(strInsert);
  136. }
  137. else
  138. {
  139. for ( vector<TblNetShareInfo>::iterator it = vtRSet.begin(); it != vtRSet.end(); it++ )
  140. {
  141. ImgShareInfo *pImgInfo = new ImgShareInfo;
  142. pImgInfo->bEnable = it->_enable;
  143. pImgInfo->byImgType = it->_phototype;
  144. pImgInfo->byMaxCapacity = it->_maxcapacity;
  145. pImgInfo->byMinCapacity = it->_mincapacity;
  146. pImgInfo->byPriority = it->_priority;
  147. _stprintf_s(pImgInfo->szBranchId, MAX_PATH, _T("%s"), it->_branchid.c_str());
  148. _stprintf_s(pImgInfo->szShareDirectory, MAX_PATH, _T("%s"), it->_sharepath.c_str());
  149. m_ImgShareInfo.push_back(pImgInfo);
  150. }
  151. }
  152. m_pImgkernel = new ImgOfOriginal();
  153. m_pImgkernel->InitializeEnvironment(g_szEncryS1, &m_ImgShareInfo);
  154. InitCtrlList();
  155. Inputdata();
  156. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  157. }
  158. void CtestDlg::InitCtrlList()
  159. {
  160. INT nIndex = 0;
  161. m_list.InsertColumn(nIndex,_T("订单号"));
  162. m_list.SetColumnWidth(nIndex,120);
  163. nIndex++;
  164. m_list.InsertColumn(nIndex,_T("名称1"));
  165. m_list.SetColumnWidth(nIndex,70);
  166. nIndex++;
  167. m_list.InsertColumn(nIndex,_T("名称2"));
  168. m_list.SetColumnWidth(nIndex,70);
  169. nIndex++;
  170. m_list.InsertColumn(nIndex,_T("套系名称"));
  171. m_list.SetColumnWidth(nIndex,80);
  172. nIndex++;
  173. m_list.InsertColumn(nIndex,_T("套系价格"));
  174. m_list.SetColumnWidth(nIndex,60);
  175. nIndex++;
  176. m_list.InsertColumn(nIndex,_T("相片编号"));
  177. m_list.SetColumnWidth(nIndex,60);
  178. nIndex++;
  179. m_list.SetExtendedStyle(m_list.GetExtendedStyle() | LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
  180. }
  181. void CtestDlg::Inputdata()
  182. {
  183. // 清除之前的数据;
  184. m_list.DeleteAllItems();
  185. INT nFieldCount = 0;
  186. vector<Tbldindan> vtRSet;
  187. INT nRet = g_AdoImpl->GetTbl_dindanRecordSet(_T("dindan"), NULL, SELECT_dindan, nFieldCount, vtRSet);
  188. if ( nRet == -1 )
  189. {
  190. OutputDebugString(_T("获取表记录失败"));
  191. return ;
  192. }
  193. INT nItemIndex = 0;
  194. for ( vector<Tbldindan>::iterator it = vtRSet.begin(); it != vtRSet.end(); it++ )
  195. {
  196. nItemIndex = m_list.InsertItem(0,it->_id.c_str());
  197. m_list.SetItemText(nItemIndex,1,it->_name1.c_str());
  198. m_list.SetItemText(nItemIndex,2,it->_name2.c_str());
  199. m_list.SetItemText(nItemIndex,3,it->_taoxiname.c_str());
  200. m_list.SetItemText(nItemIndex,4,it->_taoxijiage.c_str());
  201. m_list.SetItemText(nItemIndex,4,it->_curno.c_str());
  202. }
  203. }
  204. void CtestDlg::OnSysCommand(UINT nID, LPARAM lParam)
  205. {
  206. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  207. {
  208. CAboutDlg dlgAbout;
  209. dlgAbout.DoModal();
  210. }
  211. else
  212. {
  213. CDialog::OnSysCommand(nID, lParam);
  214. }
  215. }
  216. // 如果向对话框添加最小化按钮,则需要下面的代码
  217. // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  218. // 这将由框架自动完成。
  219. void CtestDlg::OnPaint()
  220. {
  221. if (IsIconic())
  222. {
  223. CPaintDC dc(this); // 用于绘制的设备上下文
  224. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  225. // 使图标在工作区矩形中居中
  226. int cxIcon = GetSystemMetrics(SM_CXICON);
  227. int cyIcon = GetSystemMetrics(SM_CYICON);
  228. CRect rect;
  229. GetClientRect(&rect);
  230. int x = (rect.Width() - cxIcon + 1) / 2;
  231. int y = (rect.Height() - cyIcon + 1) / 2;
  232. // 绘制图标
  233. dc.DrawIcon(x, y, m_hIcon);
  234. }
  235. else
  236. {
  237. CDialog::OnPaint();
  238. }
  239. }
  240. //当用户拖动最小化窗口时系统调用此函数取得光标
  241. //显示。
  242. HCURSOR CtestDlg::OnQueryDragIcon()
  243. {
  244. return static_cast<HCURSOR>(m_hIcon);
  245. }
  246. void CtestDlg::OnBnClickedButton1() // 导入相片;
  247. {
  248. // 获取选中行;
  249. CString strOrder;
  250. CString strName1;
  251. CString strName2;
  252. CString strTaoxi;
  253. CString strTXJG;
  254. CString strImgNo;
  255. POSITION pos;
  256. pos = m_list.GetFirstSelectedItemPosition();
  257. if ( pos == NULL )
  258. {
  259. AfxMessageBox(_T("未选中任何行!"));
  260. return;
  261. }
  262. int nItem = m_list.GetNextSelectedItem(pos);
  263. strOrder = m_list.GetItemText(nItem,0);
  264. strName1 = m_list.GetItemText(nItem,1);
  265. strName2 = m_list.GetItemText(nItem,2);
  266. strTaoxi = m_list.GetItemText(nItem,3);
  267. strTXJG = m_list.GetItemText(nItem,4);
  268. strImgNo = m_list.GetItemText(nItem,5);
  269. // TODO: 在此添加控件通知处理程序代码
  270. switch (m_nImgtype)
  271. {
  272. case OImgtype:
  273. {
  274. STR_VEC vtfiles;
  275. LPCTSTR lpExt = _T("*.jpg|*.jpeg");
  276. underlyingapi::OpenFloder(vtfiles);
  277. if ( vtfiles.size() == 0 ) return;
  278. TCHAR szEnablefolder[MAX_PATH] = {0};
  279. if ( !m_pImgkernel ) return;
  280. if ( !m_pImgkernel->GetEnableShareDirectory(OImgtype, g_szEncryS1, strOrder, szEnablefolder, MAX_PATH) )
  281. {
  282. AfxMessageBox(_T("无可用共享目录"));
  283. return;
  284. }
  285. LPCTSTR lpWithExt = _T("*.nef|*.cr2");
  286. INT nCount = m_pImgkernel->CopyImg2Specifiedpath(vtfiles, szEnablefolder, lpWithExt, SET_PIX(100,100), FALSE, NULL, 0);
  287. if ( nCount == 0 )
  288. {
  289. OutputDebugString(_T("复制失败~"));
  290. }
  291. else
  292. {
  293. AfxMessageBox(_T("导入成功~"));
  294. }
  295. }
  296. break;
  297. case EImgtype:
  298. break;
  299. case FImgtype:
  300. break;
  301. case DImgtype:
  302. break;
  303. default:
  304. break;
  305. }
  306. OutputDebugString(_T("导入按钮\n"));
  307. }
  308. void CtestDlg::OnBnClickedButton2() // 导出相片;
  309. {
  310. // TODO: 在此添加控件通知处理程序代码
  311. }
  312. void CtestDlg::OnBnClickedButton3() // 查看相片;
  313. {
  314. // TODO: 在此添加控件通知处理程序代码
  315. }
  316. void CtestDlg::OnBnClickedRadio1() // 原片;
  317. {
  318. m_nImgtype = 1;
  319. }
  320. void CtestDlg::OnBnClickedRadio2() // 修片;
  321. {
  322. m_nImgtype = 2;
  323. }
  324. void CtestDlg::OnBnClickedRadio3() // 精修;
  325. {
  326. m_nImgtype = 3;
  327. }
  328. void CtestDlg::OnBnClickedRadio4() // 设计;
  329. {
  330. m_nImgtype = 4;
  331. }
  332. #if USE_ThumbNail
  333. int CtestDlg::StartThread()
  334. {
  335. m_hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); // 无信号事件;
  336. if (m_hEvent == NULL){
  337. return -1;
  338. }
  339. m_hThread = CreateThread(NULL, 0, ThreadThumbNail, this, 0, NULL);
  340. if ( m_hThread )
  341. {
  342. CloseHandle(m_hThread);
  343. m_hThread = NULL;
  344. }
  345. return 0;
  346. }
  347. DWORD CtestDlg::ThreadThumbNail(LPVOID lpParameter)
  348. {
  349. CtestDlg *pInstance = (CtestDlg*)lpParameter;
  350. // 初始化参数;
  351. CListCtrl *pListCtrl =&pInstance->m_listThumbNail;
  352. CImageList *pImgList = &pInstance->m_ImageList;
  353. STR_VEC *pvtfiles = &pInstance->m_vtfiles;
  354. // 清除列表;
  355. for ( int i = 0; i < pImgList->GetImageCount(); i++ )
  356. {
  357. pImgList->Remove(i);
  358. }
  359. pListCtrl->DeleteAllItems();
  360. if ( pvtfiles->size() == 0 )
  361. {
  362. OutputDebugString(_T("无文件\n"));
  363. return 0;
  364. }
  365. // 重新设置数量;
  366. pImgList->SetImageCount(pvtfiles->size());
  367. // 设置列表不可重绘,直到添加元素完毕;
  368. INT nIndex = 0;
  369. TString strname;
  370. pListCtrl->SetRedraw(FALSE);
  371. for ( STR_VEC::iterator it = pvtfiles->begin(); it != pvtfiles->end(); it++ )
  372. {
  373. strname = filehelpImpl::getfilename(*it);
  374. pListCtrl->InsertItem(nIndex, strname.c_str(), nIndex);
  375. }
  376. pListCtrl->SetRedraw();
  377. pListCtrl->Invalidate();
  378. return 0L;
  379. }
  380. int CtestDlg::EndofThread()
  381. {
  382. if (m_hEvent){
  383. SetEvent(m_hEvent);
  384. }
  385. if (m_hThread){
  386. if (WaitForSingleObject(m_hThread, INFINITE) != WAIT_TIMEOUT)
  387. {
  388. CloseHandle(m_hThread);
  389. m_hThread = NULL;
  390. }
  391. }
  392. if (m_hEvent){
  393. CloseHandle(m_hEvent);
  394. }
  395. m_hEvent = NULL;
  396. return 0;
  397. }
  398. #endif
  399. BOOL CtestDlg::DestroyWindow()
  400. {
  401. // TODO: 在此添加专用代码和/或调用基类
  402. if ( m_pImgkernel )
  403. {
  404. delete m_pImgkernel;
  405. }
  406. ImgShareInfo *pImg = NULL;
  407. for ( IMGSHARE_VEC::iterator it = m_ImgShareInfo.begin(); it != m_ImgShareInfo.end(); )
  408. {
  409. pImg = *it;
  410. delete pImg;
  411. pImg = NULL;
  412. it = m_ImgShareInfo.erase(it);
  413. }
  414. if ( g_AdoImpl )
  415. {
  416. delete g_AdoImpl;
  417. g_AdoImpl = NULL;
  418. }
  419. return CDialog::DestroyWindow();
  420. }