You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

389 lines
14 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System.Collections;
using Microsoft.AspNetCore.Mvc;
using Estsh.Core.Services.IServices;
using Estsh.Core.Model.Result;
using Estsh.Core.Controllers;
using System.Data;
using Estsh.Core.Model.ExcelModel;
using Estsh.Core.Util;
/***************************************************************************************************
*
* 更新人sitong.dong
* 描述采购日程单维护Service层
* 修改时间2022.06.22
* 修改日志:系统迭代升级
*
**************************************************************************************************/
namespace Estsh.Web.Controllers
{
public class PurchaseScheduleSingleController : BaseController
{
private IPurchaseScheduleSingleService service;
public PurchaseScheduleSingleController(IPurchaseScheduleSingleService _service)
{
service = _service;
}
public ActionResult Index()
{
return View();
}
/// <summary>
/// 根据查询条件得出日程单收货数据结果集
/// </summary>
/// <param name="aWhere">查询条件</param>
/// <returns>符合条件的结果集</returns>
public ActionResult GetQuery()
{
string _where = " and ";
if (!string.IsNullOrEmpty(Request.Form["txtOrderNo"]))
{
_where += " a.order_no like '%" + Request.Form["txtOrderNo"].ToString() + "%' and ";
}
if (!string.IsNullOrEmpty(Request.Form["txtWeeklyOrderNo"]))
{
_where += " a.weekly_order_no like '%" + Request.Form["txtWeeklyOrderNo"].ToString() + "%' and ";
}
if (!string.IsNullOrEmpty(Request.Form["cbTypeName"]))
{
_where += " b.type_name = '" + Request.Form["cbTypeName"].ToString() + "' and ";
}
if (!string.IsNullOrEmpty(Request.Form["txtBuyNo"]))
{
_where += " a.buy_no like '%" + Request.Form["txtBuyNo"].ToString() + "%' and ";
}
if (!string.IsNullOrEmpty(Request.Form["txtPartNo"]))
{
_where += " d.part_no = '" + Request.Form["txtPartNo"].ToString() + "' and ";
}
if (!string.IsNullOrEmpty(Request.Form["txtVerdorName"]))
{
_where += " c.vendor_name = '" + Request.Form["txtVerdorName"].ToString() + "' and ";
}
if (!string.IsNullOrEmpty(Request.Form["txLotNo"]))
{
_where += " a.lot_no like '%" + Request.Form["txLotNo"].ToString() + "%' and ";
}
if (!string.IsNullOrEmpty(Request.Form["cmbFactory"]))
{
_where += " e.factory_name = '" + Request.Form["cmbFactory"].ToString() + "' and ";
}
if (!string.IsNullOrEmpty(Request.Form["StartTime"]) && !string.IsNullOrEmpty(Request.Form["EndTime"]))
{
_where += " a.create_time between Convert(DATETIME,'" + Request.Form["StartTime"].ToString() + "') and Convert(datetime,'" + Request.Form["EndTime"].ToString() + "') and ";
}
if (_where.Contains(" and "))
{
_where = _where.Remove(_where.LastIndexOf(" and "));
}
Hashtable hs = new Hashtable();
DataTable dt = new DataTable();
Hashtable res = service.GetQuery(_where);
ArrayList list = res["datalist"] as ArrayList;
dt = res["data"] as DataTable;
ViewData.Add("users", dt);
ViewData.Add("order_no", Request.Form["txtOrderNo"].ToString().Trim());
ViewData.Add("weekly_order_no", Request.Form["txtWeeklyOrderNo"].ToString().Trim());
ViewData.Add("type_name", Request.Form["cbTypeName"].ToString().Trim());
ViewData.Add("buy_no", Request.Form["txtBuyNo"].ToString());
ViewData.Add("part_no", Request.Form["txtPartNo"].ToString());
ViewData.Add("lot_no", Request.Form["txLotNo"].ToString());
ViewData.Add("factory_name", Request.Form["cmbFactory"].ToString());
ViewData.Add("vendor_name", Request.Form["txtVerdorName"].ToString());
//Session["dt"] = dt;
Hashtable result = new Hashtable();
result.Add("rows", res["datalist"]);
result.Add("pager.totalRows", 0);
return Json(result);
}
///// <summary>
///// 根据单号和车型查询库存明细
///// </summary>
///// <param name="orderNo">单据号</param>
///// <param name="typeName">车型名称</param>
///// <returns></returns>
//public ActionResult GetStockDetail()
//{
// string orderNo = Request.Form["order_no"].ToString();
// string typeName = Request.Form["type_name"].ToString();
// Hashtable result = new Hashtable();
// string awhere = string.Empty;
// Hashtable hs = service.GetStockDetail(orderNo, typeName);
// result.Add("rows", hs["dataList"]);
// Session["dtTetail"] = hs["data"];
// return Json(result);
//}
/// <summary>
/// 获取工厂
/// </summary>
/// <returns></returns>
public ActionResult GetFactory()
{
Hashtable result = new Hashtable();
List<KeyValueResult> list = service.GetFactory();
result.Add("list", list);
return Json(result);
}
/// <summary>
/// 获取车型
/// </summary>
/// <returns></returns>
public ActionResult GetType()
{
Hashtable result = new Hashtable();
List<KeyValueResult> list = service.GetType();
result.Add("list", list);
return Json(result);
}
public ActionResult GetVendor(string q)
{
List<string> list = filterVendor(q);
return writeResult(list);
}
/// <summary>
/// 根据汉字进行查询
/// </summary>
/// <param name="q"></param>
/// <returns></returns>
public ActionResult getPartNo(string q)
{
List<string> list = filterKey(q);
return writeResult(list);
}
/// <summary>
/// 根据零件汉字过滤
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
private List<String> filterKey(String key)
{
Hashtable autoComplateList = getItemList(key);
List<String> result = new List<string>();
foreach (System.Collections.DictionaryEntry item in autoComplateList)
{
if (item.Key.ToString().ToUpper().StartsWith(key.ToUpper()))
{
result.Add(item.Key.ToString());
}
}
return result;
}
/// <summary>
/// 根据供应商汉字过滤
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
private List<String> filterVendor(String key)
{
Hashtable autoComplateList = GetItemVendor(key);
List<String> result = new List<string>();
foreach (System.Collections.DictionaryEntry item in autoComplateList)
{
if (item.Key.ToString().ToUpper().StartsWith(key.ToUpper()))
{
result.Add(item.Key.ToString());
}
}
return result;
}
/// <summary>
/// 获取零件
/// </summary>
/// <returns></returns>
private Hashtable getItemList(string key)
{
List<String> autoComplateList = new List<string>();
Hashtable result = new Hashtable();
try
{
List<KeyValueResult> dt = service.GetPart(key);
for (int i = 0; i < dt.Count; i++)
{
result.Add(dt[i].value, dt[i].key);
}
}
catch (Exception e)
{
result = new Hashtable();
}
return result;
}
/// <summary>
/// 查询供应商
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public Hashtable GetItemVendor(string key)
{
List<String> autoComplateList = new List<string>();
Hashtable result = new Hashtable();
try
{
List<KeyValueResult> dt = service.GetVendor(key);
for (int i = 0; i < dt.Count; i++)
{
result.Add(dt[i].value.ToString(), dt[i].key.ToString());
}
}
catch (Exception e)
{
result = new Hashtable();
}
return result;
}
private ActionResult writeResult(List<string> list)
{
Hashtable result = new Hashtable();
result.Add("list", list);
return Json(result);
}
/// <summary>
/// 打印
/// </summary>
/// <returns></returns>
public ActionResult OnPrint()
{
Hashtable result = new Hashtable();
if (string.IsNullOrEmpty(Request.Form["query"]))
{
result.Add("status", "-2");
return Json(result);
}
string[] where = Request.Form["query"].ToString().Split(',');
string orderNo = where[0];
string typeName = where[1];
string awhere = string.Empty;
Hashtable hs = service.GetStockDetail(orderNo, typeName);
DataTable dt = hs["data"] as DataTable;
if (dt == null || dt.Rows.Count <= 0)
{
result.Add("status", "-1");
return Json(result);
}
//Printer.PrintSerialData(dt);
result.Add("status", "1");
return Json(result);
}
public ActionResult exportData()
{
//DataTable dataHt = Session["dt"] as DataTable;
string _where = " and ";
if (!string.IsNullOrEmpty(Request.Form["txtOrderNo"]))
{
_where += " a.order_no like '%" + Request.Form["txtOrderNo"].ToString() + "%' and ";
}
if (!string.IsNullOrEmpty(Request.Form["txtWeeklyOrderNo"]))
{
_where += " a.weekly_order_no like '%" + Request.Form["txtWeeklyOrderNo"].ToString() + "%' and ";
}
if (!string.IsNullOrEmpty(Request.Form["cbTypeName"]))
{
_where += " b.type_name = '" + Request.Form["cbTypeName"].ToString() + "' and ";
}
if (!string.IsNullOrEmpty(Request.Form["txtBuyNo"]))
{
_where += " a.buy_no like '%" + Request.Form["txtBuyNo"].ToString() + "%' and ";
}
if (!string.IsNullOrEmpty(Request.Form["txtPartNo"]))
{
_where += " d.part_no = '" + Request.Form["txtPartNo"].ToString() + "' and ";
}
if (!string.IsNullOrEmpty(Request.Form["txtVerdorName"]))
{
_where += " c.vendor_name = '" + Request.Form["txtVerdorName"].ToString() + "' and ";
}
if (!string.IsNullOrEmpty(Request.Form["txLotNo"]))
{
_where += " a.lot_no like '%" + Request.Form["txLotNo"].ToString() + "%' and ";
}
if (!string.IsNullOrEmpty(Request.Form["cmbFactory"]))
{
_where += " e.factory_name = '" + Request.Form["cmbFactory"].ToString() + "' and ";
}
if (!string.IsNullOrEmpty(Request.Form["StartTime"]) && !string.IsNullOrEmpty(Request.Form["EndTime"]))
{
_where += " a.create_time between Convert(DATETIME,'" + Request.Form["StartTime"].ToString() + "') and Convert(datetime,'" + Request.Form["EndTime"].ToString() + "') and ";
}
if (_where.Contains(" and "))
{
_where = _where.Remove(_where.LastIndexOf(" and "));
}
List<PurchaseScheduleSingle> dataHt = service.getTableListByPage(_where);
var memoryStream = ExcelHelper.ToExcel(dataHt);
return File(memoryStream.ToArray(), "application/ms-excel", "采购日程单汇总.xls");
}
public ActionResult save()
{
Hashtable result = new Hashtable();
String WritePwd = Request.Form["pwd"].ToString();
string pwd = service.GetSysBase();
String message = string.Empty;
if (WritePwd.Equals(pwd))
{
string isClose = Request.Form["is_closed"].ToString();
string ruid = Request.Form["ruid"].ToString();
if (isClose == "Y")
{
message = "该订单已经关闭,不可变更!";
}
else
{
if (service.UpdateIsClose(ruid))
{
message = "关闭成功";
}
else
{
message = "关闭失败";
}
}
}
else
{
message = "密码错误,无法关闭订单!";
}
result.Add("message", message);
return Json(result);
}
}
}