天津投入产出系统后端
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.

299 lines
8.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
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 QMFrameWork.WebUI.DataSource;
using QMFrameWork.Common.Serialization;
using QMAPP.MESReport.Entity.LineQTY;
using System.Collections;
using System.Reflection;
using QMFrameWork.ServiceInterface;
using System.Data.SqlClient;
using System.Data;
using QMAPP.Common.Web.Util;
using QMFrameWork.WebUI.QMEChart;
using QMFrameWork.WebUI.QMEChart.Data;
using QMAPP.MESReport.Web.Models;
using QMAPP.MESReport.BLL.LineQTY;
using System.Text;
namespace QMAPP.MESReport.Web.Controllers
{
/// <summary>
/// 节拍统计
/// 于子清
/// 2017-10-30
/// </summary>
public class ProduceCycleTimeController : QController
{
/// <summary>
///
/// </summary>
/// <returns></returns>
public ActionResult Index()
{
ProduceCycleTimeVModel seachModel = new ProduceCycleTimeVModel();
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);
}
#region 异步刷新TABLE
/// <summary>
/// 异步刷新TABLE
/// </summary>
/// <param name="pageIndex"></param>
/// <returns></returns>
public ActionResult GetTable(string MACHINECODDE, string START_DATE, string END_DATE)
{
ServiceAgent wcfAgent = this.GetServiceAgent();
ProduceCycleTimeDModel condition = new ProduceCycleTimeDModel();
condition.MACHINECODDE = MACHINECODDE;
condition.START_DATE = START_DATE;
condition.END_DATE = END_DATE;
List<ProduceCycleTimeDModel> nli = new List<ProduceCycleTimeDModel>();
try
{
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<ProduceCycleTimeDModel>>>("ProduceCycleTimeBLL_GetAllList", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
string sss = GetHTMLStr(nli);
return Json(sss);
}
#endregion
#region 拼接字符串
/// <summary>
/// 拼接字符串
/// </summary>
/// <returns></returns>
public string GetHTMLStr(List<ProduceCycleTimeDModel> nli)
{
StringBuilder html = new StringBuilder();
if (nli == null)
{
return "没有数据";
}
//拼接表头
html.Append("<tr><td class='L1cos'>设备编号</td>");
foreach (ProduceCycleTimeDModel item in nli)
{
html.Append("<td>");
if (item.MACHINECODDE.Equals("累计"))
{
html.Append(item.MACHINECODDE);
}
else
{
html.Append(item.MACHINECODDE);
}
html.Append("</td>");
}
html.Append("</tr>");
Dictionary<string, List<ProduceCycleTimeDModel>> dls = new Dictionary<string, List<ProduceCycleTimeDModel>>();
//对结果集分类
foreach (ProduceCycleTimeDModel item in nli)
{
if (dls.Keys.Contains(item.MACHINECODDE))// + item.MATERIAL_CODE
{
//则添加到KEY下
dls[item.MACHINECODDE].Add(item);//+ item.MATERIAL_CODE
continue;
}
else
{
//新建key
List<ProduceCycleTimeDModel> li = new List<ProduceCycleTimeDModel>();
li.Add(item);
dls.Add(item.MACHINECODDE, li);//+ item.MATERIAL_CODE
}
}
//拼接主体数据
//html.Append("<tr>");
//html.Append("<td>生产节拍(s)</td>");
//foreach (List<ProduceCycleTimeDModel> item in dls.Values)
//{
// foreach (ProduceCycleTimeDModel itit in item)
// {
// html.Append("<td>");
// html.Append(Convert.ToDouble(itit.CYCLETIME).ToString("#0.00"));
// html.Append("</td>");
// }
//}
//html.Append("</tr>");
html.Append("<tr>");
html.Append("<td>生产节拍(s)</td>");
foreach (List<ProduceCycleTimeDModel> item in dls.Values)
{
foreach (ProduceCycleTimeDModel itit in item)
{
html.Append("<td>");
html.Append(Convert.ToDouble(itit.val).ToString("#0.00"));
html.Append("</td>");
}
}
html.Append("</tr>");
return html.ToString();
}
#endregion
/// <summary>
/// 堆积柱状图
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult GetEchartDataBar2()
{
ProduceCycleTimeVModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
ProduceCycleTimeDModel condition = null;
List<ProduceCycleTimeDModel> nli = new List<ProduceCycleTimeDModel>();
try
{
//获取查询对象
seachModel = GetModel<ProduceCycleTimeVModel>();
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<ProduceCycleTimeDModel, ProduceCycleTimeVModel>(seachModel);
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<ProduceCycleTimeDModel>>>("ProduceCycleTimeBLL_GetAllList", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
#region 源数据定义
string category = "", val1 = "",dou="";
bool first = true;
foreach (ProduceCycleTimeDModel item in nli)
{
category += dou + "'" + item.MACHINECODDE + "'";
val1 += dou + "'" + item.val + "'";
if (first)
{
first = false;
dou = ",";
}
}
string strOption = @"{
tooltip: {
trigger: 'axis'
},
toolbox: {
show: false,
feature: {
mark: { show: true },
dataView: { show: true, readOnly: false },
magicType: { show: true, type: ['line', 'bar'] },
restore: { show: true },
saveAsImage: { show: true }
}
},
calculable: true,
legend: {
data: ['生产节拍(s)']
},
xAxis: [
{
type: 'category',
data: ["+category+@"]
}
],
yAxis: [
{
type: 'value',
name: 's',
axisLabel: {
formatter: '{value} s'
}
}
],
series: [
{
name: '生产节拍(s)',
type: 'bar',
data: ["+val1+@"]
}
]
}";
#endregion
return Content(strOption);
}
#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
}
}