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-30 /// public class ProduceCycleTimeController : QController { /// /// /// /// 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 /// /// 异步刷新TABLE /// /// /// 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 nli = new List(); try { #region wcf服务统一接口 var dataResult = wcfAgent.InvokeServiceFunction>>("ProduceCycleTimeBLL_GetAllList", condition); nli = dataResult.Result; #endregion } catch (Exception ex) { throw ex; } string sss = GetHTMLStr(nli); return Json(sss); } #endregion #region 拼接字符串 /// /// 拼接字符串 /// /// public string GetHTMLStr(List nli) { StringBuilder html = new StringBuilder(); if (nli == null) { return "没有数据"; } //拼接表头 html.Append("设备编号"); foreach (ProduceCycleTimeDModel item in nli) { html.Append(""); if (item.MACHINECODDE.Equals("累计")) { html.Append(item.MACHINECODDE); } else { html.Append(item.MACHINECODDE); } html.Append(""); } html.Append(""); Dictionary> dls = new Dictionary>(); //对结果集分类 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 li = new List(); li.Add(item); dls.Add(item.MACHINECODDE, li);//+ item.MATERIAL_CODE } } //拼接主体数据 //html.Append(""); //html.Append("生产节拍(s)"); //foreach (List item in dls.Values) //{ // foreach (ProduceCycleTimeDModel itit in item) // { // html.Append(""); // html.Append(Convert.ToDouble(itit.CYCLETIME).ToString("#0.00")); // html.Append(""); // } //} //html.Append(""); html.Append(""); html.Append("生产节拍(s)"); foreach (List item in dls.Values) { foreach (ProduceCycleTimeDModel itit in item) { html.Append(""); html.Append(Convert.ToDouble(itit.val).ToString("#0.00")); html.Append(""); } } html.Append(""); return html.ToString(); } #endregion /// /// 堆积柱状图 /// /// 处理结果 [HandleException] public ActionResult GetEchartDataBar2() { ProduceCycleTimeVModel seachModel = null; DataPage page = null; ServiceAgent wcfAgent = this.GetServiceAgent(); ProduceCycleTimeDModel condition = null; List nli = new List(); try { //获取查询对象 seachModel = GetModel(); //获取前台分页设置信息 page = this.GetDataPage(seachModel); condition = CopyToModel(seachModel); #region wcf服务统一接口 var dataResult = wcfAgent.InvokeServiceFunction>>("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 } }