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

566 lines
21 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using QMAPP.Common.Web.Controllers;
using QMFrameWork.WebUI.Attribute;
using QMFrameWork.Data;
using QMAPP.Entity;
using QMAPP.ServicesAgent;
using System.Data;
using QMFrameWork.WebUI.QMEChart;
using QMFrameWork.WebUI.QMEChart.Data;
using System.Text;
using QMFrameWork.Log;
using ExcelOperationHelper = QMAPP.Web.Common.ExcelOperationHelper;
using QMFrameWork.Common.ExcelOperation;
using QMAPP.FJC.Web.Models.TianJin;
using QMAPP.MD.Entity.Bucket;
using QMAPP.FJC.Web.Models;
namespace QMAPP.FJC.Web.Controllers
{
/// <summary>
/// 生产发运统计
/// 于子清
/// 2017-10-12
/// </summary>
public class InjectionCountController : QController
{
public ActionResult QTYInjectionCount()
{
InjectionCountModel seachModel = new InjectionCountModel();
seachModel.TYPE_COUNT = DateTime.Now.ToString("DAY");
seachModel.START_DATE = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd HH:mm:ss");
seachModel.END_DATE = DateTime.Now.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss");
return View(seachModel);
}
/// <summary>
/// 异步刷新TABLE
/// </summary>
/// <param name="pageIndex"></param>
/// <returns></returns>
public ActionResult GetTable(string TYPE_COUNT, string START_DATE, string END_DATE)
{
ServiceAgent wcfAgent = this.GetServiceAgent();
RawMaterialRecord condition = new RawMaterialRecord();
condition.TYPE_COUNT = TYPE_COUNT;
condition.START_DATE = START_DATE;
condition.END_DATE = END_DATE;
List<RawMaterialRecord> nli = new List<RawMaterialRecord>();
try
{
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<RawMaterialRecord>>>("RawMaterialRecordBLL_GetMainListB", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
string sss = GetHTMLStr(nli);
return Json(sss);
}
/// <summary>
/// 拼接字符串
/// </summary>
/// <returns></returns>
public string GetHTMLStr(List<RawMaterialRecord> nli)
{
StringBuilder html = new StringBuilder();
if (nli==null)
{
return "";
}
//拼接表头
Dictionary<string, int> sumDic = new Dictionary<string, int>();
Dictionary<string, int> timeDic = new Dictionary<string, int>();
html.Append("<tr><td class='L1cos'></td>");
List<string> headList = nli.Select(o => o.PartCode).Distinct().OrderBy(o => o.ToString()).ToList<string>();
List<string> materialList=nli.Select(o => o.planNumber).Distinct().OrderBy(o =>o.ToString()).ToList<string>();
materialList.Add("合计");
foreach (var str in headList)
{
html.AppendFormat("<td>{0}</td>", str);
sumDic[str]=0;
}
html.Append("<td style='background-color:#ECF5FF'>合计</td>");
html.Append("</tr>");
for (int i = 0; i < materialList.Count; i++)
{
timeDic[materialList[i]] = 0;
if (materialList[i] != "合计")
{
//增加行
html.Append("<tr>");
//增加类型
//html.AppendFormat("<td>{0}</td>", materialList[i]);
var ss = nli.Where(p => p.planNumber == materialList[i]).ToList()[0].planNumber;
html.AppendFormat("<td>{0}</td>", ss);
for (int j = 0; j < headList.Count; j++)
{
int countValue=0;
if (nli.Exists(o => (o.planNumber) == materialList[i] && o.PartCode == headList[j]))
{
var no= nli.First(o => (o.planNumber) == materialList[i] && o.PartCode == headList[j]);
html.AppendFormat("<td>{0}</td>", no.RawMaterialCount.ToString());
countValue=Convert.ToInt32(no.RawMaterialCount);
}
else
{
html.AppendFormat("<td></td>", materialList[i]);
}
sumDic[headList[j]] = sumDic[headList[j]] + countValue;
timeDic[materialList[i]] = timeDic[materialList[i]] + countValue;
}
html.AppendFormat("<td style='background-color:#ECF5FF'>{0}</td>", timeDic[materialList[i]].ToString());
html.Append("</tr>");
}
else
{
//增加行
html.Append("<tr style='background-color:#ECF5FF'>");
html.AppendFormat("<td>合计</td>");
//html.AppendFormat("<td class='L1cos'></td>");
for (int j = 0; j < headList.Count; j++)
{
html.AppendFormat("<td>{0}</td>", sumDic[headList[j]].ToString());
}
html.AppendFormat("<td>{0}</td>",timeDic.Values.Sum().ToString());
html.Append("</tr>");
}
}
return html.ToString();
}
#region
/// <summary>
/// 堆积柱状图
/// </summary>
/// <returns>处理结果</returns>
[HandleException]
public ActionResult GetEchartDataBar2()
{
InjectionCountModel seachModel = null;
DataPage page = null;
ServiceAgent wcfAgent = this.GetServiceAgent();
RawMaterialRecord condition = null;
List<RawMaterialRecord> nli = new List<RawMaterialRecord>();
try
{
//获取查询对象
seachModel = GetModel<InjectionCountModel>();
//获取前台分页设置信息
page = this.GetDataPage(seachModel);
condition = CopyToModel<RawMaterialRecord, InjectionCountModel>(seachModel);
#region wcf服务统一接口
var dataResult = wcfAgent.InvokeServiceFunction<DataResult<List<RawMaterialRecord>>>("RawMaterialRecordBLL_GetMainListB", condition);
nli = dataResult.Result;
#endregion
}
catch (Exception ex)
{
throw ex;
}
#region 源数据定义
//生成数据
List<TestEChartModel> dataList = new List<TestEChartModel>();
if (nli == null)
{
nli = new List<RawMaterialRecord>();
dataList.Add(new TestEChartModel() { Week = "", Value = "0", TypeValue = " ", StackValue = "产品数量!" });
}
foreach (RawMaterialRecord item in nli)
{
dataList.Add(new TestEChartModel() { Week = item.PartCode, Value = item.RawMaterialCount, TypeValue = item.planNumber, StackValue = "产品数量!" });
}
#endregion
#region 默认设置
QMEChartBar chartLBar = new QMEChartBar() { BarType = "bar2" };
//设置源数据列表
chartLBar.DataList = dataList;
#region 设置标题
//不为空时显示Title,为空时不显示
//chartLBar.Title = new QMECTitle();
//chartLBar.Title.Text = "";
//chartLBar.Title.Subtext = "";
#endregion
#region Tooltip提示窗口设置
//是否显示ToolTip工具条
chartLBar.HaveTooltip = true;
#endregion
#region Legend图例设置
//是否有Legend
chartLBar.HaveLegend = true;
//Legend的自动统计字段,对应chartLine.DataList中用于统计的字段
chartLBar.LegendField = "TypeValue";
#endregion
#region Toolbox工具栏设置
//是否存在工具栏,为空时使用默认设置
chartLBar.HaveToolBox = false;
#endregion
#region XAxis横坐标轴设置
//为空时使用默认值并从数据源中统计类型,需要设置DataList数据源
chartLBar.HaveXAxis = true;
//设置X轴统计类型字段
chartLBar.XAxisField = "Week";
#endregion
#region YAxis纵坐标轴设置
//设置Y轴显示格式。
chartLBar.HaveYAxis = true;
//自定义设置
chartLBar.YAxis = new QMECYAxis() { AxisLabel = new QMECAxisLabel() };
chartLBar.YAxis.Type = "value";
#endregion
#region 堆积字段设置
//堆积字段,是否是堆积图形
chartLBar.StackField = "StackValue";
#endregion
#region 生成图表所需要数据格式
//转换数据格式,值字段
chartLBar.ValueField = "Value";
chartLBar.Series = QMEChartHelper.CovertDataToSeries(chartLBar);
#endregion
#region 辅助线设置,有则设置,没有则无需设置
//设置辅助线
QMECMarkLine ml = new QMECMarkLine() { ItemStyle = new QMECItemStyle() { Normal = new QMECNormal() { LineStyle = new QMECLineStyle() } }, LineData = new List<QMECPoint>() };
ml.ItemStyle.Normal.LineStyle = new QMECLineStyle() { Type = "dashed", Width = 1 };
List<QMECMarkPoint> mp = new List<QMECMarkPoint>();
QMECPoint mpstart = new QMECPoint();
QMECPoint mpend = new QMECPoint();
mpstart.Type = "min";
mpend.Type = "max";
ml.LineData.Add(mpstart);
ml.LineData.Add(mpend);
foreach (QMECSerie ser in chartLBar.Series)
{
if (ser.Name == "搜索引擎")
{
ser.MarkLine = ml;
}
}
#endregion
return Content(QMEChartHelper.QMECHelper<QMEChartBar>(chartLBar));
#endregion
}
#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()
{
InjectionCountModel seachModel = null;
RawMaterialRecord condition = null;
DataTable exportDt = new DataTable();
string selectKey = Request["selectKey"];
ServiceAgent wcfAgent = this.GetServiceAgent();
try
{
//获取查询对象
seachModel = GetModel<InjectionCountModel>();
condition = CopyToModel<RawMaterialRecord, InjectionCountModel>(seachModel);
//获取数据
var dataResult = wcfAgent.InvokeServiceFunction<DataTable>("RawMaterialRecordBLL_GetExportData", condition);
exportDt = dataResult;
//通过返回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 sheetInfoName = "RawMaterialRecordExp";
var sheetInfo = ieExcelHelper.GetMainInfo(sheetInfoName);
var fileName = System.Guid.NewGuid().ToString() + ".xlsx";
ieExcelHelper.ExportExcel(sheetInfo, exportDt, 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(int Trend)
{
String filePath = ExcelOperationHelper.GetTempPath();
String fileName = Request["FileName"];
var sheetInfoName = "电量统计.xlsx";
ExcelOperationHelper.FileDownload(Response, filePath + fileName, sheetInfoName);
return Content("");
}
#endregion
//#region 导出excel
//#region 导出excel
///// <summary>
///// 导出excel
///// </summary>
///// <returns>结果</returns>
//[HttpPost]
//public ActionResult ExportExcel()
//{
// using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\ceshi\WriteLines.txt", true))
// {
// file.WriteLine("==1111===");
// }
// InjectionCountModel seachModel = null;
// RawMaterialRecord condition = null;
// ServiceAgent wcfAgent = this.GetServiceAgent();
// DataTable result = new DataTable();
// string selectKey = Request.Form["selectKey"];
// try
// {
// using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\ceshi\WriteLines.txt", true))
// {
// file.WriteLine("==2222===");
// }
// //获取查询对象
// seachModel = GetModel<InjectionCountModel>();
// condition = CopyToModel<RawMaterialRecord, InjectionCountModel>(seachModel);
// using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\ceshi\WriteLines.txt", true))
// {
// file.WriteLine("==3333===");
// }
// //获取数据
// result = wcfAgent.InvokeServiceFunction<DataTable>(QMAPP.ServicesAgent.B9BasicService.RawMaterialRecordBLL_GetExportData.ToString(), condition);
// using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\ceshi\WriteLines.txt", true))
// {
// file.WriteLine("==444===");
// }
// //导出
// QMFrameWork.WebUI.Util.IEFileTool efTool = new QMFrameWork.WebUI.Util.IEFileTool();
// return efTool.GetExcelFileResult("RawMaterialRecordExp", "加工信息.xlsx", result);
// }
// catch (Exception ex)
// {
// throw ex;
// }
//}
//#endregion
/////// <summary>
/////// 导出excel
/////// </summary>
/////// <returns>结果</returns>
////[HandleException]
////public ActionResult ExportExcel()
////{
//// using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\ceshi\WriteLines.txt", true))
//// {
//// file.WriteLine("==1111===");
//// }
//// InjectionCountModel seachModel = null;
//// RawMaterialRecord condition = null;
//// DataTable exportDt = new DataTable();
//// string selectKey = Request["selectKey"];
//// ServiceAgent wcfAgent = this.GetServiceAgent();
//// try
//// {
//// using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\ceshi\WriteLines.txt", true))
//// {
//// file.WriteLine("==22222===");
//// }
//// //获取查询对象
//// seachModel = GetModel<InjectionCountModel>();
//// condition = CopyToModel<RawMaterialRecord, InjectionCountModel>(seachModel);
//// //condition.TYPE_COUNT = TYPE_COUNT;
//// //condition.START_DATE = START_DATE;
//// //condition.END_DATE = END_DATE;
//// using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\ceshi\WriteLines.txt", true))
//// {
//// file.WriteLine("==33333===");
//// }
//// //获取数据
//// var dataResult = wcfAgent.InvokeServiceFunction<DataTable>("RawMaterialRecordBLL_GetExportData", condition);
//// using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\ceshi\WriteLines.txt", true))
//// {
//// file.WriteLine("==4444===");
//// }
//// //通过返回dataResult判断
//// exportDt = dataResult;
//// //根据所选信息进行导出
//// //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 sheetInfoName = "RawMaterialRecordExp";
//// var sheetInfo = ieExcelHelper.GetMainInfo(sheetInfoName);
//// var fileName = System.Guid.NewGuid().ToString() + ".xlsx";
//// ieExcelHelper.ExportExcel(sheetInfo, exportDt, 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(int Trend)
//{
// String filePath = ExcelOperationHelper.GetTempPath();
// String fileName = Request["FileName"];
// var sheetInfoName = "耗电量统计.xlsx";
// ExcelOperationHelper.FileDownload(Response, filePath + fileName, sheetInfoName);
// return Content("");
//}
//#endregion
}
}