天津投入产出系统后端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

202 lines
6.8 KiB

using System;
using System.Collections.Generic;
using System.Web.Mvc;
using QMAPP.MESReport.Web.Models.LineQTY;
using QMAPP.Common.Web.Controllers;
using QMFrameWork.WebUI.Attribute;
using QMFrameWork.Data;
using QMAPP.Entity;
using QMAPP.ServicesAgent;
using QMAPP.MESReport.Entity.LineQTY;
using QMFrameWork.WebUI.QMEChart;
using QMFrameWork.WebUI.QMEChart.Data;
using QMAPP.MESReport.Web.Models;
namespace QMAPP.MESReport.Web.Controllers
{
/// <summary>
/// 合格率分析
/// 于子清
/// 2017-10-13
/// </summary>
public class StandardRateCountController : QController
{
/// <summary>
/// 主界面
/// </summary>
/// <returns></returns>
public ActionResult QTYStandardRate()
{
StandardRateVModel seachModel = new StandardRateVModel();
seachModel.START_DATE = DateTime.Now.Date.AddDays(-30).ToString("yyyy-MM-dd HH:mm:ss");
seachModel.END_DATE = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
return View(seachModel);
}
/// <summary>
/// 堆积柱状图
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult GetEchartDataBar2()
{
StandardRateVModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
StandardRateDModel condition = null;
List<StandardRateDModel> nli = new List<StandardRateDModel>();
try
{
//获取查询对象
seachModel = GetModel<StandardRateVModel>();
if (string.IsNullOrEmpty(seachModel.START_DATE) || string.IsNullOrEmpty(seachModel.END_DATE))
{
//return Content(null);
}
else
{
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<StandardRateDModel, StandardRateVModel>(seachModel);
#region wcf服务统一接口
var dataResult =
wcfAgent.InvokeServiceFunction<DataResult<List<StandardRateDModel>>>(
"StandardRateCountBLL_GetMainList", condition);
nli = dataResult.Result;
#endregion
}
}
catch (Exception ex)
{
throw ex;
}
#region 源数据定义
//生成数据
List<TestEChartModel> dataList = new List<TestEChartModel>();
foreach (StandardRateDModel item in nli)
{
dataList.Add(new TestEChartModel() { Week = item.WORKCELL_NAME, Value = item.OK_QTY, TypeValue = "合格", StackValue = "产品数量!" });
dataList.Add(new TestEChartModel() { Week = item.WORKCELL_NAME, Value = item.NOK_QTY, TypeValue = "不合格", StackValue = "产品数量!" });
}
#endregion
#region 默认设置
QMEChartBar chartLBar = new QMEChartBar() { BarType = "bar2" };
//设置源数据列表
chartLBar.DataList = dataList;
#region 设置标题
//不为空时显示Title,为空时不显示
chartLBar.Title = new QMECTitle();
chartLBar.Title.Text = "合格率分析";
chartLBar.Title.Subtext = "数量";
#endregion
#region Tooltip提示窗口设置
//是否显示ToolTip工具条
chartLBar.HaveTooltip = true;
#endregion
#region Legend图例设置
//是否有Legend
chartLBar.HaveLegend = true;
//Legend的自动统计字段,对应chartLine.DataList中用于统计的字段
chartLBar.LegendField = "TypeValue";
#endregion
#region Toolbox工具栏设置
//是否存在工具栏,为空时使用默认设置
chartLBar.HaveToolBox = false;
#endregion
#region XAxis横坐标轴设置
//为空时使用默认值并从数据源中统计类型,需要设置DataList数据源
chartLBar.HaveXAxis = true;
//设置X轴统计类型字段
chartLBar.XAxisField = "Week";
#endregion
#region YAxis纵坐标轴设置
//设置Y轴显示格式。
chartLBar.HaveYAxis = true;
//自定义设置
chartLBar.YAxis = new QMECYAxis() { AxisLabel = new QMECAxisLabel() };
chartLBar.YAxis.Type = "value";
#endregion
#region 堆积字段设置
//堆积字段,是否是堆积图形
chartLBar.StackField = "StackValue";
#endregion
#region 生成图表所需要数据格式
//转换数据格式,值字段
chartLBar.ValueField = "Value";
chartLBar.Series = QMEChartHelper.CovertDataToSeries(chartLBar);
#endregion
#region 辅助线设置,有则设置,没有则无需设置
//设置辅助线
QMECMarkLine ml = new QMECMarkLine() { ItemStyle = new QMECItemStyle() { Normal = new QMECNormal() { LineStyle = new QMECLineStyle() } }, LineData = new List<QMECPoint>() };
ml.ItemStyle.Normal.LineStyle = new QMECLineStyle() { Type = "dashed", Width = 1 };
List<QMECMarkPoint> mp = new List<QMECMarkPoint>();
QMECPoint mpstart = new QMECPoint();
QMECPoint mpend = new QMECPoint();
mpstart.Type = "min";
mpend.Type = "max";
ml.LineData.Add(mpstart);
ml.LineData.Add(mpend);
foreach (QMECSerie ser in chartLBar.Series)
{
if (ser.Name == "搜索引擎")
{
ser.MarkLine = ml;
}
}
#endregion
return Content(QMEChartHelper.QMECHelper<QMEChartBar>(chartLBar));
#endregion
}
#region 导出图片
[HttpPost]
[HandleException]
public ActionResult ExportBanCi()
{
string imgSend = Request.Form["hiChartImg"];
imgSend = imgSend.Replace(" ", "+");
string[] contents = imgSend.Split(',');
imgSend = contents[1];
byte[] content = Convert.FromBase64String(imgSend);
System.Web.Mvc.FileContentResult result = null;
result = new System.Web.Mvc.FileContentResult(content, "application/png");
result.FileDownloadName = System.Web.HttpUtility.UrlEncode("合格率分析.png", System.Text.Encoding.UTF8);
return result;
}
#endregion
}
}