using Newtonsoft.Json; using NFine.Application.WMS; using NFine.Code; using NFine.Data.Extensions; using System; using System.Collections.Generic; using System.Data; using System.Data.Common; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; namespace NFine.Web.Areas.WMS.Controllers { /// /// 检具管理(铭锋) /// public class CheckingFixtureController : ControllerBase { private CheckingFixtureApp app = new CheckingFixtureApp(); // GET: WMS/CheckingFixture #region 检具档案 public ActionResult CheckingFixtureQuery() { return View(); } /// /// 模具档案封存 /// /// public ActionResult CheckingFixtureStopQuery() { return View(); } /// /// 解封时间 /// /// public ActionResult UpdateTime() { return View(); } public ActionResult CheckingFixtureEdit(string ids) { ViewData["ids"] = ids; //ViewData["line"] = line; return View(); } /// /// 获取库位列表 /// /// /// [HttpGet] public ActionResult GetLocationList(string keyValue) { var dt = app.GetLocationList(keyValue); return Content(dt.ToJson()); } /// /// 查询列表 /// /// /// /// [HttpPost] [HandlerAjaxOnly] public ActionResult GetGridJsonChengPing(Pagination pagination, string type,string queryJson) { DataTable ListData = app.GetGridJsonChengPing(queryJson, type,ref pagination); var JsonData = new { total = pagination.total, page = pagination.page, records = pagination.records, rows = ListData, }; return Content(JsonData.ToJson()); } /// /// 保存 /// /// /// [HttpPost] [HandlerAjaxOnly] public ActionResult SaveCheckingFixture(string keyValue) { string msg = app.SaveCheckingFixture(keyValue); if (!string.IsNullOrEmpty(msg)) { return Error(msg); } else { return Success("操作成功!"); } } /// /// 获取单个 /// /// /// [HttpGet] [HandlerAjaxOnly] public ActionResult GetCheckingFixture(string keyValue) { var dt = app.GetCheckingFixture(keyValue); return Content(dt.ToJson()); } /// /// 删除 /// /// /// [HttpPost] [HandlerAjaxOnly] public ActionResult DeleteCheckingFixture(string keyValue) { var msg = app.DeleteCheckingFixture(keyValue); if (!string.IsNullOrEmpty(msg)) { return Error(msg); } else { return Success("操作成功!"); } } /// /// 封存/解封 /// /// /// [HttpPost] [HandlerAjaxOnly] public ActionResult PostSealed(string type,string keyValue,string time) { var msg = app.PostSealed(type,keyValue,time); if (!string.IsNullOrEmpty(msg)) { return Error(msg); } else { return Success("修改成功!"); } } /// /// 导出列表 /// /// /// /// [HttpPost] public void ExportAll(string id, string CheckFixtureName, string Status) { DataTable dt = app.ExportAll(id, CheckFixtureName, Status); AsposeCell.Export(dt); } /// /// 导入列表 /// /// /// /// [HttpPost] public string UploadFile() { try { //string str_Year = Request.Form["txt_Year"]; //String UPLoadType = Request.Form["UPLoadType"]; HttpFileCollection hpFiles = System.Web.HttpContext.Current.Request.Files; if (hpFiles != null && hpFiles.Count > 0) { string IsXls = System.IO.Path.GetExtension(hpFiles[0].FileName).ToString().ToLower();//System.IO.Path.GetExtension获得文件的扩展名 if (IsXls != ".xls" && IsXls != ".xlsx") { return "只可以选择Excel(.xls .xlsx)文件";//当选择的不是Excel文件时,返回 } string filename = DateTime.Now.ToString("yyyyMMddhhmmss") + IsXls; //获取Execle文件名 DateTime日期函数 string savePath = System.Web.HttpContext.Current.Server.MapPath("~\\File\\CheckingFixture\\" + filename);//Server.MapPath 获得虚拟服务器相对路径 int iLen = hpFiles[0].ContentLength; if (Directory.Exists(savePath)) return "文件已存在"; byte[] bData = new byte[iLen]; hpFiles[0].InputStream.Read(bData, 0, iLen); FileStream newFile = new FileStream(savePath, FileMode.OpenOrCreate); newFile.Write(bData, 0, bData.Length); newFile.Flush(); int _FileSizeTemp = hpFiles[0].ContentLength; newFile.Close(); newFile.Dispose(); //bool del = false; string mess = ""; mess = app.SetData_PR(savePath); if (System.IO.File.Exists(savePath))//删除文件 { System.IO.File.Delete(savePath); } return mess; } else { return "获取文件失败"; } } catch (Exception ex) { return ex.ToString(); } } /// /// 导出列表 /// /// /// /// [HttpPost] public ActionResult PrintLabel(string keyValue) { //var msg = app.PrintLabel(keyValue); // return Success(msg); var JsonData = new { strPrintData_1 = "", bIsInstallPrintControl_1 = true, strPrintControlCookie_1 = "", msg="" }; try { var strPrintData = ""; List parameter = new List(); string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string MUSER = NFine.Code.OperatorProvider.Provider.GetCurrent().UserCode; string MUSERNAME = NFine.Code.OperatorProvider.Provider.GetCurrent().UserName; //var sql var keyValues = JsonConvert.DeserializeObject>(keyValue); if (keyValues == null || keyValues.Count == 0) { throw new Exception("参数为传入"); } string strPrintFileName = Server.MapPath("/File/CheckingFixture/") + "检具4025.fr3"; PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName); pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息 // SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件 string strSql = @"select a.CheckFixtureNo as 编码 ,a.CheckFixtureName as 客户名称,a.CustomerItemCode as 客户料号 , a.* from IcsCheckingFixture a with(nolock) where 1=1 --and a.WorkPoint=@WorkPoint and a.CheckFixtureNo in ('" + string.Join("','", keyValues) + "')"; parameter.Add(new SqlParameter("@WorkPoint", SqlDbType.VarChar) { Value = WorkPoint }); DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, parameter.ToArray()); DataTable newDT = new DataTable(); newDT.Columns.Add("编码1", typeof(string)); newDT.Columns.Add("客户名称1", typeof(string)); newDT.Columns.Add("客户料号1", typeof(string)); newDT.Columns.Add("编码2", typeof(string)); newDT.Columns.Add("客户名称2", typeof(string)); newDT.Columns.Add("客户料号2", typeof(string)); // List listRow = new List(); int rowCount = (dtInInfo.Rows.Count % 2)+(dtInInfo.Rows.Count / 2); List SingleRow = new List(); List DoubleRow = new List(); for (int i = 0; i < dtInInfo.Rows.Count; i++) { // 1,2 =>1 3,4 =>2 if ((i + 1) % 2 == 1) { //基数行 SingleRow.Add(dtInInfo.Rows[i]); } else { //偶数行 DoubleRow.Add(dtInInfo.Rows[i]); } } for (int i = 0; i < rowCount; i++) { var newrow = newDT.NewRow(); newrow["编码1"] = SingleRow[i]["编码"]; newrow["客户名称1"] = SingleRow[i]["客户名称"]; newrow["客户料号1"] = SingleRow[i]["客户料号"]; if (i+1<= DoubleRow.Count) { newrow["编码2"] = DoubleRow[i]["编码"]; newrow["客户名称2"] = DoubleRow[i]["客户名称"]; newrow["客户料号2"] = DoubleRow[i]["客户料号"]; } newDT.Rows.Add(newrow); } string strPrintTempFile = pJson.ShowReport(newDT);//产生ISON文件内容 //把服务器的URL+此文件名 传递给控件,由控件下载还原数据进行打印 string strServerURL = GetUrlPath() + "PrintTemp/"; string strData = strServerURL + strPrintTempFile; strPrintData = PrintFunction.EnBase64(strData); JsonData = new { strPrintData_1 = strPrintData, bIsInstallPrintControl_1 = true, strPrintControlCookie_1 = "", msg="", }; } catch (Exception ex) { JsonData = new { strPrintData_1 = "", bIsInstallPrintControl_1 = true, strPrintControlCookie_1 = "", msg = ex.Message }; return Content(JsonData.ToJson()); } return Content(JsonData.ToJson()); } #endregion private string GetUrlPath() { string strUrl = Request.Url.ToString(); int iEnd = strUrl.LastIndexOf("/"); strUrl = strUrl.Substring(0, iEnd + 1); return strUrl; } #region 检具流转 public ActionResult CheckingFixtureTransferQuery() { return View(); } /// /// 查询列表 /// /// /// /// [HttpPost] [HandlerAjaxOnly] public ActionResult QueryTransferList(Pagination pagination, string queryJson) { DataTable ListData = app.QueryTransferList(queryJson, ref pagination); var JsonData = new { total = pagination.total, page = pagination.page, records = pagination.records, rows = ListData, }; return Content(JsonData.ToJson()); } /// /// 转换操作 /// /// public ActionResult TransferInsert(string type) { ViewData["type"] = type; return View(); } /// /// 转换操作 /// /// public ActionResult TransferInsertOther(string type) { ViewData["type"] = type; return View(); } /// /// 新增转换 /// /// /// [HttpPost] [HandlerAjaxOnly] public ActionResult SaveTransfer(string keyValue) { string msg = app.SaveTransfer(keyValue); if (!string.IsNullOrEmpty(msg)) { return Error(msg); } else { return Success("操作成功!"); } } /// /// 获取人员 /// /// /// [HttpGet] [HandlerAjaxOnly] public ActionResult GetUserInfo(string keyValue) { var dt = app.GetUserInfo(keyValue); return Content(dt.ToJson()); } /// /// 获取单个 /// /// /// [HttpGet] [HandlerAjaxOnly] public ActionResult GetCheckingFixtureByNo(string keyValue) { var dt = app.GetCheckingFixtureByNo(keyValue); return Content(dt.ToJson()); } /// /// 删除转换日志 /// /// /// [HttpPost] [HandlerAjaxOnly] public ActionResult DeleteTransfer(string keyValue) { var msg = app.DeleteTransfer(keyValue); if (!string.IsNullOrEmpty(msg)) { return Error(msg); } else { return Success("操作成功!"); } } /// /// 导出列表 /// /// /// /// [HttpPost] public void ExportAllTransfer(string CheckFixtureNo, string CheckFixtureName, string TransferNo, string TransferType) { DataTable dt = app.ExportAllTransfer(CheckFixtureNo, CheckFixtureName, TransferNo, TransferType); AsposeCell.Export(dt); } #endregion public ActionResult GetType(string type) { string sql = $@"select '' as Code,'' as Name UNION all select b.F_ItemCode as Code ,b.F_ItemName as Name from Sys_SRM_Items a left join Sys_SRM_ItemsDetail b on a.F_Id=b.F_ItemId where a.F_EnCode='{type}' "; DataTable ListData = SqlHelper.GetDataTableBySql(sql); return Content(ListData.ToJson()); } } }