ClientFromChart.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. // ClientFromChart.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ClientFromChart.h"
  6. #include "MyMdi.H"
  7. #include "VcPlot.h"
  8. #include "VcAxis.h"
  9. #include "VcValueScale.h"
  10. #include "VcSeriesCollection.h"
  11. #include "VcSeries.h"
  12. #include "VcPen.h"
  13. #include "VcCategoryScale.h"
  14. #include "VcColor.h"
  15. #include "VcDataGrid.h"
  16. #include "VcBackdrop.h"
  17. #include "VcFill.h"
  18. #include "VcBrush.h"
  19. #include "VcDataPoints.h"
  20. #include "VcDataPoint.h"
  21. #include "VcDataPointLabel.h"
  22. #include "VcAxisTitle.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // ClientFromChart IDC_STATIC1
  30. IMPLEMENT_DYNCREATE(ClientFromChart, MyFormView)
  31. ClientFromChart::ClientFromChart()
  32. : MyFormView(ClientFromChart::IDD)
  33. {
  34. //{{AFX_DATA_INIT(ClientFromChart)
  35. m_year = atoi(g_date.Mid(0, 4));
  36. m_month = atoi(g_date.Mid(5, 2));
  37. m_day = 12;
  38. m_radio1 = 1;
  39. m_bInit = 0;
  40. //}}AFX_DATA_INIT
  41. g_pMainWnd->GetOcx();
  42. }
  43. ClientFromChart::~ClientFromChart()
  44. {
  45. }
  46. void ClientFromChart::DoDataExchange(CDataExchange* pDX)
  47. {
  48. MyFormView::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(ClientFromChart)
  50. DDX_Control(pDX, IDC_SPIN3, m_spinday);
  51. DDX_Control(pDX, IDC_SPIN2, m_spinmonth);
  52. DDX_Control(pDX, IDC_SPIN1, m_spinyear);
  53. DDX_Control(pDX, IDC_STATIC1, m_static1);
  54. DDX_Text(pDX, IDC_EDITyear, m_year);
  55. DDV_MinMaxUInt(pDX, m_year, 1900, 3000);
  56. DDX_Text(pDX, IDC_EDITmonth, m_month);
  57. DDV_MinMaxUInt(pDX, m_month, 1, 12);
  58. DDX_Text(pDX, IDC_EDITday, m_day);
  59. DDV_MinMaxUInt(pDX, m_day, 1, 31);
  60. DDX_Radio(pDX, IDC_RADIO3, m_radio1);
  61. //}}AFX_DATA_MAP
  62. }
  63. BEGIN_MESSAGE_MAP(ClientFromChart, MyFormView)
  64. //{{AFX_MSG_MAP(ClientFromChart)
  65. ON_BN_CLICKED(IDC_BUTclose, OnBUTclose)
  66. ON_EN_CHANGE(IDC_EDITyear, OnChangeEDITyear)
  67. ON_EN_CHANGE(IDC_EDITmonth, OnChangeEDITmonth)
  68. ON_EN_CHANGE(IDC_EDITday, OnChangeEDITday)
  69. ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
  70. ON_BN_CLICKED(IDC_RADIO4, OnRadio4)
  71. ON_WM_DESTROY()
  72. ON_BN_CLICKED(IDC_RADIO5, OnRadio5)
  73. //}}AFX_MSG_MAP
  74. END_MESSAGE_MAP()
  75. /////////////////////////////////////////////////////////////////////////////
  76. // ClientFromChart diagnostics
  77. #ifdef _DEBUG
  78. void ClientFromChart::AssertValid() const
  79. {
  80. MyFormView::AssertValid();
  81. }
  82. void ClientFromChart::Dump(CDumpContext& dc) const
  83. {
  84. MyFormView::Dump(dc);
  85. }
  86. #endif //_DEBUG
  87. /////////////////////////////////////////////////////////////////////////////
  88. // ClientFromChart message handlers
  89. void ClientFromChart::OnInitialUpdate()
  90. {
  91. MyFormView::OnInitialUpdate();
  92. // TODO: Add your specialized code here and/or call the base class
  93. CMyMdi Mdi;
  94. Mdi.SetSubView((CWnd*)GetParent(), (CWnd*)this);
  95. // Here we create the outbar control using the splitter as its parent
  96. // and setting its id to the first pane.
  97. CRect rc2;
  98. GetWindowRect(rc2);
  99. ::MoveWindow(m_hWnd, g_rc.left, g_rc.top, g_rc.Width(), g_rc.Height(), TRUE);
  100. EnumChildWindows(m_hWnd, (WNDENUMPROC)EnumChildProc, 0);
  101. m_static1.SetFont(&g_titlefont);
  102. m_spinyear.SetRange(1900, 3000);
  103. m_spinmonth.SetRange(1, 12);
  104. m_spinday.SetRange(1, 31);
  105. m_day = AfxGetApp()->GetProfileInt(LYFZVERSION, "rowcount4", 12);
  106. UpdateData(false);
  107. m_bInit = 1;
  108. DateChange();
  109. }
  110. void ClientFromChart::FillGrid()
  111. {
  112. }
  113. void ClientFromChart::OnBUTclose()
  114. {
  115. // TODO: Add your control notification handler code here
  116. GetParent()->SendMessage(WM_CLOSE);
  117. }
  118. void ClientFromChart::OnChangeEDITyear()
  119. {
  120. // TODO: If this is a RICHEDIT control, the control will not
  121. // send this notification unless you override the MyFormView::OnInitDialog()
  122. // function and call CRichEditCtrl().SetEventMask()
  123. // with the ENM_CHANGE flag ORed into the mask.
  124. DateChange();
  125. // TODO: Add your control notification handler code here
  126. }
  127. void ClientFromChart::OnChangeEDITmonth()
  128. {
  129. // TODO: If this is a RICHEDIT control, the control will not
  130. // send this notification unless you override the MyFormView::OnInitDialog()
  131. // function and call CRichEditCtrl().SetEventMask()
  132. // with the ENM_CHANGE flag ORed into the mask.
  133. DateChange();
  134. // TODO: Add your control notification handler code here
  135. }
  136. void ClientFromChart::OnChangeEDITday()
  137. {
  138. // TODO: If this is a RICHEDIT control, the control will not
  139. // send this notification unless you override the MyFormView::OnInitDialog()
  140. // function and call CRichEditCtrl().SetEventMask()
  141. // with the ENM_CHANGE flag ORed into the mask.
  142. if (m_bInit == 0)return;
  143. DateChange();
  144. UpdateData();
  145. AfxGetApp()->WriteProfileInt(LYFZVERSION, "rowcount4", m_day);
  146. // TODO: Add your control notification handler code here
  147. }
  148. void ClientFromChart::DateChange()
  149. {
  150. if (m_bInit == 0)return;
  151. m_spinyear.EnableWindow(0);
  152. m_spinmonth.EnableWindow(0);
  153. m_spinday.EnableWindow(0);
  154. UpdateData();
  155. CString date1, date2;
  156. date1.Format("%d-%02d-01", m_year, m_month);
  157. date2.Format("%d-%02d-31", m_year, m_month);
  158. CString filter = "[date]>='" + date1 + "' and [date]<='" + date2 + "' and [from]<>''";
  159. g_sendhead.code[0] = 92;
  160. g_sendhead.tabcount = 1;
  161. g_sendhead.bsql = 0;
  162. g_pMainWnd->ProcessChatMessageRequest2(filter);
  163. if (g_bSendOK == 0)
  164. {
  165. m_spinyear.EnableWindow(1);
  166. m_spinmonth.EnableWindow(1);
  167. m_spinday.EnableWindow(1);
  168. return;
  169. }
  170. DataToArray(&m_List1array);
  171. KindChange();
  172. m_spinyear.EnableWindow(1);
  173. m_spinmonth.EnableWindow(1);
  174. m_spinday.EnableWindow(1);
  175. }
  176. void ClientFromChart::KindChange()
  177. {
  178. if (m_day < 1)return;
  179. int chartcount = m_List1array.GetSize() / m_day;
  180. if (m_List1array.GetSize() % m_day)chartcount++;
  181. int i = 0;
  182. for ( i = 0; i < m_pChartArray.GetSize(); i++)
  183. {
  184. CMSChart *pChart = m_pChartArray.ElementAt(i);
  185. pChart->ShowWindow(SW_HIDE);
  186. }
  187. if (chartcount == 0)
  188. return;
  189. while (m_pChartArray.GetSize() < chartcount)
  190. {
  191. CMSChart *pChart = new CMSChart;
  192. CRect rc(0, 0, 0, 0);
  193. WCHAR pwchLicenseKey[] =
  194. {
  195. 0x0038, 0x0045, 0x0031, 0x0034, 0x0037, 0x0043,
  196. 0x0036, 0x0039, 0x002D, 0x0042, 0x0044, 0x0035,
  197. 0x0030, 0x002D, 0x0031, 0x0031, 0x0064, 0x0031,
  198. 0x002D, 0x0042, 0x0031, 0x0033, 0x0037, 0x002D,
  199. 0x0030, 0x0030, 0x0030, 0x0030, 0x0046, 0x0038,
  200. 0x0037, 0x0035, 0x0033, 0x0046, 0x0035, 0x0044
  201. };
  202. BSTR bstrLicense = ::SysAllocStringLen(pwchLicenseKey,
  203. sizeof(pwchLicenseKey) / sizeof(WCHAR));
  204. pChart->Create("", WS_VISIBLE | WS_CHILD, rc, this, m_pChartArray.GetSize(), NULL, 0, bstrLicense);
  205. ::SysFreeString(bstrLicense);
  206. m_pChartArray.Add(pChart);
  207. InitChartStyle(pChart);
  208. SetChartStyle(pChart);
  209. }
  210. CRect rc;
  211. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  212. ScreenToClient(rc);
  213. int hei = rc.Height() / chartcount;
  214. for (i = 0; i < chartcount; i++)
  215. {
  216. CMSChart *pChart = m_pChartArray.ElementAt(i);
  217. rc.bottom = rc.top + hei;
  218. pChart->MoveWindow(rc);
  219. pChart->ShowWindow(SW_SHOW);
  220. rc.top += hei;
  221. int nRowCount = min(m_day, m_List1array.GetSize() - i*m_day);
  222. pChart->SetRowCount(nRowCount);
  223. for (int row = 1; row <= nRowCount; ++row)
  224. {
  225. pChart->SetRow(row);
  226. pChart->SetRowLabel(m_List1array.ElementAt(i*m_day + row - 1).ElementAt(0));
  227. pChart->GetDataGrid().SetData(row, 1, atof(m_List1array.ElementAt(i*m_day + row - 1).ElementAt(1)), 0);
  228. }
  229. pChart->Refresh();
  230. }
  231. OnRadio3();
  232. }
  233. void ClientFromChart::OnRadio3()
  234. {
  235. // TODO: Add your control notification handler code here
  236. UpdateData();
  237. if (m_radio1 == 0)
  238. {
  239. for (int i = 0; i < m_pChartArray.GetSize(); i++)
  240. {
  241. CMSChart *pChart = m_pChartArray.ElementAt(i);
  242. pChart->SetChartType(3);
  243. }
  244. }
  245. else if (m_radio1 == 1)
  246. {
  247. for (int i = 0; i < m_pChartArray.GetSize(); i++)
  248. {
  249. CMSChart *pChart = m_pChartArray.ElementAt(i);
  250. pChart->SetChartType(1);
  251. }
  252. }
  253. else if (m_radio1 == 2)
  254. {
  255. for (int i = 0; i < m_pChartArray.GetSize(); i++)
  256. {
  257. CMSChart *pChart = m_pChartArray.ElementAt(i);
  258. pChart->SetChartType(14);
  259. }
  260. }
  261. }
  262. void ClientFromChart::OnRadio4()
  263. {
  264. // TODO: Add your control notification handler code here
  265. OnRadio3();
  266. }
  267. void ClientFromChart::OnRadio5()
  268. {
  269. // TODO: Add your control notification handler code here
  270. OnRadio3();
  271. }
  272. void ClientFromChart::SetChartStyle(CMSChart *pChart)
  273. {
  274. pChart->SetColumnCount(1);
  275. pChart->SetColumn(1);
  276. // pChart->SetColumnLabel((LPCTSTR)"全部");
  277. pChart->GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetBrush().GetFillColor().Set(255, 0, 0);
  278. // 线宽(对点线图有效)
  279. pChart->GetPlot().GetSeriesCollection().GetItem(1).GetPen().SetWidth(30);
  280. // 数据点类型显示数据值的模式(对柱柱状图和点线图有效)
  281. // 0: 不显示 1: 显示在柱状图外
  282. // 2: 显示在柱状图内上方 3: 显示在柱状图内中间 4: 显示在柱状图内下方
  283. pChart->GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
  284. }
  285. void ClientFromChart::InitChartStyle(CMSChart *pChart)
  286. {
  287. VARIANT var;
  288. pChart->GetBackdrop().GetFill().SetStyle(1);
  289. pChart->GetBackdrop().GetFill().GetBrush().GetFillColor().Set(255, 255, 255);
  290. pChart->SetShowLegend(false);
  291. pChart->SetChartType(3);
  292. // 栈模式
  293. pChart->SetStacking(FALSE);
  294. pChart->GetPlot().GetAxis(1, var).GetValueScale().SetAuto(1); // 不自动标注Y轴刻度
  295. pChart->GetPlot().GetAxis(0, var).GetCategoryScale().SetAuto(0); // 不自动标注X轴刻度
  296. pChart->GetPlot().GetAxis(0, var).GetCategoryScale().SetDivisionsPerLabel(1);// 每刻度一个标注
  297. pChart->GetPlot().GetAxis(0, var).GetCategoryScale().SetDivisionsPerTick(1); // 每刻度一个刻度线
  298. }
  299. void ClientFromChart::OnDestroy()
  300. {
  301. for (int i = 0; i < m_pChartArray.GetSize(); i++)
  302. {
  303. CMSChart *pChart = m_pChartArray.ElementAt(i);
  304. pChart->DestroyWindow();
  305. delete pChart;
  306. }
  307. m_pChartArray.RemoveAll();
  308. MyFormView::OnDestroy();
  309. }
  310. BOOL ClientFromChart::PreTranslateMessage(MSG* pMsg)
  311. {
  312. // TODO: Add your specialized code here and/or call the base class
  313. try
  314. {
  315. if (pMsg->message == WM_KEYDOWN)
  316. {
  317. switch (pMsg->wParam)
  318. {
  319. case 0x43: // copy
  320. if ((GetKeyState(VK_CONTROL) & 0x80))
  321. {
  322. GetFocus()->SendMessage(WM_COPY);
  323. return TRUE;
  324. }
  325. break;
  326. case 0x56: //Ctrl + V:
  327. if ((GetKeyState(VK_CONTROL) & 0x80))
  328. {
  329. GetFocus()->SendMessage(WM_PASTE);
  330. return TRUE;
  331. }
  332. break;
  333. case 0x58: // cut
  334. if ((GetKeyState(VK_CONTROL) & 0x80))
  335. {
  336. GetFocus()->SendMessage(WM_CUT);
  337. return TRUE;
  338. }
  339. break;
  340. case 0x5A: //undo
  341. case 0x59: //redo
  342. if ((GetKeyState(VK_CONTROL) & 0x80))
  343. {
  344. GetFocus()->SendMessage(WM_UNDO);
  345. return TRUE;
  346. }
  347. break;
  348. }
  349. }
  350. return MyFormView::PreTranslateMessage(pMsg);
  351. }
  352. catch (...)
  353. {
  354. }
  355. return true;
  356. }