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 System.Data;
using NPOI.HSSF.UserModel;
using System.IO;
/***************************************************************************************************
*
* 作者:王勇
* 创建时间:2013.04.15
* 描述:客户订单维护
*
* *************************************************************************************************/
namespace Estsh.Core.Web.Controllers
{
///
/// 客户订单维护
///
public class DetectionControlController : Controller
{
private DetectionControlService service = new DetectionControlService();
//
// GET: /ModelPart/
public ActionResult Index()
{
return View();
}
///
/// 获取列表数据
///
/// 菜单名称
/// 分页
/// 排序方式
/// 排序列
///
public ActionResult getDetectionControlListByPage(string part_no, Pager pager, String direction, String sort)
{
Hashtable result = new Hashtable();
Hashtable dataHt = this.service.getDetectionControlListByPage(part_no, 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 getSelectModelPart()
{
Hashtable result = new Hashtable();
ArrayList ModelPartList = this.service.getSelectModelPart();
result.Add("list", ModelPartList);
return Json(result, JsonRequestBehavior.AllowGet);
}
///
/// 保存数据
///
///
public ActionResult saveModelPart()
{
//String ruid = Request["ruid"].ToString();
String type_code = Request["type_code"].ToString();
String model_name = Request["model_name"].ToString();
String model_spec = Request["model_spec"].ToString();
String part_no = Request["part_no"].ToString();
String part_spec = Request["part_spec"].ToString();
String PF_DJC = Request["PF_DJC"].ToString();
String QP_DJC = Request["QP_DJC"].ToString();
String QP_IMS = Request["QP_IMS"].ToString();
String QP_JYF = Request["QP_JYF"].ToString();
String QP_TLL = Request["QP_TLL"].ToString();
String QP_SBR = Request["QP_SBR"].ToString();
String QP_SJYX = Request["QP_SJYX"].ToString();
String QM_TLL = Request["QM_TLL"].ToString();
String QM_DJC = Request["QM_DJC"].ToString();
String editType = Request["editType"].ToString();
Hashtable htParams = new Hashtable();
//htParams.Add("@ruid", ruid);
htParams.Add("@type_code", type_code);
htParams.Add("@model_name", model_name);
htParams.Add("@model_spec", model_spec);
htParams.Add("@part_no", part_no);
htParams.Add("@part_spec", part_spec);
htParams.Add("@PF_DJC", PF_DJC);
htParams.Add("@QP_DJC", QP_DJC);
htParams.Add("@QP_IMS", QP_IMS);
htParams.Add("@QP_JYF", QP_JYF);
htParams.Add("@QP_TLL", QP_TLL);
htParams.Add("@QP_SBR", QP_SBR);
htParams.Add("@QP_SJYX", QP_SJYX);
htParams.Add("@QM_TLL", QM_TLL);
htParams.Add("@QM_DJC", QM_DJC);
String message = "";
string flag = "";
if (editType != null && editType.Trim().Equals("1"))
{
try
{
//htParams.Add("@model_id", model_id);
//htParams.Add("@ruid", ruid);
//htParams.Add("@model_name", model_name);
//htParams.Add("@part_no", part_no);
int return_value = this.service.updateModelPart(htParams);
if (return_value > 0)
{
//this.service.updateModelPart_Sys_part(htParams);
message = "修改成功";
flag = "OK";
}
else
{
message = "更新失败";
flag = "Fail";
}
}
catch (Exception e)
{
message = "修改失败!";
flag = "Fail";
}
}
else
{
try
{
int return_value = this.service.saveDetectionControl(htParams);
if (return_value > 0)
{
// this.service.saveModelPart_Sys_part(htParams);
message = "添加成功";
flag = "OK";
}
else
{
message = "新增失败";
flag = "Fail";
}
}
catch (Exception e)
{
message = "添加失败!";
flag = "Fail";
}
}
Hashtable result = new Hashtable();
result.Add("message", message);
result.Add("flag", flag);
return Json(result);
}
///
/// 编辑
///
///
///
public ActionResult editDetectionC(String ruid)
{
ArrayList ModelPartInfo = this.service.getModelPart(ruid);
Hashtable htModelPartInfo = (Hashtable)ModelPartInfo[0];
ViewData.Add("editType", "1");
//ViewData.Add("ruid", htModelPartInfo["ruid"]);
ViewData.Add("type_code", htModelPartInfo["type_code"]);
ViewData.Add("model_name", htModelPartInfo["model_name"]);
ViewData.Add("model_spec", htModelPartInfo["model_spec"]);
ViewData.Add("part_no", htModelPartInfo["part_no"]);
ViewData.Add("part_spec", htModelPartInfo["part_spec"]);
ViewData.Add("PF_DJC", htModelPartInfo["PF_DJC"]);
ViewData.Add("QP_DJC", htModelPartInfo["QP_DJC"]);
ViewData.Add("QP_IMS", htModelPartInfo["QP_IMS"]);
ViewData.Add("QP_JYF", htModelPartInfo["QP_JYF"]);
ViewData.Add("QP_TLL", htModelPartInfo["QP_TLL"]);
ViewData.Add("QP_SBR", htModelPartInfo["QP_SBR"]);
ViewData.Add("QP_SJYX", htModelPartInfo["QP_SJYX"]);
ViewData.Add("QM_TLL", htModelPartInfo["QM_TLL"]);
ViewData.Add("QM_DJC", htModelPartInfo["QM_DJC"]);
return View("~/Views/DetectionControl/EditDetectionControl.aspx");
}
///
/// 删除
///
///
///
public ActionResult deleteDetectionControl(String ids)
{
int delCount = 0;
try
{
delCount = this.service.deleteDetectionControl(ids);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 变更状态
///
///
///
public ActionResult onState(String model_id, String enabled)
{
int delCount = 0;
try
{
delCount = this.service.onState(model_id, enabled);
}
catch (Exception e)
{
delCount = -1;
}
Hashtable result = new Hashtable();
result.Add("status", delCount);
return Json(result);
}
///
/// 导出数据到Excel
///
///
///
///
///
///
///
public ActionResult exportData(string part_no, Pager pager, String sort, String direction, String isPage)
{
Boolean paging = false;
if (isPage == null || "".Equals(isPage))
{
paging = false;
}
else
{
if ("1".Equals(isPage.Trim()))
{
paging = true;
}
else
{
paging = false;
}
}
DataTable dataHt = this.service.getModelPartListByPage2(part_no, pager, direction, sort);//txtOrderNo, 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("配置别名");
headRow.CreateCell(4).SetCellValue("配置描述");
headRow.CreateCell(5).SetCellValue("车型名称");
}
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]["model_code"].ToString());
dataRow.CreateCell(1).SetCellValue(dataHt.Rows[i]["model_type"].ToString());
dataRow.CreateCell(2).SetCellValue(dataHt.Rows[i]["model_name"].ToString());
dataRow.CreateCell(3).SetCellValue(dataHt.Rows[i]["model_alias"].ToString());
dataRow.CreateCell(4).SetCellValue(dataHt.Rows[i]["model_desc"].ToString());
dataRow.CreateCell(5).SetCellValue(dataHt.Rows[i]["type_name"].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;
}
///
/// 导入Excel文件
///
///
public ActionResult importModelPart()
{
Hashtable result = new Hashtable();
HttpPostedFileBase userDataFile = Request.Files[0];
UserInfo user = (UserInfo)Session["loginedUser"];
if (userDataFile == null)
{
return null;
}
result = service.ReadExcelFile(userDataFile.InputStream, user.empId);
return Json(result);
}
///
/// 查看详情
///
///
///
public ActionResult getModelPart(String ModelPart_id)
{
ArrayList ModelPartInfo = this.service.getModelPart(ModelPart_id);
Hashtable htModelPartInfo = (Hashtable)ModelPartInfo[0];
ViewData.Add("part_id", htModelPartInfo["part_id"]);
ViewData.Add("cust_order", htModelPartInfo["cust_order"]);
ViewData.Add("ship_unit", htModelPartInfo["ship_unit"]);
return View("~/Views/ModelPartManage/viewModelPart.aspx");
}
}
}