Client2Form.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. // Client2Form.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "Client2Form.h"
  6. #include "MyMdi.H"
  7. #include "ModifyDinDan.h"
  8. #include "InputPsw.h"
  9. #include "NeroDlg.h"
  10. #include "ClientRequirement.h"
  11. #include "ChoosePhotoSkin2.h"
  12. #include "./helper/ffsco.h"
  13. #include "AddClient.h"
  14. #include "SendMsgDlg.h"
  15. #include "BasicExcelVC6.h"
  16. #include "SelExportType.h"
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22. #pragma comment(lib, "Shlwapi.lib")
  23. /////////////////////////////////////////////////////////////////////////////
  24. // Client2Form
  25. IMPLEMENT_DYNCREATE(Client2Form, MyFormView)
  26. Client2Form::Client2Form()
  27. : MyFormView(Client2Form::IDD)
  28. {
  29. //{{AFX_DATA_INIT(Client2Form)
  30. m_filter = _T("");
  31. //}}AFX_DATA_INIT
  32. }
  33. Client2Form::~Client2Form()
  34. {
  35. }
  36. void Client2Form::DoDataExchange(CDataExchange* pDX)
  37. {
  38. MyFormView::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(Client2Form)
  40. DDX_Control(pDX, IDC_COMBO1, m_combo1);
  41. DDX_Control(pDX, IDC_LIST2, m_List1);
  42. DDX_Control(pDX, IDC_STATIC1, m_static1);
  43. DDX_CBString(pDX, IDC_COMBO1, m_filter);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(Client2Form, MyFormView)
  47. //{{AFX_MSG_MAP(Client2Form)
  48. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  49. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  50. ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
  51. ON_WM_TIMER()
  52. ON_BN_CLICKED(IDC_BUTshowphoto, OnBUTshowphoto)
  53. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  54. ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST2, OnItemchangedList2)
  55. ON_BN_CLICKED(IDC_BUTburncd, OnBUTClient2Form)
  56. ON_NOTIFY(NM_DBLCLK, IDC_LIST2, OnDblclkList2)
  57. ON_BN_CLICKED(IDC_BUTburncd2, OnBUTburncd2)
  58. ON_BN_CLICKED(IDC_BUTburncd3, OnBUTburncd3)
  59. ON_BN_CLICKED(IDC_BUTsendmsg, OnBUTsendmsg)
  60. ON_BN_CLICKED(IDC_BUTprint3, OnBUTprint3)
  61. //}}AFX_MSG_MAP
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. // Client2Form diagnostics
  65. #ifdef _DEBUG
  66. void Client2Form::AssertValid() const
  67. {
  68. MyFormView::AssertValid();
  69. }
  70. void Client2Form::Dump(CDumpContext& dc) const
  71. {
  72. MyFormView::Dump(dc);
  73. }
  74. #endif //_DEBUG
  75. /////////////////////////////////////////////////////////////////////////////
  76. // Client2Form message handlers
  77. void Client2Form::OnInitialUpdate()
  78. {
  79. MyFormView::OnInitialUpdate();
  80. GetDlgItem(IDC_BUTTON2)->ShowWindow(SW_HIDE);
  81. // GetDlgItem(IDC_BUTshowphoto)->EnableWindow(IsHasRights2new(49));
  82. GetDlgItem(IDC_BUTburncd3)->EnableWindow(IsHasRights2new(49));
  83. GetDlgItem(IDC_BUTprint3)->EnableWindow(IsHasRights2new(49));
  84. // TODO: Add your specialized code here and/or call the base class
  85. CMyMdi Mdi;
  86. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  87. // Here we create the outbar control using the splitter as its parent
  88. // and setting its id to the first pane.
  89. CRect rc2;
  90. GetWindowRect(rc2);
  91. ::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
  92. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc, 0);
  93. int idarray[] = { IDC_BUTburncd, IDC_BUTburncd2, IDC_BUTburncd3, IDC_BUTsendmsg, IDC_BUTshowphoto, IDC_BUTprint3, IDC_BUTclose };
  94. int idcount = 7;
  95. int btnwid;
  96. CRect prerc;
  97. for (int a = idcount - 2; a >= 0; a--)
  98. {
  99. GetDlgItem(idarray[a + 1])->GetWindowRect(prerc);
  100. ScreenToClient(prerc);
  101. GetDlgItem(idarray[a])->GetWindowRect(rc2);
  102. ScreenToClient(rc2);
  103. btnwid = rc2.Width();
  104. rc2.right = prerc.left;
  105. rc2.left = rc2.right - btnwid;
  106. GetDlgItem(idarray[a])->MoveWindow(rc2);
  107. }
  108. m_static1.SetFont(&g_titlefont);
  109. m_List1.SetHeadings("id,0;客户姓名,100;性别,100;电话,100;QQ,100;地址,100;来源,100;流失原因,100;备注,100;生日,100;日期,100;门市,100");
  110. m_List1.LoadColumnInfo(144);
  111. GetData();
  112. m_combo1.GetWindowRect(rc2);
  113. ScreenToClient(rc2);
  114. rc2.bottom += 200;
  115. m_combo1.MoveWindow(rc2);
  116. GetDlgItem(IDC_BUTclose)->GetWindowRect(rc2);
  117. SetComboHei(&m_combo1, rc2.Height());
  118. }
  119. void Client2Form::FillGrid(BOOL bStatus)
  120. {
  121. m_List1.DeleteAllItems2();
  122. int ii = 0;
  123. m_List1.m_arLabels.SetSize(m_List1array.GetSize(), 1);
  124. int count = 0;
  125. if (m_filter.IsEmpty())
  126. {
  127. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  128. {
  129. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  130. }
  131. }
  132. else
  133. {
  134. int type = GetType(m_filter);
  135. if (type == 1)//电话
  136. {
  137. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  138. {
  139. if (m_List1array.ElementAt(ii).ElementAt(3).Find(m_filter) != -1)
  140. {
  141. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  142. }
  143. }
  144. }
  145. else if (type == 2)//拼音
  146. {
  147. m_filter.MakeUpper();
  148. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  149. {
  150. if (m_List1array.ElementAt(ii).ElementAt(12).Find(m_filter) != -1)
  151. {
  152. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  153. }
  154. }
  155. }
  156. else
  157. {
  158. for (ii = 0; ii < m_List1.m_arLabels.GetSize(); ii++)
  159. {
  160. if (m_List1array.ElementAt(ii).ElementAt(0).Find(m_filter) != -1 || \
  161. m_List1array.ElementAt(ii).ElementAt(1).Find(m_filter) != -1 || \
  162. m_List1array.ElementAt(ii).ElementAt(2).Find(m_filter) != -1 || \
  163. m_List1array.ElementAt(ii).ElementAt(3).Find(m_filter) != -1 || \
  164. m_List1array.ElementAt(ii).ElementAt(4).Find(m_filter) != -1 || \
  165. m_List1array.ElementAt(ii).ElementAt(5).Find(m_filter) != -1 || \
  166. m_List1array.ElementAt(ii).ElementAt(6).Find(m_filter) != -1 || \
  167. m_List1array.ElementAt(ii).ElementAt(7).Find(m_filter) != -1 || \
  168. m_List1array.ElementAt(ii).ElementAt(9).Find(m_filter) != -1 || \
  169. m_List1array.ElementAt(ii).ElementAt(8).Find(m_filter) != -1)
  170. {
  171. m_List1.m_arLabels.ElementAt(count++).Copy(m_List1array.ElementAt(ii));
  172. }
  173. }
  174. }
  175. }
  176. m_List1.m_arLabels.SetSize(count, 1);
  177. ii = count;
  178. m_List1.m_LabelCount = ii;
  179. m_List1.SetItemCountEx(ii);
  180. CString str;
  181. str.Format("客人:%d", ii);
  182. SetDlgItemText(IDC_STATIC2, str);
  183. CRect rc;
  184. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  185. ScreenToClient(rc);
  186. InvalidateRect(rc);
  187. }
  188. void Client2Form::OnBUTclose()
  189. {
  190. // TODO: Add your control notification handler code here
  191. GetParent()->SendMessage(WM_CLOSE);
  192. }
  193. void Client2Form::OnSelchangeCombo1()
  194. {
  195. // TODO: Add your control notification handler code here
  196. SetTimer(1, 100, NULL);
  197. }
  198. void Client2Form::OnTimer(UINT nIDEvent)
  199. {
  200. // TODO: Add your message handler code here and/or call default
  201. KillTimer(nIDEvent);
  202. OnButton1();
  203. }
  204. BOOL Client2Form::PreTranslateMessage(MSG* pMsg)
  205. {
  206. // TODO: Add your specialized code here and/or call the base class
  207. try
  208. {
  209. if (pMsg->message == WM_KEYDOWN)
  210. {
  211. switch (pMsg->wParam)
  212. {
  213. case VK_RETURN:
  214. OnButton1();
  215. return 1;
  216. case 0x43: // copy
  217. if ((GetKeyState(VK_CONTROL) & 0x80))
  218. {
  219. GetFocus()->SendMessage(WM_COPY);
  220. return TRUE;
  221. }
  222. break;
  223. case 0x56: //Ctrl + V:
  224. if ((GetKeyState(VK_CONTROL) & 0x80))
  225. {
  226. GetFocus()->SendMessage(WM_PASTE);
  227. return TRUE;
  228. }
  229. break;
  230. case 0x58: // cut
  231. if ((GetKeyState(VK_CONTROL) & 0x80))
  232. {
  233. GetFocus()->SendMessage(WM_CUT);
  234. return TRUE;
  235. }
  236. break;
  237. case 0x5A: //undo
  238. case 0x59: //redo
  239. if ((GetKeyState(VK_CONTROL) & 0x80))
  240. {
  241. GetFocus()->SendMessage(WM_UNDO);
  242. return TRUE;
  243. }
  244. break;
  245. }
  246. }
  247. return MyFormView::PreTranslateMessage(pMsg);
  248. }
  249. catch (...)
  250. {
  251. }
  252. }
  253. extern int CALLBACK BrowseProc(HWND hwnd, UINT msg, LPARAM lParam, LPARAM lpData);
  254. /*{
  255. switch(msg)
  256. {
  257. case BFFM_INITIALIZED:
  258. SendMessage(hwnd, BFFM_SETSELECTION, TRUE, NULL);
  259. break;
  260. case BFFM_SELCHANGED:
  261. {
  262. char szFileName[MAX_PATH];
  263. LPITEMIDLIST pidlCurrent = (LPITEMIDLIST)lParam;
  264. SHGetPathFromIDList(pidlCurrent, szFileName);
  265. SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szFileName);
  266. }
  267. break;
  268. }
  269. return 0;
  270. }*/
  271. void Client2Form::GetSavePath(CString &path)
  272. {
  273. char lpszDisplayName[MAX_PATH], szFileName[MAX_PATH];
  274. LPITEMIDLIST pidlDesktop, pidlCurrent;
  275. if (SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidlDesktop)
  276. == NOERROR)
  277. {
  278. BROWSEINFO bi;
  279. bi.hwndOwner = this->m_hWnd;
  280. bi.pidlRoot = pidlDesktop;
  281. bi.pszDisplayName = lpszDisplayName;
  282. bi.lpszTitle = "\n文档保存的目录:";
  283. bi.ulFlags = BIF_STATUSTEXT&BIF_RETURNONLYFSDIRS;
  284. bi.lpfn = BrowseProc;
  285. bi.lParam = 0;
  286. bi.iImage = 0;
  287. pidlCurrent = SHBrowseForFolder(&bi);
  288. SHGetPathFromIDList(pidlCurrent, szFileName);
  289. path = szFileName;
  290. }
  291. }
  292. int Client2Form::FindArray(CStringArray *pArray, CString Str)
  293. {
  294. for (int i = 0; i < pArray->GetSize(); i++)
  295. {
  296. if (pArray->ElementAt(i) == Str)
  297. return i;
  298. }
  299. return -1;
  300. }
  301. //-----------------------------------------------------------------
  302. // remark by Jeff 2014-12-12
  303. // 函数:GetNo
  304. // 描述:从str中解析出每个相片名,然后存入空的CStringArray中;
  305. // 参数:
  306. // str:选好的相片名串,如:"001,002,003" 后分隔符改为"|",结果应是"001|002|003"
  307. // array:空的数组,用来存放解析后的相片名;
  308. // 返回:
  309. // 注意:更换分隔符造成的问题,在该函数已解决;
  310. //-----------------------------------------------------------------
  311. void Client2Form::GetNo(CString str, CStringArray &array)
  312. {
  313. if (!str.IsEmpty())
  314. {
  315. int pos = str.Find(",");
  316. while (pos != -1)
  317. {
  318. if (FindArray(&array, str.Left(pos)) == -1)
  319. array.Add(str.Left(pos));
  320. str = str.Right(str.GetLength() - pos - 1);
  321. pos = str.Find(",");
  322. }
  323. if (FindArray(&array, str) == -1)
  324. array.Add(str);
  325. }
  326. }
  327. //-----------------------------------------------------------------
  328. // remark by Jeff 2014-12-12
  329. // 函数:GetSelName
  330. // 描述:
  331. // 参数:
  332. // name:由GetNo解析出来后的单个相片名,如:"001"
  333. // spnamearray:订单下的商品数组,case 50所得;
  334. // 返回:
  335. // 注意:更换分隔符造成的问题,在该函数已解决;
  336. //-----------------------------------------------------------------
  337. CString Client2Form::GetSelName(CString name, CArray<CStringArray, CStringArray>&spnamearray)
  338. {
  339. CString ret;
  340. name = "," + name + ",";
  341. CString str;
  342. for (int i = 0; i < spnamearray.GetSize(); i++)
  343. {
  344. str = "," + spnamearray.ElementAt(i).ElementAt(6) + ",";
  345. if (str.Find(name) != -1)
  346. {
  347. ret += spnamearray.ElementAt(i).ElementAt(5);
  348. ret += ";";
  349. }
  350. }
  351. ret.TrimRight(";");
  352. ret.Replace("*", "x");
  353. return ret;
  354. }
  355. void Client2Form::OnButton1()
  356. {
  357. // TODO: Add your control notification handler code here
  358. UpdateData();
  359. m_filter.TrimLeft();
  360. m_filter.TrimRight();
  361. FillGrid();
  362. }
  363. void Client2Form::OnButton2()
  364. {
  365. // TODO: Add your control notification handler code here
  366. }
  367. void Client2Form::OnItemchangedList2(NMHDR* pNMHDR, LRESULT* pResult)
  368. {
  369. NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
  370. // TODO: Add your control notification handler code here
  371. *pResult = 0;
  372. }
  373. void Client2Form::OnBUTClient2Form()
  374. {
  375. // TODO: Add your control notification handler code here
  376. AddClient dlg;
  377. if (dlg.DoModal() == IDOK)
  378. {
  379. g_sendhead.bsql = 0;
  380. g_sendhead.code[0] = 90;
  381. g_sendhead.tabcount = 1;
  382. g_pMainWnd->ProcessChatMessageRequest2(1); if (g_bSendOK == 0)return;
  383. DataToArray(&m_List1array);
  384. m_List1arrayBak.SetSize(m_List1array.GetSize());
  385. for (int i = 0; i < m_List1array.GetSize(); i++)
  386. {
  387. m_List1arrayBak.ElementAt(i).Copy(m_List1array.ElementAt(i));
  388. if (m_List1array.ElementAt(i).ElementAt(8).GetLength()>256)
  389. m_List1array.ElementAt(i).SetAt(8, m_List1array.ElementAt(i).ElementAt(8).Left(256) + "..");
  390. }
  391. FillGrid();
  392. }
  393. }
  394. void Client2Form::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
  395. {
  396. // TODO: Add your control notification handler code here
  397. POSITION pos;
  398. pos = m_List1.GetFirstSelectedItemPosition();
  399. if (pos == NULL)return;
  400. OnBUTburncd2();
  401. *pResult = 0;
  402. }
  403. void Client2Form::OnBUTburncd2()
  404. {
  405. // TODO: Add your control notification handler code here
  406. POSITION pos;
  407. pos = m_List1.GetFirstSelectedItemPosition();
  408. if (pos == NULL)
  409. {
  410. AfxMessageBox("请先选中您要修改的客户!", MB_ICONINFORMATION);
  411. return;
  412. }
  413. int iItem = m_List1.GetNextSelectedItem(pos);
  414. AddClient dlg;
  415. dlg.m_bAdd = 0;
  416. dlg.id = m_List1.GetItemText(iItem, 0);
  417. dlg.m_name1 = m_List1.GetItemText(iItem, 1);
  418. dlg.m_sex = m_List1.GetItemText(iItem, 2);
  419. dlg.m_phone1 = m_List1.GetItemText(iItem, 3);
  420. dlg.m_qq1 = m_List1.GetItemText(iItem, 4);
  421. dlg.m_addr1 = m_List1.GetItemText(iItem, 5);
  422. dlg.m_from = m_List1.GetItemText(iItem, 6);
  423. dlg.m_reason = m_List1.GetItemText(iItem, 7);
  424. dlg.m_birthday1 = m_List1.GetItemText(iItem, 9);
  425. CString id = m_List1.GetItemText(iItem, 0);
  426. for (int ii = 0; ii < m_List1arrayBak.GetSize(); ii++)
  427. {
  428. if (m_List1arrayBak.ElementAt(ii).ElementAt(0) == id)
  429. {
  430. dlg.m_check1 = atoi(m_List1arrayBak.ElementAt(ii).ElementAt(13));
  431. dlg.m_bz = m_List1arrayBak.ElementAt(ii).ElementAt(8);
  432. break;
  433. }
  434. }
  435. if (dlg.DoModal() == IDOK)
  436. {
  437. g_sendhead.bsql = 0;
  438. g_sendhead.code[0] = 90;
  439. g_sendhead.tabcount = 1;
  440. g_pMainWnd->ProcessChatMessageRequest2(1); if (g_bSendOK == 0)return;
  441. DataToArray(&m_List1array);
  442. m_List1arrayBak.SetSize(m_List1array.GetSize());
  443. for (int i = 0; i < m_List1array.GetSize(); i++)
  444. {
  445. m_List1arrayBak.ElementAt(i).Copy(m_List1array.ElementAt(i));
  446. if (m_List1array.ElementAt(i).ElementAt(8).GetLength()>256)
  447. m_List1array.ElementAt(i).SetAt(8, m_List1array.ElementAt(i).ElementAt(8).Left(256) + "..");
  448. }
  449. FillGrid();
  450. }
  451. }
  452. void Client2Form::OnBUTburncd3()
  453. {
  454. // TODO: Add your control notification handler code here
  455. POSITION pos;
  456. pos = m_List1.GetFirstSelectedItemPosition();
  457. if (pos == NULL)
  458. {
  459. AfxMessageBox("请先选中您要删除的客户!", MB_ICONINFORMATION);
  460. return;
  461. }
  462. int iItem = m_List1.GetNextSelectedItem(pos);
  463. CString id = m_List1.GetItemText(iItem, 0);
  464. if (AfxMessageBox("确认删除吗?", MB_YESNO | MB_ICONINFORMATION) != IDYES)return;
  465. CString sql;
  466. sql.Format("delete from client2 where id=%d ", atoi(id));
  467. g_sendhead.bsql = 1;
  468. g_pMainWnd->ProcessChatMessageRequest2(sql); if (g_bSendOK == 0)return;
  469. g_sendhead.bsql = 0;
  470. g_sendhead.code[0] = 90;
  471. g_sendhead.tabcount = 1;
  472. g_pMainWnd->ProcessChatMessageRequest2(1); if (g_bSendOK == 0)return;
  473. DataToArray(&m_List1array);
  474. m_List1arrayBak.SetSize(m_List1array.GetSize());
  475. for (int i = 0; i < m_List1array.GetSize(); i++)
  476. {
  477. m_List1arrayBak.ElementAt(i).Copy(m_List1array.ElementAt(i));
  478. if (m_List1array.ElementAt(i).ElementAt(8).GetLength()>256)
  479. m_List1array.ElementAt(i).SetAt(8, m_List1array.ElementAt(i).ElementAt(8).Left(256) + "..");
  480. }
  481. FillGrid();
  482. }
  483. void Client2Form::OnBUTsendmsg()
  484. {
  485. // TODO: Add your control notification handler code here
  486. POSITION pos;
  487. pos = m_List1.GetFirstSelectedItemPosition();
  488. if (pos == NULL)
  489. {
  490. AfxMessageBox("请先选中您要发送短信的客人!", MB_ICONINFORMATION);
  491. return;
  492. }
  493. int iItem;
  494. CStringArray array;
  495. while (pos)
  496. {
  497. iItem = m_List1.GetNextSelectedItem(pos);
  498. if (!m_List1.GetItemText(iItem, 3).IsEmpty())
  499. array.Add(m_List1.GetItemText(iItem, 3));
  500. }
  501. SendMsgDlg dlg;
  502. dlg.m_mode = 2;
  503. dlg.m_pArray = &array;
  504. dlg.DoModal();
  505. }
  506. void Client2Form::OnBUTprint3()
  507. {
  508. SelExportType dlg;
  509. if (dlg.DoModal() != IDOK)return;
  510. if (dlg.m_type == 1)
  511. {
  512. ListToXLS(&m_List1, "c:\\客户资料.xls", 0);
  513. return;
  514. }
  515. CStdioFile fp;
  516. /* if(::PathFileExists ("c:\\clientphone.txt"))
  517. {
  518. fp.Open ("c:\\clientphone.txt", CFile::modeWrite);
  519. fp.SeekToEnd ();
  520. }
  521. else*/
  522. fp.Open("c:\\clientphone.txt", CFile::modeCreate | CFile::modeWrite);
  523. CString str;
  524. CString str1, str2, str3, str4, str5, str6;
  525. CString phone;
  526. CString txname, txprice, mensi;
  527. int leng1 = 20;
  528. int leng2 = 10;
  529. int leng3 = 20;
  530. int leng4 = 20;
  531. int leng5 = 20;
  532. int leng6 = 30;
  533. str1 = "姓名";
  534. str2 = "性别";
  535. str3 = "电话";
  536. str4 = "QQ";
  537. str5 = "生日";
  538. str6 = "地址";
  539. FillLength(str1, leng1);
  540. FillLength(str2, leng2);
  541. FillLength(str3, leng3);
  542. FillLength(str4, leng4);
  543. FillLength(str5, leng5);
  544. FillLength(str6, leng6);
  545. str = str1 + str2 + str3 + str4 + str5 + str6 + "\n";
  546. fp.WriteString(str);
  547. for (int i = 0; i < m_List1.GetItemCount(); i++)
  548. {
  549. str1 = str2 = str3 = str4 = str5 = "";
  550. str1 = m_List1.GetItemText(i, 1);
  551. str2 = m_List1.GetItemText(i, 2);
  552. str3 = m_List1.GetItemText(i, 3);
  553. str4 = m_List1.GetItemText(i, 4);
  554. str5 = m_List1.GetItemText(i, 9);
  555. str6 = m_List1.GetItemText(i, 5);
  556. FillLength(str1, leng1);
  557. FillLength(str2, leng2);
  558. FillLength(str3, leng3);
  559. FillLength(str4, leng4);
  560. FillLength(str5, leng5);
  561. FillLength(str6, leng6);
  562. str = str1 + str2 + str3 + str4 + str5 + str6 + "\n";
  563. fp.WriteString(str);
  564. }
  565. fp.Close();
  566. MessageBox("电话已保存到c:\\clientphone.txt");
  567. ShellExecute(NULL, _T("open"), _T("c:\\clientphone.txt"), NULL, NULL, SW_SHOWMAXIMIZED);
  568. }
  569. extern void CheckDate(CString &date);
  570. void Client2Form::OnBUTshowphoto()
  571. {
  572. using namespace YExcel;
  573. // TODO: Add your control notification handler code here
  574. BasicExcel e;
  575. CFileDialog fdlg(true, NULL, "", OFN_HIDEREADONLY, "Excel files(*.xls)|*.xls||");
  576. if (fdlg.DoModal() != IDOK)return;
  577. CString path = fdlg.GetPathName();
  578. e.Load(path);
  579. BasicExcelWorksheet* sheet1 = e.GetWorksheet("Sheet1");
  580. if (sheet1)
  581. {
  582. size_t maxRows = sheet1->GetTotalRows();
  583. size_t maxCols = sheet1->GetTotalCols();
  584. if (maxCols > 6)maxCols = 6;
  585. if (maxCols < 6)
  586. {
  587. AfxMessageBox("格式不对:缺少项目!"); return;
  588. }
  589. if (maxRows < 2)
  590. {
  591. AfxMessageBox("没有资料!"); return;
  592. }
  593. CStringArray array;
  594. for (size_t r = 0; r < maxRows; ++r)
  595. {
  596. for (size_t c = 0; c < maxCols; ++c)
  597. {
  598. BasicExcelCell* cell = sheet1->Cell(r, c);
  599. switch (cell->Type())
  600. {
  601. case BasicExcelCell::STRING:
  602. array.Add(cell->GetString());
  603. break;
  604. case BasicExcelCell::WSTRING:
  605. {
  606. int leng = wcslen(cell->GetWString());
  607. char* ppszA = new char[2 * leng + 1];
  608. memset(ppszA, 0, 2 * leng + 1);
  609. WideCharToMultiByte(CP_ACP, 0, cell->GetWString(), -1, ppszA, leng * 2, NULL, NULL);
  610. CString str = ppszA; str.TrimLeft(); str.TrimRight();
  611. array.Add(str);
  612. delete[]ppszA;
  613. }
  614. break;
  615. default:
  616. array.Add("");
  617. }
  618. }
  619. if (r == 0)
  620. {
  621. if (array.GetSize() != maxCols)
  622. {
  623. AfxMessageBox("资料读取错误"); return;
  624. }
  625. if (array.ElementAt(0) != "客户姓名")
  626. {
  627. AfxMessageBox("格式错误2"); return;
  628. }
  629. array.RemoveAll();
  630. }
  631. }
  632. ///////////////////////
  633. CString sql, temp;
  634. CString m_name1, m_phone1, m_qq1, m_addr1, strRes1, m_sex, m_birthday1;
  635. int count = 0;
  636. for (int i = 0; i < array.GetSize(); i += 6)
  637. {
  638. m_name1 = array.ElementAt(i + 0);
  639. m_sex = array.ElementAt(i + 1);
  640. m_phone1 = array.ElementAt(i + 2);
  641. m_qq1 = array.ElementAt(i + 3);
  642. m_addr1 = array.ElementAt(i + 4);
  643. m_birthday1 = array.ElementAt(i + 5);
  644. CheckDate(m_birthday1);
  645. GetFirstLetter(m_name1, strRes1);
  646. if (m_name1.IsEmpty())continue;
  647. if (CheckExist(m_name1, m_phone1))continue;
  648. temp.Format("insert into [client2]([name],[phone],[qq],[addr],[pinyin],[date],[sex],[birthday])values('%s','%s','%s','%s','%s','%s','%s','%s')", m_name1, m_phone1, m_qq1, m_addr1, strRes1, g_date, m_sex, m_birthday1);
  649. sql += temp;
  650. sql += "***";
  651. count++;
  652. if (count == 5)
  653. {
  654. sql.TrimRight("***");
  655. g_sendhead.bsql = 1;
  656. g_pMainWnd->ProcessChatMessageRequest2(sql);
  657. if (g_bSendOK == 0)
  658. {
  659. AfxMessageBox("保存过程中出现错误!");
  660. return;
  661. }
  662. sql.Empty(); count = 0; GetData();
  663. }
  664. ::Sleep(1000);
  665. }
  666. /////////////////////////////////////
  667. if (!sql.IsEmpty())
  668. {
  669. sql.TrimRight("***");
  670. g_sendhead.bsql = 1;
  671. g_pMainWnd->ProcessChatMessageRequest2(sql);
  672. if (g_bSendOK == 0)
  673. {
  674. AfxMessageBox("保存过程中出现错误!");
  675. return;
  676. }
  677. sql.Empty(); count = 0; GetData();
  678. }
  679. ///////////////////////
  680. }
  681. else
  682. AfxMessageBox("格式错误,或文件未关闭!!");
  683. }
  684. void Client2Form::GetData()
  685. {
  686. g_sendhead.bsql = 0;
  687. g_sendhead.code[0] = 90;
  688. g_sendhead.tabcount = 1;
  689. g_pMainWnd->ProcessChatMessageRequest2(1); if (g_bSendOK == 0)return;
  690. DataToArray(&m_List1array);
  691. m_List1arrayBak.SetSize(m_List1array.GetSize());
  692. for (int i = 0; i < m_List1array.GetSize(); i++)
  693. {
  694. m_List1arrayBak.ElementAt(i).Copy(m_List1array.ElementAt(i));
  695. if (m_List1array.ElementAt(i).ElementAt(8).GetLength()>256)
  696. m_List1array.ElementAt(i).SetAt(8, m_List1array.ElementAt(i).ElementAt(8).Left(256) + "..");
  697. }
  698. FillGrid();
  699. }
  700. BOOL Client2Form::CheckExist(CString m_name1, CString m_phone1)
  701. {
  702. for (int i = 0; i < m_List1array.GetSize(); i++)
  703. {
  704. if (m_List1array.ElementAt(i).ElementAt(1) == m_name1 && m_List1array.ElementAt(i).ElementAt(3) == m_phone1)return 1;
  705. }
  706. return 0;
  707. }