ClientReasonChart.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  1. // ClientReasonChart.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "ClientReasonChart.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. // ClientReasonChart IDC_STATIC1
  30. IMPLEMENT_DYNCREATE(ClientReasonChart, MyFormView)
  31. ClientReasonChart::ClientReasonChart()
  32. : MyFormView(ClientReasonChart::IDD)
  33. {
  34. //{{AFX_DATA_INIT(ClientReasonChart)
  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. ClientReasonChart::~ClientReasonChart()
  44. {
  45. }
  46. void ClientReasonChart::DoDataExchange(CDataExchange* pDX)
  47. {
  48. MyFormView::DoDataExchange(pDX);
  49. //{{AFX_DATA_MAP(ClientReasonChart)
  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(ClientReasonChart, MyFormView)
  64. //{{AFX_MSG_MAP(ClientReasonChart)
  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. // ClientReasonChart diagnostics
  77. #ifdef _DEBUG
  78. void ClientReasonChart::AssertValid() const
  79. {
  80. MyFormView::AssertValid();
  81. }
  82. void ClientReasonChart::Dump(CDumpContext& dc) const
  83. {
  84. MyFormView::Dump(dc);
  85. }
  86. #endif //_DEBUG
  87. /////////////////////////////////////////////////////////////////////////////
  88. // ClientReasonChart message handlers
  89. void ClientReasonChart::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. CString version = _T("Version 1.0");
  106. m_day = AfxGetApp()->GetProfileInt(version, "rowcount3", 12);
  107. UpdateData(false);
  108. m_bInit = 1;
  109. DateChange();
  110. }
  111. void ClientReasonChart::FillGrid()
  112. {
  113. }
  114. void ClientReasonChart::OnBUTclose()
  115. {
  116. // TODO: Add your control notification handler code here
  117. GetParent()->SendMessage(WM_CLOSE);
  118. }
  119. void ClientReasonChart::OnChangeEDITyear()
  120. {
  121. // TODO: If this is a RICHEDIT control, the control will not
  122. // send this notification unless you override the MyFormView::OnInitDialog()
  123. // function and call CRichEditCtrl().SetEventMask()
  124. // with the ENM_CHANGE flag ORed into the mask.
  125. DateChange();
  126. // TODO: Add your control notification handler code here
  127. }
  128. void ClientReasonChart::OnChangeEDITmonth()
  129. {
  130. // TODO: If this is a RICHEDIT control, the control will not
  131. // send this notification unless you override the MyFormView::OnInitDialog()
  132. // function and call CRichEditCtrl().SetEventMask()
  133. // with the ENM_CHANGE flag ORed into the mask.
  134. DateChange();
  135. // TODO: Add your control notification handler code here
  136. }
  137. void ClientReasonChart::OnChangeEDITday()
  138. {
  139. // TODO: If this is a RICHEDIT control, the control will not
  140. // send this notification unless you override the MyFormView::OnInitDialog()
  141. // function and call CRichEditCtrl().SetEventMask()
  142. // with the ENM_CHANGE flag ORed into the mask.
  143. if (m_bInit == 0)return;
  144. DateChange();
  145. UpdateData();
  146. CString version = _T("Version 1.0");
  147. AfxGetApp()->WriteProfileInt(version, "rowcount3", m_day);
  148. // TODO: Add your control notification handler code here
  149. }
  150. void ClientReasonChart::DateChange()
  151. {
  152. if (m_bInit == 0)return;
  153. m_spinyear.EnableWindow(0);
  154. m_spinmonth.EnableWindow(0);
  155. m_spinday.EnableWindow(0);
  156. UpdateData();
  157. CString date1, date2;
  158. date1.Format("%d-%02d-01", m_year, m_month);
  159. date2.Format("%d-%02d-31", m_year, m_month);
  160. CString filter = "[date]>='" + date1 + "' and [date]<='" + date2 + "' and [reason]<>''";
  161. g_sendhead.code[0] = 91;
  162. g_sendhead.tabcount = 1;
  163. g_sendhead.bsql = 0;
  164. g_pMainWnd->ProcessChatMessageRequest2(filter);
  165. if (g_bSendOK == 0)
  166. {
  167. m_spinyear.EnableWindow(1);
  168. m_spinmonth.EnableWindow(1);
  169. m_spinday.EnableWindow(1);
  170. return;
  171. }
  172. DataToArray(&m_List1array);
  173. KindChange();
  174. m_spinyear.EnableWindow(1);
  175. m_spinmonth.EnableWindow(1);
  176. m_spinday.EnableWindow(1);
  177. }
  178. void ClientReasonChart::KindChange()
  179. {
  180. if (m_day < 1)return;
  181. int chartcount = m_List1array.GetSize() / m_day;
  182. if (m_List1array.GetSize() % m_day)chartcount++;
  183. for (int i = 0; i < m_pChartArray.GetSize(); i++)
  184. {
  185. CMSChart *pChart = m_pChartArray.ElementAt(i);
  186. pChart->ShowWindow(SW_HIDE);
  187. }
  188. if (chartcount == 0)
  189. return;
  190. while (m_pChartArray.GetSize() < chartcount)
  191. {
  192. CMSChart *pChart = new CMSChart;
  193. CRect rc(0, 0, 0, 0);
  194. WCHAR pwchLicenseKey[] =
  195. {
  196. 0x0038, 0x0045, 0x0031, 0x0034, 0x0037, 0x0043,
  197. 0x0036, 0x0039, 0x002D, 0x0042, 0x0044, 0x0035,
  198. 0x0030, 0x002D, 0x0031, 0x0031, 0x0064, 0x0031,
  199. 0x002D, 0x0042, 0x0031, 0x0033, 0x0037, 0x002D,
  200. 0x0030, 0x0030, 0x0030, 0x0030, 0x0046, 0x0038,
  201. 0x0037, 0x0035, 0x0033, 0x0046, 0x0035, 0x0044
  202. };
  203. BSTR bstrLicense = ::SysAllocStringLen(pwchLicenseKey,
  204. sizeof(pwchLicenseKey) / sizeof(WCHAR));
  205. pChart->Create("", WS_VISIBLE | WS_CHILD, rc, this, m_pChartArray.GetSize(), NULL, 0, bstrLicense);
  206. ::SysFreeString(bstrLicense);
  207. m_pChartArray.Add(pChart);
  208. InitChartStyle(pChart);
  209. SetChartStyle(pChart);
  210. }
  211. CRect rc;
  212. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc);
  213. ScreenToClient(rc);
  214. int hei = rc.Height() / chartcount;
  215. for (i = 0; i < chartcount; i++)
  216. {
  217. CMSChart *pChart = m_pChartArray.ElementAt(i);
  218. rc.bottom = rc.top + hei;
  219. pChart->MoveWindow(rc);
  220. pChart->ShowWindow(SW_SHOW);
  221. rc.top += hei;
  222. int nRowCount = min(m_day, m_List1array.GetSize() - i*m_day);
  223. pChart->SetRowCount(nRowCount);
  224. for (int row = 1; row <= nRowCount; ++row)
  225. {
  226. pChart->SetRow(row);
  227. pChart->SetRowLabel(m_List1array.ElementAt(i*m_day + row - 1).ElementAt(0));
  228. pChart->GetDataGrid().SetData(row, 1, atof(m_List1array.ElementAt(i*m_day + row - 1).ElementAt(1)), 0);
  229. }
  230. pChart->Refresh();
  231. }
  232. OnRadio3();
  233. }
  234. void ClientReasonChart::OnRadio3()
  235. {
  236. // TODO: Add your control notification handler code here
  237. UpdateData();
  238. if (m_radio1 == 0)
  239. {
  240. for (int i = 0; i < m_pChartArray.GetSize(); i++)
  241. {
  242. CMSChart *pChart = m_pChartArray.ElementAt(i);
  243. pChart->SetChartType(3);
  244. }
  245. }
  246. else if (m_radio1 == 1)
  247. {
  248. for (int i = 0; i < m_pChartArray.GetSize(); i++)
  249. {
  250. CMSChart *pChart = m_pChartArray.ElementAt(i);
  251. pChart->SetChartType(1);
  252. }
  253. }
  254. else if (m_radio1 == 2)
  255. {
  256. for (int i = 0; i < m_pChartArray.GetSize(); i++)
  257. {
  258. CMSChart *pChart = m_pChartArray.ElementAt(i);
  259. pChart->SetChartType(14);
  260. }
  261. }
  262. }
  263. void ClientReasonChart::OnRadio4()
  264. {
  265. // TODO: Add your control notification handler code here
  266. OnRadio3();
  267. }
  268. void ClientReasonChart::OnRadio5()
  269. {
  270. // TODO: Add your control notification handler code here
  271. OnRadio3();
  272. }
  273. void ClientReasonChart::SetChartStyle(CMSChart *pChart)
  274. {
  275. pChart->SetColumnCount(1);
  276. pChart->SetColumn(1);
  277. // pChart->SetColumnLabel((LPCTSTR)"全部");
  278. pChart->GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetBrush().GetFillColor().Set(255, 0, 0);
  279. // 线宽(对点线图有效)
  280. pChart->GetPlot().GetSeriesCollection().GetItem(1).GetPen().SetWidth(30);
  281. // 数据点类型显示数据值的模式(对柱柱状图和点线图有效)
  282. // 0: 不显示 1: 显示在柱状图外
  283. // 2: 显示在柱状图内上方 3: 显示在柱状图内中间 4: 显示在柱状图内下方
  284. pChart->GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
  285. }
  286. void ClientReasonChart::InitChartStyle(CMSChart *pChart)
  287. {
  288. VARIANT var;
  289. pChart->GetBackdrop().GetFill().SetStyle(1);
  290. pChart->GetBackdrop().GetFill().GetBrush().GetFillColor().Set(255, 255, 255);
  291. pChart->SetShowLegend(false);
  292. pChart->SetChartType(3);
  293. // 栈模式
  294. pChart->SetStacking(FALSE);
  295. pChart->GetPlot().GetAxis(1, var).GetValueScale().SetAuto(1); // 不自动标注Y轴刻度
  296. pChart->GetPlot().GetAxis(0, var).GetCategoryScale().SetAuto(0); // 不自动标注X轴刻度
  297. pChart->GetPlot().GetAxis(0, var).GetCategoryScale().SetDivisionsPerLabel(1);// 每刻度一个标注
  298. pChart->GetPlot().GetAxis(0, var).GetCategoryScale().SetDivisionsPerTick(1); // 每刻度一个刻度线
  299. }
  300. void ClientReasonChart::OnDestroy()
  301. {
  302. for (int i = 0; i < m_pChartArray.GetSize(); i++)
  303. {
  304. CMSChart *pChart = m_pChartArray.ElementAt(i);
  305. pChart->DestroyWindow();
  306. delete pChart;
  307. }
  308. m_pChartArray.RemoveAll();
  309. MyFormView::OnDestroy();
  310. }
  311. BOOL ClientReasonChart::PreTranslateMessage(MSG* pMsg)
  312. {
  313. // TODO: Add your specialized code here and/or call the base class
  314. try
  315. {
  316. if (pMsg->message == WM_KEYDOWN)
  317. {
  318. switch (pMsg->wParam)
  319. {
  320. case 0x43: // copy
  321. if ((GetKeyState(VK_CONTROL) & 0x80))
  322. {
  323. GetFocus()->SendMessage(WM_COPY);
  324. return TRUE;
  325. }
  326. break;
  327. case 0x56: //Ctrl + V:
  328. if ((GetKeyState(VK_CONTROL) & 0x80))
  329. {
  330. GetFocus()->SendMessage(WM_PASTE);
  331. return TRUE;
  332. }
  333. break;
  334. case 0x58: // cut
  335. if ((GetKeyState(VK_CONTROL) & 0x80))
  336. {
  337. GetFocus()->SendMessage(WM_CUT);
  338. return TRUE;
  339. }
  340. break;
  341. case 0x5A: //undo
  342. case 0x59: //redo
  343. if ((GetKeyState(VK_CONTROL) & 0x80))
  344. {
  345. GetFocus()->SendMessage(WM_UNDO);
  346. return TRUE;
  347. }
  348. break;
  349. }
  350. }
  351. return MyFormView::PreTranslateMessage(pMsg);
  352. }
  353. catch (...)
  354. {
  355. }
  356. }