Client2Form.cpp 20 KB

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