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(); } /// /// 根据查询条件得出日程单收货数据结果集 /// /// 查询条件 /// 符合条件的结果集 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); } ///// ///// 根据单号和车型查询库存明细 ///// ///// 单据号 ///// 车型名称 ///// //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); //} /// /// 获取工厂 /// /// public ActionResult GetFactory() { Hashtable result = new Hashtable(); List list = service.GetFactory(); result.Add("list", list); return Json(result); } /// /// 获取车型 /// /// public ActionResult GetType() { Hashtable result = new Hashtable(); List list = service.GetType(); result.Add("list", list); return Json(result); } public ActionResult GetVendor(string q) { List list = filterVendor(q); return writeResult(list); } /// /// 根据汉字进行查询 /// /// /// public ActionResult getPartNo(string q) { List list = filterKey(q); return writeResult(list); } /// /// 根据零件汉字过滤 /// /// /// private List filterKey(String key) { Hashtable autoComplateList = getItemList(key); List result = new List(); foreach (System.Collections.DictionaryEntry item in autoComplateList) { if (item.Key.ToString().ToUpper().StartsWith(key.ToUpper())) { result.Add(item.Key.ToString()); } } return result; } /// /// 根据供应商汉字过滤 /// /// /// private List filterVendor(String key) { Hashtable autoComplateList = GetItemVendor(key); List result = new List(); foreach (System.Collections.DictionaryEntry item in autoComplateList) { if (item.Key.ToString().ToUpper().StartsWith(key.ToUpper())) { result.Add(item.Key.ToString()); } } return result; } /// /// 获取零件 /// /// private Hashtable getItemList(string key) { List autoComplateList = new List(); Hashtable result = new Hashtable(); try { List 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; } /// /// 查询供应商 /// /// /// public Hashtable GetItemVendor(string key) { List autoComplateList = new List(); Hashtable result = new Hashtable(); try { List 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 list) { Hashtable result = new Hashtable(); result.Add("list", list); return Json(result); } /// /// 打印 /// /// 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 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); } } }