265 lines
9.7 KiB
C#
265 lines
9.7 KiB
C#
using ClosedXML.Excel;
|
|
using LeatherApp.Utils;
|
|
using Models;
|
|
using Newtonsoft.Json.Linq;
|
|
using Service;
|
|
using SqlSugar;
|
|
using Sunny.UI;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Drawing.Imaging;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace LeatherApp.Page
|
|
{
|
|
public partial class FChart : UIPage
|
|
{
|
|
RecordsService service=new RecordsService();
|
|
public FChart()
|
|
{
|
|
InitializeComponent();
|
|
initData();
|
|
}
|
|
private void initData()
|
|
{
|
|
this.uiProcessDay.Maximum = this.uiProcessMonth.Maximum = this.uiProcessQuarter.Maximum = this.uiProcessYear.Maximum = 100;
|
|
|
|
var list1 = service.GetReport_Qualified_Total("");
|
|
this.lblTotal_Day.Text += list1[0][0].ToString();
|
|
this.lblQualified_Day.Text += list1[0][1].ToString();
|
|
this.uiProcessDay.Value = list1[0][0] > 0 ? list1[0][1] / list1[0][0] : 0;
|
|
|
|
this.lblTotal_Month.Text += list1[1][0].ToString();
|
|
this.lblQualified_Month.Text += list1[1][1].ToString();
|
|
this.uiProcessMonth.Value = list1[1][0] > 0 ? list1[1][1] / list1[1][0] : 0;
|
|
|
|
this.lblTotal_Quarter.Text += list1[2][0].ToString();
|
|
this.lblQualified_Quarter.Text += list1[2][1].ToString();
|
|
this.uiProcessQuarter.Value = list1[2][0] > 0 ? list1[2][1] / list1[2][0] : 0;
|
|
|
|
this.lblTotal_Year.Text += list1[3][0].ToString();
|
|
this.lblQualified_Year.Text += list1[3][1].ToString();
|
|
this.uiProcessYear.Value = list1[3][0] > 0 ? list1[3][1] / list1[3][0] : 0;
|
|
|
|
//
|
|
var exp = createQueryExpression();
|
|
|
|
try
|
|
{
|
|
string data = service.GetReport_Qualified_Date(exp);
|
|
JArray jArray = JArray.Parse(data);
|
|
initQualifiedChar(jArray);
|
|
|
|
data = service.GetReport_Defects_Date(exp);
|
|
jArray = JArray.Parse(data);
|
|
initDefectChar(jArray);
|
|
|
|
data = service.GetReport_Defects_Total(exp);
|
|
jArray = JArray.Parse(data);
|
|
initPieChar((JObject)jArray[0]);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
API.OutputDebugString("FCHAR Err:"+ex.Message+ex.StackTrace);
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 合格率趋势图
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
private void initQualifiedChar(JArray data)
|
|
{
|
|
UIBarOption option = new UIBarOption();
|
|
option.Title = new UITitle();
|
|
option.Title.Text = barcharQualified.Text;
|
|
//option.Title.SubText = "BarChart";
|
|
|
|
//设置Legend
|
|
option.Legend = new UILegend();
|
|
option.Legend.Orient = UIOrient.Horizontal;
|
|
option.Legend.Top = UITopAlignment.Top;
|
|
option.Legend.Left = UILeftAlignment.Left;
|
|
option.Legend.AddData("总量");
|
|
option.Legend.AddData("合格量");
|
|
|
|
var series = new UIBarSeries();
|
|
series.Name = "总量";
|
|
var series2 = new UIBarSeries();
|
|
series2.Name = "合格量";
|
|
foreach (JObject item in data)
|
|
{
|
|
series.AddData(item.Value<int>("Total"));
|
|
series2.AddData(item.Value<int>("Qualified"));
|
|
option.XAxis.Data.Add(item.Value<DateTime>("Date").ToString("yyyy-MM-dd"));
|
|
}
|
|
|
|
//数据显示小数位数
|
|
series.DecimalPlaces = 0;
|
|
series2.DecimalPlaces = 0;
|
|
option.Series.Add(series);
|
|
option.Series.Add(series2);
|
|
|
|
option.ToolTip.Visible = true;
|
|
option.YAxis.Scale = true;
|
|
|
|
option.XAxis.Name = "日期";
|
|
option.XAxis.AxisLabel.Angle = 30;//(0° ~ 90°)
|
|
|
|
option.YAxis.Name = "数值";
|
|
|
|
//坐标轴显示小数位数
|
|
option.YAxis.AxisLabel.DecimalPlaces = 0;
|
|
|
|
//option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Red, Name = "上限", Value = 12 });
|
|
//option.YAxisScaleLines.Add(new UIScaleLine() { Color = Color.Gold, Name = "下限", Value = -20 });
|
|
|
|
option.ToolTip.AxisPointer.Type = UIAxisPointerType.Shadow;
|
|
|
|
option.ShowValue = true;
|
|
|
|
barcharQualified.SetOption(option);
|
|
}
|
|
/// <summary>
|
|
/// 瑕疵量趋势图
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
private void initDefectChar(JArray data)
|
|
{
|
|
UILineOption option = new UILineOption();
|
|
option.ToolTip.Visible = true;
|
|
option.Title = new UITitle();
|
|
option.Title.Text = linecharDefect.Text;
|
|
//option.Title.SubText = "LineChart";
|
|
|
|
option.XAxisType = UIAxisType.DateTime;
|
|
foreach (JObject obj in data)
|
|
{
|
|
string date = obj.Value<DateTime>("Date").ToString("yyyy-MM-dd");
|
|
if(!option.XAxis.Data.Contains(date))
|
|
option.XAxis.Data.Add(date);
|
|
foreach (var item in obj.Properties())
|
|
{
|
|
if (item.Name == "Date") continue;
|
|
if (!option.Series.ContainsKey(item.Name))
|
|
option.AddSeries(new UILineSeries(item.Name)).ShowLine=true;
|
|
|
|
option.Series[item.Name].Add(date, (int)item.Value);
|
|
}
|
|
}
|
|
option.GreaterWarningArea = new UILineWarningArea(3.5);
|
|
option.LessWarningArea = new UILineWarningArea(2.2, Color.Gold);
|
|
|
|
option.YAxisScaleLines.Add(new UIScaleLine("上限", 3.5, Color.Red));
|
|
option.YAxisScaleLines.Add(new UIScaleLine("下限", 2.2, Color.Gold));
|
|
|
|
option.XAxis.Name = "日期";
|
|
option.YAxis.Name = "数值";
|
|
//X轴坐标轴显示格式化
|
|
option.XAxis.AxisLabel.DateTimeFormat = "yyyy-MM-dd";
|
|
|
|
//Y轴坐标轴显示小数位数
|
|
option.YAxis.AxisLabel.DecimalPlaces = 0;
|
|
|
|
//设置X轴显示范围
|
|
//option.XAxis.SetRange(dt, dt.AddHours(8));
|
|
linecharDefect.SetOption(option);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 瑕疵分布图
|
|
/// </summary>
|
|
/// <param name="data"></param>
|
|
private void initPieChar(JObject data)
|
|
{
|
|
var option = new UIPieOption();
|
|
|
|
//设置Title
|
|
option.Title = new UITitle();
|
|
option.Title.Text = pieDefect.Text;
|
|
option.Title.SubText = "";
|
|
option.Title.Left = UILeftAlignment.Center;
|
|
|
|
//设置ToolTip
|
|
option.ToolTip.Visible = true;
|
|
|
|
//设置Legend
|
|
option.Legend = new UILegend();
|
|
option.Legend.Orient = UIOrient.Vertical;
|
|
option.Legend.Top = UITopAlignment.Top;
|
|
option.Legend.Left = UILeftAlignment.Left;
|
|
|
|
//设置Series
|
|
var series = new UIPieSeries();
|
|
series.Name = "瑕疵数量";
|
|
series.Center = new UICenter(50, 55);
|
|
series.Radius = 70;
|
|
series.Label.Show = true;
|
|
|
|
foreach (var item in data.Properties())
|
|
{
|
|
option.Legend.AddData(item.Name);
|
|
series.AddData(item.Name, (double)item.Value);
|
|
}
|
|
|
|
//增加Series
|
|
option.Series.Clear();
|
|
option.Series.Add(series);
|
|
|
|
//显示数据小数位数
|
|
option.DecimalPlaces = 1;
|
|
|
|
//设置Option
|
|
pieDefect.SetOption(option);
|
|
}
|
|
|
|
private Expression<Func<Records, bool>> createQueryExpression()
|
|
{
|
|
//return Expressionable.Create<Records>()
|
|
// .And(it => it.CreateTime >= uiDatePicker1.Value.SetTime(0,0,0))
|
|
// .And(it => it.CreateTime < uiDatePicker2.Value.SetTime(0, 0, 0).AddDays(1))
|
|
// .AndIF(!string.IsNullOrWhiteSpace(txtBatchId.Text), it => it.BatchId.Contains(txtBatchId.Text.Trim()))
|
|
// .AndIF(!string.IsNullOrWhiteSpace(txtReelId.Text), it => it.ReelId.Contains(txtReelId.Text.Trim()))
|
|
// .ToExpression();//注意 这一句 不能少
|
|
return null;
|
|
}
|
|
|
|
private void FChart_Shown(object sender, EventArgs e)
|
|
{
|
|
barcharQualified.Height = linecharDefect.Height = pieDefect.Height / 2 - 5;
|
|
linecharDefect.Top = pieDefect.Top+ pieDefect.Height/2 + 5;
|
|
}
|
|
|
|
private void btnQuery_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void btnBack_Click(object sender, EventArgs e)
|
|
{
|
|
Frame.SelectPage(1002);
|
|
}
|
|
|
|
private void btnExport_Click(object sender, EventArgs e)
|
|
{
|
|
Bitmap bmp = new Bitmap(this.Width, this.Height);
|
|
Graphics graphics = Graphics.FromImage(bmp);
|
|
Rectangle rectangle = new Rectangle(0, 0, this.Width, this.Height);
|
|
this.DrawToBitmap(bmp, rectangle);
|
|
var path=FileUtil.saveAsFile("分析图.jpg", "图像文件|*.jpg");
|
|
if (string.IsNullOrWhiteSpace(path))
|
|
return;
|
|
bmp.Save(path,ImageFormat.Jpeg);
|
|
UIMessageTip.ShowOk("导出成功!", 1000);
|
|
System.Diagnostics.Process.Start(path);
|
|
}
|
|
}
|
|
}
|