Other2SaleChart.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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. int g_nYearposTemp=g_nYearpos;
  142. BOOL bLastYear=0;
  143. BOOL bThisYear=0;
  144. if(m_year==atoi(g_date.Left (4)) && g_hisyeararray.GetSize () )
  145. bThisYear=1;
  146. else if(m_year<=atoi(g_date.Left (4))-1 && g_hisyeararray.GetSize ())
  147. bLastYear=1;
  148. g_nYearpos=GetYearPos(m_year);
  149. g_sendhead.bsql=0;
  150. g_sendhead.code[0]=198;
  151. g_sendhead.tabcount=1;
  152. CString sql,strdate,strdate2;
  153. strdate.Format ("%04d-%02d-%02d", m_year, 1, 1);
  154. strdate2.Format ("%04d-%02d-%02d", m_year, 12, 31);
  155. sql.Format ("date>='"+strdate+"' and date<='"+strdate2+"'");
  156. g_pMainWnd->ProcessChatMessageRequest2(sql);
  157. if(g_bSendOK==0)
  158. {
  159. g_nYearpos=g_nYearposTemp;
  160. m_spinyear.EnableWindow(1);
  161. return;
  162. }
  163. DataToArray(&other2salearray);
  164. if(bLastYear)//如果是去年, 则加今年的补款
  165. {
  166. g_nYearpos=-1;//今年
  167. g_sendhead.bsql=0;
  168. g_sendhead.code[0]=198;
  169. g_sendhead.tabcount=1;
  170. g_pMainWnd->ProcessChatMessageRequest2(sql);
  171. if(g_bSendOK==0)
  172. {
  173. g_nYearpos=g_nYearposTemp;
  174. m_spinyear.EnableWindow(1);
  175. return;
  176. }
  177. CArray<CStringArray, CStringArray>ThisYearother2salearray;
  178. DataToArray(&ThisYearother2salearray);
  179. int oldsize;
  180. oldsize=other2salearray.GetSize ();
  181. other2salearray.SetSize(oldsize+ThisYearother2salearray.GetSize ());
  182. for(i=oldsize; i<oldsize+ThisYearother2salearray.GetSize (); i++)
  183. {
  184. other2salearray.ElementAt (i).Copy(ThisYearother2salearray.ElementAt (i-oldsize));
  185. }
  186. }
  187. else if(bThisYear)//如果是今年, 则加去年的补款
  188. {
  189. g_nYearpos=0;//去年
  190. g_sendhead.bsql=0;
  191. g_sendhead.code[0]=198;
  192. g_sendhead.tabcount=1;
  193. g_pMainWnd->ProcessChatMessageRequest2(sql);
  194. if(g_bSendOK==0)
  195. {
  196. g_nYearpos=g_nYearposTemp;
  197. m_spinyear.EnableWindow(1);
  198. return;
  199. }
  200. CArray<CStringArray, CStringArray>ThisYearother2salearray;
  201. DataToArray(&ThisYearother2salearray);
  202. int oldsize;
  203. oldsize=other2salearray.GetSize ();
  204. other2salearray.SetSize(oldsize+ThisYearother2salearray.GetSize ());
  205. for(i=oldsize; i<oldsize+ThisYearother2salearray.GetSize (); i++)
  206. {
  207. other2salearray.ElementAt (i).Copy(ThisYearother2salearray.ElementAt (i-oldsize));
  208. }
  209. }
  210. g_nYearpos=g_nYearposTemp;
  211. KindChange();
  212. m_spinyear.EnableWindow(1);
  213. }
  214. void Other2SaleChart::KindChange()
  215. {
  216. int i=0;
  217. float incomedata1[12]={0};
  218. float incomedata2[12]={0};
  219. float incomedata3[12]={0};
  220. float incomedata4[12]={0};
  221. float incomedata5[12]={0};
  222. float incomedata6[12]={0};
  223. CString stryear[12]={"1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月"};
  224. CStringArray array;
  225. for( i=0; i<other2salearray.GetSize (); i++)
  226. {
  227. if(::FindArray (&array, other2salearray.ElementAt (i).ElementAt (0))==-1)
  228. array.Add (other2salearray.ElementAt (i).ElementAt (0));
  229. }
  230. for(i=0; i<array.GetSize (); i++)
  231. {
  232. if(FindList(array.ElementAt (i))==-1)
  233. m_List1.AddString (array.ElementAt (i));
  234. }
  235. CStringArray arraytemp;
  236. arraytemp.Copy (array);
  237. array.RemoveAll ();
  238. if(m_selarray.GetSize ())array.Copy (m_selarray);
  239. while(array.GetSize ()>6)
  240. array.RemoveAt (array.GetSize ()-1);
  241. if(array.GetSize ()<6)
  242. {
  243. for(int i=0; i<arraytemp.GetSize (); i++)
  244. {
  245. if(::FindArray (&array, arraytemp.ElementAt (i))==-1)
  246. {
  247. array.Add (arraytemp.ElementAt (i));
  248. if(array.GetSize ()>=6)break;
  249. }
  250. }
  251. }
  252. m_Chart.SetColumnCount(array.GetSize ());
  253. for(i=0; i<array.GetSize (); i++)
  254. {
  255. m_Chart.SetColumn(i+1);
  256. m_Chart.SetColumnLabel((LPCTSTR)array.ElementAt (i));
  257. }
  258. for( i=0; i<other2salearray.GetSize (); i++)
  259. {
  260. if(array.GetSize ()>0)
  261. {
  262. if(other2salearray.ElementAt (i).ElementAt (0)==array.ElementAt (0))
  263. incomedata1[atoi(other2salearray.ElementAt (i).ElementAt (5).Mid (5, 2))-1]+=atof(other2salearray.ElementAt (i).ElementAt (4));
  264. }
  265. if(array.GetSize ()>1)
  266. {
  267. if(other2salearray.ElementAt (i).ElementAt (0)==array.ElementAt (1))
  268. incomedata2[atoi(other2salearray.ElementAt (i).ElementAt (5).Mid (5, 2))-1]+=atof(other2salearray.ElementAt (i).ElementAt (4));
  269. }
  270. if(array.GetSize ()>2)
  271. {
  272. if(other2salearray.ElementAt (i).ElementAt (0)==array.ElementAt (2))
  273. incomedata3[atoi(other2salearray.ElementAt (i).ElementAt (5).Mid (5, 2))-1]+=atof(other2salearray.ElementAt (i).ElementAt (4));
  274. }
  275. if(array.GetSize ()>3)
  276. {
  277. if(other2salearray.ElementAt (i).ElementAt (0)==array.ElementAt (3))
  278. incomedata4[atoi(other2salearray.ElementAt (i).ElementAt (5).Mid (5, 2))-1]+=atof(other2salearray.ElementAt (i).ElementAt (4));
  279. }
  280. if(array.GetSize ()>4)
  281. {
  282. if(other2salearray.ElementAt (i).ElementAt (0)==array.ElementAt (4))
  283. incomedata5[atoi(other2salearray.ElementAt (i).ElementAt (5).Mid (5, 2))-1]+=atof(other2salearray.ElementAt (i).ElementAt (4));
  284. }
  285. if(array.GetSize ()>5)
  286. {
  287. if(other2salearray.ElementAt (i).ElementAt (0)==array.ElementAt (5))
  288. incomedata6[atoi(other2salearray.ElementAt (i).ElementAt (5).Mid (5, 2))-1]+=atof(other2salearray.ElementAt (i).ElementAt (4));
  289. }
  290. }
  291. int nRowCount=12;// VARIANT var;
  292. m_Chart.SetRowCount(nRowCount);
  293. float ftemp;
  294. for(int row = 1; row <= nRowCount; ++row)
  295. {
  296. m_Chart.SetRow(row);
  297. m_Chart.SetRowLabel(stryear[row-1]);
  298. if(array.GetSize ()>0)
  299. m_Chart.GetDataGrid().SetData(row, 1, incomedata1[row-1], 0);
  300. if(array.GetSize ()>1)
  301. m_Chart.GetDataGrid().SetData(row, 2, incomedata2[row-1], 0);
  302. if(array.GetSize ()>2)
  303. m_Chart.GetDataGrid().SetData(row, 3, incomedata3[row-1], 0);
  304. if(array.GetSize ()>3)
  305. m_Chart.GetDataGrid().SetData(row, 4, incomedata4[row-1], 0);
  306. if(array.GetSize ()>4)
  307. m_Chart.GetDataGrid().SetData(row, 5, incomedata5[row-1], 0);
  308. if(array.GetSize ()>5)
  309. m_Chart.GetDataGrid().SetData(row, 6, incomedata6[row-1], 0);
  310. }
  311. m_Chart.Refresh();
  312. }
  313. void Other2SaleChart::OnChangeEDITyear()
  314. {
  315. // TODO: If this is a RICHEDIT control, the control will not
  316. // send this notification unless you override the CDialog::OnInitDialog()
  317. // function and call CRichEditCtrl().SetEventMask()
  318. // with the ENM_CHANGE flag ORed into the mask.
  319. GetData();
  320. // TODO: Add your control notification handler code here
  321. }
  322. void Other2SaleChart::OnSelchangeList1()
  323. {
  324. // TODO: Add your control notification handler code here
  325. UpdateData();
  326. int count= m_List1.GetSelCount() ;
  327. if(count==0)return;
  328. m_selarray.RemoveAll ();
  329. int *pIndex=new int[count];
  330. m_List1.GetSelItems(count, pIndex);
  331. CString str;
  332. for(int i=0; i<count; i++)
  333. {
  334. m_List1.GetText (pIndex[i], str);
  335. m_selarray.Add (str);
  336. }
  337. delete []pIndex;
  338. KindChange();
  339. }
  340. int Other2SaleChart::FindList(CString str)
  341. {
  342. CString temp;
  343. for(int i=0; i<m_List1.GetCount (); i++)
  344. {
  345. m_List1.GetText (i, temp);
  346. if(str==temp)return i;
  347. }
  348. return -1;
  349. }
  350. BEGIN_EVENTSINK_MAP(Other2SaleChart, CDialog)
  351. //{{AFX_EVENTSINK_MAP(Other2SaleChart)
  352. ON_EVENT(Other2SaleChart, IDC_MSCHART1, -601 /* DblClick */, OnDblClickMschart1, VTS_NONE)
  353. //}}AFX_EVENTSINK_MAP
  354. END_EVENTSINK_MAP()
  355. extern BOOL g_bShowMsChart;
  356. extern HWND g_hShowChartWnd;
  357. void Other2SaleChart::OnDblClickMschart1()
  358. {
  359. // TODO: Add your control notification handler code here
  360. if(g_bShowMsChart)
  361. {
  362. ::SendMessage (g_hShowChartWnd, WM_CLOSE, 0, 0);
  363. return;
  364. }
  365. g_bShowMsChart=1;
  366. CRect rc;
  367. m_Chart.GetWindowRect (rc);
  368. ScreenToClient(rc);
  369. ShowMschart dlg;
  370. dlg.m_pParent =this;
  371. dlg.m_pChart=&m_Chart;
  372. dlg.DoModal ();
  373. m_Chart.MoveWindow (rc);
  374. g_bShowMsChart=0;
  375. }