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 { /// /// 设备利用率分析 /// 于子清 /// 2017-10-26 /// public class EqueUseCountController : QController { public ActionResult Index() { return View(); } /// /// 异步刷新TABLE /// /// /// public ActionResult GetTable(string EQPT_CODE, string TYPE_COUNT, string START_DATE, string END_DATE) { ServiceAgent wcfAgent = this.GetServiceAgent(); EqueUseCountDModel condition = new EqueUseCountDModel(); condition.EQPT_CODE = EQPT_CODE; condition.TYPE_COUNT = TYPE_COUNT; condition.START_DATE = START_DATE; condition.END_DATE = END_DATE; List nli = new List(); try { #region wcf服务统一接口 var dataResult = wcfAgent.InvokeServiceFunction>>("EqueUseCountBLL_GetAllList", condition); nli = dataResult.Result; #endregion } catch (Exception ex) { throw ex; } string sss = GetHTMLStr(nli, TYPE_COUNT); return Json(sss); } /// /// 拼接字符串 /// /// public string GetHTMLStr(List nli, string TYPE_COUNT) { StringBuilder html = new StringBuilder(); if (nli == null) { return "没有数据"; } //拼接表头 第一行 html.Append("产品种类"); string timetype = "号"; if (TYPE_COUNT == "WEEK") { timetype = "周"; } else if (TYPE_COUNT == "MONTH") { timetype = "月"; } foreach (EqueUseCountDModel item in nli) { if (html.ToString().Contains(item.TDAY + timetype)) { continue; } html.Append(""); if (item.TDAY.Equals("累计")) { html.Append(item.TDAY); } else { html.Append(item.TDAY + timetype); } html.Append(""); } html.Append(""); //拼接主体数据 html.Append(""); html.Append("开机时间(h)"); html.Append(""); foreach (EqueUseCountDModel item in nli) { html.Append(""); html.Append(item.BOOTTIMES); html.Append(""); } html.Append(""); html.Append(""); html.Append("加工时间(h)"); html.Append(""); foreach (EqueUseCountDModel item in nli) { html.Append(""); html.Append(item.WORKTIMES); html.Append(""); } html.Append(""); html.Append(""); html.Append("利用率"); html.Append(""); foreach (EqueUseCountDModel item in nli) { html.Append(""); html.Append((Convert.ToDouble(item.WORKTIMES) / Convert.ToDouble(item.BOOTTIMES) * 100).ToString("0")+"%"); html.Append(""); } html.Append(""); html.Append(""); html.Append("目标值"); html.Append(""); foreach (EqueUseCountDModel item in nli) { html.Append(""); html.Append(item.val+"%"); html.Append(""); } html.Append(""); return html.ToString(); } /// /// 堆积柱状图 /// /// 处理结果 [HandleException] public ActionResult GetEchartDataBar2() { EqueUseCountVModel seachModel = null; DataPage page = null; ServiceAgent wcfAgent = this.GetServiceAgent(); EqueUseCountDModel condition = null; List nli = new List(); try { //获取查询对象 seachModel = GetModel(); //获取前台分页设置信息 page = this.GetDataPage(seachModel); condition = CopyToModel(seachModel); #region wcf服务统一接口 var dataResult = wcfAgent.InvokeServiceFunction>>("EqueUseCountBLL_GetAllList", condition); nli = dataResult.Result; #endregion } catch (Exception ex) { throw ex; } string kaiji = "", jiagong = "", wlv = "", mlv = "",dou="",tday="",timetype="号"; bool first = true; if (condition.TYPE_COUNT=="WEEK") { timetype = "周"; } else if (condition.TYPE_COUNT=="MONTH") { timetype = "月"; } if (nli==null) { return Content("没有数据"); } foreach (EqueUseCountDModel item in nli) { kaiji += dou + "'" + item.BOOTTIMES + "'"; jiagong += dou + "'" + item.WORKTIMES + "'"; wlv += dou + "'" + (Convert.ToDouble(item.WORKTIMES) / Convert.ToDouble(item.BOOTTIMES) * 100).ToString("0") + "'"; mlv += dou + "'" + item.val + "'"; tday += dou + "'" + item.TDAY + timetype + "'"; if (first) { first = false; dou = ","; } } #region 源数据定义 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: ['开机时间', '加工时间', '利用率', '目标值'] }, xAxis: [ { type: 'category', data: [" + tday + @"] } ], yAxis: [ { type: 'value', name: '小时', axisLabel: { formatter: '{value} h' } }, { type: 'value', name: '百分比', axisLabel: { formatter: '{value} %' } } ], series: [ { name: '开机时间', type: 'bar', data: [" + kaiji + @"] }, { name: '加工时间', type: 'bar', data: [" + jiagong + @"] }, { name: '利用率', type: 'line', yAxisIndex: 1, data: [" + wlv + @"] ,itemStyle: { normal: { label: { show: true}} } }, { name: '目标值', type: 'line', yAxisIndex: 1, data: [" + mlv + @"] , itemStyle: { normal: { label: { show: true}} } } ] }"; #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 } }