SendInsideMsg2.cpp 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405
  1. // SendInsideMsg2.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "SendInsideMsg2.h"
  6. #include "ShowPhoto.h"
  7. #include "SelFile.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // SendInsideMsg2 dialog messagebox
  15. SendInsideMsg2::SendInsideMsg2(CWnd* pParent /*=NULL*/)
  16. : CDialog(SendInsideMsg2::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(SendInsideMsg2)
  19. m_content = _T("");
  20. m_path = _T("");
  21. m_bShow=0;
  22. m_pArray=NULL;
  23. m_pos=0;
  24. //}}AFX_DATA_INIT
  25. }
  26. void SendInsideMsg2::DoDataExchange(CDataExchange* pDX)
  27. {
  28. CDialog::DoDataExchange(pDX);
  29. //{{AFX_DATA_MAP(SendInsideMsg2)
  30. DDX_Text(pDX, IDC_EDT_SMS, m_content);
  31. DDX_Text(pDX, IDC_EDT_RECV_MOBI, m_path);
  32. //}}AFX_DATA_MAP
  33. }
  34. BEGIN_MESSAGE_MAP(SendInsideMsg2, CDialog)
  35. //{{AFX_MSG_MAP(SendInsideMsg2)
  36. ON_BN_CLICKED(IDC_BTN_SEND, OnBtnSend)
  37. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  38. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  39. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  40. //}}AFX_MSG_MAP
  41. END_MESSAGE_MAP()
  42. /////////////////////////////////////////////////////////////////////////////
  43. // SendInsideMsg2 message handlers
  44. BOOL SendInsideMsg2::OnInitDialog()
  45. {
  46. CDialog::OnInitDialog();
  47. // TODO: Add extra initialization here
  48. if(m_bShow && m_pArray)
  49. {
  50. SetWindowText("公告详情");
  51. GetDlgItem(IDC_STATIC1)->SetWindowText("公告详情");
  52. GetDlgItem(IDC_BUTTON1)->SetWindowText("查看");
  53. GetDlgItem(IDC_BTN_SEND)->ShowWindow(SW_HIDE);
  54. if(m_pArray->GetSize ()>1)
  55. {
  56. GetDlgItem(IDC_BUTTON2)->ShowWindow(SW_SHOW);
  57. GetDlgItem(IDC_BUTTON3)->ShowWindow(SW_SHOW);
  58. }
  59. OnButton2();
  60. // CString str;
  61. // str.Format ("发布人(%s) 时间(%s) 内容:", sender, time);
  62. // GetDlgItem(IDC_STATIC2)->SetWindowText(str);
  63. }
  64. else if(m_bShow)
  65. {
  66. SetWindowText("公告详情");
  67. GetDlgItem(IDC_STATIC1)->SetWindowText("公告详情");
  68. GetDlgItem(IDC_BUTTON1)->SetWindowText("查看");
  69. GetDlgItem(IDC_BTN_SEND)->ShowWindow(SW_HIDE);
  70. CString str;
  71. str.Format ("发布人(%s) 时间(%s) 内容:", sender, time);
  72. GetDlgItem(IDC_STATIC2)->SetWindowText(str);
  73. }
  74. CenterWindow(g_pMainWnd);
  75. return TRUE; // return TRUE unless you set the focus to a control
  76. // EXCEPTION: OCX Property Pages should return FALSE
  77. }
  78. void SendInsideMsg2::OnBtnSend()
  79. {
  80. // TODO: Add your control notification handler code here
  81. UpdateData();
  82. if(m_content.IsEmpty ())
  83. {
  84. AfxMessageBox("内容不能为空!");return;
  85. }
  86. if(m_content.GetLength ()>4000)
  87. {
  88. AfxMessageBox("内容太长!");return;
  89. }
  90. CString filename,curfile,filename2;
  91. int pos=m_path.Find(";");
  92. BYTE *pData=new BYTE[1024*200*5+4000];
  93. DWORD length=0;
  94. DWORD fileleng;
  95. int filenum=0;
  96. while(pos!=-1 || m_path!="")
  97. {
  98. if(filenum>=5)
  99. { AfxMessageBox("注意:文件太多,仅保存了前5个文件!", MB_ICONINFORMATION);
  100. break;
  101. }
  102. if(pos!=-1)
  103. curfile=m_path.Left(pos);
  104. else
  105. {
  106. curfile=m_path;
  107. m_path="";
  108. }
  109. CFile fp;
  110. if(fp.Open(curfile, CFile::modeRead))
  111. {
  112. filename2=curfile.Right(curfile.GetLength()-curfile.ReverseFind('\\')-1);
  113. filename+=filename2;
  114. filename+=";";
  115. fileleng=fp.GetLength();
  116. if(fileleng>1024*200)
  117. {
  118. CString ext;
  119. if(curfile.Find(".")!=-1)
  120. ext=curfile.Right(curfile.GetLength()-curfile.ReverseFind('.')-1);
  121. ext.MakeLower ();
  122. if(!(ext=="jpg" || ext=="jpeg" || ext=="png"|| ext=="bmp"))
  123. {
  124. AfxMessageBox("文件太大,请上传小于200K的文件!");
  125. fp.Close();
  126. delete []pData;
  127. return;
  128. }
  129. else
  130. {
  131. fp.Close();
  132. Image *m_pImg=NULL;
  133. ::LoadImageFromBuf(&m_pImg, curfile);
  134. if(m_pImg==NULL)
  135. {
  136. AfxMessageBox("无效图片!");
  137. delete []pData;
  138. return;
  139. }
  140. Image *simg2=NULL;
  141. CRect rc2(0,0,1600,1600);
  142. RectFitDes(m_pImg->GetWidth(), m_pImg->GetHeight(), rc2);
  143. simg2=m_pImg->GetThumbnailImage(rc2.Width (), rc2.Height (), NULL, NULL);
  144. Graphics graphic2(simg2);//防止GetThumbnailImage影响质量
  145. graphic2.Clear(Color(255,255,255,255));
  146. graphic2.DrawImage(m_pImg, 0,0,simg2->GetWidth(), simg2->GetHeight() );
  147. if(m_pImg)delete m_pImg;m_pImg=NULL;
  148. CString path=g_mainpath+"\\1."+ext;
  149. ::SaveImageToFile2 (simg2, path, 40); delete simg2;
  150. if(!fp.Open(path, CFile::modeRead))
  151. {
  152. AfxMessageBox("文件打开失败!"); delete []pData;
  153. return;
  154. }
  155. fileleng=fp.GetLength();
  156. }
  157. }
  158. memcpy(pData+length, &fileleng, sizeof(fileleng));length+=sizeof(fileleng);
  159. fp.Read(pData+length, fileleng);length+=fileleng;
  160. fp.Close();
  161. filenum++;
  162. }
  163. else
  164. {
  165. AfxMessageBox("附件未找到!", MB_ICONINFORMATION);
  166. }
  167. if(pos!=-1)
  168. m_path=m_path.Right(m_path.GetLength()-pos-1);
  169. pos=m_path.Find(";");
  170. }
  171. filename.TrimRight(";");
  172. CString timestamp=g_date+" curtimereplace";
  173. timestamp="msgtimestamp2";
  174. CString sql="insert into insidemsg([content],[timestamp],[sender],[receiver],[file]) values('"+m_content+"','"+timestamp+"','"+g_user.name+"','','"+filename+"')";
  175. fileleng=sql.GetLength();
  176. memcpy(pData+length, &fileleng, sizeof(fileleng));
  177. DWORD nSqlPos=length;
  178. length+=sizeof(fileleng);
  179. memcpy(pData+length, sql.GetBuffer(0), fileleng); sql.ReleaseBuffer();
  180. length+=fileleng;
  181. memcpy(pData+length, &nSqlPos, sizeof(nSqlPos));length+=sizeof(nSqlPos);
  182. g_nSendCode=33;
  183. g_pMainWnd->ProcessChatMessageRequest2(pData, length);
  184. g_nSendCode=0;
  185. delete []pData;
  186. if(g_bSendOK==0)return;
  187. AfxMessageBox("公告发布成功!", MB_ICONINFORMATION);
  188. CDialog::OnOK();
  189. }
  190. void SendInsideMsg2::OnButton1()
  191. {
  192. // TODO: Add your control notification handler code here
  193. if(m_bShow)
  194. {
  195. CString m_pathtemp=m_path;
  196. CString curfile;
  197. int pos=m_path.Find(";");
  198. CStringArray patharray;
  199. while(pos!=-1 || m_path!="")
  200. {
  201. if(pos!=-1)
  202. curfile=m_path.Left(pos);
  203. else
  204. {
  205. curfile=m_path;
  206. m_path="";
  207. }
  208. CString str=g_path1+"\\公告附件\\"+curfile;patharray.Add(str);
  209. if(pos!=-1)
  210. m_path=m_path.Right(m_path.GetLength()-pos-1);
  211. pos=m_path.Find(";");
  212. }
  213. m_path=m_pathtemp;
  214. char no[20];
  215. memset(no, 0, 20);
  216. strcpy(no, time);
  217. g_nSendCode=34;
  218. g_pMainWnd->ProcessChatMessageRequest2((BYTE*)no, 20);
  219. g_nSendCode=0;
  220. if(g_bSendOK==0)
  221. {
  222. return;
  223. }
  224. DWORD nReaded=0;
  225. int filepos=0;
  226. DeleteDirectory(g_mainpath+"\\公告");
  227. ::CreateDirectory(g_mainpath+"\\公告", NULL);
  228. CStringArray patharraytemp;
  229. while(nReaded<g_nLeng)
  230. {
  231. if(filepos>=patharray.GetSize())break;
  232. CString path=patharray.ElementAt(filepos);filepos++;
  233. path=g_mainpath+"\\公告"+path.Right(path.GetLength()-path.ReverseFind('\\'));
  234. DWORD leng;
  235. memcpy(&leng, g_pData+nReaded, sizeof(DWORD));nReaded+=sizeof(DWORD);
  236. CFile fp;
  237. fp.Open(path, CFile::modeWrite|CFile::modeCreate);
  238. fp.Write(g_pData+nReaded, leng);nReaded+=leng;
  239. fp.Close();
  240. patharraytemp.Add(path);
  241. }
  242. patharray.RemoveAll();
  243. patharray.Copy(patharraytemp);
  244. ShowFile(&patharray);
  245. return;
  246. }
  247. UpdateData();
  248. CFileDialog fdlg(true, NULL,"", OFN_ALLOWMULTISELECT, "文档(*.*)|*.*||");
  249. TCHAR szBuffer[60000]={0};
  250. fdlg.m_ofn.lpstrFile = szBuffer;
  251. fdlg.m_ofn.nMaxFile = 60000;
  252. if(fdlg.DoModal ()!=IDOK)return;
  253. // m_path="";
  254. POSITION pos=fdlg.GetStartPosition ();
  255. while(pos!=NULL)
  256. {
  257. m_path+=fdlg.GetNextPathName (pos);
  258. m_path+=";";
  259. }
  260. // m_path.TrimRight(";");
  261. // m_path=fdlg.GetPathName();
  262. UpdateData(0);
  263. }
  264. void SendInsideMsg2::OnButton2()
  265. {
  266. // TODO: Add your control notification handler code here
  267. m_pos--;
  268. if(m_pos<0)m_pos=m_pArray->GetSize ()-1;
  269. sender=m_pArray->ElementAt (m_pos).ElementAt (0);
  270. m_content=m_pArray->ElementAt (m_pos).ElementAt (1);
  271. time=m_pArray->ElementAt (m_pos).ElementAt (2);
  272. m_path=m_pArray->ElementAt (m_pos).ElementAt (5);
  273. CString str;
  274. str.Format ("发布人(%s) 时间(%s) 内容:", sender, time);
  275. GetDlgItem(IDC_STATIC2)->SetWindowText(str);
  276. UpdateData(false);
  277. MarkRead();
  278. }
  279. void SendInsideMsg2::OnButton3()
  280. {
  281. // TODO: Add your control notification handler code here
  282. m_pos++;
  283. if(m_pos>=m_pArray->GetSize ())m_pos=0;
  284. sender=m_pArray->ElementAt (m_pos).ElementAt (0);
  285. m_content=m_pArray->ElementAt (m_pos).ElementAt (1);
  286. time=m_pArray->ElementAt (m_pos).ElementAt (2);
  287. m_path=m_pArray->ElementAt (m_pos).ElementAt (5);
  288. CString str;
  289. str.Format ("发布人(%s) 时间(%s) 内容:", sender, time);
  290. GetDlgItem(IDC_STATIC2)->SetWindowText(str);
  291. UpdateData(false);
  292. MarkRead();
  293. }
  294. void SendInsideMsg2::MarkRead()
  295. {
  296. CString receivers2,str;
  297. str=","+g_user.name+",";
  298. receivers2=m_pArray->ElementAt (m_pos).ElementAt (4);
  299. receivers2.TrimLeft(",");
  300. receivers2.TrimRight(",");
  301. receivers2=","+receivers2+",";
  302. if(receivers2.Find(str)==-1)
  303. {
  304. receivers2.TrimLeft(",");
  305. receivers2+=str;
  306. CString sql="update insidemsg set [receiver2]='"+receivers2+"' where [timestamp]='"+m_pArray->ElementAt (m_pos).ElementAt (2)+"' and [sender]='"+m_pArray->ElementAt (m_pos).ElementAt (0)+"'";
  307. g_sendhead.bsql=1;
  308. g_pMainWnd->ProcessChatMessageRequest2(sql);
  309. if(g_bSendOK==1)
  310. {
  311. m_pArray->ElementAt (m_pos).SetAt (4, receivers2);
  312. }
  313. }
  314. }
  315. void SendInsideMsg2::ShowFile(CStringArray *patharray)
  316. {
  317. if(patharray->GetSize()==0)return;
  318. if(patharray->GetSize()==1)
  319. {
  320. CString str=patharray->ElementAt(0);
  321. CString ext;
  322. if(str.Find(".")!=-1)
  323. ext=str.Right(str.GetLength()-str.ReverseFind('.')-1);
  324. ext.MakeLower ();
  325. if(0)//ext=="jpg" || ext=="jpeg" || ext=="png" || ext=="gif"|| ext=="bmp")
  326. {
  327. Image *m_pImg=NULL;
  328. ::LoadImageFromBuf (&m_pImg, str);
  329. if(m_pImg==NULL)
  330. {
  331. AfxMessageBox("无效图片文件!");return;
  332. }
  333. ShowPhoto dlg;
  334. dlg.m_pImg=m_pImg;
  335. dlg.DoModal();
  336. delete m_pImg;
  337. }
  338. else
  339. {
  340. ShellExecute(NULL, _T("open"), str, NULL, NULL, SW_SHOWMAXIMIZED);
  341. }
  342. return;
  343. }
  344. SelFile dlg;
  345. dlg.m_pArray=patharray;
  346. dlg.DoModal();
  347. }