Other2SaleChart.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. // Other2SaleChart.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "ylgl.h"
  5. #include "Other2SaleChart.h"
  6. #include "VcPlot.h"
  7. #include "VcAxis.h"
  8. #include "VcValueScale.h"
  9. #include "VcSeriesCollection.h"
  10. #include "VcSeries.h"
  11. #include "VcPen.h"
  12. #include "VcCategoryScale.h"
  13. #include "VcColor.h"
  14. #include "VcDataGrid.h"
  15. #include "VcBackdrop.h"
  16. #include "VcFill.h"
  17. #include "VcBrush.h"
  18. #include "VcDataPoints.h"
  19. #include "VcDataPoint.h"
  20. #include "VcDataPointLabel.h"
  21. #include "VcAxisTitle.h"
  22. #include "ShowMschart.h"
  23. #ifdef _DEBUG
  24. #define new DEBUG_NEW
  25. #undef THIS_FILE
  26. static char THIS_FILE[] = __FILE__;
  27. #endif
  28. /////////////////////////////////////////////////////////////////////////////
  29. // Other2SaleChart dialog
  30. Other2SaleChart::Other2SaleChart(CWnd* pParent /*=NULL*/)
  31. : CDialog(Other2SaleChart::IDD, pParent)
  32. {
  33. //{{AFX_DATA_INIT(Other2SaleChart)
  34. m_year = atoi(g_date.Mid(0, 4));
  35. m_bInit = 0;
  36. //}}AFX_DATA_INIT
  37. }
  38. void Other2SaleChart::DoDataExchange(CDataExchange* pDX)
  39. {
  40. CDialog::DoDataExchange(pDX);
  41. //{{AFX_DATA_MAP(Other2SaleChart)
  42. DDX_Control(pDX, IDC_LIST1, m_List1);
  43. DDX_Control(pDX, IDC_SPIN1, m_spinyear);
  44. DDX_Control(pDX, IDC_MSCHART1, m_Chart);
  45. DDX_Text(pDX, IDC_EDITyear, m_year);
  46. //}}AFX_DATA_MAP
  47. }
  48. BEGIN_MESSAGE_MAP(Other2SaleChart, CDialog)
  49. //{{AFX_MSG_MAP(Other2SaleChart)
  50. ON_EN_CHANGE(IDC_EDITyear, OnChangeEDITyear)
  51. ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
  52. //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54. /////////////////////////////////////////////////////////////////////////////
  55. // Other2SaleChart message handlers
  56. BOOL Other2SaleChart::OnInitDialog()
  57. {
  58. CDialog::OnInitDialog();
  59. // TODO: Add extra initialization here
  60. m_spinyear.SetRange(1900, 3000);
  61. VARIANT var;
  62. m_Chart.GetBackdrop().GetFill().SetStyle(1);
  63. m_Chart.GetBackdrop().GetFill().GetBrush().GetFillColor().Set(255, 255, 255);
  64. m_Chart.SetShowLegend(TRUE);
  65. m_Chart.SetChartType(1);
  66. // 栈模式
  67. m_Chart.SetStacking(FALSE);
  68. m_Chart.GetPlot().GetAxis(1, var).GetValueScale().SetAuto(1); // 不自动标注Y轴刻度
  69. m_Chart.GetPlot().GetAxis(0, var).GetCategoryScale().SetAuto(0); // 不自动标注X轴刻度
  70. m_Chart.GetPlot().GetAxis(0, var).GetCategoryScale().SetDivisionsPerLabel(1);// 每刻度一个标注
  71. m_Chart.GetPlot().GetAxis(0, var).GetCategoryScale().SetDivisionsPerTick(1); // 每刻度一个刻度线
  72. m_Chart.SetColumnCount(6);
  73. m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetBrush().GetFillColor().Set(255, 0, 0);
  74. m_Chart.GetPlot().GetSeriesCollection().GetItem(2).GetDataPoints().GetItem(-1).GetBrush().GetFillColor().Set(0, 255, 0);
  75. m_Chart.GetPlot().GetSeriesCollection().GetItem(3).GetDataPoints().GetItem(-1).GetBrush().GetFillColor().Set(0, 0, 255);
  76. m_Chart.GetPlot().GetSeriesCollection().GetItem(4).GetDataPoints().GetItem(-1).GetBrush().GetFillColor().Set(0, 255, 255);
  77. m_Chart.GetPlot().GetSeriesCollection().GetItem(5).GetDataPoints().GetItem(-1).GetBrush().GetFillColor().Set(255, 255, 0);
  78. m_Chart.GetPlot().GetSeriesCollection().GetItem(6).GetDataPoints().GetItem(-1).GetBrush().GetFillColor().Set(255, 0, 255);
  79. // 线宽(对点线图有效)
  80. m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetPen().SetWidth(30);
  81. m_Chart.GetPlot().GetSeriesCollection().GetItem(2).GetPen().SetWidth(30);
  82. m_Chart.GetPlot().GetSeriesCollection().GetItem(3).GetPen().SetWidth(30);
  83. m_Chart.GetPlot().GetSeriesCollection().GetItem(4).GetPen().SetWidth(30);
  84. m_Chart.GetPlot().GetSeriesCollection().GetItem(5).GetPen().SetWidth(30);
  85. m_Chart.GetPlot().GetSeriesCollection().GetItem(6).GetPen().SetWidth(30);
  86. // 数据点类型显示数据值的模式(对柱柱状图和点线图有效)
  87. // 0: 不显示 1: 显示在柱状图外
  88. // 2: 显示在柱状图内上方 3: 显示在柱状图内中间 4: 显示在柱状图内下方
  89. m_Chart.GetPlot().GetSeriesCollection().GetItem(1).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
  90. m_Chart.GetPlot().GetSeriesCollection().GetItem(2).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
  91. m_Chart.GetPlot().GetSeriesCollection().GetItem(3).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
  92. m_Chart.GetPlot().GetSeriesCollection().GetItem(4).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
  93. m_Chart.GetPlot().GetSeriesCollection().GetItem(5).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
  94. m_Chart.GetPlot().GetSeriesCollection().GetItem(6).GetDataPoints().GetItem(-1).GetDataPointLabel().SetLocationType(1);
  95. m_bInit = 1;
  96. GetData();
  97. MoveWindow(g_rc);
  98. CRect rc, rc2, rc3;
  99. GetClientRect(rc);
  100. GetDlgItem(IDC_EDITyear)->GetWindowRect(rc2);
  101. ScreenToClient(rc2);
  102. int top = rc2.bottom + 5;
  103. m_List1.GetWindowRect(rc2);
  104. ScreenToClient(rc2);
  105. rc2.top = top;
  106. rc2.bottom = rc.bottom;
  107. m_List1.MoveWindow(rc2);
  108. rc2.left = rc2.right;
  109. rc2.right = rc.right;
  110. m_Chart.MoveWindow(rc2);
  111. GetDlgItem(IDC_STATIC2)->GetWindowRect(rc2);
  112. ScreenToClient(rc2);
  113. int dt = rc.right - rc2.right;
  114. rc2.left += dt;
  115. rc2.right += dt;
  116. GetDlgItem(IDC_STATIC2)->MoveWindow(rc2);
  117. GetDlgItem(IDC_EDITyear)->GetWindowRect(rc2);
  118. ScreenToClient(rc2);
  119. rc2.left += dt / 2;
  120. rc2.right += dt / 2;
  121. GetDlgItem(IDC_EDITyear)->MoveWindow(rc2);
  122. GetDlgItem(IDC_STATIC1)->GetWindowRect(rc2);
  123. ScreenToClient(rc2);
  124. rc2.left += dt / 2;
  125. rc2.right += dt / 2;
  126. GetDlgItem(IDC_STATIC1)->MoveWindow(rc2);
  127. m_spinyear.GetWindowRect(rc2);
  128. ScreenToClient(rc2);
  129. rc2.left += dt / 2;
  130. rc2.right += dt / 2;
  131. m_spinyear.MoveWindow(rc2);
  132. return TRUE; // return TRUE unless you set the focus to a control
  133. // EXCEPTION: OCX Property Pages should return FALSE
  134. }
  135. void Other2SaleChart::GetData()
  136. {
  137. if (m_bInit == 0)return;
  138. m_spinyear.EnableWindow(0);
  139. UpdateData();
  140. int i;
  141. BOOL bLastYear = 0;
  142. BOOL bThisYear = 0;
  143. int g_nYearposTemp = g_nYearpos;
  144. #if JEFF_TEST_ON // 2015开始禁用跨年数据;
  145. int g_nYearposPre = -1;
  146. if (m_year >= 2014 && m_year <= atoi(g_date.Left(4)) && g_hisyeararray.GetSize())
  147. {
  148. g_nYearpos = -1;
  149. bThisYear = 1;
  150. if (m_year == 2014)
  151. {
  152. g_nYearposPre = GetYearPos(m_year - 1);
  153. }
  154. }
  155. else if (m_year <= 2013 && g_hisyeararray.GetSize())
  156. {
  157. g_nYearpos = GetYearPos(m_year);
  158. if (g_nYearpos != -1)
  159. g_nYearposPre = GetYearPos(m_year - 1);
  160. bLastYear = 1;
  161. }
  162. #else
  163. if (m_year == atoi(g_date.Left(4)) && g_hisyeararray.GetSize())
  164. bThisYear = 1;
  165. else if (m_year <= atoi(g_date.Left(4)) - 1 && g_hisyeararray.GetSize())
  166. bLastYear = 1;
  167. g_nYearpos = GetYearPos(m_year);
  168. #endif
  169. g_sendhead.bsql = 0;
  170. g_sendhead.code[0] = 198;
  171. g_sendhead.tabcount = 1;
  172. CString sql, strdate, strdate2;
  173. strdate.Format("%04d-%02d-%02d", m_year, 1, 1);
  174. strdate2.Format("%04d-%02d-%02d", m_year, 12, 31);
  175. sql.Format("date>='" + strdate + "' and date<='" + strdate2 + "'");
  176. g_pMainWnd->ProcessChatMessageRequest2(sql);
  177. if (g_bSendOK == 0)
  178. {
  179. g_nYearpos = g_nYearposTemp;
  180. m_spinyear.EnableWindow(1);
  181. return;
  182. }
  183. DataToArray(&other2salearray);
  184. if (bLastYear)//如果是去年, 则加今年的补款
  185. {
  186. g_nYearpos = -1;//今年
  187. g_sendhead.bsql = 0;
  188. g_sendhead.code[0] = 198;
  189. g_sendhead.tabcount = 1;
  190. g_pMainWnd->ProcessChatMessageRequest2(sql);
  191. if (g_bSendOK == 0)
  192. {
  193. g_nYearpos = g_nYearposTemp;
  194. m_spinyear.EnableWindow(1);
  195. return;
  196. }
  197. CArray<CStringArray, CStringArray>ThisYearother2salearray;
  198. DataToArray(&ThisYearother2salearray);
  199. int oldsize;
  200. oldsize = other2salearray.GetSize();
  201. other2salearray.SetSize(oldsize + ThisYearother2salearray.GetSize());
  202. for (i = oldsize; i < oldsize + ThisYearother2salearray.GetSize(); i++)
  203. {
  204. other2salearray.ElementAt(i).Copy(ThisYearother2salearray.ElementAt(i - oldsize));
  205. }
  206. }
  207. else if (bThisYear)//如果是今年, 则加去年的补款
  208. {
  209. g_nYearpos = 0;//去年
  210. g_sendhead.bsql = 0;
  211. g_sendhead.code[0] = 198;
  212. g_sendhead.tabcount = 1;
  213. g_pMainWnd->ProcessChatMessageRequest2(sql);
  214. if (g_bSendOK == 0)
  215. {
  216. g_nYearpos = g_nYearposTemp;
  217. m_spinyear.EnableWindow(1);
  218. return;
  219. }
  220. CArray<CStringArray, CStringArray>ThisYearother2salearray;
  221. DataToArray(&ThisYearother2salearray);
  222. int oldsize;
  223. oldsize = other2salearray.GetSize();
  224. other2salearray.SetSize(oldsize + ThisYearother2salearray.GetSize());
  225. for (i = oldsize; i < oldsize + ThisYearother2salearray.GetSize(); i++)
  226. {
  227. other2salearray.ElementAt(i).Copy(ThisYearother2salearray.ElementAt(i - oldsize));
  228. }
  229. }
  230. g_nYearpos = g_nYearposTemp;
  231. KindChange();
  232. m_spinyear.EnableWindow(1);
  233. }
  234. void Other2SaleChart::KindChange()
  235. {
  236. int i = 0;
  237. float incomedata1[12] = { 0 };
  238. float incomedata2[12] = { 0 };
  239. float incomedata3[12] = { 0 };
  240. float incomedata4[12] = { 0 };
  241. float incomedata5[12] = { 0 };
  242. float incomedata6[12] = { 0 };
  243. CString stryear[12] = { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
  244. CStringArray array;
  245. for (i = 0; i < other2salearray.GetSize(); i++)
  246. {
  247. if (::FindArray(&array, other2salearray.ElementAt(i).ElementAt(0)) == -1)
  248. array.Add(other2salearray.ElementAt(i).ElementAt(0));
  249. }
  250. for (i = 0; i < array.GetSize(); i++)
  251. {
  252. if (FindList(array.ElementAt(i)) == -1)
  253. m_List1.AddString(array.ElementAt(i));
  254. }
  255. CStringArray arraytemp;
  256. arraytemp.Copy(array);
  257. array.RemoveAll();
  258. if (m_selarray.GetSize())array.Copy(m_selarray);
  259. while (array.GetSize()>6)
  260. array.RemoveAt(array.GetSize() - 1);
  261. if (array.GetSize() < 6)
  262. {
  263. for (int i = 0; i < arraytemp.GetSize(); i++)
  264. {
  265. if (::FindArray(&array, arraytemp.ElementAt(i)) == -1)
  266. {
  267. array.Add(arraytemp.ElementAt(i));
  268. if (array.GetSize() >= 6)break;
  269. }
  270. }
  271. }
  272. m_Chart.SetColumnCount(array.GetSize());
  273. for (i = 0; i < array.GetSize(); i++)
  274. {
  275. m_Chart.SetColumn(i + 1);
  276. m_Chart.SetColumnLabel((LPCTSTR)array.ElementAt(i));
  277. }
  278. for (i = 0; i < other2salearray.GetSize(); i++)
  279. {
  280. if (array.GetSize() > 0)
  281. {
  282. if (other2salearray.ElementAt(i).ElementAt(0) == array.ElementAt(0))
  283. incomedata1[atoi(other2salearray.ElementAt(i).ElementAt(5).Mid(5, 2)) - 1] += atof(other2salearray.ElementAt(i).ElementAt(4));
  284. }
  285. if (array.GetSize() > 1)
  286. {
  287. if (other2salearray.ElementAt(i).ElementAt(0) == array.ElementAt(1))
  288. incomedata2[atoi(other2salearray.ElementAt(i).ElementAt(5).Mid(5, 2)) - 1] += atof(other2salearray.ElementAt(i).ElementAt(4));
  289. }
  290. if (array.GetSize() > 2)
  291. {
  292. if (other2salearray.ElementAt(i).ElementAt(0) == array.ElementAt(2))
  293. incomedata3[atoi(other2salearray.ElementAt(i).ElementAt(5).Mid(5, 2)) - 1] += atof(other2salearray.ElementAt(i).ElementAt(4));
  294. }
  295. if (array.GetSize() > 3)
  296. {
  297. if (other2salearray.ElementAt(i).ElementAt(0) == array.ElementAt(3))
  298. incomedata4[atoi(other2salearray.ElementAt(i).ElementAt(5).Mid(5, 2)) - 1] += atof(other2salearray.ElementAt(i).ElementAt(4));
  299. }
  300. if (array.GetSize() > 4)
  301. {
  302. if (other2salearray.ElementAt(i).ElementAt(0) == array.ElementAt(4))
  303. incomedata5[atoi(other2salearray.ElementAt(i).ElementAt(5).Mid(5, 2)) - 1] += atof(other2salearray.ElementAt(i).ElementAt(4));
  304. }
  305. if (array.GetSize() > 5)
  306. {
  307. if (other2salearray.ElementAt(i).ElementAt(0) == array.ElementAt(5))
  308. incomedata6[atoi(other2salearray.ElementAt(i).ElementAt(5).Mid(5, 2)) - 1] += atof(other2salearray.ElementAt(i).ElementAt(4));
  309. }
  310. }
  311. int nRowCount = 12;// VARIANT var;
  312. m_Chart.SetRowCount(nRowCount);
  313. for (int row = 1; row <= nRowCount; ++row)
  314. {
  315. m_Chart.SetRow(row);
  316. m_Chart.SetRowLabel(stryear[row - 1]);
  317. if (array.GetSize() > 0)
  318. m_Chart.GetDataGrid().SetData(row, 1, incomedata1[row - 1], 0);
  319. if (array.GetSize() > 1)
  320. m_Chart.GetDataGrid().SetData(row, 2, incomedata2[row - 1], 0);
  321. if (array.GetSize() > 2)
  322. m_Chart.GetDataGrid().SetData(row, 3, incomedata3[row - 1], 0);
  323. if (array.GetSize() > 3)
  324. m_Chart.GetDataGrid().SetData(row, 4, incomedata4[row - 1], 0);
  325. if (array.GetSize() > 4)
  326. m_Chart.GetDataGrid().SetData(row, 5, incomedata5[row - 1], 0);
  327. if (array.GetSize() > 5)
  328. m_Chart.GetDataGrid().SetData(row, 6, incomedata6[row - 1], 0);
  329. }
  330. m_Chart.Refresh();
  331. }
  332. void Other2SaleChart::OnChangeEDITyear()
  333. {
  334. // TODO: If this is a RICHEDIT control, the control will not
  335. // send this notification unless you override the CDialog::OnInitDialog()
  336. // function and call CRichEditCtrl().SetEventMask()
  337. // with the ENM_CHANGE flag ORed into the mask.
  338. GetData();
  339. // TODO: Add your control notification handler code here
  340. }
  341. void Other2SaleChart::OnSelchangeList1()
  342. {
  343. // TODO: Add your control notification handler code here
  344. UpdateData();
  345. int count = m_List1.GetSelCount();
  346. if (count == 0)return;
  347. m_selarray.RemoveAll();
  348. int *pIndex = new int[count];
  349. m_List1.GetSelItems(count, pIndex);
  350. CString str;
  351. for (int i = 0; i < count; i++)
  352. {
  353. m_List1.GetText(pIndex[i], str);
  354. m_selarray.Add(str);
  355. }
  356. delete[]pIndex;
  357. KindChange();
  358. }
  359. int Other2SaleChart::FindList(CString str)
  360. {
  361. CString temp;
  362. for (int i = 0; i < m_List1.GetCount(); i++)
  363. {
  364. m_List1.GetText(i, temp);
  365. if (str == temp)return i;
  366. }
  367. return -1;
  368. }
  369. BEGIN_EVENTSINK_MAP(Other2SaleChart, CDialog)
  370. //{{AFX_EVENTSINK_MAP(Other2SaleChart)
  371. ON_EVENT(Other2SaleChart, IDC_MSCHART1, -601 /* DblClick */, OnDblClickMschart1, VTS_NONE)
  372. //}}AFX_EVENTSINK_MAP
  373. END_EVENTSINK_MAP()
  374. extern BOOL g_bShowMsChart;
  375. extern HWND g_hShowChartWnd;
  376. void Other2SaleChart::OnDblClickMschart1()
  377. {
  378. // TODO: Add your control notification handler code here
  379. if (g_bShowMsChart)
  380. {
  381. ::SendMessage(g_hShowChartWnd, WM_CLOSE, 0, 0);
  382. return;
  383. }
  384. g_bShowMsChart = 1;
  385. CRect rc;
  386. m_Chart.GetWindowRect(rc);
  387. ScreenToClient(rc);
  388. ShowMschart dlg;
  389. dlg.m_pParent = this;
  390. dlg.m_pChart = &m_Chart;
  391. dlg.DoModal();
  392. m_Chart.MoveWindow(rc);
  393. g_bShowMsChart = 0;
  394. }