nli)
{
StringBuilder html = new StringBuilder();
if (nli == null || nli.Count == 0)
{
return "没有数据";
}
//拼接表头
html.Append(" | ");
foreach (AnDongCallDModel item in nli)
{
html.Append("");
html.Append(item.MACHINENAME);
html.Append(" | ");
}
html.Append("
");
//拼接第一行
html.Append("时间 | ");
foreach (AnDongCallDModel item in nli)
{
html.Append("");
html.Append(item.REPAIR_TIME);
html.Append(" | ");
}
html.Append("
");
//拼接第二行
html.Append("次数 | ");
foreach (AnDongCallDModel item in nli)
{
html.Append("");
html.Append(item.NUM);
html.Append(" | ");
}
html.Append("
");
return html.ToString();
}
#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 图表
///
/// 多图叠加
///
/// 处理结果
[HandleException]
public ActionResult GetEchartDataGroup1()
{
AnDongCallVModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
AnDongCallDModel condition = null;
List nli = new List();
try
{
//获取查询对象
seachModel = GetModel();
if (string.IsNullOrEmpty(seachModel.START_DATE) || string.IsNullOrEmpty(seachModel.END_DATE))
{
//return Content(null);
}
else
{
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel(seachModel);
#region wcf服务统一接口
var dataResult =
wcfAgent.InvokeServiceFunction>>(
"AnDongCallBLL_GetRepairTimeAvg", condition);
nli = dataResult.Result;
#endregion
}
}
catch (Exception ex)
{
throw ex;
}
#region 源数据定义
string fenmu = "", fenzi = "", bfb = "", xLabe = "", dou = "";
bool first = true;
foreach (AnDongCallDModel item in nli)
{
fenmu += dou + "'" + item.NUM + "'";
fenzi += dou + "'" + item.REPAIR_TIME + "'";
bfb += dou + "'" + (Convert.ToDouble(item.REPAIR_TIME) / Convert.ToDouble(item.NUM)).ToString("0") + "'";
xLabe += dou + "'" + item.MACHINENAME + "'";
if (first)
{
first = false;
dou = ",";
}
}
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:0,
rotate:10
},
data: [" + xLabe + @"]
}
],
yAxis: [
{
type: 'value',
name: '维修时间(分钟)',
axisLabel: {
formatter: '{value}'
}
},
{
type: 'value',
name: '平均时间(分钟)',
axisLabel: {
formatter: '{value}'
}
}
],
series: [
{
name: '修理时间',
type: 'bar',
data: [" + fenzi + @"]
},
{
name: '修理次数',
type: 'bar',
data: [" + fenmu + @"]
},
{
name: '平均时间',
type: 'line',
yAxisIndex: 1,
data: [" + bfb + @"]
, itemStyle: { normal: { label: { show: true}} }
}
]
}";
#endregion
return Content(strOption);
}
///
/// 统计图页面配置
///
///
public static string QMEChartPageConfig()
{
StringBuilder configBuilder = new StringBuilder();
configBuilder.AppendLine("");
configBuilder.AppendLine("");
configBuilder.AppendLine("");
configBuilder.AppendLine("");
return configBuilder.ToString();
}
#endregion
#region 导出excel
///
/// 导出excel
///
/// 结果
[HandleException]
public ActionResult ExportExcel()
{
AnDongCallVModel seachModel = null;
AnDongCallDModel condition = null;
DataTable exportDt = new DataTable();
string selectKey = Request["selectKey"];
ServiceAgent wcfAgent = this.GetServiceAgent();
try
{
//获取查询对象
seachModel = GetModel();
condition = CopyToModel(seachModel);
//选择Excel
condition.selectExcel = 1;
//获取数据
var dataResult = wcfAgent.InvokeServiceFunction>("AnDongCallBLL_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("AnDongRepairTimeAvgExp");
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
}
}