AddClient.cpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. // AddClient.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "UPhoneBox.h"
  5. #include "AddClient.h"
  6. #include "UPhoneBoxDlg.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // AddClient dialog
  14. AddClient::AddClient(CWnd* pParent /*=NULL*/)
  15. : CDialog(AddClient::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(AddClient)
  18. m_addr1 = _T("");
  19. m_name1 = _T("");
  20. m_phone1 = _T("");
  21. m_qq1 = _T("");
  22. m_from = _T("");
  23. m_reason = _T("");
  24. m_bz = _T("");
  25. m_bAdd = 1;
  26. m_sex = _T("");
  27. //}}AFX_DATA_INIT
  28. }
  29. void AddClient::DoDataExchange(CDataExchange* pDX)
  30. {
  31. CDialog::DoDataExchange(pDX);
  32. //{{AFX_DATA_MAP(AddClient)
  33. DDX_Control(pDX, IDC_COMBOsex, m_combosex);
  34. DDX_Control(pDX, IDC_COMBOreason, m_comboreason);
  35. DDX_Control(pDX, IDC_COMBOfrom, m_combofrom);
  36. DDX_Text(pDX, IDC_EDITaddr, m_addr1);
  37. DDX_Text(pDX, IDC_EDITname, m_name1);
  38. DDX_Text(pDX, IDC_EDITphone, m_phone1);
  39. DDX_Text(pDX, IDC_EDITqq, m_qq1);
  40. DDX_CBString(pDX, IDC_COMBOfrom, m_from);
  41. DDX_CBString(pDX, IDC_COMBOreason, m_reason);
  42. DDX_Text(pDX, IDC_EDIT1, m_bz);
  43. DDX_CBString(pDX, IDC_COMBOsex, m_sex);
  44. //}}AFX_DATA_MAP
  45. }
  46. BEGIN_MESSAGE_MAP(AddClient, CDialog)
  47. //{{AFX_MSG_MAP(AddClient)
  48. //}}AFX_MSG_MAP
  49. END_MESSAGE_MAP()
  50. /////////////////////////////////////////////////////////////////////////////
  51. // AddClient message handlers
  52. BOOL AddClient::OnInitDialog()
  53. {
  54. CDialog::OnInitDialog();
  55. // TODO: Add extra initialization here
  56. m_combofrom.AddString("广告");
  57. m_combofrom.AddString("报纸");
  58. m_combofrom.AddString("网络");
  59. m_combofrom.AddString("朋友介绍");
  60. m_combofrom.AddString("路过");
  61. m_combofrom.AddString("外展");
  62. m_comboreason.AddString("产品");
  63. m_comboreason.AddString("价格");
  64. m_comboreason.AddString("品牌");
  65. m_comboreason.AddString("服装");
  66. m_comboreason.AddString("外景");
  67. m_comboreason.AddString("随便逛逛");
  68. m_combosex.AddString("男");
  69. m_combosex.AddString("女");
  70. m_combosex.SetCurSel(m_combosex.FindString(0, m_sex));
  71. m_combofrom.SetCurSel(m_combofrom.FindString(0, m_from));
  72. m_comboreason.SetCurSel(m_comboreason.FindString(0, m_reason));
  73. CenterWindow();
  74. return false; // return TRUE unless you set the focus to a control
  75. // EXCEPTION: OCX Property Pages should return FALSE
  76. }
  77. /********************************************************************************************
  78. /* Syntax
  79. /* void FirstLetter(int nCode, CString& strLetter)
  80. /* Remarks:
  81. /* Get the first letter of pinyin according to specified Chinese character code.
  82. /* Parameters:
  83. /* nCode - the code of the chinese character.
  84. /* strLetter - a CString object that is to receive the string of the first letter.
  85. /* Return Values:
  86. /* None.
  87. /* Author:
  88. /* lixiaosan
  89. /* Create Date:
  90. /* 05-26-2006
  91. /********************************************************************************************/
  92. void FirstLetter(int nCode, CString& strLetter)
  93. {
  94. if (nCode >= 1601 && nCode < 1637) strLetter = _T("A");
  95. if (nCode >= 1637 && nCode < 1833) strLetter = _T("B");
  96. if (nCode >= 1833 && nCode < 2078) strLetter = _T("C");
  97. if (nCode >= 2078 && nCode < 2274) strLetter = _T("D");
  98. if (nCode >= 2274 && nCode < 2302) strLetter = _T("E");
  99. if (nCode >= 2302 && nCode < 2433) strLetter = _T("F");
  100. if (nCode >= 2433 && nCode < 2594) strLetter = _T("G");
  101. if (nCode >= 2594 && nCode < 2787) strLetter = _T("H");
  102. if (nCode >= 2787 && nCode < 3106) strLetter = _T("J");
  103. if (nCode >= 3106 && nCode < 3212) strLetter = _T("K");
  104. if (nCode >= 3212 && nCode < 3472) strLetter = _T("L");
  105. if (nCode >= 3472 && nCode < 3635) strLetter = _T("M");
  106. if (nCode >= 3635 && nCode < 3722) strLetter = _T("N");
  107. if (nCode >= 3722 && nCode < 3730) strLetter = _T("O");
  108. if (nCode >= 3730 && nCode < 3858) strLetter = _T("P");
  109. if (nCode >= 3858 && nCode < 4027) strLetter = _T("Q");
  110. if (nCode >= 4027 && nCode < 4086) strLetter = _T("R");
  111. if (nCode >= 4086 && nCode < 4390) strLetter = _T("S");
  112. if (nCode >= 4390 && nCode < 4558) strLetter = _T("T");
  113. if (nCode >= 4558 && nCode < 4684) strLetter = _T("W");
  114. if (nCode >= 4684 && nCode < 4925) strLetter = _T("X");
  115. if (nCode >= 4925 && nCode < 5249) strLetter = _T("Y");
  116. if (nCode >= 5249 && nCode < 5590) strLetter = _T("Z");
  117. }
  118. /********************************************************************************************
  119. /* Syntax
  120. /* GetFirstLetter(CString strName, CString& strFirstLetter)
  121. /* Remarks:
  122. /* Get the first letter of pinyin according to specified Chinese character.
  123. /* Parameters:
  124. /* strName - a CString object that is to be parsed.
  125. /* strFirstLetter - a CString object that is to receive the string of the first letter.
  126. /* Return Values:
  127. /* None.
  128. /* Author:
  129. /* lixiaosan
  130. /* Create Date:
  131. /* 05-26-2006
  132. /********************************************************************************************/
  133. void GetFirstLetter(CString strName, CString& strFirstLetter)
  134. {
  135. TBYTE ucHigh, ucLow;
  136. int nCode;
  137. CString strRet;
  138. strFirstLetter.Empty();
  139. for (int i = 0; i < strName.GetLength(); i++)
  140. {
  141. if ((TBYTE)strName[i] < 0x80)
  142. {
  143. strRet = strName.Mid(i, 1);
  144. strRet.MakeUpper();
  145. strFirstLetter += strRet;
  146. continue;
  147. }
  148. ucHigh = (TBYTE)strName[i];
  149. ucLow = (TBYTE)strName[i + 1];
  150. if (ucHigh < 0xa1 || ucLow < 0xa1)
  151. continue;
  152. else
  153. // Treat code by section-position as an int type parameter,
  154. // so make following change to nCode.
  155. nCode = (ucHigh - 0xa0) * 100 + ucLow - 0xa0;
  156. FirstLetter(nCode, strRet);
  157. strFirstLetter += strRet;
  158. i++;
  159. }
  160. }
  161. extern int g_nYearpos;
  162. extern BOOL g_bReturned2;
  163. extern CUPhoneBoxDlg *g_pMainWnd;
  164. void AddClient::OnOK()
  165. {
  166. // TODO: Add extra validation here
  167. UpdateData();
  168. m_name1.TrimLeft();
  169. m_name1.TrimRight();
  170. if (m_name1.IsEmpty())
  171. {
  172. AfxMessageBox("姓名不能为空!", MB_ICONINFORMATION); return;
  173. }
  174. if (m_name1.Find("*") != -1)
  175. {
  176. AfxMessageBox("客人名字非法!", MB_ICONINFORMATION);
  177. return;
  178. }
  179. CString strRes1;
  180. GetFirstLetter(m_name1, strRes1);
  181. CString g_date = CTime::GetCurrentTime().Format("%Y-%m-%d");
  182. CString sql, sql2;
  183. sql.Format("insert into [client2]([name],[phone],[qq],[addr],[from],[reason],[bz],[pinyin],[date],[sex],[ren])values(\
  184. '%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')", m_name1, m_phone1, m_qq1, m_addr1, m_from, m_reason, m_bz, strRes1, g_date, m_sex, "");
  185. g_sendhead.bsql = 1;
  186. g_nYearpos = -1;
  187. g_pMainWnd->ProcessChatMessageRequest2(sql);
  188. int i ;
  189. for ( i = 0; i < 20; i++)
  190. {
  191. if (g_bReturned2)break;
  192. ::Sleep(500);
  193. }
  194. if (i >= 20)
  195. {
  196. nNeedConn2 = 1;
  197. AfxMessageBox("保存失败!", MB_ICONINFORMATION);
  198. return;
  199. }
  200. AfxMessageBox("保存成功!", MB_ICONINFORMATION);
  201. CDialog::OnOK();
  202. }
  203. void AddClient::OnCancel()
  204. {
  205. // TODO: Add extra cleanup here
  206. CDialog::OnCancel();
  207. }