|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
using System.Linq;
|
|
|
using System.Web;
|
|
|
using System.Web.Mvc;
|
|
|
using Estsh.Web.Service;
|
|
|
using System.Collections;
|
|
|
using Estsh.Web.Util;
|
|
|
using System.Data;
|
|
|
using NPOIReport;
|
|
|
using System.IO;
|
|
|
using NPOI.HSSF.UserModel;
|
|
|
|
|
|
namespace Estsh.Core.Web.Controllers
|
|
|
{
|
|
|
public class CheckStockPrintController : Controller
|
|
|
{
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 作者:张茂忠
|
|
|
* 创建时间:2013.04.17
|
|
|
* 描述:盘点单打印模块Controller层
|
|
|
* 修改日志:
|
|
|
*
|
|
|
*
|
|
|
* *************************************************************************************************/
|
|
|
CheckStockPrintService service = new CheckStockPrintService();
|
|
|
|
|
|
public ActionResult Index()
|
|
|
{
|
|
|
return View();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取库区
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult GetFactoryListData()
|
|
|
{
|
|
|
Hashtable resault = new Hashtable();
|
|
|
ArrayList FactoryList = service.GetFactoryListData();
|
|
|
resault.Add("list", FactoryList);
|
|
|
return Json(resault, JsonRequestBehavior.AllowGet);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 获取大库位
|
|
|
/// </summary>
|
|
|
/// <param name="factoryCode"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult GetWarehouseListData()
|
|
|
{
|
|
|
Hashtable resault = new Hashtable();
|
|
|
ArrayList WareHouseList = service.GetWarehouseListData(Request["parentid"].ToString());
|
|
|
resault.Add("list", WareHouseList);
|
|
|
return Json(resault, JsonRequestBehavior.AllowGet);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 生成盘点单
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult GenCSOrder(string pdline_id, string modelType, string serchFilter, int totalRows)
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(pdline_id) && string.IsNullOrEmpty(modelType) && string.IsNullOrEmpty(serchFilter))
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
string wheres = InitWhereStr(pdline_id, modelType, serchFilter);
|
|
|
|
|
|
|
|
|
Hashtable result = service.GenCSOrder(wheres, totalRows);
|
|
|
return Json(result, JsonRequestBehavior.AllowGet);
|
|
|
|
|
|
|
|
|
//Hashtable resault = new Hashtable();
|
|
|
//int count = 0;
|
|
|
//if (service.GenCSOrder((DataTable)Session["table"]))
|
|
|
//{
|
|
|
// count = 1;
|
|
|
//}
|
|
|
//resault.Add("status", count);
|
|
|
//return Json(resault);
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 打印盘点单
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult OnPrint()
|
|
|
{
|
|
|
#if(false)
|
|
|
Hashtable resault = new Hashtable();
|
|
|
_dt = (DataTable)Session["table"];
|
|
|
// 如果没有数据就直接返回
|
|
|
if (_dt == null || _dt.Rows.Count <= 0)
|
|
|
{
|
|
|
resault.Add("status", "-1");
|
|
|
return Json(resault);
|
|
|
}
|
|
|
if (_dt.Rows[0]["order_no1"].ToString() == "")
|
|
|
{
|
|
|
resault.Add("status", "-2");
|
|
|
return Json(resault);
|
|
|
}
|
|
|
//if (string.IsNullOrEmpty(_dt.Rows[0]["order_no"].ToString()))
|
|
|
//{
|
|
|
// MessageBox.Show("盘点单号不能为空,请先生成盘点单");
|
|
|
// return;
|
|
|
//}
|
|
|
|
|
|
// 模板文件的路径
|
|
|
string TemplateFile =
|
|
|
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Template\CheckStockOrder.xls");
|
|
|
|
|
|
// 输出文件的路径
|
|
|
string TempFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
|
|
|
string.Format(@"Temp\CheckStockOrder_{0}.xls", DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")));
|
|
|
|
|
|
NPOIReporter Reporter = new NPOIReporter(TemplateFile, TempFile);
|
|
|
|
|
|
Hashtable Variables = new Hashtable();
|
|
|
|
|
|
// 添加报表中使用的变量
|
|
|
Variables.Add("OrderNo", _dt.Rows[0]["order_no"].ToString());
|
|
|
Variables.Add("CreateDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
|
// 生成报表
|
|
|
if (Reporter.GeneratorReport("CheckStockOrder", Variables, _dt))
|
|
|
{
|
|
|
// 打印到默认打印机
|
|
|
MeExcel.Print(TempFile);
|
|
|
}
|
|
|
resault.Add("status", "1");
|
|
|
return Json(resault);
|
|
|
//#elseif (false)
|
|
|
Hashtable resault = new Hashtable();
|
|
|
_dt = (DataTable)Session["table"];
|
|
|
// 如果没有数据就直接返回
|
|
|
if (_dt == null || _dt.Rows.Count==0)
|
|
|
return null;
|
|
|
|
|
|
//if (string.IsNullOrEmpty(_dt.Rows[0]["order_no"].ToString()))
|
|
|
//{
|
|
|
// MessageBox.Show("盘点单号不能为空,请先生成盘点单");
|
|
|
// return;
|
|
|
//}
|
|
|
|
|
|
// 模板文件的路径
|
|
|
string TemplateFile =
|
|
|
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Template\CheckStockOrder.xls");
|
|
|
|
|
|
// 输出文件的路径
|
|
|
string TempFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
|
|
|
string.Format(@"Temp\CheckStockOrder_{0}.xls", DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss")));
|
|
|
|
|
|
NPOIReporter Reporter = new NPOIReporter(TemplateFile, TempFile);
|
|
|
|
|
|
Hashtable Variables = new Hashtable();
|
|
|
|
|
|
// 添加报表中使用的变量
|
|
|
Variables.Add("OrderNo", _dt.Rows[0]["order_no"].ToString());
|
|
|
Variables.Add("CreateDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
|
|
|
|
|
// 生成报表
|
|
|
if (Reporter.GeneratorReport("CheckStockOrder", Variables, _dt))
|
|
|
{
|
|
|
// 打印到默认打印机
|
|
|
MyExcel.Print(TempFile);
|
|
|
}
|
|
|
resault.Add("status", "1");
|
|
|
return Json(resault);
|
|
|
#endif
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
|
|
|
#region jerome
|
|
|
/// <summary>
|
|
|
/// 获取产线名称
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult GetPdLineName()
|
|
|
{
|
|
|
Hashtable resault = new Hashtable();
|
|
|
ArrayList pdlineList = service.GetPdLineName();
|
|
|
resault.Add("list", pdlineList);
|
|
|
return Json(resault, JsonRequestBehavior.AllowGet);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 获取项目
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult GetModelTypeNameList()
|
|
|
{
|
|
|
Hashtable resault = new Hashtable();
|
|
|
ArrayList pdlineList = service.GetModelTypeNameList();
|
|
|
resault.Add("list", pdlineList);
|
|
|
return Json(resault, JsonRequestBehavior.AllowGet);
|
|
|
}
|
|
|
|
|
|
private string InitWhereStr(string pdline_id, string modelType, string serchFilter)
|
|
|
{
|
|
|
string wheres = string.Empty;
|
|
|
string pdlineStr = string.Empty;
|
|
|
string[] pdLineArr = pdline_id.Split(',');
|
|
|
foreach (string str in pdLineArr)
|
|
|
{
|
|
|
pdlineStr += " '" + str + "' ,";
|
|
|
}
|
|
|
pdlineStr = pdlineStr.Substring(0, pdlineStr.Length - 2);
|
|
|
wheres += string.Format(" AND ( a.pdline_id IN ({0}))", pdlineStr);
|
|
|
|
|
|
if (!string.IsNullOrEmpty(modelType))
|
|
|
{
|
|
|
string modelTypeStr = string.Empty;
|
|
|
string[] modelTypeArr = modelType.Split(',');
|
|
|
foreach (string str in modelTypeArr)
|
|
|
{
|
|
|
modelTypeStr += " '" + str + "' ,";
|
|
|
}
|
|
|
modelTypeStr = modelTypeStr.Substring(0, modelTypeStr.Length - 1);
|
|
|
wheres += string.Format(" AND (type_name in ({0}))", modelTypeStr);
|
|
|
}
|
|
|
|
|
|
if (!string.IsNullOrEmpty(serchFilter))
|
|
|
{
|
|
|
string[] filterArr = serchFilter.Split(',');
|
|
|
|
|
|
#region 良品还是全部产品(包含良品及不良品) current_status
|
|
|
///返回参数中:1、只盘点不良品;2、包含在制品;3、包含不良品;4、包含没有生产线的总成;5、包含没有配置的总成
|
|
|
int index = Array.FindIndex<string>(filterArr, str => str.Equals("1"));
|
|
|
if (index >= 0)//如果为【只盘点不良品】
|
|
|
{
|
|
|
wheres += " AND current_status in (1) ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
index = Array.FindIndex<string>(filterArr, str => str.Equals("3"));
|
|
|
if (index >= 0)//如果为【包含不良品】
|
|
|
{
|
|
|
wheres += " AND current_status in (0,1) ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
wheres += " AND current_status in (0) ";
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 是否包含在制品 work_flag in (0,1) or work_falg in (1)
|
|
|
index = Array.FindIndex<string>(filterArr, str => str.Equals("2"));
|
|
|
if (index >= 0)
|
|
|
{
|
|
|
wheres += " AND work_flag in (0,1) ";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
wheres += " AND work_flag in (1) ";
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
|
|
|
return wheres;
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 根据用户选择的条件查找盘点数据
|
|
|
/// </summary>
|
|
|
/// <param name="wheres">筛选条件</param>
|
|
|
/// <returns>盘点数据</returns>
|
|
|
public ActionResult GetCheckStockWhere(string pdline_id, string modelType, string serchFilter,Pager pager)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(pdline_id) && string.IsNullOrEmpty(modelType) && string.IsNullOrEmpty(serchFilter))
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
string wheres = InitWhereStr(pdline_id, modelType, serchFilter);
|
|
|
Hashtable result = new Hashtable();
|
|
|
result.Add("pager.pageNo", pager.pageNo);
|
|
|
Hashtable dataHt = service.GetCheckStockWhere(wheres, pager);
|
|
|
result.Add("rows", dataHt["dataList"]);
|
|
|
result.Add("pager.totalRows", dataHt["totalCount"]);
|
|
|
|
|
|
return Json(result);
|
|
|
}
|
|
|
|
|
|
public ActionResult ExportData(string order_no, string pdline_id, string modelType, string serchFilter, Pager pager)
|
|
|
{
|
|
|
if (string.IsNullOrEmpty(pdline_id) && string.IsNullOrEmpty(modelType) && string.IsNullOrEmpty(serchFilter))
|
|
|
{
|
|
|
return null;
|
|
|
}
|
|
|
#if(false)
|
|
|
string wheres = InitWhereStr(pdline_id, modelType, serchFilter);
|
|
|
//Hashtable result = new Hashtable();
|
|
|
|
|
|
Hashtable dataHt = service.GetCheckStockWhere(wheres, pager);
|
|
|
if (dataHt.ContainsKey("dataList"))
|
|
|
{
|
|
|
//FileStream SourceStream = new FileStream(@"Template\CheckStockOrder.xls", FileMode.Open);
|
|
|
HSSFWorkbook workbook = new HSSFWorkbook();
|
|
|
Stream outputStream = Response.OutputStream;
|
|
|
HSSFSheet sheet = (HSSFSheet)workbook.CreateSheet("盘点单");
|
|
|
try
|
|
|
{
|
|
|
if (workbook != null)
|
|
|
{
|
|
|
HSSFRow headRow = (HSSFRow)sheet.CreateRow(0);
|
|
|
headRow.CreateCell(0).SetCellValue("产线");
|
|
|
headRow.CreateCell(1).SetCellValue("库区");
|
|
|
headRow.CreateCell(2).SetCellValue("配置");
|
|
|
headRow.CreateCell(3).SetCellValue("零件号");
|
|
|
headRow.CreateCell(4).SetCellValue("零件描述");
|
|
|
headRow.CreateCell(5).SetCellValue("条码");
|
|
|
headRow.CreateCell(6).SetCellValue("车号");
|
|
|
headRow.CreateCell(7).SetCellValue("状态1");
|
|
|
headRow.CreateCell(8).SetCellValue("状态2");
|
|
|
headRow.CreateCell(9).SetCellValue("上线时间");
|
|
|
headRow.CreateCell(10).SetCellValue("下线时间");
|
|
|
headRow.CreateCell(11).SetCellValue("盘点单");
|
|
|
}
|
|
|
ArrayList arr = dataHt["dataList"] as ArrayList;
|
|
|
for (int i = 0; i < arr.Count; i++)
|
|
|
{
|
|
|
Hashtable dtRow = arr[i] as Hashtable;
|
|
|
int row = i + 1;
|
|
|
HSSFRow dataRow = (HSSFRow)sheet.CreateRow(row);
|
|
|
|
|
|
dataRow.CreateCell(0).SetCellValue(dtRow["pdline_name"].ToString());
|
|
|
dataRow.CreateCell(1).SetCellValue(dtRow["fg_wh_code"].ToString());
|
|
|
dataRow.CreateCell(2).SetCellValue(dtRow["model_name"].ToString());
|
|
|
dataRow.CreateCell(3).SetCellValue(dtRow["part_no"].ToString());
|
|
|
dataRow.CreateCell(4).SetCellValue(dtRow["part_spec"].ToString());
|
|
|
dataRow.CreateCell(5).SetCellValue(dtRow["serial_number"].ToString());
|
|
|
dataRow.CreateCell(6).SetCellValue(dtRow["car_no"].ToString());
|
|
|
dataRow.CreateCell(7).SetCellValue(dtRow["work_flag"].ToString());
|
|
|
dataRow.CreateCell(8).SetCellValue(dtRow["current_status"].ToString());
|
|
|
dataRow.CreateCell(9).SetCellValue(dtRow["in_pdline_time"].ToString());
|
|
|
dataRow.CreateCell(10).SetCellValue(dtRow["out_pdline_time"].ToString());
|
|
|
dataRow.CreateCell(11).SetCellValue(order_no);
|
|
|
}
|
|
|
|
|
|
Response.Clear();
|
|
|
workbook.Write(outputStream);
|
|
|
|
|
|
Response.Buffer = true;
|
|
|
Response.AppendHeader("Content-Disposition", "attachment;filename=盘点明细.xls");
|
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
|
Response.ContentType = "application/vnd.ms-excel";
|
|
|
Response.Flush();
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
workbook = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
#else
|
|
|
|
|
|
string wheres = InitWhereStr(pdline_id, modelType, serchFilter);
|
|
|
|
|
|
Hashtable dataHt = service.GetCheckStockWhere(wheres, pager);
|
|
|
if (dataHt.ContainsKey("dataList"))
|
|
|
{
|
|
|
// 模板文件的路径
|
|
|
string TemplateFile =
|
|
|
Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Template\CheckStockOrder.xls");
|
|
|
FileStream SourceStream = new FileStream(TemplateFile, FileMode.Open);
|
|
|
HSSFWorkbook workbook = new HSSFWorkbook(SourceStream);
|
|
|
Stream outputStream = Response.OutputStream;
|
|
|
|
|
|
HSSFSheet sheet = workbook.GetSheetAt(0) as HSSFSheet;
|
|
|
try
|
|
|
{
|
|
|
ArrayList arr = dataHt["dataList"] as ArrayList;
|
|
|
sheet.GetRow(1).Cells[1].SetCellValue(order_no);
|
|
|
sheet.GetRow(2).Cells[1].SetCellValue(DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
|
|
|
string AbsolutePath= Request.UrlReferrer.AbsolutePath;
|
|
|
string url = AbsolutePath.Remove(0, Request.ApplicationPath.Length);
|
|
|
GridColumnService colService = new GridColumnService();
|
|
|
Models.SysWebGridColumn[] gridItems = colService.GetColumnByUrl(url);
|
|
|
#region 数据
|
|
|
for (int i = 0; i < arr.Count; i++)
|
|
|
{
|
|
|
Hashtable dtRow = arr[i] as Hashtable;
|
|
|
int row = i + 5;
|
|
|
HSSFRow dataRow = (HSSFRow)sheet.CreateRow(row);
|
|
|
|
|
|
for (int idx = 0; idx < gridItems.Length; idx++)
|
|
|
{
|
|
|
if (gridItems[idx].export)
|
|
|
{
|
|
|
string key = gridItems[idx].name;
|
|
|
if (dtRow.ContainsKey(key))
|
|
|
{
|
|
|
object obj = dtRow[key];
|
|
|
if (obj != null && obj != DBNull.Value)
|
|
|
{
|
|
|
dataRow.CreateCell(idx).SetCellValue(obj.ToString());
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 样式
|
|
|
HSSFCellStyle style = workbook.CreateCellStyle() as HSSFCellStyle;
|
|
|
style.BorderBottom = NPOI.SS.UserModel.CellBorderType.HAIR;
|
|
|
//设置字体;
|
|
|
HSSFFont font = workbook.CreateFont() as HSSFFont;
|
|
|
//设置字体大小;
|
|
|
font.FontHeightInPoints = 8;
|
|
|
style.SetFont(font);
|
|
|
#endregion
|
|
|
Response.Clear();
|
|
|
workbook.Write(outputStream);
|
|
|
|
|
|
Response.Buffer = true;
|
|
|
if (Request.Browser.Type.ToUpper().IndexOf("IE") >= 0)
|
|
|
{
|
|
|
Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode("盘点单" + order_no + ".xls", System.Text.Encoding.UTF8));
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
Response.AppendHeader("Content-Disposition", "attachment;filename=盘点单" + order_no + ".xls");
|
|
|
}
|
|
|
|
|
|
Response.ContentEncoding = System.Text.Encoding.UTF8;
|
|
|
Response.ContentType = "application/vnd.ms-excel";
|
|
|
Response.Flush();
|
|
|
}
|
|
|
catch (Exception e)
|
|
|
{
|
|
|
}
|
|
|
finally
|
|
|
{
|
|
|
workbook = null;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
#endif
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
}
|
|
|
}
|