using System; using System.Collections.Generic; using System.Data; using System.Linq; 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 System.Text; using QMFrameWork.Common.ExcelOperation; using QMFrameWork.Log; using ExcelOperationHelper = QMAPP.MESReport.Web.Common.ExcelOperationHelper; namespace QMAPP.MESReport.Web.Controllers { /// /// 返修率统计 /// 于子清 /// 2017-10-25 /// public class RepairRateCountController : QController { public ActionResult Index() { RepairRateCountVModel seachModel = new RepairRateCountVModel(); 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); } /// /// 异步刷新TABLE /// /// /// public ActionResult GetTable(string WORKCENTER_CODE, string START_DATE, string END_DATE) { ServiceAgent wcfAgent = this.GetServiceAgent(); RepairRateCountDModel condition = new RepairRateCountDModel(); condition.WORKCENTER_CODE = WORKCENTER_CODE; condition.START_DATE = START_DATE; condition.END_DATE = END_DATE; //返修结果-维修 condition.MENDRESULT = "0"; List nli = new List(); try { #region wcf服务统一接口 var dataResult = wcfAgent.InvokeServiceFunction>>("RepairRateCountBLL_GetAllList", condition); nli = dataResult.Result; #endregion } catch (Exception ex) { throw ex; } string sss = GetHTMLStr(nli, WORKCENTER_CODE); return Json(sss); } /// /// 拼接字符串 /// /// public string GetHTMLStr(List nli, string WORKCENTER_CODE) { StringBuilder html = new StringBuilder(); if (nli == null || nli.Count == 0) { return "没有数据"; } var workcenter = ""; if (!string.IsNullOrEmpty(WORKCENTER_CODE)) { if (WORKCENTER_CODE == "0") { workcenter = "注塑"; } if (WORKCENTER_CODE == "1") { workcenter = "门板"; } if (WORKCENTER_CODE == "2") { workcenter = "仪表板"; } } //拼接表头 html.Append("" + workcenter + ""); foreach (RepairRateCountDModel item in nli) { html.Append(""); html.Append(item.MATERIAL_SHORT); html.Append(""); } html.Append(""); //拼接第一行 html.Append("返修"); foreach (RepairRateCountDModel item in nli) { html.Append(""); html.Append(item.QTY); html.Append(""); } html.Append(""); //拼接第二行 html.Append("生产"); foreach (RepairRateCountDModel item in nli) { html.Append(""); html.Append(item.COMPLETE_QTY); html.Append(""); } html.Append(""); return html.ToString(); } /// /// 堆积柱状图 /// /// 处理结果 [HandleException] public ActionResult GetEchartDataBar2() { RepairRateCountVModel seachModel = null; DataPage page = null; ServiceAgent wcfAgent = this.GetServiceAgent(); QTYCompletionRateDModel condition = null; List nli = new List(); try { //获取查询对象 seachModel = GetModel(); //获取前台分页设置信息 page = this.GetDataPage(seachModel); condition = CopyToModel(seachModel); //返修结果-返修 condition.MENDRESULT = "0"; #region wcf服务统一接口 var dataResult = wcfAgent.InvokeServiceFunction>>("RepairRateCountBLL_GetAllList", condition); nli = dataResult.Result; #endregion } catch (Exception ex) { throw ex; } #region //源数据定义 // string mubiao = "", fxlv = "", riqi = "", dou = ""; // bool first = true; // foreach (RepairRateCountDModel item in nli) // { // mubiao += dou + "'" + item.MFlV + "'"; // fxlv += dou + "'" + (Convert.ToDouble(item.REWORK_QTY) / Convert.ToDouble(item.QTY) * 100).ToString("0") + "'"; // riqi += dou + "'" + item.TDAY + "'"; // 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: ['返修率', '目标值'] // }, // xAxis: [ // { // type: 'category', // data: ["+riqi+@"] // } // ], // yAxis: [ // { // type: 'value', // name: '百分比', // axisLabel: { // formatter: '{value} %' // } // } // ], // series: [ // // { // name: '返修率', // type: 'line', // data: [" + fxlv + @"] // }, // { // name: '目标值', // type: 'line', // data: [" + mubiao + @"] // } // ] // }"; #endregion //return Content(strOption); var workcenter = ""; if (!string.IsNullOrEmpty(condition.WORKCENTER_CODE)) { if (condition.WORKCENTER_CODE == "0") { workcenter = "注塑"; } if (condition.WORKCENTER_CODE == "1") { workcenter = "仪表板"; } if (condition.WORKCENTER_CODE == "2") { workcenter = "门板"; } } return Content(setOptionRepair(nli, workcenter + "返修数量", workcenter + "生产数量")); } public string setOptionRepair(List nli, string name1, string name2) { #region 源数据定义 string jihua = "", wancheng = "", wclv = "", riqi = "", dou = ""; bool first = true; if (nli == null || nli.Count == 0) { jihua += "''"; wancheng += "''"; wclv += "''"; riqi += "''"; } else { //jihua += "'',"; //wancheng += "'',"; //wclv += "'',"; //riqi += "'',"; foreach (QTYCompletionRateDModel item in nli) { //jihua=生成数量QTY,wancheng=返修数量COMPLETE_QTY。 借用 jihua += dou + "'" + item.QTY + "'"; wancheng += dou + "'" + item.COMPLETE_QTY + "'"; double fenmu = 1; if (!string.IsNullOrEmpty(item.COMPLETE_QTY) && item.COMPLETE_QTY != "0") { fenmu = Convert.ToDouble(item.COMPLETE_QTY); } double fenzi = 0; if (!string.IsNullOrEmpty(item.QTY)) { fenzi = Convert.ToDouble(item.QTY); } wclv += dou + "'" + (fenzi / fenmu * 100).ToString("0") + "'"; riqi += dou + "'" + item.MATERIAL_SHORT + "'"; if (first) { first = false; dou = ","; } } //jihua += ",''"; //wancheng += ",''"; //wclv += ",''"; //riqi += ",''"; } string strOption = @"{ noDataLoadingOption: { text: '无数据', effect: 'bubble', effectOption: { effect: { n: 0 } } }, dataZoom : { show : true, realtime : true, start : 0, end : 100 }, grid: { y2: 80 }, 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: ['" + name1 + @"', '" + name2 + @"'] }, xAxis: [ { type: 'category', axisLabel : { //坐标轴刻度标签的相关设置。 interval:'auto', rotate:10 }, data: [" + riqi + @"] } ], yAxis: [ { type: 'value', name: '件', axisLabel: { formatter: '{value}' } }, { type: 'value', // name: '百分比', // axisLabel: { // formatter: '{value} %' // } scale: true, name: '百分比', max: 100, min: 0, boundaryGap: [" + wclv + @"] } ], series: [ { name: '" + name1 + @"', type: 'bar', data: [" + jihua + @"] }, { name: '" + name2 + @"', type: 'bar', data: [" + wancheng + @"] }, { name: '返修率', type: 'line', yAxisIndex: 1, data: [" + wclv + @"], itemStyle: { normal: { label: { show: true}} } } ] }"; #endregion return 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 #region 导出excel /// /// 导出excel /// /// 结果 [HandleException] public ActionResult ExportExcel() { QTYCompletionRateVModel seachModel = null; QTYCompletionRateDModel condition = null; DataTable exportDt = new DataTable(); string selectKey = Request["selectKey"]; ServiceAgent wcfAgent = this.GetServiceAgent(); try { //获取查询对象 seachModel = GetModel(); condition = CopyToModel(seachModel); //返修结果-返修 condition.MENDRESULT = "0"; //获取数据 var dataResult = wcfAgent.InvokeServiceFunction>("RepairRateCountBLL_GetExportData", condition); //通过返回dataResult判断 if (dataResult.Ex != null) { throw dataResult.Ex; } else if (dataResult.IsSuccess) { exportDt = dataResult.Result; } else { SetMessage(dataResult.Msg); return View(true); } //根据所选信息进行导出 if (!String.IsNullOrEmpty(selectKey)) { DataView dv = new DataView(exportDt); string strWhere = ""; string[] list = selectKey.Split(":".ToCharArray()); foreach (string ID in list) { strWhere += " PID='" + ID + "' or"; } if (strWhere != "") { strWhere = strWhere.Remove((strWhere.Length - 2), 2); } dv.RowFilter = strWhere; exportDt = dv.ToTable(); } //导出 IEExcelHelper ieExcelHelper = new IEExcelHelper(); var sheetInfo = ieExcelHelper.GetMainInfo("RepairRateCountExp"); var fileName = System.Guid.NewGuid().ToString() + ".xlsx"; ieExcelHelper.ExportExcel(sheetInfo, exportDt, Common.ExcelOperationHelper.GetTempPath() + fileName, true); return Content(fileName); } catch (Exception ex) { LogManager.LogHelper.Error(new LogInfo { ErrorInfo = ex, Info = "导出excel", Tag = "返修率" }); SetMessage("导出excel失败"); return View(true); } } /// /// 导出文件 /// /// public ActionResult ExportFile() { String filePath = Common.ExcelOperationHelper.GetTempPath(); String fileName = Request["FileName"]; ExcelOperationHelper.FileDownload(Response, filePath + fileName, "返修率.xlsx"); return Content(""); } #endregion } }