frmDDTJChart.cs 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Windows.Forms.DataVisualization.Charting;
  10. using CoreFS.CA06;
  11. using Core.Mes.Client.Comm.Server;
  12. using Core.Mes.Client.Comm.Control;
  13. using Core.Mes.Client.Comm.Tool;
  14. using Infragistics.Win.UltraWinGrid;
  15. using Infragistics.Win;
  16. using Infragistics.Win.UltraWinDataSource;
  17. namespace Core.StlMes.Client.BuyBillet
  18. {
  19. public partial class frmDDTJChart : FrmBase
  20. {
  21. private int angle = 0;
  22. private int angle1 = 0;
  23. private int colorsIndex = 0;
  24. private DataTable dtNew;
  25. //ctrl shift 键被按下
  26. private bool ctrlKeyDown;
  27. private bool shiftKeyDown;
  28. //自定义图颜色
  29. private Color[] chartColors;
  30. //当前活动 chart
  31. private Chart chartActive;
  32. public frmDDTJChart()
  33. {
  34. InitializeComponent();
  35. }
  36. private void Initial_ChartColors()
  37. {
  38. chartColors = new Color[] {
  39. Color.FromArgb(0,112,192), //蓝色 预留给作业时间
  40. Color.FromArgb(255,0,0), //橙红 预留给作业率
  41. Color.FromArgb(134,164,74),//橄榄色 预留给 停机时间
  42. Color.FromArgb(227,160,93),
  43. Color.FromArgb(178,90,126),
  44. Color.FromArgb(113,175,164),
  45. Color.FromArgb(3,54,73),
  46. Color.FromArgb(89,69,61),
  47. Color.FromArgb(1,77,103),
  48. Color.FromArgb(91,74,66),
  49. Color.FromArgb(90,13,67),
  50. Color.FromArgb(87,96,105),
  51. Color.FromArgb(147,224,255),
  52. Color.FromArgb(250,227,113),
  53. Color.FromArgb(107,194,53),
  54. Color.FromArgb(205,164,158),
  55. Color.FromArgb(23,44,60),
  56. Color.FromArgb(87,105,60),
  57. Color.FromArgb(28,120,135),
  58. Color.FromArgb(131,175,155),
  59. Color.FromArgb(192,0,0), //深红 预留给作业率
  60. Color.FromArgb(247,150,70),//橙色
  61. Color.FromArgb(165,151,185),//淡紫
  62. Color.FromArgb(206,142,141),//玫瑰红
  63. Color.FromArgb(142,165,203),//冰蓝
  64. Color.FromArgb(181,202,146),//浅绿
  65. Color.FromArgb(112,48,160),//紫色
  66. Color.FromArgb(61,150,174) //水绿色
  67. };
  68. }
  69. private void Hide_Dept()
  70. {
  71. foreach (var row in ucb1.DisplayLayout.Rows)
  72. {
  73. if (row.Cells["plinecode"].Value.ToString() == "-1")
  74. {
  75. row.Hidden = true;
  76. break;
  77. }
  78. }
  79. }
  80. private void frmDDTJChart_Load(object sender, EventArgs e)
  81. {
  82. initial_UltraDataSource1();
  83. this.ctrlKeyDown = false;
  84. this.shiftKeyDown = false;
  85. Initial_ChartColors();
  86. //chart 绑定鼠标滚轮缩放事件
  87. Chart1.MouseWheel += Chart_MouseWheel;
  88. Chart2.MouseWheel += Chart_MouseWheel;
  89. Chart3.MouseWheel += Chart_MouseWheel;
  90. //chart1、2、3 鼠标进入时事件注册
  91. Chart1.MouseEnter += Chart_MouseEnter;
  92. Chart2.MouseEnter += Chart_MouseEnter;
  93. Chart3.MouseEnter += Chart_MouseEnter;
  94. //this.KeyDown += frmDDTJChart_KeyDown;
  95. //this.KeyUp += frmDDTJChart_KeyUp;
  96. this.panel1.MouseWheel += panel1_MouseWheel;
  97. //Chart1、2、3 注册 键盘事件
  98. Chart1.KeyUp +=Chart_KeyUp;
  99. Chart1.KeyDown +=Chart_KeyDown;
  100. Chart2.KeyUp += Chart_KeyUp;
  101. Chart2.KeyDown += Chart_KeyDown;
  102. Chart3.KeyUp += Chart_KeyUp;
  103. Chart3.KeyDown += Chart_KeyDown;
  104. Hide_Dept();
  105. //隐藏图控件,当有数据时显示
  106. Chart_Hide_Show(false);
  107. this.startDate.Value = this.endDate.Value.AddMonths(-1);
  108. //ucb1.DisplayLayout.Bands[0].Columns["dept"].Width = 135;
  109. //ucb1.DisplayLayout.Bands[0].Columns["plinename1"].Width = 50;
  110. //ucb1.DisplayLayout.Bands[0].Columns["plinename2"].Width = 70;
  111. ucb1.DisplayLayout.Bands[0].Columns["dept"].Width = 200;
  112. ucb1.DisplayLayout.Bands[0].Columns["plinename1"].Width = 100;
  113. ucb1.DisplayLayout.Bands[0].Columns["plinename2"].Width = 100;
  114. ucb1.DisplayLayout.Bands[0].Columns["dept"].CellAppearance.TextHAlign = HAlign.Center;
  115. ucb1.DisplayLayout.Bands[0].Columns["plinename1"].CellAppearance.TextHAlign = HAlign.Center;
  116. ucb1.DisplayLayout.Bands[0].Columns["plinename2"].CellAppearance.TextHAlign = HAlign.Center;
  117. ucb1.DisplayLayout.Bands[0].Columns["dept"].CellAppearance.TextVAlign = VAlign.Middle;
  118. ucb1.DisplayLayout.Bands[0].Columns["plinename1"].CellAppearance.TextVAlign = VAlign.Middle;
  119. ucb1.DisplayLayout.Bands[0].Columns["plinename2"].CellAppearance.TextVAlign = VAlign.Middle;
  120. ucb1.DisplayLayout.Bands[0].Columns["dept"].CellAppearance.BackColor = Color.Wheat;
  121. ucb1.DisplayLayout.Bands[0].Columns["plinename1"].CellAppearance.BackColor = Color.YellowGreen;
  122. ucb1.DisplayLayout.Bands[0].Columns["plinename2"].CellAppearance.BackColor = Color.SkyBlue;
  123. ucb1.Width = 273;
  124. //以下设置图控件初始大小
  125. this.Chart1.Width = Convert.ToInt32(Math.Ceiling(this.Width * 0.8))>900?Convert.ToInt32(Math.Ceiling(this.Width * 0.8)):900;
  126. this.Chart2.Width = this.Width - this.Chart1.Width > 900 ? this.Width - this.Chart1.Width : 900;
  127. this.Chart3.Width = this.Chart2.Width-200;
  128. UltraGridBand band = this.ucb1.DisplayLayout.Bands[0];
  129. foreach (UltraGridRow row in band.GetRowEnumerator(GridRowType.DataRow))
  130. {
  131. if (row.Cells["dept"].Value.ToString().Contains("全部"))
  132. {
  133. row.Cells["dept"].Appearance.FontData.Bold = DefaultableBoolean.True;
  134. }
  135. if (row.Cells["plinename2"].Value.ToString().Contains("全部"))
  136. {
  137. row.Cells["plinename2"].Appearance.FontData.Bold = DefaultableBoolean.True;
  138. }
  139. }
  140. }
  141. void panel1_MouseWheel(object sender, MouseEventArgs e)
  142. {
  143. HandledMouseEventArgs h = e as HandledMouseEventArgs;
  144. if (h != null)
  145. {
  146. h.Handled = false;
  147. }
  148. }
  149. void frmDDTJChart_KeyUp(object sender, KeyEventArgs e)
  150. {
  151. this.ctrlKeyDown = e.Control;
  152. this.shiftKeyDown = e.Shift;
  153. }
  154. void frmDDTJChart_KeyDown(object sender, KeyEventArgs e)
  155. {
  156. this.ctrlKeyDown = e.Control;
  157. this.shiftKeyDown = e.Shift;
  158. }
  159. void Chart_MouseWheel(object sender, MouseEventArgs e)
  160. {
  161. //var chart = (Chart)sender;
  162. //var xAxis = chart.ChartAreas[0].AxisX;
  163. //var yAxis = chart.ChartAreas[0].AxisY;
  164. //try
  165. //{
  166. // if (e.Delta < 0) // Scrolled down.
  167. // {
  168. // //xAxis.ScaleView.ZoomReset();
  169. // //yAxis.ScaleView.ZoomReset();
  170. // Chart1.Width -= 20;
  171. // }
  172. // else if (e.Delta > 0) // Scrolled up.
  173. // {
  174. // //var xMin = xAxis.ScaleView.ViewMinimum;
  175. // //var xMax = xAxis.ScaleView.ViewMaximum;
  176. // //var yMin = yAxis.ScaleView.ViewMinimum;
  177. // //var yMax = yAxis.ScaleView.ViewMaximum;
  178. // //var posXStart = xAxis.PixelPositionToValue(e.Location.X) - (xMax - xMin) / 4;
  179. // //var posXFinish = xAxis.PixelPositionToValue(e.Location.X) + (xMax - xMin) / 4;
  180. // //var posYStart = yAxis.PixelPositionToValue(e.Location.Y) - (yMax - yMin) / 4;
  181. // //var posYFinish = yAxis.PixelPositionToValue(e.Location.Y) + (yMax - yMin) / 4;
  182. // //xAxis.ScaleView.Zoom(posXStart, posXFinish);
  183. // //yAxis.ScaleView.Zoom(posYStart, posYFinish);
  184. // Chart1.Width += 20;
  185. // }
  186. //}
  187. //catch { }
  188. Chart chart = sender as Chart;
  189. HandledMouseEventArgs h = e as HandledMouseEventArgs;
  190. if (h != null)
  191. {
  192. h.Handled = true;
  193. }
  194. bool IsGoUp = e.Delta > 0 ? true : false;
  195. if (this.ctrlKeyDown)
  196. {
  197. if (chart != null)
  198. {
  199. if (IsGoUp)
  200. {
  201. chartActive.Width += 20;
  202. }
  203. if (!IsGoUp)
  204. {
  205. chartActive.Width -= 20;
  206. }
  207. }
  208. }
  209. else if (this.shiftKeyDown)
  210. {
  211. //int hStep = (int)(this.pictureBox2.Image.Width * 0.02);
  212. //int vStep = (int)(this.pictureBox2.Image.Height * 0.02);
  213. if (IsGoUp)
  214. {
  215. //this.pictureBox2.Width += hStep;
  216. //this.pictureBox2.Height += vStep;
  217. }
  218. else
  219. {
  220. //this.pictureBox2.Width -= hStep;
  221. //this.pictureBox2.Height -= vStep;
  222. }
  223. }
  224. else
  225. {
  226. //if (IsGoUp && this.panel1.VerticalScroll.Value > 5)
  227. //{
  228. // this.panel1.VerticalScroll.Value -= 5;
  229. //}
  230. //if (!IsGoUp && this.panel1.VerticalScroll.Value < this.panel1.VerticalScroll.Maximum - 5)
  231. //{
  232. // this.panel1.VerticalScroll.Value += 5;
  233. //}
  234. }
  235. }
  236. //显示或隐藏图控件
  237. private void Chart_Hide_Show(bool flag)
  238. {
  239. if (flag)
  240. {
  241. this.Chart1.Show();
  242. this.Chart2.Show();
  243. this.Chart3.Show();
  244. }
  245. else
  246. {
  247. this.Chart1.Hide();
  248. this.Chart2.Hide();
  249. this.Chart3.Hide();
  250. }
  251. }
  252. public override void ToolBar_Click(object sender, string ToolbarKey)
  253. {
  254. base.ToolBar_Click(sender, ToolbarKey);
  255. switch (ToolbarKey)
  256. {
  257. case "Query":
  258. Query();
  259. break;
  260. case "Close":
  261. this.Close();
  262. break;
  263. }
  264. }
  265. private void Query()
  266. {
  267. string plinecode = ucb1.Value==null?string.Empty:ucb1.Value.ToString();
  268. if(string.IsNullOrEmpty(plinecode)){
  269. MessageUtil.ShowTips("请选择机组产线!");
  270. return;
  271. }
  272. int flag = DateTime.Compare(this.startDate.Value, this.endDate.Value);
  273. string startDate = this.startDate.Value.ToString("yyyyMMdd");
  274. string endDate = this.endDate.Value.ToString("yyyyMMdd");
  275. if (Convert.ToInt32(startDate) > Convert.ToInt32(endDate))
  276. {
  277. MessageUtil.ShowWarning("起始日期不能大于截止日期!");
  278. return;
  279. }
  280. int days = DateDiff(this.startDate.Value.AddDays(-1), this.endDate.Value);
  281. startDate = this.startDate.Value.AddDays(-1).ToString("yyyyMMdd");
  282. DataTable dt = ServerHelper.GetData("com.steering.pss.buybillet.Buybillet.get_FrmddTJChart_data", new object[] { startDate, endDate, days.ToString(), plinecode }, this.ob);
  283. //dt.Columns["optime"].DataType = Type.GetType("System.Decimal");
  284. dtNew = dt.Clone();  //复制baidt表数据结构
  285. dtNew.Columns["optime"].DataType = Type.GetType("System.Decimal");
  286. for (int i = 0; i < dt.Rows.Count; i++)
  287. {
  288. dtNew.Rows.Add(dt.Rows[i].ItemArray);  //添加数du据行
  289. }
  290. if (dtNew != null && dtNew.Rows.Count > 0)
  291. {
  292. Build_Chart(dtNew);
  293. Build_ChartPie1(dtNew);
  294. Build_ChartPie2(dtNew);
  295. Chart_Hide_Show(true);
  296. index = 0;
  297. colorsIndex = 3;
  298. timer1.Enabled = false;
  299. //Chart1.Width = 1000;
  300. //Chart1.Width = 800;
  301. }
  302. else
  303. {
  304. MessageUtil.ShowTips("未查询到相关数据!");
  305. }
  306. }
  307. private void Chart_Initial(Chart chart)
  308. {
  309. if (chart.Series.Count > 0)
  310. {
  311. chart.Series.Clear();
  312. }
  313. if (chart.Titles.Count > 0)
  314. {
  315. chart.Titles.Clear();
  316. }
  317. //以下是图例属性的设置
  318. chart.Legends[0].Enabled = true; //是否显示图例
  319. //Chart1.Legends[0].Position.Auto = true;
  320. chart.Legends[0].Docking = Docking.Bottom; //Docking是图例的停靠位置
  321. chart.Legends[0].Alignment = StringAlignment.Center;//Alignment属性是图例的对齐方式
  322. //设置控件背景、图区域、图例的背景色为透明 同产销Form一致
  323. chart.BackColor = Color.Transparent;
  324. chart.ChartAreas[0].BackColor = Color.Transparent;
  325. chart.Legends[0].BackColor = Color.Transparent;
  326. //if (chart.Name == "Chart1")
  327. //{
  328. // chart.Width = 800;
  329. //}
  330. //if (chart.Name == "Chart2")
  331. //{
  332. // chart.Width = 600;
  333. //}
  334. }
  335. //以下代码生成左侧柱状曲线图
  336. private void Build_Chart(DataTable dt)
  337. {
  338. //初始化图控件,设置公共属性
  339. Chart_Initial(Chart1);
  340. //if (Chart1.Series.Count > 0)
  341. //{
  342. // Chart1.Series.Clear();
  343. //}
  344. //if (Chart1.Titles.Count > 0)
  345. //{
  346. // Chart1.Titles.Clear();
  347. //}
  348. //Get the DISTINCT Countries.
  349. List<string> depts = (from p in dt.AsEnumerable()
  350. select p.Field<string>("dept")).Distinct().ToList();
  351. //Remove the Default Series.
  352. //if (Chart1.Series.Count() == 1)
  353. //{
  354. // Chart1.Series.Remove(Chart1.Series[0]);
  355. //}
  356. //Loop through the Countries.
  357. foreach (string dept in depts)
  358. {
  359. //Get the Year for each Country.
  360. DateTime[] x = (from p in dt.AsEnumerable()
  361. where p.Field<string>("dept") == dept
  362. orderby p.Field<DateTime>("opdate") ascending
  363. select p.Field<DateTime>("opdate")).ToArray();
  364. //Get the Total of Orders for each Country.
  365. decimal[] y = (from p in dt.AsEnumerable()
  366. where p.Field<string>("dept") == dept
  367. orderby p.Field<DateTime>("opdate") ascending
  368. select p.Field<decimal>("optime")).ToArray();
  369. //Add Series to the Chart.
  370. Chart1.Series.Add(new Series(dept));
  371. Chart1.Series[dept].IsValueShownAsLabel = true;
  372. Chart1.Series[dept].ChartType = SeriesChartType.StackedColumn;
  373. Chart1.Series[dept].Points.DataBindXY(x, y);
  374. for (int i = 0; i < y.Length; i++)
  375. {
  376. if (y[i] == 0)
  377. {
  378. Chart1.Series[dept].Points[i].IsValueShownAsLabel = false;
  379. }
  380. Chart1.Series[dept].Points[i].IsValueShownAsLabel = false;
  381. }
  382. }
  383. foreach (string dept in depts)
  384. {
  385. if (dept != "作业时间")
  386. continue;
  387. //Get the Year for each Country.
  388. DateTime[] x = (from p in dt.AsEnumerable()
  389. where p.Field<string>("dept") == dept
  390. orderby p.Field<DateTime>("opdate") ascending
  391. select p.Field<DateTime>("opdate")).ToArray();
  392. //Get the Total of Orders for each Country.
  393. decimal[] y = (from p in dt.AsEnumerable()
  394. where p.Field<string>("dept") == dept
  395. orderby p.Field<DateTime>("opdate") ascending
  396. select p.Field<decimal>("optime")).ToArray();
  397. //Add Series to the Chart.
  398. string str = "作业率";
  399. Chart1.Series.Add(new Series(str));
  400. Chart1.Series[str].IsValueShownAsLabel = true;
  401. Chart1.Series[str].ChartType = SeriesChartType.Line;
  402. Chart1.Series[str].Points.DataBindXY(x, y);
  403. for (int i = 0; i < y.Length; i++)
  404. {
  405. Chart1.Series[str].Points[i].IsValueShownAsLabel = false;
  406. //Chart1.Series[str].Points[i].Color = chartColors[1];
  407. }
  408. }
  409. Chart1.Series[0].YAxisType = AxisType.Primary;
  410. //Chart1.Series[5].YAxisType = AxisType.Secondary;
  411. Chart1.Series["作业率"].MarkerStyle = MarkerStyle.Circle;
  412. Chart1.Series["作业率"].Color = Color.Red;
  413. Chart1.Series["作业率"].MarkerSize = 9;
  414. Chart1.Series["作业率"].MarkerBorderWidth = 9;
  415. Chart1.Series["作业率"].BorderWidth = 3;
  416. Chart1.Series["作业率"].IsValueShownAsLabel = false;
  417. //Chart1.Series["作业率"].SetCustomProperty("LineTension", "0.05");
  418. //foreach (string country in countries)
  419. //{
  420. // if (country != "Brazil")
  421. // continue;
  422. // //Get the Year for each Country.
  423. // int[] x = (from p in dt.AsEnumerable()
  424. // where p.Field<string>("ShipCountry") == country
  425. // orderby p.Field<int>("Year") ascending
  426. // select p.Field<int>("Year")).ToArray();
  427. // //Get the Total of Orders for each Country.
  428. // //int[] y = (from p in dt.AsEnumerable()
  429. // // where p.Field<string>("ShipCountry") == country
  430. // // orderby p.Field<int>("Year") ascending
  431. // // select p.Field<int>("Total")).ToArray();
  432. // double[] y = new double[] { 0.25, 0.45, 0.79 };
  433. // //Add Series to the Chart.
  434. // string str = country + "test";
  435. // Chart1.Series.Add(new Series(str));
  436. // //Chart1.Series[str].IsValueShownAsLabel = true;
  437. // Chart1.Series[str].ChartType = SeriesChartType.Line;
  438. // Chart1.Series[str].Points.DataBindXY(x, y);
  439. //}
  440. Chart1.Series[0].YAxisType = AxisType.Primary;
  441. //Chart1.Series[3].YAxisType = AxisType.Secondary;
  442. //Chart1.Series[3].MarkerStyle = MarkerStyle.Diamond;
  443. //Chart1.Series[3].MarkerSize = 35;
  444. //Chart1.Series[3].MarkerBorderWidth = 35;
  445. //Chart1.ChartAreas[0].AxisY2.LineColor = System.Color.Transparent;
  446. //Chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;
  447. //Chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
  448. //Chart1.ChartAreas[0].AxisY2.IsStartedFromZero = Chart1.ChartAreas[0].AxisY.IsStartedFromZero;
  449. //Chart1.ChartAreas[0].AxisY2.Minimum = 0;
  450. //Chart1.ChartAreas[0].AxisY2.Minimum = 1;
  451. ////Chart1.ChartAreas[0].AxisY2.Interval = 0.1;
  452. //Chart1.ChartAreas[0].AxisY2.LabelStyle.Format = "0%";
  453. //Chart1.Series[3].Label = "#VAL{P}";
  454. Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;//不显示网格线
  455. Chart1.ChartAreas[0].AxisY2.MajorGrid.Enabled = false;//不显示网格线
  456. Chart1.ChartAreas[0].AxisY2.Enabled = AxisEnabled.True;
  457. Chart1.ChartAreas[0].AxisY2.LabelStyle.Format = "0%";//格式化,为了显示百分号
  458. Chart1.ChartAreas[0].AxisY2.Interval = 0.1;//设置刻度间隔为5%
  459. Chart1.ChartAreas[0].AxisY2.Maximum = 1;
  460. //Chart1.Series[3].Label = "#VAL{P}";
  461. Chart1.ChartAreas[0].Area3DStyle.Enable3D = false;//设置3D效果
  462. //chart2.ChartAreas[0].Area3DStyle.PointDepth =
  463. Chart1.ChartAreas[0].Area3DStyle.PointGapDepth = 50;//设置一下深度,看起来舒服点……
  464. Chart1.ChartAreas[0].Area3DStyle.WallWidth = 0;//设置墙的宽度为0;
  465. ////以下是图例属性的设置
  466. //Chart1.Legends[0].Enabled = true; //是否显示图例
  467. ////Chart1.Legends[0].Position.Auto = true;
  468. //Chart1.Legends[0].Docking = Docking.Bottom; //Docking是图例的停靠位置
  469. //Chart1.Legends[0].Alignment = StringAlignment.Center;//Alignment属性是图例的对齐方式
  470. //Chart1.Series[0]["PointWidth"] = "1";
  471. //Chart1.Series[1]["PointWidth"] = "1";
  472. //Chart1.Series[2]["PointWidth"] = "1";
  473. //Chart1.Series[3]["PointWidth"] = "1";
  474. //Chart1.Series[4]["PointWidth"] = "1";
  475. //Chart1.Series[0].Label = "#PERCENT -- #VALY";
  476. Chart1.ChartAreas[0].AxisX.LabelAutoFitStyle = LabelAutoFitStyles.None; //设置当前X轴Label自动设置格式=关闭
  477. Chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 1;//设置当前X轴Label的显示间隔周期=1 (1个项目) (=2的意思: 间隔2个项目显示...以此类推)
  478. Chart1.ChartAreas[0].AxisX.LabelStyle.IsStaggered = false;//设置当前X轴Label的双行显示格式= 打开. (双行显示的效果如下图)
  479. Chart1.ChartAreas[0].AxisX.LabelStyle.Angle = -60;//x轴倾斜的角度。
  480. Chart1.ChartAreas["ChartArea1"].AxisX.LabelStyle.Format = "MM-dd";//x轴Label 格式化。
  481. Chart1.ChartAreas[0].AxisY.Maximum = 24;
  482. Chart1.ChartAreas[0].AxisY.Interval = 3;//设置刻度间隔为3
  483. Chart1.ChartAreas[0].BackColor = Color.Transparent;
  484. Chart1.Legends[0].BackColor = Color.Transparent;
  485. //Chart1.ChartAreas[0].AxisY.Title = "生产厂停机";
  486. //Chart1.ChartAreas[0].AxisY.TitleFont = new Font("Arial Unicode MS", float.Parse("10"),FontStyle.Regular);
  487. //Chart1.ChartAreas[0].AxisY.TitleForeColor = Color.FromName("Black");
  488. //Chart1.ChartAreas[0].AxisY.Title = "简体中文";
  489. //Chart1.ChartAreas[0].AxisY.IsLabelAutoFit = true;
  490. //Chart1.ChartAreas[0].AxisY2.IsLabelAutoFit = true;
  491. //以下设置Chart四周空白面积
  492. Chart1.ChartAreas[0].Position.X = 0;
  493. Chart1.ChartAreas[0].Position.Width = 100;
  494. Chart1.ChartAreas[0].Position.Height = 75;
  495. Chart1.ChartAreas[0].Position.Y = 6;
  496. //Chart1.ChartAreas[0].AxisX.IsMarginVisible = true;
  497. //Chart1.ChartAreas[0].AxisX.IntervalOffset = 1;
  498. //Chart1.ChartAreas[0].AxisX.Minimum = Double.NaN;
  499. //Chart1.ChartAreas[0].AxisX.Maximum = Double.NaN;
  500. //Chart1.ChartAreas[0].AxisX.IsMarginVisible = false;
  501. //Chart1.ChartAreas[0].AxisX.IsMarginVisible = false;
  502. //Chart1.ChartAreas[0].AxisY.IsMarginVisible = false;
  503. //Chart1.ChartAreas[0].AxisY2.IsMarginVisible = false;
  504. //Chart1.ChartAreas[0].InnerPlotPosition.Y = 100;
  505. //Chart1.ChartAreas[0].AxisX.LabelStyle.IntervalOffset = -1;
  506. //Chart1.ChartAreas[0].AxisX.MajorGrid.IntervalOffset = 0.5;
  507. //Chart1.ChartAreas[0].AxisX.MajorTickMark.IntervalOffset = 0.5;
  508. string deptName = ucb1.Text;
  509. this.Chart1.Titles.Add(new Title(deptName + "运行停机图", Docking.Top, new Font("Arial Unicode MS", float.Parse("15"), FontStyle.Regular), Color.FromName("Black")));
  510. //设置柱状图宽度
  511. foreach (var series in Chart1.Series)
  512. {
  513. series["PixelPointWidth"] = "10";
  514. //Chart1.Series[0]["PixelPointWidth"] = "15";
  515. }
  516. //设置chart 颜色
  517. //for (int i = 0; i < Chart1.Series[0].Points.Count; i++)
  518. //{
  519. // DataPoint p = Chart1.Series[0].Points[i];
  520. // if (p.AxisLabel == "作业时间")
  521. // {
  522. // p.Color = chartColors[0];
  523. // continue;
  524. // }
  525. // if (colorsIndex > chartColors.Length - 1)
  526. // {
  527. // break;
  528. // }
  529. // else
  530. // {
  531. // p.Color = chartColors[colorsIndex++];
  532. // }
  533. //}
  534. //设置chart column 颜色
  535. //for (int i = 0; i < Chart1.Series.Count; i++)
  536. //{
  537. // if (Chart1.Series[i].Name == "作业时间")
  538. // {
  539. // //foreach (DataPoint p in Chart1.Series[i].Points)
  540. // //{
  541. // // p.Color = chartColors[0];
  542. // //}
  543. // Chart1.Series[i].Color = chartColors[0];
  544. // }
  545. // else if (Chart1.Series[i].Name == "作业率")
  546. // {
  547. // //foreach (DataPoint p in Chart1.Series[i].Points)
  548. // //{
  549. // // p.Color = chartColors[0];
  550. // //}
  551. // Chart1.Series[i].Color = chartColors[1];
  552. // }
  553. // else
  554. // {
  555. // if (colorsIndex > chartColors.Length - 1)
  556. // {
  557. // break;
  558. // }
  559. // else
  560. // {
  561. // //foreach (DataPoint p in Chart1.Series[i].Points)
  562. // //{
  563. // // p.Color = chartColors[colorsIndex];
  564. // //}
  565. // Chart1.Series[i].Color = chartColors[colorsIndex];
  566. // colorsIndex++;
  567. // }
  568. // }
  569. //}
  570. }
  571. //以下代码生成右侧饼图(Pie)
  572. private void Build_ChartPie(DataTable dt)
  573. {
  574. //初始化图控件,设置公共属性
  575. Chart_Initial(Chart2);
  576. var query = from r in dt.AsEnumerable()
  577. group r by r.Field<string>("DEPT")
  578. into s
  579. select new
  580. {
  581. DEPT = s.Select(m => m.Field<string>("DEPT")).First(),
  582. OPTIME = s.Sum(p => p.Field<decimal>("OPTIME"))
  583. };
  584. //Get the names of Cities.
  585. string[] x = query.Select(p => p.DEPT).ToArray();
  586. //Get the Total of Orders for each City.
  587. decimal[] y = query.Select(p => p.OPTIME).ToArray();
  588. Chart2.Series.Add(new Series());
  589. Chart2.Series[0].ChartType = SeriesChartType.Pie;
  590. Chart2.Series[0].Points.DataBindXY(x, y);
  591. //foreach (DataPoint p in Chart2.Series[0].Points)
  592. //{
  593. // p.Label = x[0] + " #PERCENT{P2}";
  594. //}
  595. //Chart2.Series[0]["PieLabelStyle"] = "Outside";
  596. //Chart2.Legends[0].Enabled = true;
  597. Chart2.Series[0]["PieLabelStyle"] = "Outside";
  598. for (int i=0;i< Chart2.Series[0].Points.Count;i++)
  599. {
  600. DataPoint p = Chart2.Series[0].Points[i];
  601. p.Label = x[i] + " #PERCENT{P2}";
  602. p.LegendText = x[i];
  603. }
  604. Chart2.ChartAreas[0].Area3DStyle.Enable3D = true;
  605. string deptName = ucb1.Text;
  606. Chart2.Titles.Add(new Title(deptName + "运行停机比", Docking.Top, new Font("Arial Unicode MS", float.Parse("15"), FontStyle.Regular), Color.FromName("Black")));
  607. //Chart2.Legends[0].Docking = Docking.Bottom; //Docking是图例的停靠位置
  608. //Chart2.Legends[0].Alignment = StringAlignment.Center;//Alignment属性是图例的对齐方式
  609. //Chart2.BackColor = Color.Transparent;
  610. //Chart2.ChartAreas[0].BackColor = Color.Transparent;
  611. //Chart2.Legends[0].BackColor = Color.Transparent;
  612. foreach (DataPoint point in Chart2.Series[0].Points)
  613. {
  614. point["Exploded"] = "false";
  615. if (point.AxisLabel == "作业时间")
  616. {
  617. point["Exploded"] = "true";
  618. point.Color = chartColors[0];
  619. }
  620. if (point.AxisLabel == "停机时间")
  621. {
  622. point.Color = chartColors[0];
  623. }
  624. }
  625. }
  626. //以下代码生成右侧饼图(Pie 作业时间 + 停机时间)
  627. private void Build_ChartPie1(DataTable dt)
  628. {
  629. //初始化图控件,设置公共属性
  630. Chart_Initial(Chart2);
  631. var query = from r in dt.AsEnumerable()
  632. where r.Field<string>("DEPT") == "作业时间"
  633. group r by r.Field<string>("DEPT")
  634. into s
  635. select new
  636. {
  637. DEPT = s.Select(m => m.Field<string>("DEPT")).First(),
  638. OPTIME = s.Sum(p => p.Field<decimal>("OPTIME"))
  639. };
  640. var query1 = from r in dt.AsEnumerable()
  641. where r.Field<string>("DEPT") != "作业时间"
  642. group r by r.Field<string>("DEPT")
  643. into s
  644. select new
  645. {
  646. DEPT = s.Select(m => m.Field<string>("DEPT")).First(),
  647. OPTIME = s.Sum(p => p.Field<decimal>("OPTIME"))
  648. };
  649. //Get the names of Cities.
  650. decimal zytime = dt.AsEnumerable().Where(r=>r.Field<string>("DEPT") == "作业时间").Sum(r => r.Field<decimal>("OPTIME"));
  651. decimal tjtime = dt.AsEnumerable().Where(r => r.Field<string>("DEPT") != "作业时间").Sum(r => r.Field<decimal>("OPTIME"));
  652. string[] x = {"作业时间","停机时间"};
  653. //Get the Total of Orders for each City.
  654. decimal[] y = {zytime,tjtime};
  655. Chart2.Series.Add(new Series());
  656. Chart2.Series[0].ChartType = SeriesChartType.Pie;
  657. Chart2.Series[0].Points.DataBindXY(x, y);
  658. foreach (DataPoint p in Chart2.Series[0].Points)
  659. {
  660. if (p.AxisLabel == "作业时间")
  661. {
  662. p.Color = chartColors[0];
  663. }
  664. if (p.AxisLabel == "停机时间")
  665. {
  666. p.Color = chartColors[2];
  667. }
  668. }
  669. //Chart2.Series[0]["PieLabelStyle"] = "Outside";
  670. //Chart2.Legends[0].Enabled = true;
  671. //Chart2.Series[0]["PieLabelStyle"] = "Outside";
  672. for (int i = 0; i < Chart2.Series[0].Points.Count; i++)
  673. {
  674. DataPoint p = Chart2.Series[0].Points[i];
  675. //p.Label = x[i] + " #PERCENT{P2}";
  676. p.Label = " #PERCENT{P2}";
  677. p.LegendText = x[i];
  678. }
  679. Chart2.ChartAreas[0].Area3DStyle.Enable3D = true;
  680. string deptName = ucb1.Text;
  681. Chart2.Titles.Add(new Title(deptName + "作业停机图", Docking.Top, new Font("Arial Unicode MS", float.Parse("15"), FontStyle.Regular), Color.FromName("Black")));
  682. //Chart2.Legends[0].Docking = Docking.Bottom; //Docking是图例的停靠位置
  683. //Chart2.Legends[0].Alignment = StringAlignment.Center;//Alignment属性是图例的对齐方式
  684. //Chart2.BackColor = Color.Transparent;
  685. //Chart2.ChartAreas[0].BackColor = Color.Transparent;
  686. //Chart2.Legends[0].BackColor = Color.Transparent;
  687. foreach (DataPoint point in Chart2.Series[0].Points)
  688. {
  689. point["Exploded"] = "false";
  690. if (point.AxisLabel == "作业时间")
  691. {
  692. point["Exploded"] = "true";
  693. }
  694. }
  695. }
  696. //以下代码生成右侧饼图(Pie 停机时间)
  697. private void Build_ChartPie2(DataTable dt)
  698. {
  699. //初始化图控件,设置公共属性
  700. Chart_Initial(Chart3);
  701. var query = from r in dt.AsEnumerable()
  702. where r.Field<string>("DEPT") != "作业时间"
  703. group r by r.Field<string>("DEPT")
  704. into s
  705. select new
  706. {
  707. DEPT = s.Select(m => m.Field<string>("DEPT")).First(),
  708. OPTIME = s.Sum(p => p.Field<decimal>("OPTIME"))
  709. };
  710. //Get the names of Cities.
  711. string[] x = query.Select(p => p.DEPT).ToArray();
  712. //Get the Total of Orders for each City.
  713. decimal[] y = query.Select(p => p.OPTIME).ToArray();
  714. Chart3.Series.Add(new Series());
  715. Chart3.Series[0].ChartType = SeriesChartType.Pie;
  716. Chart3.Series[0].Points.DataBindXY(x, y);
  717. //foreach (DataPoint p in Chart3.Series[0].Points)
  718. //{
  719. // p.Label = x[0] + " #PERCENT{P2}";
  720. //}
  721. Chart3.Series[0]["PieLabelStyle"] = "Outside";
  722. Chart3.Legends[0].Enabled = true;
  723. //Chart3.Series[0]["PieLabelStyle"] = "Outside";
  724. Chart3.Series[0]["3DLabelLineSize"] = "30";
  725. Chart3.Series[0]["MinimumRelativePieSize"] = "30";
  726. for (int i = 0; i < Chart3.Series[0].Points.Count; i++)
  727. {
  728. DataPoint p = Chart3.Series[0].Points[i];
  729. //p.Label = x[i] +Environment.NewLine+ " #PERCENT{P2}";
  730. //p.Label = " #PERCENT{P2}";
  731. p.Label = x[i] + " #PERCENT{P2}";
  732. p.LegendText = x[i];
  733. }
  734. Chart3.ChartAreas[0].Area3DStyle.Enable3D = true;
  735. Chart3.Series[0].SmartLabelStyle.Enabled = true;
  736. Chart3.Series[0].SmartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.No;
  737. Chart3.Series[0].SmartLabelStyle.CalloutLineAnchorCapStyle = LineAnchorCapStyle.None;
  738. Chart3.Series[0].SmartLabelStyle.CalloutLineColor = Color.Red;
  739. Chart3.Series[0].SmartLabelStyle.CalloutLineWidth = 1;
  740. Chart3.Series[0].SmartLabelStyle.CalloutStyle = LabelCalloutStyle.None;
  741. string deptName = ucb1.Text;
  742. Chart3.Titles.Add(new Title(deptName + "停机责任图", Docking.Top, new Font("Arial Unicode MS", float.Parse("15"), FontStyle.Regular), Color.FromName("Black")));
  743. //Chart3.Legends[0].Docking = Docking.Bottom; //Docking是图例的停靠位置
  744. //Chart3.Legends[0].Alignment = StringAlignment.Center;//Alignment属性是图例的对齐方式
  745. //Chart3.BackColor = Color.Transparent;
  746. //Chart3.ChartAreas[0].BackColor = Color.Transparent;
  747. //Chart3.Legends[0].BackColor = Color.Transparent;
  748. foreach (DataPoint point in Chart3.Series[0].Points)
  749. {
  750. point["Exploded"] = "false";
  751. if (point.AxisLabel == "作业时间")
  752. {
  753. point["Exploded"] = "true";
  754. }
  755. }
  756. }
  757. //以下代码相应左侧柱状图鼠标移动事件
  758. private void Chart1_GetToolTipText(object sender, System.Windows.Forms.DataVisualization.Charting.ToolTipEventArgs e)
  759. {
  760. if (e.HitTestResult.ChartElementType == ChartElementType.DataPoint)
  761. {
  762. int i = e.HitTestResult.PointIndex;
  763. DataPoint dp = e.HitTestResult.Series.Points[i];
  764. string dept = e.HitTestResult.Series.Name;
  765. if (dept == "作业率")
  766. {
  767. string percent = Math.Round((Chart1.Series["作业时间"].Points[i].YValues[0] * 100 / 24), 2).ToString("0.00") + "%";
  768. e.Text = string.Format("日期:{0};\n{2}:{1:F2} ", DateTime.FromOADate(dp.XValue).ToString("yy-M-dd"), percent, dept);
  769. }
  770. else
  771. {
  772. //分别显示x轴和y轴的数值,其中{1:F3},表示显示的是float类型,精确到小数点后3位。
  773. e.Text = string.Format("日期:{0};\n{2}:{1:F2}小时 ", DateTime.FromOADate(dp.XValue).ToString("yy-M-dd"), dp.YValues[0], dept);
  774. }
  775. }
  776. }
  777. private int DateDiff(DateTime dateStart, DateTime dateEnd)
  778. {
  779. DateTime start = Convert.ToDateTime(dateStart.ToShortDateString());
  780. DateTime end = Convert.ToDateTime(dateEnd.ToShortDateString());
  781. TimeSpan sp = end.Subtract(start);
  782. return sp.Days;
  783. }
  784. private void btn_month_Click(object sender, EventArgs e)
  785. {
  786. this.startDate.Value = this.endDate.Value.AddMonths(-1);
  787. }
  788. private void ucb1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
  789. {
  790. this.ucb1.DisplayMember = "plinename";
  791. this.ucb1.ValueMember = "plinecode";
  792. }
  793. private void timer1_Tick(object sender, EventArgs e)
  794. {
  795. angle += 1;
  796. if (angle >= 360)
  797. {
  798. angle = 0;
  799. }
  800. Chart2.Series[0]["PieStartAngle"] = angle.ToString();
  801. PieExploed(angle);
  802. }
  803. private void timer2_Tick(object sender, EventArgs e)
  804. {
  805. angle1 += 1;
  806. if (angle1 >= 360)
  807. {
  808. angle1 = 0;
  809. }
  810. Chart3.Series[0]["PieStartAngle"] = angle1.ToString();
  811. PieExploed1(angle);
  812. }
  813. //图点索引
  814. private int index = 0;
  815. private void PieExploed(int angle)
  816. {
  817. if (angle == 1)
  818. {
  819. Chart2.Series[0].Points[0]["Exploded"] = "true";
  820. }
  821. if (angle % 30 == 0)
  822. {
  823. foreach (DataPoint point in Chart2.Series[0].Points)
  824. {
  825. point["Exploded"] = "false";
  826. }
  827. Chart2.Series[0].Points[index]["Exploded"] = "true";
  828. if (index == Chart2.Series[0].Points.Count - 1)
  829. {
  830. index = 0;
  831. }
  832. else
  833. {
  834. index++;
  835. }
  836. }
  837. }
  838. private int index1 = 0;
  839. private void PieExploed1(int angle)
  840. {
  841. if (angle == 1)
  842. {
  843. Chart3.Series[0].Points[0]["Exploded"] = "true";
  844. }
  845. if (angle % 30 == 0)
  846. {
  847. foreach (DataPoint point in Chart3.Series[0].Points)
  848. {
  849. point["Exploded"] = "false";
  850. }
  851. Chart3.Series[0].Points[index1]["Exploded"] = "true";
  852. if (index1 == Chart3.Series[0].Points.Count - 1)
  853. {
  854. index1 = 0;
  855. }
  856. else
  857. {
  858. index1++;
  859. }
  860. }
  861. }
  862. //旋转停止
  863. private void toolStripMenuItem1_Click(object sender, EventArgs e)
  864. {
  865. if (chartActive != null)
  866. {
  867. if (chartActive.Name == "Chart2")
  868. {
  869. this.timer1.Enabled = !this.timer1.Enabled;
  870. }
  871. if (chartActive.Name == "Chart3")
  872. {
  873. this.timer2.Enabled = !this.timer2.Enabled;
  874. }
  875. }
  876. }
  877. //另存为
  878. private void toolStripMenuItem4_Click(object sender, EventArgs e)
  879. {
  880. if (chartActive != null)
  881. {
  882. // Create a new save file dialog
  883. SaveFileDialog saveFileDialog1 = new SaveFileDialog();
  884. // Sets the current file name filter string, which determines
  885. // the choices that appear in the "Save as file type" or
  886. // "Files of type" box in the dialog box.
  887. saveFileDialog1.Filter = "Bitmap (*.bmp)|*.bmp|JPEG (*.jpg)|*.jpg|EMF (*.emf)|*.emf|PNG (*.png)|*.png|GIF (*.gif)|*.gif|TIFF (*.tif)|*.tif";
  888. saveFileDialog1.FilterIndex = 2;
  889. saveFileDialog1.RestoreDirectory = true;
  890. // Set image file format
  891. if (saveFileDialog1.ShowDialog() == DialogResult.OK)
  892. {
  893. ChartImageFormat format = ChartImageFormat.Bmp;
  894. if (saveFileDialog1.FileName.EndsWith("bmp"))
  895. {
  896. format = ChartImageFormat.Bmp;
  897. }
  898. else if (saveFileDialog1.FileName.EndsWith("jpg"))
  899. {
  900. format = ChartImageFormat.Jpeg;
  901. }
  902. else if (saveFileDialog1.FileName.EndsWith("emf"))
  903. {
  904. format = ChartImageFormat.Emf;
  905. }
  906. else if (saveFileDialog1.FileName.EndsWith("gif"))
  907. {
  908. format = ChartImageFormat.Gif;
  909. }
  910. else if (saveFileDialog1.FileName.EndsWith("png"))
  911. {
  912. format = ChartImageFormat.Png;
  913. }
  914. else if (saveFileDialog1.FileName.EndsWith("tif"))
  915. {
  916. format = ChartImageFormat.Tiff;
  917. }
  918. chartActive.BackColor = Color.White;
  919. chartActive.ChartAreas[0].BackColor = Color.White;
  920. chartActive.Legends[0].BackColor = Color.White;
  921. // Save image
  922. chartActive.SaveImage(saveFileDialog1.FileName, format);
  923. }
  924. chartActive.BackColor = Color.Transparent;
  925. chartActive.ChartAreas[0].BackColor = Color.Transparent;
  926. chartActive.Legends[0].BackColor = Color.Transparent;
  927. }
  928. }
  929. //拷贝
  930. private void toolStripMenuItem3_Click(object sender, EventArgs e)
  931. {
  932. if (chartActive != null)
  933. {
  934. chartActive.BackColor = Color.White;
  935. chartActive.ChartAreas[0].BackColor = Color.White;
  936. chartActive.Legends[0].BackColor = Color.White;
  937. // create a memory stream to save the chart image
  938. System.IO.MemoryStream stream = new System.IO.MemoryStream();
  939. // save the chart image to the stream
  940. chartActive.SaveImage(stream, System.Drawing.Imaging.ImageFormat.Bmp);
  941. // create a bitmap using the stream
  942. Bitmap bmp = new Bitmap(stream);
  943. // save the bitmap to the clipboard
  944. Clipboard.SetDataObject(bmp);
  945. chartActive.BackColor = Color.Transparent;
  946. chartActive.ChartAreas[0].BackColor = Color.Transparent;
  947. chartActive.Legends[0].BackColor = Color.Transparent;
  948. MessageUtil.ShowTips("图片已拷贝至剪切板!");
  949. }
  950. }
  951. //鼠标进入 chart控件获取焦点
  952. private void Chart_MouseEnter(object sender, EventArgs e)
  953. {
  954. Chart chart = sender as Chart;
  955. if (chart != null)
  956. {
  957. chartActive = chart;
  958. chart.Focus();
  959. }
  960. }
  961. private void Chart_KeyDown(object sender, KeyEventArgs e)
  962. {
  963. this.ctrlKeyDown = e.Control;
  964. this.shiftKeyDown = e.Shift;
  965. }
  966. private void Chart_KeyUp(object sender, KeyEventArgs e)
  967. {
  968. this.ctrlKeyDown = e.Control;
  969. this.shiftKeyDown = e.Shift;
  970. }
  971. //右键菜单打开事件(正在打开时)
  972. private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
  973. {
  974. ContextMenuStrip ctx = sender as ContextMenuStrip;
  975. Control control = ctx.SourceControl;
  976. Chart chart = control as Chart;
  977. if (chart != null)
  978. {
  979. //Chart1 柱状图屏蔽 转动命令
  980. if (chart.Name == "Chart1")
  981. {
  982. ctx.Items[0].Visible = false;
  983. }
  984. else
  985. {
  986. ctx.Items[0].Visible = true;
  987. }
  988. }
  989. }
  990. //初始化数据源,为部门、产销下拉列表准备
  991. private void initial_UltraDataSource1()
  992. {
  993. UltraDataRow row;
  994. // Initialize rows with data.
  995. // Get the first row.
  996. this.ultraDataSource1.Rows.SetCount(37);
  997. int index = 0;
  998. row = this.ultraDataSource1.Rows[index++];
  999. row["dept"] = "全部";
  1000. row["plinecode"] = "-1";
  1001. row["plinename"] = "全部";
  1002. row = this.ultraDataSource1.Rows[index++];
  1003. row["dept"] = "炼钢厂全部";
  1004. row["plinecode"] = "A";
  1005. row["plinename"] = "炼钢厂全部";
  1006. row = this.ultraDataSource1.Rows[index++];
  1007. row["dept"] = "炼钢厂";
  1008. row["plinename2"] = "一炼钢";
  1009. row["plinecode"] = "C001";
  1010. row["plinename"] = "一炼钢";
  1011. row = this.ultraDataSource1.Rows[index++];
  1012. row["dept"] = "炼钢厂";
  1013. row["plinename2"] = "二炼钢";
  1014. row["plinecode"] = "C003";
  1015. row["plinename"] = "二炼钢";
  1016. row = this.ultraDataSource1.Rows[index++];
  1017. row["dept"] = "轧管厂全部";
  1018. row["plinecode"] = "D";
  1019. row["plinename"] = "轧管厂全部";
  1020. row = this.ultraDataSource1.Rows[index++];
  1021. row["dept"] = "轧管厂";
  1022. row["plinename2"] = "250机组";
  1023. row["plinecode"] = "C008";
  1024. row["plinename"] = "250机组";
  1025. row = this.ultraDataSource1.Rows[index++];
  1026. row["dept"] = "轧管厂";
  1027. row["plinename2"] = "258机组";
  1028. row["plinecode"] = "C009";
  1029. row["plinename"] = "258机组";
  1030. row = this.ultraDataSource1.Rows[index++];
  1031. row["dept"] = "轧管厂";
  1032. row["plinename2"] = "168机组";
  1033. row["plinecode"] = "C010";
  1034. row["plinename"] = "168机组";
  1035. row = this.ultraDataSource1.Rows[index++];
  1036. row["dept"] = "轧管厂";
  1037. row["plinename2"] = "460机组";
  1038. row["plinecode"] = "C017";
  1039. row["plinename"] = "460机组";
  1040. row = this.ultraDataSource1.Rows[index++];
  1041. row["dept"] = "管加工热处理炉全部";
  1042. row["plinecode"] = "F0";
  1043. row["plinename"] = "管加工热处理炉全部";
  1044. row = this.ultraDataSource1.Rows[index++];
  1045. row["dept"] = "管加工热处理炉";
  1046. row["plinename1"] = "本部";
  1047. row["plinename2"] = "全部";
  1048. row["plinecode"] = "F01";
  1049. row["plinename"] = "管加工热处理炉本部全部";
  1050. row = this.ultraDataSource1.Rows[index++];
  1051. row["dept"] = "管加工热处理炉";
  1052. row["plinename1"] = "本部";
  1053. row["plinename2"] = "1#热处理";
  1054. row["plinecode"] = "C0220";
  1055. row["plinename"] = "1#热处理炉";
  1056. row = this.ultraDataSource1.Rows[index++];
  1057. row["dept"] = "管加工热处理炉";
  1058. row["plinename1"] = "本部";
  1059. row["plinename2"] = "2#热处理";
  1060. row["plinecode"] = "C0230";
  1061. row["plinename"] = "2#热处理炉";
  1062. row = this.ultraDataSource1.Rows[index++];
  1063. row["dept"] = "管加工热处理炉";
  1064. row["plinename1"] = "本部";
  1065. row["plinename2"] = "3#热处理";
  1066. row["plinecode"] = "C0240";
  1067. row["plinename"] = "3#热处理炉";
  1068. row = this.ultraDataSource1.Rows[index++];
  1069. row["dept"] = "管加工热处理炉";
  1070. row["plinename1"] = "本部";
  1071. row["plinename2"] = "4#热处理";
  1072. row["plinecode"] = "C0250";
  1073. row["plinename"] = "4#热处理炉";
  1074. row = this.ultraDataSource1.Rows[index++];
  1075. row["dept"] = "管加工热处理炉";
  1076. row["plinename1"] = "本部";
  1077. row["plinename2"] = "5#热处理";
  1078. row["plinecode"] = "C0260";
  1079. row["plinename"] = "5#热处理炉";
  1080. row = this.ultraDataSource1.Rows[index++];
  1081. row["dept"] = "管加工热处理炉";
  1082. row["plinename1"] = "深加工";
  1083. row["plinename2"] = "全部";
  1084. row["plinecode"] = "F02";
  1085. row["plinename"] = "管加工热处理炉深加工全部";
  1086. row = this.ultraDataSource1.Rows[index++];
  1087. row["dept"] = "管加工热处理炉";
  1088. row["plinename1"] = "深加工";
  1089. row["plinename2"] = "6#热处理";
  1090. row["plinecode"] = "C0540";
  1091. row["plinename"] = "6#热处理炉";
  1092. row = this.ultraDataSource1.Rows[index++];
  1093. row["dept"] = "管加工热处理炉";
  1094. row["plinename1"] = "深加工";
  1095. row["plinename2"] = "7#热处理";
  1096. row["plinecode"] = "C0550";
  1097. row["plinename"] = "7#热处理炉";
  1098. row = this.ultraDataSource1.Rows[index++];
  1099. row["dept"] = "管加工热处理炉";
  1100. row["plinename1"] = "深加工";
  1101. row["plinename2"] = "8#热处理";
  1102. row["plinecode"] = "C0480";
  1103. row["plinename"] = "8#热处理炉";
  1104. row = this.ultraDataSource1.Rows[index++];
  1105. row["dept"] = "管加工热处理炉";
  1106. row["plinename1"] = "元通";
  1107. row["plinename2"] = "全部";
  1108. row["plinecode"] = "F03";
  1109. row["plinename"] = "管加工热处理炉元通全部";
  1110. row = this.ultraDataSource1.Rows[index++];
  1111. row["dept"] = "管加工热处理炉";
  1112. row["plinename1"] = "元通";
  1113. row["plinename2"] = "9#热处理";
  1114. row["plinecode"] = "C0490";
  1115. row["plinename"] = "9#热处理炉";
  1116. row = this.ultraDataSource1.Rows[index++];
  1117. row["dept"] = "管加工热处理炉";
  1118. row["plinename1"] = "元通";
  1119. row["plinename2"] = "10#热处理";
  1120. row["plinecode"] = "C0500";
  1121. row["plinename"] = "10#热处理炉";
  1122. row = this.ultraDataSource1.Rows[index++];
  1123. row["dept"] = "管加工热处理探伤全部";
  1124. row["plinecode"] = "F1";
  1125. row["plinename"] = "管加工热处理探伤全部";
  1126. row = this.ultraDataSource1.Rows[index++];
  1127. row["dept"] = "管加工热处理探伤";
  1128. row["plinename1"] = "本部";
  1129. row["plinename2"] = "全部";
  1130. row["plinecode"] = "F11";
  1131. row["plinename"] = "管加工热处理探伤本部全部";
  1132. row = this.ultraDataSource1.Rows[index++];
  1133. row["dept"] = "管加工热处理探伤";
  1134. row["plinename1"] = "本部";
  1135. row["plinename2"] = "1#热处理";
  1136. row["plinecode"] = "C0221";
  1137. row["plinename"] = "1#热处理探伤";
  1138. row = this.ultraDataSource1.Rows[index++];
  1139. row["dept"] = "管加工热处理探伤";
  1140. row["plinename1"] = "本部";
  1141. row["plinename2"] = "2#热处理";
  1142. row["plinecode"] = "C0231";
  1143. row["plinename"] = "2#热处理探伤";
  1144. row = this.ultraDataSource1.Rows[index++];
  1145. row["dept"] = "管加工热处理探伤";
  1146. row["plinename1"] = "本部";
  1147. row["plinename2"] = "3#热处理";
  1148. row["plinecode"] = "C0241";
  1149. row["plinename"] = "3#热处理探伤";
  1150. row = this.ultraDataSource1.Rows[index++];
  1151. row["dept"] = "管加工热处理探伤";
  1152. row["plinename1"] = "本部";
  1153. row["plinename2"] = "4#热处理";
  1154. row["plinecode"] = "C0251";
  1155. row["plinename"] = "4#热处理探伤";
  1156. row = this.ultraDataSource1.Rows[index++];
  1157. row["dept"] = "管加工热处理探伤";
  1158. row["plinename1"] = "本部";
  1159. row["plinename2"] = "5#热处理";
  1160. row["plinecode"] = "C0261";
  1161. row["plinename"] = "5#热处理探伤";
  1162. row = this.ultraDataSource1.Rows[index++];
  1163. row["dept"] = "管加工热处理探伤";
  1164. row["plinename1"] = "深加工";
  1165. row["plinename2"] = "全部";
  1166. row["plinecode"] = "F12";
  1167. row["plinename"] = "管加工热处理探伤深加工全部";
  1168. row = this.ultraDataSource1.Rows[index++];
  1169. row["dept"] = "管加工热处理探伤";
  1170. row["plinename1"] = "深加工";
  1171. row["plinename2"] = "6#热处理";
  1172. row["plinecode"] = "C0541";
  1173. row["plinename"] = "6#热处理探伤";
  1174. row = this.ultraDataSource1.Rows[index++];
  1175. row["dept"] = "管加工热处理探伤";
  1176. row["plinename1"] = "深加工";
  1177. row["plinename2"] = "7#热处理";
  1178. row["plinecode"] = "C0551";
  1179. row["plinename"] = "7#热处理探伤";
  1180. row = this.ultraDataSource1.Rows[index++];
  1181. row["dept"] = "管加工热处理探伤";
  1182. row["plinename1"] = "深加工";
  1183. row["plinename2"] = "8#热处理";
  1184. row["plinecode"] = "C0481";
  1185. row["plinename"] = "8#热处理探伤";
  1186. row = this.ultraDataSource1.Rows[index++];
  1187. row["dept"] = "管加工热处理探伤";
  1188. row["plinename1"] = "元通";
  1189. row["plinename2"] = "全部";
  1190. row["plinecode"] = "F13";
  1191. row["plinename"] = "管加工热处理探伤元通全部";
  1192. row = this.ultraDataSource1.Rows[index++];
  1193. row["dept"] = "管加工热处理探伤";
  1194. row["plinename1"] = "元通";
  1195. row["plinename2"] = "9#热处理";
  1196. row["plinecode"] = "C0491";
  1197. row["plinename"] = "9#热处理探伤";
  1198. row = this.ultraDataSource1.Rows[index++];
  1199. row["dept"] = "管加工热处理探伤";
  1200. row["plinename1"] = "元通";
  1201. row["plinename2"] = "10#热处理";
  1202. row["plinecode"] = "C0501";
  1203. row["plinename"] = "10#热处理探伤";
  1204. }
  1205. }
  1206. }