-
Notifications
You must be signed in to change notification settings - Fork 1
/
后台数据.cs
707 lines (692 loc) · 44.1 KB
/
后台数据.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace i_car1
{
public partial class 后台数据 : Form
{
public static 后台数据 后台数据2;
public SqlConnection conn;
public 后台数据()
{
InitializeComponent();
this.StartPosition = FormStartPosition.CenterScreen;
后台数据2 = this;
string constr = @"Server=.\sqlexpress;Database=2021040614;Integrated security=True;";
conn = new SqlConnection(constr);
}
string i;
private void Form24_Load(object sender, EventArgs e)
{
string sql订单 = "select * from order1 ";
SqlCommand cmd订单 = new SqlCommand(sql订单, conn);
SqlDataAdapter ad订单 = new SqlDataAdapter(cmd订单);
DataTable dt订单 = new DataTable();
ad订单.Fill(dt订单);
uiDataGridView1.DataSource = dt订单;
string sql反馈 = "select * from baoxiu";
SqlCommand cmd反馈 = new SqlCommand(sql反馈, conn);
SqlDataAdapter ad反馈 = new SqlDataAdapter(cmd反馈);
DataTable dt反馈 = new DataTable();
ad反馈.Fill(dt反馈);
uiDataGridView2.DataSource = dt反馈;
string sql载入 = "select 汽车名称 from cars where 厂商='" + Class1.厂商 + "'";
SqlCommand cmd载入 = new SqlCommand(sql载入, conn);
conn.Open();
SqlDataReader rd载入 = cmd载入.ExecuteReader();
while (rd载入.Read())
{
comboBox3.Items.Add(rd载入[0]);
comboBox4.Items.Add(rd载入[0]);
}
rd载入.Close();
conn.Close();
comboBox3.SelectedIndex = 1;
comboBox1.SelectedIndex = 1;
comboBox4.SelectedIndex = 2;
string sql = "select order1.汽车名称,count(order1.汽车名称) as 销售量 from order1,cars where 厂商='" + Class1.厂商 + "'and cars.汽车名称=order1.汽车名称 group by order1.汽车名称";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
chart1.DataSource = dt;
chart1.Series["Series1"]["PieLineColor"] = "Black";//连线颜色
chart1.Series["Series1"]["PieLabelStyle"] = "Outside";//标签位置
chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 45;//倾斜度(0~90)
chart1.Series[0].IsValueShownAsLabel = true;
chart1.Series["Series1"].XValueMember = "汽车名称";
chart1.Series["Series1"].YValueMembers = "销售量";
int j;
string sql汽车 = "select count(汽车名称) from cars where 厂商='" + Class1.厂商 + "'";
SqlCommand cmd汽车 = new SqlCommand(sql汽车, conn);
conn.Open();
j = Convert.ToInt32(cmd汽车.ExecuteScalar());
conn.Close();
string[] a = new string[j];
for (int x = 0; x < j; x++)
{
a[x] = dt.Rows[x][0].ToString();
chart2.Series[x].Name = a[x];
chart3.Series[x].Name = a[x];
}
i = comboBox1.Text;
string[] 月份 = new string[] { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
for (int x = 0; x < j; x++)
{
double[] b = new double[12];
double[] c = new double[12];
for (int y = 1; y <= 12; y++)
{
var FirstDay = new DateTime(Convert.ToInt32(i), y, 1);
var LastDay = FirstDay.AddMonths(1).AddDays(-1);
string sql2 = "select isnull(count(*),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
b[y - 1] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
string sql3 = "select isnull(sum(总价),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd3 = new SqlCommand(sql3, conn);
conn.Open();
c[y - 1] = Convert.ToInt32(cmd3.ExecuteScalar());
conn.Close();
}
chart2.Series[x].Points.DataBindXY(月份, b);
chart3.Series[x].Points.DataBindXY(月份, c);
}
chart2.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart2.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart2.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart2.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
chart3.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart3.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart3.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart3.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart3.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart3.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
string s = comboBox3.Text;
string[] 年龄 = new string[] { "18岁以下", "18-30岁", "31-40岁", "41-50岁", "51-60岁", "60岁以上" };
double[] 数量 = new double[6];
for (int x = 0; x < 6; x++)
{
string sql2 = "select isnull(count(*),0) from order1,users where order1.用户名=users.用户名 and 汽车名称='" + s + "' and 年龄='" + 年龄[x] + "'";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
数量[x] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
}
chart4.Series[0].Points.DataBindXY(年龄, 数量);
chart4.Series["Series1"]["PieLineColor"] = "Black";//连线颜色
chart4.Series["Series1"]["PieLabelStyle"] = "Outside";//标签位置
chart4.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart4.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart4.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 45;//倾斜度(0~90)
chart4.Series[0].IsValueShownAsLabel = true;
chart4.Series["Series1"].XValueMember = "年龄";
chart4.Series["Series1"].YValueMembers = "销售量";
//string sql报修 = "select baoxiu.类型,count(*) 数量 from baoxiu,order1 where baoxiu.订单编号=order1.订单编号 and order1.汽车名称='" + comboBox4.Text + "' and baoxiu.时间>='"+uiDatePicker1.Text+"' and baoxiu.时间<='"+uiDatePicker2.Text+"' group by baoxiu.类型";
//SqlCommand cmd报修 = new SqlCommand(sql报修, conn);
//SqlDataAdapter ad报修 = new SqlDataAdapter(cmd报修);
//DataTable dt报修 = new DataTable();
//ad报修.Fill(dt报修);
//chart5.DataSource = dt报修;
//chart5.Series["Series0"].XValueMember = "类型";
//chart5.Series["Series0"].YValueMembers = "数量";
string t = comboBox4.Text;
string[] 种类 = new string[] { "外观异常", "动力异常", "内饰损坏", "系统安全", "其他"};
double[] 数量1 = new double[5];
for (int x = 0; x < 5; x++)
{
string sql2 = "select isnull(count(*),0) from baoxiu,order1 where baoxiu.类型='"+种类[x]+"' and baoxiu.订单编号=order1.订单编号 and order1.汽车名称='" + comboBox4.Text + "' and baoxiu.时间>='" + uiDatePicker1.Text + "' and baoxiu.时间<='" + uiDatePicker2.Text + "' group by baoxiu.类型";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
数量1[x] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
}
chart5.Series[0].Points.DataBindXY(种类, 数量1);
}//后台数据加载
public string ChartArea1 { get; set; }
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox2.SelectedIndex = comboBox1.SelectedIndex;
string sql = "select order1.汽车名称,count(order1.汽车名称) as 销售量 from order1,cars where 厂商='" + Class1.厂商 + "'and cars.汽车名称=order1.汽车名称 group by order1.汽车名称";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
chart1.DataSource = dt;
chart1.Series["Series1"]["PieLineColor"] = "Black";//连线颜色
chart1.Series["Series1"]["PieLabelStyle"] = "Outside";//标签位置
chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 45;//倾斜度(0~90)
chart1.Series[0].IsValueShownAsLabel = true;
chart1.Series["Series1"].XValueMember = "汽车名称";
chart1.Series["Series1"].YValueMembers = "销售量";
int j;
string sql汽车 = "select count(汽车名称) from cars where 厂商='" + Class1.厂商 + "'";
SqlCommand cmd汽车 = new SqlCommand(sql汽车, conn);
conn.Open();
j = Convert.ToInt32(cmd汽车.ExecuteScalar());
conn.Close();
string[] a = new string[j];
for (int x = 0; x < j; x++)
{
a[x] = dt.Rows[x][0].ToString();
chart2.Series[x].Name = a[x];
chart3.Series[x].Name = a[x];
}
i = comboBox1.Text;
string[] 月份 = new string[] { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
for (int x = 0; x < j; x++)
{
double[] b = new double[12];
double[] c = new double[12];
for (int y = 1; y <= 12; y++)
{
var FirstDay = new DateTime(Convert.ToInt32(i), y, 1);
var LastDay = FirstDay.AddMonths(1).AddDays(-1);
string sql2 = "select isnull(count(*),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
b[y - 1] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
string sql3 = "select isnull(sum(总价),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd3 = new SqlCommand(sql3, conn);
conn.Open();
c[y - 1] = Convert.ToInt32(cmd3.ExecuteScalar());
conn.Close();
}
chart2.Series[x].Points.DataBindXY(月份, b);
chart3.Series[x].Points.DataBindXY(月份, c);
}
chart2.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart2.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart2.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart2.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
chart3.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart3.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart3.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart3.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart3.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart3.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
}
private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
{
comboBox1.SelectedIndex = comboBox2.SelectedIndex;
string sql = "select order1.汽车名称,isnull(count(order1.汽车名称),0) as 销售量 from order1,cars where 厂商='" + Class1.厂商 + "'and cars.汽车名称=order1.汽车名称 group by order1.汽车名称";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
chart1.DataSource = dt;
chart1.Series["Series1"]["PieLineColor"] = "Black";//连线颜色
chart1.Series["Series1"]["PieLabelStyle"] = "Outside";//标签位置
chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 45;//倾斜度(0~90)
chart1.Series[0].IsValueShownAsLabel = true;
chart1.Series["Series1"].XValueMember = "汽车名称";
chart1.Series["Series1"].YValueMembers = "销售量";
int j;
string sql汽车 = "select count(汽车名称) from cars where 厂商='" + Class1.厂商 + "'";
SqlCommand cmd汽车 = new SqlCommand(sql汽车, conn);
conn.Open();
j = Convert.ToInt32(cmd汽车.ExecuteScalar());
conn.Close();
string[] a = new string[j];
for (int x = 0; x < j; x++)
{
a[x] = dt.Rows[x][0].ToString();
chart2.Series[x].Name = a[x];
chart3.Series[x].Name = a[x];
}
i = comboBox1.Text;
string[] 月份 = new string[] { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
for (int x = 0; x < j; x++)
{
double[] b = new double[12];
double[] c = new double[12];
for (int y = 1; y <= 12; y++)
{
var FirstDay = new DateTime(Convert.ToInt32(i), y, 1);
var LastDay = FirstDay.AddMonths(1).AddDays(-1);
string sql2 = "select isnull(count(*),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
b[y - 1] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
string sql3 = "select isnull(sum(总价),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd3 = new SqlCommand(sql3, conn);
conn.Open();
c[y - 1] = Convert.ToInt32(cmd3.ExecuteScalar());
conn.Close();
}
chart2.Series[x].Points.DataBindXY(月份, b);
chart3.Series[x].Points.DataBindXY(月份, c);
}
chart2.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart2.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart2.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart2.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
chart3.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart3.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart3.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart3.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart3.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart3.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
}
//图像展示
private void uiButton1_Click(object sender, EventArgs e)
{
string sql = "select order1.汽车名称,count(order1.汽车名称) as 销售量 from order1,cars where 厂商='" + Class1.厂商 + "'and cars.汽车名称=order1.汽车名称 group by order1.汽车名称";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
chart1.DataSource = dt;
chart1.Series["Series1"]["PieLineColor"] = "Black";//连线颜色
chart1.Series["Series1"]["PieLabelStyle"] = "Outside";//标签位置
chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 45;//倾斜度(0~90)
chart1.Series[0].IsValueShownAsLabel = true;
chart1.Series["Series1"].XValueMember = "汽车名称";
chart1.Series["Series1"].YValueMembers = "销售量";
int j;
string sql汽车 = "select count(汽车名称) from cars where 厂商='" + Class1.厂商 + "'";
SqlCommand cmd汽车 = new SqlCommand(sql汽车, conn);
conn.Open();
j = Convert.ToInt32(cmd汽车.ExecuteScalar());
conn.Close();
string[] a = new string[j];
for (int x = 0; x < j; x++)
{
a[x] = dt.Rows[x][0].ToString();
chart2.Series[x].Name = a[x];
chart3.Series[x].Name = a[x];
}
i = comboBox1.Text;
string[] 月份 = new string[] { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
for (int x = 0; x < j; x++)
{
double[] b = new double[12];
double[] c = new double[12];
for (int y = 1; y <= 12; y++)
{
var FirstDay = new DateTime(Convert.ToInt32(i), y, 1);
var LastDay = FirstDay.AddMonths(1).AddDays(-1);
string sql2 = "select isnull(count(*),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
b[y - 1] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
string sql3 = "select isnull(sum(总价),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd3 = new SqlCommand(sql3, conn);
conn.Open();
c[y - 1] = Convert.ToInt32(cmd3.ExecuteScalar());
conn.Close();
}
chart2.Series[x].Points.DataBindXY(月份, b);
chart3.Series[x].Points.DataBindXY(月份, c);
}
chart2.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart2.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart2.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart2.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
chart3.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart3.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart3.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart3.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart3.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart3.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
}
//图像展示
private void uiButton2_Click(object sender, EventArgs e)
{
string sql = "select order1.汽车名称,count(order1.汽车名称) as 销售量 from order1,cars where 厂商='" + Class1.厂商 + "'and cars.汽车名称=order1.汽车名称 group by order1.汽车名称";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
chart1.DataSource = dt;
chart1.Series["Series1"]["PieLineColor"] = "Black";//连线颜色
chart1.Series["Series1"]["PieLabelStyle"] = "Outside";//标签位置
chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 45;//倾斜度(0~90)
chart1.Series[0].IsValueShownAsLabel = true;
chart1.Series["Series1"].XValueMember = "汽车名称";
chart1.Series["Series1"].YValueMembers = "销售量";
int j;
string sql汽车 = "select count(汽车名称) from cars where 厂商='" + Class1.厂商 + "'";
SqlCommand cmd汽车 = new SqlCommand(sql汽车, conn);
conn.Open();
j = Convert.ToInt32(cmd汽车.ExecuteScalar());
conn.Close();
string[] a = new string[j];
for (int x = 0; x < j; x++)
{
a[x] = dt.Rows[x][0].ToString();
chart2.Series[x].Name = a[x];
chart3.Series[x].Name = a[x];
}
i = comboBox1.Text;
string[] 季度 = new string[] { "第一季度", "第二季度", "第三季度", "第四季度" };
for (int x = 0; x < j; x++)
{
double[] b = new double[4];
double[] c = new double[4];
for (int y = 0; y <= 3; y++)
{
var FirstDay = new DateTime(Convert.ToInt32(i), 3 * y + 1, 1);
var FirstDay1 = new DateTime(Convert.ToInt32(i), 3 * y + 3, 1);
var LastDay = FirstDay1.AddMonths(1).AddDays(-1);
string sql2 = "select isnull(count(*),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
b[y] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
string sql3 = "select isnull(sum(总价),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd3 = new SqlCommand(sql3, conn);
conn.Open();
c[y] = Convert.ToInt32(cmd3.ExecuteScalar());
conn.Close();
}
chart2.Series[x].Points.DataBindXY(季度, b);
chart3.Series[x].Points.DataBindXY(季度, c);
}
chart2.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart2.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart2.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart2.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
chart3.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart3.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart3.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart3.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart3.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart3.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
}
private void uiButton4_Click(object sender, EventArgs e)
{
string sql = "select order1.汽车名称,count(order1.汽车名称) as 销售量 from order1,cars where 厂商='" + Class1.厂商 + "'and cars.汽车名称=order1.汽车名称 group by order1.汽车名称";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
chart1.DataSource = dt;
chart1.Series["Series1"]["PieLineColor"] = "Black";//连线颜色
chart1.Series["Series1"]["PieLabelStyle"] = "Outside";//标签位置
chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 45;//倾斜度(0~90)
chart1.Series[0].IsValueShownAsLabel = true;
chart1.Series["Series1"].XValueMember = "汽车名称";
chart1.Series["Series1"].YValueMembers = "销售量";
int j;
string sql汽车 = "select count(汽车名称) from cars where 厂商='" + Class1.厂商 + "'";
SqlCommand cmd汽车 = new SqlCommand(sql汽车, conn);
conn.Open();
j = Convert.ToInt32(cmd汽车.ExecuteScalar());
conn.Close();
string[] a = new string[j];
for (int x = 0; x < j; x++)
{
a[x] = dt.Rows[x][0].ToString();
chart2.Series[x].Name = a[x];
chart3.Series[x].Name = a[x];
}
i = comboBox1.Text;
string[] 月份 = new string[] { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" };
for (int x = 0; x < j; x++)
{
double[] b = new double[12];
double[] c = new double[12];
for (int y = 1; y <= 12; y++)
{
var FirstDay = new DateTime(Convert.ToInt32(i), y, 1);
var LastDay = FirstDay.AddMonths(1).AddDays(-1);
string sql2 = "select isnull(count(*),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
b[y - 1] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
string sql3 = "select isnull(sum(总价),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd3 = new SqlCommand(sql3, conn);
conn.Open();
c[y - 1] = Convert.ToInt32(cmd3.ExecuteScalar());
conn.Close();
}
chart2.Series[x].Points.DataBindXY(月份, b);
chart3.Series[x].Points.DataBindXY(月份, c);
}
chart2.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart2.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart2.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart2.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
chart3.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart3.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart3.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart3.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart3.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart3.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
}
//图像展示
private void uiButton3_Click(object sender, EventArgs e)
{
string sql = "select order1.汽车名称,count(order1.汽车名称) as 销售量 from order1,cars where 厂商='" + Class1.厂商 + "'and cars.汽车名称=order1.汽车名称 group by order1.汽车名称";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataAdapter ad = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
ad.Fill(dt);
chart1.DataSource = dt;
chart1.Series["Series1"]["PieLineColor"] = "Black";//连线颜色
chart1.Series["Series1"]["PieLabelStyle"] = "Outside";//标签位置
chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart1.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart1.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 45;//倾斜度(0~90)
chart1.Series[0].IsValueShownAsLabel = true;
chart1.Series["Series1"].XValueMember = "汽车名称";
chart1.Series["Series1"].YValueMembers = "销售量";
int j;
string sql汽车 = "select count(汽车名称) from cars where 厂商='" + Class1.厂商 + "'";
SqlCommand cmd汽车 = new SqlCommand(sql汽车, conn);
conn.Open();
j = Convert.ToInt32(cmd汽车.ExecuteScalar());
conn.Close();
string[] a = new string[j];
for (int x = 0; x < j; x++)
{
a[x] = dt.Rows[x][0].ToString();
chart2.Series[x].Name = a[x];
chart3.Series[x].Name = a[x];
}
i = comboBox1.Text;
string[] 季度 = new string[] { "第一季度", "第二季度", "第三季度", "第四季度" };
for (int x = 0; x < j; x++)
{
double[] b = new double[4];
double[] c = new double[4];
for (int y = 0; y <= 3; y++)
{
var FirstDay = new DateTime(Convert.ToInt32(i), 3 * y + 1, 1);
var FirstDay1 = new DateTime(Convert.ToInt32(i), 3 * y + 3, 1);
var LastDay = FirstDay1.AddMonths(1).AddDays(-1);
string sql2 = "select isnull(count(*),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
b[y] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
string sql3 = "select isnull(sum(总价),0) from order1 where 汽车名称='" + a[x] + "' and 下单时间>='" + FirstDay.ToString() + "' and 下单时间<='" + LastDay.ToString() + "'";
SqlCommand cmd3 = new SqlCommand(sql3, conn);
conn.Open();
c[y] = Convert.ToInt32(cmd3.ExecuteScalar());
conn.Close();
}
chart2.Series[x].Points.DataBindXY(季度, b);
chart3.Series[x].Points.DataBindXY(季度, c);
}
chart2.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart2.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart2.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart2.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart2.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart2.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
chart3.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart3.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart3.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 30;//倾斜度(0~90)
chart3.ChartAreas["ChartArea1"].AxisX.Interval = 1; //决定x轴显示文本的间隔,1为强制每个柱状体都显示,3则间隔3个显示
chart3.ChartAreas["ChartArea1"].AxisX.LabelStyle.Font = new Font("宋体", 9, FontStyle.Regular);
chart3.ChartAreas["ChartArea1"].AxisX.MajorGrid.Enabled = false;
}
//图像展示
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
string s = comboBox3.Text;
string[] 年龄 = new string[] { "18岁以下", "18-30岁", "31-40岁", "41-50岁", "51-60岁", "60岁以上" };
double[] 数量 = new double[6];
for (int x = 0; x < 6; x++)
{
string sql2 = "select isnull(count(*),0) from order1,users where order1.用户名=users.用户名 and 汽车名称='" + s + "' and 年龄='" + 年龄[x] + "'";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
数量[x] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
}
chart4.Series[0].Points.DataBindXY(年龄, 数量);
chart4.Series["Series1"]["PieLineColor"] = "Black";//连线颜色
chart4.Series["Series1"]["PieLabelStyle"] = "Outside";//标签位置
chart4.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;//开启三维模式;PointDepth:厚度BorderWidth:边框宽
chart4.ChartAreas["ChartArea1"].Area3DStyle.Rotation = 15;//起始角度
chart4.ChartAreas["ChartArea1"].Area3DStyle.Inclination = 45;//倾斜度(0~90)
chart4.Series[0].IsValueShownAsLabel = true;
chart4.Series["Series1"].XValueMember = "年龄";
chart4.Series["Series1"].YValueMembers = "销售量";
}
//年龄分析
private void 详情ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (uiDataGridView1.CurrentRow.Cells[0].Value.ToString() == string.Empty)
MessageBox.Show("请选择一个订单", "提示");
else
{
Class1.订单号 = uiDataGridView1.CurrentRow.Cells[0].Value.ToString();
string sql = @"select 姓名 from users,order1 where order1.用户名=users.用户名 and 订单编号=@订单编号";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@订单编号", SqlDbType.NVarChar, 50).Value = Class1.订单号; ;
try
{
conn.Open();
Class1.姓名 = cmd.ExecuteScalar().ToString();
}
catch(SqlException ex)
{
MessageBox.Show(ex.ToString(), "失败");
}
finally
{
conn.Close();
}
订单详情 f = new 订单详情();
f.Show();
}//查看所选订单的详情
}
private void 查看订单ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (uiDataGridView2.CurrentRow.Cells[4].Value.ToString() == string.Empty)
MessageBox.Show("请选择一个订单", "提示");
else
{
Class1.订单号 = uiDataGridView2.CurrentRow.Cells[4].Value.ToString();
string sql = @"select 姓名 from users,order1 where users.用户名=order1.用户名 and order1.订单编号=@订单编号";
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.Parameters.Add("@订单编号", SqlDbType.NVarChar, 50).Value = Class1.订单号;
conn.Open();
Class1.姓名 = cmd.ExecuteScalar().ToString();
conn.Close();
订单详情 f = new 订单详情();
f.Show();
}
}//查看所选订单的详情
private void 回复ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (uiDataGridView2.CurrentRow.Cells[0].Value.ToString() == string.Empty)
MessageBox.Show("请选择一个反馈", "提示");
else
{
Class1.反馈编号 = uiDataGridView2.CurrentRow.Cells[0].Value.ToString();
厂家回复 f = new 厂家回复();
f.Show();
}//进入回复页面,给予用户回复
}
private void uiButton5_Click(object sender, EventArgs e)
{
System.Diagnostics.Process.Start("C:\\i-car\\各地销量.py");//python地图动态展示
}
private void uiDatePicker1_ValueChanged(object sender, DateTime value)
{
string t = comboBox4.Text;
string[] 种类 = new string[] { "外观异常", "动力异常", "内饰损坏", "系统安全", "其他" };
double[] 数量1 = new double[5];
for (int x = 0; x < 5; x++)
{
string sql2 = "select isnull(count(*),0) from baoxiu,order1 where baoxiu.类型='" + 种类[x] + "' and baoxiu.订单编号=order1.订单编号 and order1.汽车名称='" + comboBox4.Text + "' and baoxiu.时间>='" + uiDatePicker1.Text + "' and baoxiu.时间<='" + uiDatePicker2.Text + "' group by baoxiu.类型";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
数量1[x] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
}
chart5.Series[0].Points.DataBindXY(种类, 数量1);
}
private void uiDatePicker2_ValueChanged(object sender, DateTime value)
{
string t = comboBox4.Text;
string[] 种类 = new string[] { "外观异常", "动力异常", "内饰损坏", "系统安全", "其他" };
double[] 数量1 = new double[5];
for (int x = 0; x < 5; x++)
{
string sql2 = "select isnull(count(*),0) from baoxiu,order1 where baoxiu.类型='" + 种类[x] + "' and baoxiu.订单编号=order1.订单编号 and order1.汽车名称='" + comboBox4.Text + "' and baoxiu.时间>='" + uiDatePicker1.Text + "' and baoxiu.时间<='" + uiDatePicker2.Text + "' group by baoxiu.类型";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
数量1[x] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
}
chart5.Series[0].Points.DataBindXY(种类, 数量1);
}
private void comboBox4_SelectedIndexChanged(object sender, EventArgs e)
{
string t = comboBox4.Text;
string[] 种类 = new string[] { "外观异常", "动力异常", "内饰损坏", "系统安全", "其他" };
double[] 数量1 = new double[5];
for (int x = 0; x < 5; x++)
{
string sql2 = "select isnull(count(*),0) from baoxiu,order1 where baoxiu.类型='" + 种类[x] + "' and baoxiu.订单编号=order1.订单编号 and order1.汽车名称='" + comboBox4.Text + "' and baoxiu.时间>='" + uiDatePicker1.Text + "' and baoxiu.时间<='" + uiDatePicker2.Text + "' group by baoxiu.类型";
SqlCommand cmd2 = new SqlCommand(sql2, conn);
conn.Open();
数量1[x] = Convert.ToInt32(cmd2.ExecuteScalar());
conn.Close();
}
chart5.Series[0].Points.DataBindXY(种类, 数量1);//不同车辆故障分析
}
}
}