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

1202 lines
40 KiB

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 QMFrameWork.WebUI.QMEChart;
using QMFrameWork.WebUI.QMEChart.Data;
using QMAPP.MESReport.Web.Models;
using System.Text;
using QMFrameWork.Common.ExcelOperation;
using QMFrameWork.Log;
using ExcelOperationHelper = QMAPP.MESReport.Web.Common.ExcelOperationHelper;
namespace QMAPP.MESReport.Web.Controllers
{
/// <summary>
/// 废品率统计--报废原因统计-报废趋势统计
/// 周晓东
/// 20180425
/// </summary>
public class WasteRateCountController : QController
{
#region 废品率统计-柱状图
public ActionResult WasteRateCountView()
{
QTYCompletionRateVModel seachModel = new QTYCompletionRateVModel();
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 表
/// <summary>
/// 异步刷新TABLE
/// </summary>
/// <param name="pageIndex"></param>
/// <returns></returns>
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 = "2";
List<RepairRateCountDModel> nli = new List<RepairRateCountDModel>();
try
{
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<RepairRateCountDModel>>>("RepairRateCountBLL_GetAllList", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
string sss = GetHTMLStr(nli, WORKCENTER_CODE);
return Json(sss);
}
/// <summary>
/// 拼接字符串
/// </summary>
/// <returns></returns>
public string GetHTMLStr(List<RepairRateCountDModel> 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("<tr><td >" + workcenter + "</td>");
foreach (RepairRateCountDModel item in nli)
{
//if (html.ToString().Contains(item.MATERIAL_SHORT))
//{
// continue;
//}
html.Append("<td>");
html.Append(item.MATERIAL_SHORT);
html.Append("</td>");
}
html.Append("</tr>");
//拼接第一行
html.Append("<tr><td >报废</td>");
foreach (RepairRateCountDModel item in nli)
{
//if (html.ToString().Contains(item.MATERIAL_SHORT))
//{
// continue;
//}
html.Append("<td>");
html.Append(item.QTY);
html.Append("</td>");
}
html.Append("</tr>");
//拼接第二行
html.Append("<tr><td >生产</td>");
foreach (RepairRateCountDModel item in nli)
{
//if (html.ToString().Contains(item.MATERIAL_SHORT))
//{
// continue;
//}
html.Append("<td>");
html.Append(item.COMPLETE_QTY);
html.Append("</td>");
}
html.Append("</tr>");
//Dictionary<string, List<RepairRateCountDModel>> dls = new Dictionary<string, List<RepairRateCountDModel>>();
////对结果集分类
//foreach (RepairRateCountDModel item in nli)
//{
// if (dls.Keys.Contains(item.MATERIAL_NAME + item.MATERIAL_SHORT ))
// {
// //则添加到KEY下
// dls[item.MATERIAL_NAME + item.MATERIAL_SHORT ].Add(item);
// continue;
// }
// else
// {
// //新建key
// List<RepairRateCountDModel> li = new List<RepairRateCountDModel>();
// li.Add(item);
// dls.Add(item.MATERIAL_NAME + item.MATERIAL_SHORT , li);
// }
//}
////拼接主体数据
//foreach (List<RepairRateCountDModel> item in dls.Values)
//{
// html.Append("<tr>");
// html.Append("<td>废品率");
// html.Append("</td>");
// foreach (RepairRateCountDModel itit in item)
// {
// html.Append("<td>");
// html.Append((Convert.ToDouble(itit.NOK_QTY)*100/Convert.ToDouble(itit.QTY)).ToString("0.00")+"%");
// html.Append("</td>");
// }
// html.Append("</tr>");
//}
return html.ToString();
}
#endregion
#region 图
[HandleException]
public ActionResult GetEchartDataBar1()
{
RepairRateCountVModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
RepairRateCountDModel condition = null;
List<RepairRateCountDModel> nli = new List<RepairRateCountDModel>();
try
{
//获取查询对象
seachModel = GetModel<RepairRateCountVModel>();
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<RepairRateCountDModel, RepairRateCountVModel>(seachModel);
//返修结果-报废
condition.MENDRESULT = "2";
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<RepairRateCountDModel>>>("RepairRateCountBLL_GetAllList", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
//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<RepairRateCountDModel> 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 (RepairRateCountDModel 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;
}
#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
#region 导出excel
/// <summary>
/// 导出excel
/// </summary>
/// <returns>结果</returns>
[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<QTYCompletionRateVModel>();
condition = CopyToModel<QTYCompletionRateDModel, QTYCompletionRateVModel>(seachModel);
//返修结果-报废
condition.MENDRESULT = "2";
//获取数据
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<DataTable>>("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("WasteRateCountExp");
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);
}
}
/// <summary>
/// 导出文件
/// </summary>
/// <returns></returns>
public ActionResult ExportFile()
{
String filePath = Common.ExcelOperationHelper.GetTempPath();
String fileName = Request["FileName"];
ExcelOperationHelper.FileDownload(Response, filePath + fileName, "废品率.xlsx");
return Content("");
}
#endregion
#endregion
#region 废品原因统计--饼状图
public ActionResult MenderReasonCountView()
{
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);
}
#region 表
/// <summary>
/// 异步刷新TABLE
/// </summary>
/// <param name="pageIndex"></param>
/// <returns></returns>
public ActionResult GetTableReason(string MaterialCode, string WORKCENTER_CODE, string MaterialName, string START_DATE, string END_DATE)
{
ServiceAgent wcfAgent = this.GetServiceAgent();
RepairRateCountDModel condition = new RepairRateCountDModel();
var materialName = MaterialName;
condition.MaterialCode = MaterialCode;
condition.WORKCENTER_CODE = WORKCENTER_CODE;
condition.MaterialName = MaterialName;
condition.START_DATE = START_DATE;
condition.END_DATE = END_DATE;
//报废原因
condition.SelectMender = "0";
List<RepairRateCountDModel> nli = new List<RepairRateCountDModel>();
try
{
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<RepairRateCountDModel>>>("RepairRateCountBLL_GetMenderReason", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
string sss = GetHTMLStrReason(nli, materialName);
return Json(sss);
}
/// <summary>
/// 拼接字符串
/// </summary>
/// <returns></returns>
public string GetHTMLStrReason(List<RepairRateCountDModel> nli, string materialName)
{
StringBuilder html = new StringBuilder();
if (nli == null || nli.Count == 0)
{
return "没有数据";
}
//拼接表头
//html.Append("<tr><td ></td>");
html.Append("<tr>");
foreach (RepairRateCountDModel item in nli)
{
html.Append("<td>");
html.Append(item.DEFECTVALUE);
html.Append("</td>");
}
html.Append("</tr>");
//拼接第一行
//html.Append("<tr><td >" + materialName + "</td>");
html.Append("<tr>");
foreach (RepairRateCountDModel item in nli)
{
html.Append("<td>");
html.Append(item.MENDNUMBER);
html.Append("</td>");
}
html.Append("</tr>");
return html.ToString();
}
#endregion
#region 图
[HandleException]
public ActionResult GetEchartDataPie1()
{
RepairRateCountVModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
RepairRateCountDModel condition = null;
List<RepairRateCountDModel> nli = new List<RepairRateCountDModel>();
var MaterialName = "";
try
{
//获取查询对象
seachModel = GetModel<RepairRateCountVModel>();
if (string.IsNullOrEmpty(seachModel.WORKCENTER_CODE))
{
//return Content("");
}
else
{
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<RepairRateCountDModel, RepairRateCountVModel>(seachModel);
MaterialName = seachModel.MaterialName;
condition.WORKCENTER_CODE = seachModel.WORKCENTER_CODE;
condition.MaterialName = seachModel.MaterialName;
//报废原因
condition.SelectMender = "0";
#region wcf服务统一接口
var dataResult =
wcfAgent.InvokeServiceFunction<DataResult<List<RepairRateCountDModel>>>(
"RepairRateCountBLL_GetMenderReason", condition);
nli = dataResult.Result;
#endregion
}
}
catch (Exception ex)
{
throw ex;
}
#region 源数据定义
//生成数据
List<TestEChartModel> dataList = new List<TestEChartModel>();
foreach (var repairRateCountDModel in nli)
{
dataList.Add(new TestEChartModel() { Value = repairRateCountDModel.MENDNUMBER, TypeValue = repairRateCountDModel.DEFECTVALUE });
}
//dataList.Add(new TestEChartModel() { Value = "335", TypeValue = "直接访问" });
//dataList.Add(new TestEChartModel() { Value = "320", TypeValue = "邮件营销" });
//dataList.Add(new TestEChartModel() { Value = "310", TypeValue = "联盟广告" });
//dataList.Add(new TestEChartModel() { Value = "135", TypeValue = "视频广告" });
//dataList.Add(new TestEChartModel() { Value = "1548", TypeValue = "搜索引擎" });
#endregion
#region 默认设置
QMEChartPie chartPie = new QMEChartPie() { PieType = "pie1" };
//if (nli == null || nli.Count == 0)
//{
// dataList.Add(new TestEChartModel() { Value = "", TypeValue = "" });
// chartPie.DataList = dataList;
// chartPie.PieData = QMEChartHelper.CovertDataToPieData(chartPie);
// return Content(QMEChartHelper.QMECHelper<QMEChartPie>(chartPie));
//}
//设置数据源
chartPie.DataList = dataList;
#region 设置标题
//标题有则显示。不设置为不显示标题
chartPie.Title = new QMECTitle();
chartPie.Title.Text = "缺陷统计";
//chartPie.Title.Subtext = MaterialName;
chartPie.Title.X = "center";//对齐方式
#endregion
#region Tooltip提示窗口设置
//是否显示ToolTip设置使用默认值初始化图形
chartPie.HaveTooltip = true;
#endregion
#region Legend图例设置
//是否生成Legend,不设置使用系统默认值
chartPie.HaveLegend = true;
chartPie.LegendField = "TypeValue";
#endregion
#region Toolbox工具栏设置
//是否生成ToolBox,不设置使用系统默认值
chartPie.HaveToolBox = false;
#endregion
//是否启用拖拽重计算特性
chartPie.Calculable = false;
#region 设置Serie显示标题
chartPie.SerieName = "缺陷类型";
//chartPie.SerieName = "访问来源";
#endregion
#region 生成图表所需要数据格式
//转换数据格式,值字段
chartPie.ValueField = "Value";
chartPie.PieData = QMEChartHelper.CovertDataToPieData(chartPie);
#endregion
return Content(QMEChartHelper.QMECHelper<QMEChartPie>(chartPie));
//return Content("");
#endregion
#region 自定义创建图表
//QMEChartPie chartPie = new QMEChartPie() { PieType = "pie1" };
//#region 设置标题
//chartPie.Title = new QMECTitle();
//chartPie.Title.Text = "某站点用户访问来源";
//chartPie.Title.Subtext = "纯属虚构";
//chartPie.Title.X = "center";//对齐方式
//#endregion
//#region Tooltip提示窗口设置
//chartPie.HaveTooltip = true;
//chartPie.Tooltip = new QMECTooltip();
//chartPie.Tooltip.Trigger = "item";
//chartPie.Tooltip.Formatter = "'{a} <br/>{b} : {c} ({d}%)'";
//#endregion
//#region Legend图例设置
//chartPie.HaveLegend = true;
//chartPie.Legend = new QMECLegend() { Data = new List<string>() };
//chartPie.Legend.Orient = "vertical";
//chartPie.Legend.X = "left";
//chartPie.Legend.Data.Add("直接访问");
//chartPie.Legend.Data.Add("邮件营销");
//chartPie.Legend.Data.Add("联盟广告");
//chartPie.Legend.Data.Add("视频广告");
//chartPie.Legend.Data.Add("搜索引擎");
//#endregion
//#region Toolbox工具栏设置
//chartPie.HaveToolBox = true;
//chartPie.Toolbox = new QMECToolbox() { Feature = new QMECFeature() { Mark = new QMECMark(), MagicType = new QMECMagicType() { Type = new List<string>(), Option = new QMECOption() { Funnel = new QMECFunnel() } }, Restore = new QMECRestore(), SaveAsImage = new QMECSaveAsImage() } };
//chartPie.Toolbox.Show = true;
//chartPie.Toolbox.Feature.Mark.Show = true;
//chartPie.Toolbox.Feature.MagicType.Show = true;
//chartPie.Toolbox.Feature.MagicType.Type.Add("pie");
//chartPie.Toolbox.Feature.MagicType.Type.Add("funnel");
//chartPie.Toolbox.Feature.MagicType.Option.Funnel.X = "25%";
//chartPie.Toolbox.Feature.MagicType.Option.Funnel.Width = "50%";
//chartPie.Toolbox.Feature.MagicType.Option.Funnel.FunnelAlign = "left";
//chartPie.Toolbox.Feature.MagicType.Option.Funnel.Max = "1548";
//chartPie.Toolbox.Feature.Restore.Show = true;
//chartPie.Toolbox.Feature.SaveAsImage.Show = true;
//#endregion
//chartPie.Calculable = true;
//#region 生成图表所需要数据格式
//chartPie.Serie = new QMECSerie();
//chartPie.Serie.PieData = "Auto";
//chartPie.Serie.Name = "访问来源";
//chartPie.Serie.Radius = "55%";
//chartPie.Serie.Type = "pie";
//chartPie.Serie.Center_X = "50%";
//chartPie.Serie.Center_Y = "60%";
//chartPie.Serie.Center = "Auto";
//List<QMECPieData> pieData = new List<QMECPieData>();
//pieData.Add(new QMECPieData() { Value = "335", Name = "直接访问" });
//pieData.Add(new QMECPieData() { Value = "310", Name = "邮件营销" });
//pieData.Add(new QMECPieData() { Value = "234", Name = "联盟广告" });
//pieData.Add(new QMECPieData() { Value = "135", Name = "视频广告" });
//pieData.Add(new QMECPieData() { Value = "1548", Name = "搜索引擎" });
//chartPie.PieData = pieData;
//#endregion
//return Content(QMAPP.Common.Web.QMEChart.QMEChartHelper.QMECHelper<QMAPP.Common.Web.QMEChart.QMEChartPie>(chartPie));
#endregion
}
#endregion
#region 导出excel
/// <summary>
/// 导出excel
/// </summary>
/// <returns>结果</returns>
[HandleException]
public ActionResult ExportExcelReason()
{
RepairRateCountVModel seachModel = null;
RepairRateCountDModel condition = null;
DataTable exportDt = new DataTable();
string selectKey = Request["selectKey"];
ServiceAgent wcfAgent = this.GetServiceAgent();
try
{
//获取查询对象
seachModel = GetModel<RepairRateCountVModel>();
condition = CopyToModel<RepairRateCountDModel, RepairRateCountVModel>(seachModel);
//报废原因
condition.SelectMender = "1";
//获取数据
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<DataTable>>("RepairRateCountBLL_GetExportDataReason", 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("MenderReasonCountExp");
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);
}
}
/// <summary>
/// 导出文件
/// </summary>
/// <returns></returns>
public ActionResult ExportFileReason()
{
String filePath = Common.ExcelOperationHelper.GetTempPath();
String fileName = Request["FileName"];
ExcelOperationHelper.FileDownload(Response, filePath + fileName, "缺陷统计.xlsx");
return Content("");
}
#endregion
#endregion
#region 废品原因统计--饼状图
public ActionResult MenderTrendCountView()
{
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);
}
#region 表
/// <summary>
/// 异步刷新TABLE
/// </summary>
/// <param name="pageIndex"></param>
/// <returns></returns>
public ActionResult GetTableTrend(string MaterialCode, string MaterialName, string START_DATE, string END_DATE)
{
ServiceAgent wcfAgent = this.GetServiceAgent();
RepairRateCountDModel condition = new RepairRateCountDModel();
var materialName = MaterialName;
condition.MaterialCode = MaterialCode;
condition.START_DATE = START_DATE;
condition.END_DATE = END_DATE;
//报废趋势
condition.SelectMender = "1";
List<RepairRateCountDModel> nli = new List<RepairRateCountDModel>();
try
{
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<RepairRateCountDModel>>>("RepairRateCountBLL_GetMenderReason", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
string sss = GetHTMLStrTrend(nli, materialName);
return Json(sss);
}
/// <summary>
/// 拼接字符串
/// </summary>
/// <returns></returns>
public string GetHTMLStrTrend(List<RepairRateCountDModel> nli, string materialName)
{
StringBuilder html = new StringBuilder();
if (nli == null || nli.Count == 0)
{
return "没有数据";
}
//拼接表头
//html.Append("<tr><td ></td>");
html.Append("<tr>");
foreach (RepairRateCountDModel item in nli)
{
html.Append("<td>");
html.Append(item.CREATEDATE);
html.Append("</td>");
}
html.Append("</tr>");
//拼接第一行
//html.Append("<tr><td >" + materialName + "</td>");
html.Append("<tr>");
foreach (RepairRateCountDModel item in nli)
{
html.Append("<td>");
html.Append(item.MENDNUMBER);
html.Append("</td>");
}
html.Append("</tr>");
return html.ToString();
}
#endregion
#region 图
[HandleException]
public ActionResult GetEchartDataBar2()
{
RepairRateCountVModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
RepairRateCountDModel condition = null;
List<RepairRateCountDModel> nli = new List<RepairRateCountDModel>();
var MaterialName = "";
try
{
//获取查询对象
seachModel = GetModel<RepairRateCountVModel>();
if (string.IsNullOrEmpty(seachModel.MaterialCode))
{
//return Content("");
}
else
{
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<RepairRateCountDModel, RepairRateCountVModel>(seachModel);
MaterialName = seachModel.MaterialName;
//报废趋势
condition.SelectMender = "1";
#region wcf服务统一接口
var dataResult =
wcfAgent.InvokeServiceFunction<DataResult<List<RepairRateCountDModel>>>(
"RepairRateCountBLL_GetMenderReason", condition);
nli = dataResult.Result;
}
#endregion
}
catch (Exception ex)
{
throw ex;
}
string XZ = "", num = "", dou = "";
bool first = true;
foreach (var item in nli)
{
XZ += dou + "'" + item.CREATEDATE + "'";
num += dou + "'" + item.MENDNUMBER + "'";
//tday += dou + "'" + DLEq[item][0].TDAY + timetype + item + "'";
if (first)
{
first = false;
dou = ",";
}
}
#region 源数据定义
string strOption = @"{
noDataLoadingOption: {
text: '无数据',
effect: 'bubble',
effectOption: {
effect: {
n: 0
}
}
},
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',
axisLabel : { //坐标轴刻度标签的相关设置。
interval:'auto',
rotate:20
},
data: [" + XZ + @"]
}
],
yAxis: [
{
type: 'value',
name: '件',
axisLabel: {
formatter: '{value}'
}
}
],
series: [
{
name: '报废数量',
type: 'bar',
data: [" + num + @"]
}
]
}";
#endregion
return Content(strOption);
}
#endregion
#region 导出excel
/// <summary>
/// 导出excel
/// </summary>
/// <returns>结果</returns>
[HandleException]
public ActionResult ExportExcelTrend()
{
RepairRateCountVModel seachModel = null;
RepairRateCountDModel condition = null;
DataTable exportDt = new DataTable();
string selectKey = Request["selectKey"];
ServiceAgent wcfAgent = this.GetServiceAgent();
try
{
//获取查询对象
seachModel = GetModel<RepairRateCountVModel>();
condition = CopyToModel<RepairRateCountDModel, RepairRateCountVModel>(seachModel);
//报废趋势
condition.SelectMender = "1";
//获取数据
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<DataTable>>("RepairRateCountBLL_GetExportDataReason", 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("MenderTrendCountExp");
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);
}
}
/// <summary>
/// 导出文件
/// </summary>
/// <returns></returns>
public ActionResult ExportFileTrend()
{
String filePath = Common.ExcelOperationHelper.GetTempPath();
String fileName = Request["FileName"];
ExcelOperationHelper.FileDownload(Response, filePath + fileName, "报废趋势.xlsx");
return Content("");
}
#endregion
#endregion
}
}