Client2Form.cpp 20 KB

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