using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Estsh.Web.Util;
using Estsh.Web.Service;
using System.Collections;
using Estsh.Web.Models;
using NPOI.HSSF.UserModel;
using System.IO;
using System.Data;
/***************************************************************************************************
*
* 作者:王勇
* 创建时间:2013.04.15
* 描述:客户订单维护
*
* *************************************************************************************************/
namespace Estsh.Core.Web.Controllers
{
///
/// 客户订单维护
///
public class SeedPartDefineController : Controller
{
private SeedPartDefineService service = new SeedPartDefineService();
//
// GET: /SeedPartDefine/
public ActionResult Index()
{
return View();
}
///
/// 获取列表数据
///
/// 菜单名称
/// 分页
/// 排序方式
/// 排序列
///
public ActionResult getSeedPartDefineListByPage(String FuLingJianHao, String ZiJieLingJianHao, Pager pager, String direction, String sort)
{
//if (string.IsNullOrEmpty(FuLingJianHao) && string.IsNullOrEmpty(ZiJieLingJianHao))
//{
// return null;
//}
Hashtable result = new Hashtable();
result.Add("pager.pageNo", pager.pageNo);
Hashtable dataHt = this.service.getSeedPartDefineListByPage(FuLingJianHao, ZiJieLingJianHao, pager, direction, sort);
result.Add("rows", dataHt["dataList"]);
result.Add("pager.totalRows", dataHt["totalCount"]);
result.Add("sort", sort);
result.Add("direction", direction);
return Json(result);
}
///
/// 获取下拉列表数据
///
///
public ActionResult getSelectSeedPartDefine()
{
Hashtable result = new Hashtable();
ArrayList SeedPartDefineList = this.service.getSelectSeedPartDefine();
result.Add("list", SeedPartDefineList);
return Json(result, JsonRequestBehavior.AllowGet);
}
///
/// 保存数据
///
///
public ActionResult saveSeedPartDefine()
{
string partID = string.Empty;
string subsPartID = string.Empty;
String message = "";
String editType = Request["editType"].ToString();
String part_id = Request["part_id"].ToString();
String sub_part_id = Request["sub_part_id"].ToString();
String sub_part_type = Request["sub_part_type"].ToString();
String GUID = Request["GUID"].ToString();
Hashtable htParams = new Hashtable();
htParams.Add("part_id", part_id);
htParams.Add("sub_part_id", sub_part_id);
htParams.Add("sub_part_type", sub_part_type);
htParams.Add("GUID", GUID);
DataTable dtPartID = service.GetPartMessage(part_id);
DataTable dtSubsPartID = service.GetPartMessage(sub_part_id);
partID = dtPartID.Rows[0][0].ToString();
subsPartID = dtSubsPartID.Rows[0][0].ToString();
if (editType != null && editType.Trim().Equals("edit"))
{
try
{
this.service.updateSeedPartDefine(htParams);
message = "修改成功";
}
catch (Exception e)
{
message = "修改失败!";
}
}
else
{
try
{
if (service.GetPartID(partID, subsPartID))
{
message = "零件已经存在";
Hashtable result_2 = new Hashtable();
result_2.Add("message", message);
return Json(result_2);
}
this.service.saveSeedPartDefine(htParams);
message = "添加成功";
}
catch (Exception e)
{
message = "添加失败!";
}
}
Hashtable result = new Hashtable();
result.Add("message", message);
return Json(result);
}
///
/// 查看详情
///
///
///
public ActionResult getSeedPartDefine(String SeedPartDefine_id)
{
ArrayList SeedPartDefineInfo = this.service.getSeedPartDefine(SeedPartDefine_id);
Hashtable htSeedPartDefineInfo = (Hashtable)SeedPartDefineInfo[0];
ViewData.Add("part_id", htSeedPartDefineInfo["part_id"]);
ViewData.Add("cust_order", htSeedPartDefineInfo["cust_order"]);
ViewData.Add("ship_unit", htSeedPartDefineInfo["ship_unit"]);
return View("~/Views/SeedPartDefineManage/viewSeedPartDefine.aspx");
}
///
/// 编辑
///
///
///
public ActionResult editSeedPartDefine(String GUID)
{
if (string.IsNullOrEmpty(GUID))
{
return null;
}
ArrayList SeedPartDefineInfo = this.service.getSeedPartDefine(GUID);
Hashtable htSeedPartDefineInfo = (Hashtable)SeedPartDefineInfo[0];
ViewData.Add("editType", "edit");
ViewData.Add("part_id", "part_id");
ViewData.Add("sub_part_id", htSeedPartDefineInfo["sub_part_id"]);
ViewData.Add("sub_part_type", htSeedPartDefineInfo["sub_part_type"]);
return View("~/Views/SeedPartDefine/EditSeedPartDefine.aspx");
}
///
/// 删除
///
///
///
public ActionResult deleteSeedPartDefine(String ids)
{
int delCount = 0;
try
{
delCount = this.service.deleteSeedPartDefine(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 导出
///
///
///
///
///
///
///
public ActionResult ExportSeedPartDefine(String FuLingJianHao, String ZiJieLingJianHao, Pager pager, String sort, String direction, String isPage)
{
Boolean paging = false;
if (isPage == null || "".Equals(isPage))
{
paging = false;
}
else
{
if ("1".Equals(isPage))
{
paging = true;
}
else
{
paging = false;
}
}
DataTable dataHt = this.service.getTableListByPage(FuLingJianHao, ZiJieLingJianHao, pager, direction, sort, paging);
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("GUID");
}
for (int i = 0; i < dataHt.Rows.Count; i++)
{
int row = i + 1;
HSSFRow dataRow = (HSSFRow)sheet.CreateRow(row);
dataRow.CreateCell(0).SetCellValue(dataHt.Rows[i]["part_no"].ToString());
dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["sub_part_no"].ToString());
dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["sub_part_type"].ToString());
dataRow.CreateCell(3).SetCellValue(dataHt.Rows[i]["guid"].ToString());
}
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;
}
}
}