ModifyPIDlg.cpp
上传用户:guangzhiyw
上传日期:2007-01-09
资源大小:495k
文件大小:8k
源码类别:

ICQ/即时通讯

开发平台:

Visual C++

  1. // ModifyPIDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "client.h"
  5. #include "ModifyPIDlg.h"
  6. #include "changepwd.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. /////////////////////////////////////////////////////////////////////////////
  13. // CModifyPIDlg dialog
  14. CModifyPIDlg::CModifyPIDlg(CWnd* pParent /*=NULL*/)
  15. : CDialog(CModifyPIDlg::IDD, pParent)
  16. {
  17. //{{AFX_DATA_INIT(CModifyPIDlg)
  18. m_strAddress = _T("");
  19. m_strAge = _T("");
  20. m_strDepartment = _T("");
  21. m_strDescription = _T("");
  22. m_strEmail = _T("");
  23. m_strFax = _T("");
  24. m_strHomepage = _T("");
  25. m_strID = _T("");
  26. m_strName = _T("");
  27. m_strPhone = _T("");
  28. m_canbeadd = -1;
  29. //}}AFX_DATA_INIT
  30. pInfo=NULL;
  31. hIcon=AfxGetApp()->LoadIcon(IDR_NOTIFY);
  32. }
  33. void CModifyPIDlg::DoDataExchange(CDataExchange* pDX)
  34. {
  35. CDialog::DoDataExchange(pDX);
  36. //{{AFX_DATA_MAP(CModifyPIDlg)
  37. DDX_Control(pDX, IDC_SEX, m_ComboSex);
  38. DDX_Control(pDX, IDC_HEADBMP, m_ComboFace);
  39. DDX_Text(pDX, IDC_ADDRESS, m_strAddress);
  40. DDX_Text(pDX, IDC_AGE, m_strAge);
  41. DDV_MaxChars(pDX, m_strAge, 6);
  42. DDX_Text(pDX, IDC_DEPARTMENT, m_strDepartment);
  43. DDX_Text(pDX, IDC_DESCRIPTION, m_strDescription);
  44. DDX_Text(pDX, IDC_EMAIL, m_strEmail);
  45. DDX_Text(pDX, IDC_FAX, m_strFax);
  46. DDX_Text(pDX, IDC_HOMEPAGE, m_strHomepage);
  47. DDX_Text(pDX, IDC_ID, m_strID);
  48. DDX_Text(pDX, IDC_NAME, m_strName);
  49. DDX_Text(pDX, IDC_PHONE, m_strPhone);
  50. DDX_Radio(pDX, IDC_ALLOW_ALL, m_canbeadd);
  51. //}}AFX_DATA_MAP
  52. }
  53. BEGIN_MESSAGE_MAP(CModifyPIDlg, CDialog)
  54. //{{AFX_MSG_MAP(CModifyPIDlg)
  55. ON_BN_CLICKED(ID_REFRESH, OnRefresh)
  56. ON_WM_TIMER()
  57. ON_BN_CLICKED(ID_SHOW_CHANGEPWD, OnShowChangepwd)
  58. ON_BN_CLICKED(ID_MODIFYPI, OnModifypi)
  59. //}}AFX_MSG_MAP
  60. ON_MESSAGE(WM_SHOW_FRIEND_DETAIL,OnShowFriendDetail)
  61. ON_MESSAGE(WM_RECIEVE_MSG,OnRecvMyDetail)
  62. END_MESSAGE_MAP()
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CModifyPIDlg message handlers
  65. void CModifyPIDlg::OnRefresh() 
  66. {
  67. if(!GetApp()->m_bOnlineState)return;
  68. CMsg1 msg;
  69. msg.index=FRIEND_DETAIL;
  70. msg.MyId=GetApp()->m_uCurrentUserID;
  71. msg.tarIP=GetApp()->m_uServerIP;
  72. msg.nPort=GetApp()->m_uServerPort;
  73. msg.FriendId=pInfo->Id;
  74. BOOL bCancel=FALSE;
  75. if(!GetApp()->m_Socket.SendData(&msg,bCancel,this))
  76. {
  77. CString str;
  78. str.LoadString(IDS_SERVER_NOT_RES);
  79. MessageBox(str);
  80. OnOK();
  81. return;
  82. }
  83. BeginWaitCursor();
  84. SetTimer(2,TimeWaitForFriendDetail,NULL);
  85. }
  86. LRESULT CModifyPIDlg::OnShowFriendDetail(WPARAM wParam,LPARAM lParam)
  87. {
  88. pInfo=(UserInfo*)wParam;
  89. ASSERT(pInfo!=NULL);
  90. m_strID.Format("%d",pInfo->Id);
  91. int photoid=0;
  92. if(pInfo->HaveDetail)
  93. {
  94. if(pInfo->CanbeAdd==0)m_canbeadd=2;
  95. else if(pInfo->CanbeAdd==1)m_canbeadd=0;
  96. else m_canbeadd=1;
  97. m_strAddress=pInfo->Address;
  98. m_strAge=pInfo->Age;
  99. m_strDepartment=pInfo->Department;
  100. m_strDescription=pInfo->Description;
  101. m_strEmail=pInfo->Email;
  102. m_strFax=pInfo->Fax;
  103. m_strHomepage=pInfo->Homepage;
  104. m_strName=pInfo->Name;
  105. m_strPhone=pInfo->Phone;
  106. photoid=pInfo->PhotoId;
  107. if(pInfo->Sex==0)m_ComboSex.SetCurSel(0);
  108. else if(pInfo->Sex==1)m_ComboSex.SetCurSel(1);
  109. }
  110. m_ComboFace.SetCurSel(photoid);
  111. UpdateData(FALSE);
  112. ShowWindow(SW_NORMAL);
  113. return 0;
  114. }
  115. BOOL CModifyPIDlg::OnInitDialog() 
  116. {
  117. CDialog::OnInitDialog();
  118. SetIcon(hIcon,TRUE);
  119. SetIcon(hIcon,FALSE);
  120. CMenu* pMenu=GetSystemMenu(FALSE);
  121. pMenu->EnableMenuItem(SC_RESTORE,MF_GRAYED|MF_DISABLED);
  122. pMenu->EnableMenuItem(SC_SIZE,MF_GRAYED|MF_DISABLED);
  123. pMenu->EnableMenuItem(SC_MAXIMIZE,MF_GRAYED|MF_DISABLED);
  124. m_ComboFace.SetImageList(&GetApp()->m_imaHead);
  125. m_ComboFace.SetCurSel(0);
  126.  
  127. return TRUE;
  128. }
  129. void CModifyPIDlg::OnTimer(UINT nIDEvent) 
  130. {
  131. if(nIDEvent==2)
  132. {
  133. EndWaitCursor();
  134. KillTimer(2);
  135. CString str;
  136. str.LoadString(IDS_SERVER_NOT_RES);
  137. MessageBox(str);
  138. OnOK();
  139. }
  140. }
  141. void CModifyPIDlg::OnShowChangepwd() 
  142. {
  143. CChangePwd dlg(this);
  144. dlg.DoModal();
  145. }
  146. LRESULT CModifyPIDlg::OnRecvMyDetail(WPARAM wParam,LPARAM lParam)
  147. {
  148. if(!GetApp()->m_bOnlineState)return 0;
  149. CData* pData=(CData*)wParam;
  150. if(pData->index==RE_FRIEND_DETAIL)
  151. {
  152. if(pInfo==NULL)return 0;
  153. CMsgPerson msg;
  154. CopyDataBuf(&msg,pData);
  155. if(!msg.LoadFromBuf())return 0;
  156. pInfo->HaveDetail=1;
  157. pInfo->CanbeAdd=msg.Canbeadd;
  158. pInfo->Sex=msg.Sex;
  159. pInfo->PhotoId=msg.PhotoId;
  160. lstrcpy(pInfo->Address,msg.Address);
  161. lstrcpy(pInfo->Age,msg.Age);
  162. lstrcpy(pInfo->Department,msg.Department);
  163. lstrcpy(pInfo->Description,msg.Description);
  164. lstrcpy(pInfo->Email,msg.Email);
  165. lstrcpy(pInfo->Fax,msg.Fax);
  166. lstrcpy(pInfo->Homepage,msg.Homepage);
  167. lstrcpy(pInfo->Phone,msg.Phone);
  168. lstrcpy(pInfo->Name,msg.Name);
  169. m_strID.Format("%d",pInfo->Id);
  170. if(pInfo->CanbeAdd==0)m_canbeadd=2;
  171. else if(pInfo->CanbeAdd==1)m_canbeadd=0;
  172. else m_canbeadd=1;
  173. m_strAddress=pInfo->Address;
  174. m_strAge=pInfo->Age;
  175. m_strDepartment=pInfo->Department;
  176. m_strDescription=pInfo->Description;
  177. m_strEmail=pInfo->Email;
  178. m_strFax=pInfo->Fax;
  179. m_strHomepage=pInfo->Homepage;
  180. m_strName=pInfo->Name;
  181. m_strPhone=pInfo->Phone;
  182. if(pInfo->Sex==0)m_ComboSex.SetCurSel(0);
  183. else if(pInfo->Sex==1)m_ComboSex.SetCurSel(1);
  184. int photoid=0;
  185. if(pInfo->PhotoId>=0&&pInfo->PhotoId<UINT(GetApp()->m_nNumberHeadBmp))
  186. photoid=pInfo->PhotoId;
  187. m_ComboFace.SetCurSel(photoid);
  188. UpdateData(FALSE);
  189. EndWaitCursor();
  190. KillTimer(2);
  191. return 1;
  192. }
  193. else
  194. {
  195. return 0;
  196. }
  197. }
  198. void CModifyPIDlg::OnModifypi() 
  199. {
  200. if(!GetApp()->m_bOnlineState)return;
  201. if(pInfo==NULL)return;
  202. UpdateData();
  203. CMsgChangePI msg;
  204. msg.index=CHANGE_PERSONAL_INFO;
  205. msg.MyId=GetApp()->m_uCurrentUserID;
  206. msg.tarIP=GetApp()->m_uServerIP;
  207. msg.nPort=GetApp()->m_uServerPort;
  208. if(pInfo->Address!=m_strAddress)
  209. {
  210. msg.Address=m_strAddress;
  211. msg.Mask|=CMsgChangePI::ADDRESS;
  212. }
  213. if(pInfo->Age!=m_strAge)
  214. {
  215. msg.Age=m_strAge;
  216. msg.Mask|=CMsgChangePI::AGE;
  217. }
  218. int CanbeAdd=1;
  219. if(m_canbeadd==1)CanbeAdd=2;
  220. else if(m_canbeadd==2)CanbeAdd=0;
  221. if(pInfo->CanbeAdd!=CanbeAdd)
  222. {
  223. msg.Canbeadd=CanbeAdd;
  224. msg.Mask|=CMsgChangePI::CANBEADD;
  225. }
  226. if(pInfo->Department!=m_strDepartment)
  227. {
  228. msg.Department=m_strDepartment;
  229. msg.Mask|=CMsgChangePI::DEPARTMENT;
  230. }
  231. if(pInfo->Description!=m_strDescription)
  232. {
  233. msg.Description=m_strDescription;
  234. msg.Mask|=CMsgChangePI::DESCRIPTION;
  235. }
  236. if(pInfo->Email!=m_strEmail)
  237. {
  238. msg.Email=m_strEmail;
  239. msg.Mask|=CMsgChangePI::EMAIL;
  240. }
  241. if(pInfo->Fax!=m_strFax)
  242. {
  243. msg.Fax=m_strFax;
  244. msg.Mask|=CMsgChangePI::FAX;
  245. }
  246. if(pInfo->Homepage!=m_strHomepage)
  247. {
  248. msg.Homepage=m_strHomepage;
  249. msg.Mask|=CMsgChangePI::HOMEPAGE;
  250. }
  251. if(pInfo->Name!=m_strName)
  252. {
  253. msg.Name=m_strName;
  254. msg.Mask|=CMsgChangePI::NAME;
  255. }
  256. if(pInfo->Phone!=m_strPhone)
  257. {
  258. msg.Phone=m_strPhone;
  259. msg.Mask|=CMsgChangePI::PHONE;
  260. }
  261. BYTE Sex=m_ComboSex.GetCurSel();
  262. if(Sex!=0&&Sex!=1)Sex=2;
  263. if(pInfo->Sex!=Sex)
  264. {
  265. msg.Sex=Sex;
  266. msg.Mask|=CMsgChangePI::SEX;
  267. }
  268. int photoid=m_ComboFace.GetCurSel();
  269. if(photoid>=0&&pInfo->PhotoId!=UINT(photoid))
  270. {
  271. msg.PhotoId=photoid;
  272. msg.Mask|=CMsgChangePI::PHOTOID;
  273. }
  274. if(msg.Mask==0)return;
  275. BeginWaitCursor();
  276. BOOL bCancel=FALSE;
  277. if(GetApp()->m_Socket.SendData(&msg,bCancel))
  278. {
  279. if(msg.Mask&CMsgChangePI::ADDRESS)lstrcpy(pInfo->Address,m_strAddress);
  280. if(msg.Mask&CMsgChangePI::AGE)lstrcpy(pInfo->Age,m_strAge);
  281. if(msg.Mask&CMsgChangePI::DEPARTMENT)lstrcpy(pInfo->Department,m_strDepartment);
  282. if(msg.Mask&CMsgChangePI::DESCRIPTION)lstrcpy(pInfo->Description,m_strDescription);
  283. if(msg.Mask&CMsgChangePI::EMAIL)lstrcpy(pInfo->Email,m_strEmail);
  284. if(msg.Mask&CMsgChangePI::FAX)lstrcpy(pInfo->Fax,m_strFax);
  285. if(msg.Mask&&CMsgChangePI::HOMEPAGE)lstrcpy(pInfo->Homepage,m_strHomepage);
  286. if(msg.Mask&CMsgChangePI::NAME)lstrcpy(pInfo->Name,m_strName);
  287. if(msg.Mask&CMsgChangePI::PHONE)lstrcpy(pInfo->Phone,m_strPhone);
  288. if(msg.Mask&CMsgChangePI::SEX)pInfo->Sex=msg.Sex;
  289. if(msg.Mask&CMsgChangePI::PHOTOID)pInfo->PhotoId=msg.PhotoId;
  290. if(msg.Mask&CMsgChangePI::CANBEADD)pInfo->CanbeAdd=msg.Canbeadd;
  291. EndWaitCursor();
  292. MessageBox("修改数据成功!");
  293. OnOK();
  294. }
  295. else
  296. {
  297. EndWaitCursor();
  298. MessageBox("服务器没有响应!");
  299. }
  300. }