|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Web;
|
|
|
using System.Web.Mvc;
|
|
|
using Estsh.Web.Service;
|
|
|
using System.Collections;
|
|
|
using System.Data;
|
|
|
using System.Text;
|
|
|
using Estsh.Web.Util;
|
|
|
using System.IO;
|
|
|
using NPOI.HSSF.UserModel;
|
|
|
|
|
|
namespace Estsh.Core.Web.Controllers
|
|
|
{
|
|
|
public class ProduceQueryController : Controller
|
|
|
{
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 作者:张茂忠
|
|
|
* 创建时间:2013.04.22
|
|
|
* 描述:产量查询模块Controller层
|
|
|
* 修改日志:
|
|
|
*
|
|
|
*
|
|
|
* *************************************************************************************************/
|
|
|
private ProduceQueryService service = new ProduceQueryService();
|
|
|
DataTable _dt = null;
|
|
|
DataTable _dtDetail = null;
|
|
|
public ActionResult Index()
|
|
|
{
|
|
|
return View();
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取汇总
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult GetSummary()
|
|
|
{
|
|
|
string _where = "";
|
|
|
string type_id = string.Empty;
|
|
|
StringBuilder data = new StringBuilder();
|
|
|
if (!string.IsNullOrEmpty(Request["cbTypeName"]))
|
|
|
{
|
|
|
_where += " and type_id='" + Request["cbTypeName"].ToString() + "'";
|
|
|
type_id = Request["cbTypeName"].ToString();
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(Request["txtStartCarno"]) && !string.IsNullOrEmpty(Request["txtEndCarno"]))
|
|
|
{
|
|
|
_where += " and a.car_no>= '" + Request["txtStartCarno"].ToString().Trim() + "' and a.car_no<='" + Request["txtEndCarno"].ToString().Trim() + "' ";
|
|
|
}
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(Request["type"]))
|
|
|
{
|
|
|
string sbustr=string.Empty;
|
|
|
String[] str = Request["type"].ToString().Split(',');
|
|
|
|
|
|
for (int i = 0; i < str.Length; i++)
|
|
|
{
|
|
|
sbustr += string.Format("'{0}',", str[i]);
|
|
|
}
|
|
|
char[] Splitor = { ',' };
|
|
|
|
|
|
sbustr = sbustr.TrimEnd(Splitor);
|
|
|
_where += "AND a.type in (" + sbustr + ")";
|
|
|
}
|
|
|
if (!string.IsNullOrEmpty(Request["StartTime"]) && !string.IsNullOrEmpty(Request["EndTime"]))
|
|
|
{
|
|
|
if (!string.IsNullOrEmpty(Request["txtStartCarno"]) && !string.IsNullOrEmpty(Request["txtEndCarno"]))
|
|
|
{
|
|
|
_where += " and convert(datetime,a.create_ymd) between convert(datetime,'" + Request["StartTime"].ToString() + "') and convert(datetime,'" + Request["EndTime"].ToString() + "') ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
_where += " and ((a.out_pdline_ymd = convert(varchar(10),'" + Request["StartTime"].ToString() + "',23) and a.out_pdline_hms >= convert(varchar(10),'" + Request["StartTime"].ToString() + "',108)) ";
|
|
|
_where += " or (a.out_pdline_ymd > convert(varchar(10),'" + Request["StartTime"].ToString() + "',23) and a.out_pdline_ymd < convert(varchar(10),'" + Request["EndTime"].ToString() + "',23))";
|
|
|
_where += " or (a.out_pdline_ymd = convert(varchar(10),'" + Request["EndTime"].ToString() + "',23) and a.out_pdline_hms <= convert(varchar(10),'" + Request["EndTime"].ToString() + "',108)))";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
Hashtable hs = new Hashtable();
|
|
|
DataTable dt = new DataTable();
|
|
|
ArrayList list = service.GetSummary(_where, ref dt);
|
|
|
|
|
|
//获取明细
|
|
|
DataTable dtdetail = new DataTable();
|
|
|
ArrayList listDetail = service.GetSummaryDtail(_where, type_id, ref dtdetail);
|
|
|
ViewData.Add("users", dt);
|
|
|
ViewData.Add("usersDetail", dtdetail);
|
|
|
ViewData.Add("type_id", type_id);
|
|
|
ViewData.Add("StartCar_no", Request["txtStartCarno"].ToString().Trim());
|
|
|
ViewData.Add("EndCar_no", Request["txtEndCarno"].ToString().Trim());
|
|
|
ViewData.Add("type", Request["type"].ToString());
|
|
|
Session["dt"] = dt;
|
|
|
Session["dtdetail"] = dtdetail;
|
|
|
return View("~/Views/ProduceQuery/ProduceQuery.aspx");
|
|
|
}
|
|
|
public ActionResult exportData()
|
|
|
{
|
|
|
// 如果没有数据就直接返回
|
|
|
Hashtable resault = new Hashtable();
|
|
|
_dt = (DataTable)Session["dt"];
|
|
|
_dtDetail = (DataTable)Session["dtdetail"];
|
|
|
|
|
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
Stream outputStream = Response.OutputStream;
|
|
|
HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("汇总信息");
|
|
|
HSSFSheet sheetDetail = (HSSFSheet)workbook.CreateSheet("明细信息");
|
|
|
if (Session["dt"].ToString() != "" || Session["dtdetail"].ToString() != "")
|
|
|
{
|
|
|
try
|
|
|
{
|
|
|
if (workbook != null)
|
|
|
{
|
|
|
HSSFRow headRow = (HSSFRow)sheet.CreateRow(0);
|
|
|
headRow.CreateCell(0).SetCellValue("车型");
|
|
|
headRow.CreateCell(1).SetCellValue("配置");
|
|
|
headRow.CreateCell(2).SetCellValue("数量");
|
|
|
|
|
|
|
|
|
HSSFRow headRowDetail = (HSSFRow)sheetDetail.CreateRow(0);
|
|
|
headRowDetail.CreateCell(0).SetCellValue("车型");
|
|
|
headRowDetail.CreateCell(1).SetCellValue("总成");
|
|
|
headRowDetail.CreateCell(2).SetCellValue("数量");
|
|
|
headRowDetail.CreateCell(3).SetCellValue("生产类型");
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < _dt.Rows.Count; i++)
|
|
|
{
|
|
|
int row = i + 1;
|
|
|
HSSFRow dataRow = (HSSFRow)sheet.CreateRow(row);
|
|
|
|
|
|
dataRow.CreateCell(0).SetCellValue(_dt.Rows[i]["type_name"].ToString());
|
|
|
dataRow.CreateCell(1).SetCellValue(_dt.Rows[i]["model_desc"].ToString());
|
|
|
dataRow.CreateCell(2).SetCellValue(Convert.ToInt32(_dt.Rows[i]["number"]));
|
|
|
}
|
|
|
|
|
|
for (int i = 0; i < _dtDetail.Rows.Count; i++)
|
|
|
{
|
|
|
int row = i + 1;
|
|
|
HSSFRow dataRow = (HSSFRow)sheetDetail.CreateRow(row);
|
|
|
|
|
|
dataRow.CreateCell(0).SetCellValue(_dtDetail.Rows[i]["type_name"].ToString());
|
|
|
dataRow.CreateCell(1).SetCellValue(_dtDetail.Rows[i]["part_no"].ToString());
|
|
|
dataRow.CreateCell(2).SetCellValue(Convert.ToInt32(_dtDetail.Rows[i]["number"]));
|
|
|
dataRow.CreateCell(3).SetCellValue(_dtDetail.Rows[i]["type"].ToString());
|
|
|
}
|
|
|
Response.Clear();
|
|
|
workbook.Write(outputStream);
|
|
|
|
|
|
Response.Buffer = true;
|
|
|
Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
|
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
|
Response.ContentType = "application/vnd.ms-excel";
|
|
|
Response.Flush();
|
|
|
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
workbook = null;
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
workbook = null;
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
|
|
|
workbook.Write(outputStream);
|
|
|
|
|
|
Response.Buffer = true;
|
|
|
Response.AppendHeader("Content-Disposition", "attachment;filename=Excel.xls");
|
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
|
Response.ContentType = "application/vnd.ms-excel";
|
|
|
Response.Flush();
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询车型
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult GetModelType()
|
|
|
{
|
|
|
Hashtable hs = new Hashtable();
|
|
|
ArrayList list = service.GetModelType();
|
|
|
hs.Add("list", list);
|
|
|
return Json(hs, JsonRequestBehavior.AllowGet);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 查询生产类型
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult GetProduceType()
|
|
|
{
|
|
|
Hashtable hs = new Hashtable();
|
|
|
//ArrayList list = service.GetProduceType();
|
|
|
//hs.Add("list", list);
|
|
|
return Json(hs, JsonRequestBehavior.AllowGet);
|
|
|
}
|
|
|
public ActionResult getDepartmentDropListData()
|
|
|
{
|
|
|
string path = Request.ApplicationPath; if (path.EndsWith("/")) { path = path.Substring(0, path.Length - 1); }
|
|
|
List<TreeNode> treeNodes = new List<TreeNode>();
|
|
|
DataTable list = service.GetProduceType();
|
|
|
for (int i = 0; i < list.Rows.Count; i++)
|
|
|
{
|
|
|
TreeNode node = new TreeNode();
|
|
|
node = service.convert(list.Rows[i]["value"].ToString(), list.Rows[i]["key"].ToString(), path);
|
|
|
node.parentId = "0";
|
|
|
treeNodes.Add(node);
|
|
|
}
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("treeNodes", treeNodes);
|
|
|
return Json(result, JsonRequestBehavior.AllowGet);
|
|
|
}
|
|
|
}
|
|
|
}
|