using NFine.Application; using NFine.Application.ProductManage; using NFine.Code; using NFine.Data.Extensions; using NFine.Domain.Entity.ProductManage; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.IO; using System.Linq; using System.Threading; using System.Web; using System.Web.Mvc; namespace NFine.Web.Areas.SRM.Controllers { public class CAManageAdminController : ControllerBase { private CAManageApp App = new CAManageApp(); [HttpGet] [HandlerAjaxOnly] public ActionResult GetGridJsonAdmin(Pagination pagination, string queryJson) { DataTable ListData = App.GetGridJsonAdmin(queryJson, ref pagination); var JsonData = new { total = pagination.total, page = pagination.page, records = pagination.records, rows = ListData, }; return Content(JsonData.ToJson()); } /// /// 查看明细 /// /// /// /// public ActionResult GetGridJsonAdminDetail(Pagination pagination, string queryJson, string WorkPoint) { DataTable ListData = App.GetGridJsonAdminDetail(queryJson, ref pagination, WorkPoint); var JsonData = new { total = pagination.total, page = pagination.page, records = pagination.records, rows = ListData, }; return Content(JsonData.ToJson()); } [HttpGet] [HandlerAjaxOnly] public ActionResult GetSubGridJson(string ID, Pagination pagination, string WorkPoint) { DataTable ListData = App.GetSubGridJson(ID, ref pagination, WorkPoint); var JsonData = new { total = pagination.total, page = pagination.page, records = pagination.records, rows = ListData, }; return Content(JsonData.ToJson()); } [HttpGet] [HandlerAjaxOnly] public ActionResult GetSubGridJson_Add(string queryJson, Pagination pagination) { DataTable ListData = App.GetSubGridJson_Add(queryJson, ref pagination); var JsonData = new { total = pagination.total, page = pagination.page, records = pagination.records, rows = ListData, }; return Content(JsonData.ToJson()); } public ActionResult Index() { return View(); } public ActionResult CADetails() { return View(); } [HttpPost] [HandlerAjaxOnly] [ValidateAntiForgeryToken] public ActionResult SubmitForm(string POCode, string PORow, string keyValue) { int i = App.CreateItemLotNo(POCode, PORow, keyValue); if (i > 0) { return Success("发布成功!"); } else { return Error("发布失败!"); } } [HttpGet] [HandlerAjaxOnly] public ActionResult GetSubGridJsonByCreate(string POCode, string PORow) { DataTable ListData = App.GetSubGridJsonByCreate(POCode, PORow); var JsonData = new { rows = ListData, }; return Content(JsonData.ToJson()); } [HttpGet] [HandlerAjaxOnly] public ActionResult GetVendorLotNo(string VenCode, string WorkPoint) { DataTable ListData = App.GetVendorLotNo(VenCode, WorkPoint); var JsonData = new { VendorLotNo = ListData.Rows[0][0].ToString(), }; return Content(JsonData.ToJson()); } [HttpPost] [HandlerAjaxOnly] [ValidateAntiForgeryToken] public ActionResult DeleteDocNo(string keyValue, string WorkPoint) { string msg = App.DeleteDocNo(keyValue, WorkPoint); if (string.IsNullOrEmpty(msg)) { return Success("删除成功!"); } else { return Error(msg); } } [HttpPost] [HandlerAjaxOnly] [ValidateAntiForgeryToken] public ActionResult UpDateByDocNoAdmin(string keyValue, string Status, string WorkPoint) { int result = App.UpDateByDocNoAdmin(keyValue, Status, WorkPoint); if (result > 0) { return Success("操作成功!"); } else { return Error("操作失败!"); } } [HttpGet] [HandlerAjaxOnly] public ActionResult CheckIsAll(string STNO) { string _result = App.CheckIsAll(STNO); var JsonData = new { result = _result }; return Content(JsonData.ToJson()); } #region 打印 /// /// 打印数据参数:服务器的URL+打印的文件名,转化为Base64编码 /// protected string strPrintData; /// /// 标识是否安装了控件 /// protected bool bIsInstallPrintControl = true; /// /// 打印控件的Cookie值 /// protected string strPrintControlCookie = ""; /// /// 获取Url中去掉文件名的路径 /// /// private string GetUrlPath() { string strUrl = Request.Url.ToString(); int iEnd = strUrl.LastIndexOf("/"); strUrl = strUrl.Substring(0, iEnd + 1); return strUrl; } /// /// 设置控件调用的Cookie值,判断是否安装了打印控件 /// /// private void SetCookieAndURL(PrintJson pJson) { bIsInstallPrintControl = false; strPrintControlCookie = ""; HttpCookie pCookieInstall = Request.Cookies["InstallPrintControl"]; if (pCookieInstall != null) { //Cookie存在 strPrintControlCookie = pCookieInstall.Value.ToString(); //以Cookie值查找在数据表中是否存在 string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie"; SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strPrintControlCookie) }; using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie)) { if (drCookie.Read()) { //标识为已经安装 bIsInstallPrintControl = true; } drCookie.Close(); } //更新Cookie的保存时间 pCookieInstall.Expires = DateTime.Now.AddYears(10); Response.SetCookie(pCookieInstall); } else {//Cookie不存在,则新建Cookie strPrintControlCookie = System.Guid.NewGuid().ToString(); pCookieInstall = new HttpCookie("InstallPrintControl", strPrintControlCookie); pCookieInstall.Expires = DateTime.Now.AddYears(10); Response.Cookies.Add(pCookieInstall); } string strUrl = Server.MapPath("/PrintTemp/") + "IsCheckInstall"; pJson.SetCookieAndURL(strPrintControlCookie, strUrl); } [HttpPost] [HandlerAjaxOnly] public ActionResult PrintItemLot(string keyValue, string WorkPoint) { //string sqlU9 = "SELECT DBIpAddress,DBName FROM dbo.Sys_DataBase WHERE DBSourceName='ERP'"; //DataTable dtU9 = SqlHelper.GetDataTableBySql(sqlU9); //string U9IP = dtU9.Rows[0]["DBIpAddress"].ToString(); //string DBName = dtU9.Rows[0]["DBName"].ToString(); string DBLANK = SqlHelper.GetItemsDetails("ERP001", WorkPoint); keyValue = keyValue.Substring(1, keyValue.Length - 2); WorkPoint = WorkPoint.Substring(1, WorkPoint.Length - 2); string strPrintFileName = Server.MapPath("/ReportFile/") + "ASN对账单.fr3"; PrintJson pJson = new PrintJson(Server.MapPath("./PrintTemp"), strPrintFileName); pJson.CheckRegister("苏州智合诚信息科技有限公司", "56DD3B4C172D0D140841CAC98A58A819F4E28EDA5D6E45711DDD64F6A439F68B6A7870CD7DAFD69A919CB870207FE4BB206F92BE3D53C221B019E0797E739EBA4"); //注册信息 pJson.MasterOptions(1, "DocNo", false); //主从关系 SetCookieAndURL(pJson);// 设置控件调用的Cookie值,判断是否安装了打印控件 //string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location; string strSql = @"select DocNo,MTIME,MUSERName from ICSCANew a WHERE a.DocNo IN (" + keyValue.TrimEnd(',') + ") and a.WorkPoint='" + WorkPoint + "'"; DataTable dtInInfo = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null); strSql = @" SELECT DISTINCT a.DocNo,a.DocLineNo,a.pocode,a.porow,c.invcode,c.invName,c.InvStd,a.Qty,--rd.iQuantity a.Remark,d.quantity,d.UnitPrice AS price,ISNULL(rd.ioriSum,0) AS TotalPrice ,rd.irowno,rd.ccode,rd.iquantity as RuQty ,ISNULL(rd.iOriMoney,0) AS iOriMoney,ISNULL(rd.iOriTaxPrice,0) AS iOriTaxPrice FROM (select isnull(CAST(qty AS DECIMAL(18,2)),0) AS Qty,ID,DocNo,DocLineNo,pocode,porow,Remark,EATTRIBUTE1,WorkPoint from ICSCANewDetail ) a LEFT JOIN dbo.ICSPurchaseOrder d ON a.POCode=d.POCode AND a.porow=d.Sequence and a.WorkPoint=d.WorkPoint LEFT JOIN ( select rd01.iPOsID,rd01.cPOID ,rd01.irowno,rd02.ccode,rd01.iquantity,rd01.AutoID,rd01.ioriSum,rd01.iOriMoney,rd01.iOriTaxPrice from {2}.dbo.rdrecords01 rd01 left join {2}.dbo.rdrecord01 rd02 on rd01.ID =rd02.ID LEFT JOIN {2}.dbo.PO_Podetails pomain on pomain.ID=rd01.iPOsID ) rd ON d.PODetailID =rd.iPOsID and a.EATTRIBUTE1=rd.AutoID LEFT JOIN ICSINVENTORY c ON d.InvCode=c.invCode AND a.WorkPoint=c.WorkPoint WHERE 1=1 AND a.DocNo = {0} AND a.WorkPoint = '{1}'"; strSql = string.Format(strSql, keyValue.TrimEnd(','), WorkPoint, DBLANK); DataTable dtInMaterial = DbHelper.ExecuteTable(DbHelper.ConnectionString, CommandType.Text, strSql, true, null); string strPrintTempFile = pJson.ShowReport(dtInInfo, dtInMaterial); //产生JSON文件内容 //把服务器的URL + 此文件名 传递给控件,由控件下载还原数据进行打印 string strServerURL = GetUrlPath() + "PrintTemp/"; string strData = strServerURL + strPrintTempFile; strPrintData = PrintFunction.EnBase64(strData); var JsonData = new { strPrintData_1 = strPrintData, bIsInstallPrintControl_1 = bIsInstallPrintControl, strPrintControlCookie_1 = strPrintControlCookie }; return Content(JsonData.ToJson()); } /// /// 写日志(用于跟踪) /// private void WriteLog(string strMessage) { string strLogFile = Server.MapPath("./Cookie_Log.txt"); StreamWriter swLogFile = null; try { if (!System.IO.File.Exists(strLogFile)) { swLogFile = System.IO.File.CreateText(strLogFile); } else { swLogFile = System.IO.File.AppendText(strLogFile); } swLogFile.WriteLine(strMessage); } catch { } finally { if (swLogFile != null) swLogFile.Close(); } } /// ///判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间 /// /// private void UpdateCheckInstall(string strCookie) { bool bIsExist = false; //判断记录是否存在 GetLastAccessTime(strCookie, ref bIsExist); string strSql = ""; SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) }; if (bIsExist) { //存在则更新最后访问的时间 strSql = @"Update sys_SRM_CheckInstall Set LastAccessTime = getDate() Where Cookie = @Cookie"; } else { //不存在则新建一条记录 strSql = @"Insert into sys_SRM_CheckInstall(Cookie, LastAccessTime) Values( @Cookie, getDate() )"; } DbHelper.ExecuteNonQuery(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie); } public DateTime ToDateTime(object SrcValue) { if (Convert.IsDBNull(SrcValue) == true) return DateTime.MinValue; else { try { return Convert.ToDateTime(SrcValue); } catch { return DateTime.MinValue; } } } /// /// 获取此Cookie的最后访问时间 /// /// /// private DateTime GetLastAccessTime(string strCookie, ref bool bIsExist) { DateTime dtLastAccessTime = DateTime.MinValue; bIsExist = false; string strSql = @"Select * From sys_SRM_CheckInstall Where Cookie = @Cookie"; SqlParameter[] pmcCookie = { new SqlParameter("Cookie", strCookie) }; using (SqlDataReader drCookie = DbHelper.ExecuteReader(DbHelper.ConnectionString, CommandType.Text, strSql, pmcCookie)) { if (drCookie.Read()) { dtLastAccessTime = ToDateTime(drCookie["LastAccessTime"]); bIsExist = true; } drCookie.Close(); } return dtLastAccessTime; } [HttpGet] [HandlerAjaxOnly] public ActionResult IsCheckInstall(string checkInstall) { string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,"); if (Request.QueryString["cookie"] != null) { //有控件上传的Cookie值 string strCookie = Request.QueryString["cookie"].ToString(); //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间 UpdateCheckInstall(strCookie); strValue = strValue + "上传的cookie:" + strCookie; } else if (checkInstall != null) {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况 string strCookie = checkInstall; //读取最后访问的时间 string strResult = "PrintControlInstall"; bool bIsExist = false; DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist); if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now) { strResult = "NOT"; } Response.Clear(); Response.Write(strResult); strValue = strValue + "检测安装的值:" + strCookie; } WriteLog(strValue); return null; } [HttpGet] [HandlerAjaxOnly] public ActionResult IsCheckInstall() { string strValue = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss 访问,"); if (Request.QueryString["cookie"] != null) { //有控件上传的Cookie值 string strCookie = Request.QueryString["cookie"].ToString(); //判断数据表中是否存在,若不存在则新建一条记录,若存在则更新最后访问的时间 UpdateCheckInstall(strCookie); strValue = strValue + "上传的cookie:" + strCookie; } else if (Request.QueryString["checkInstall"] != null) {//Ajax检查控件是否安装了,防止那种客户把打印控件卸装了,打印时无法检测到的情况 string strCookie = Request.QueryString["checkInstall"]; //读取最后访问的时间 string strResult = "PrintControlInstall"; bool bIsExist = false; DateTime dtLastAccessTime = GetLastAccessTime(strCookie, ref bIsExist); if (!bIsExist || dtLastAccessTime.AddSeconds(30) < DateTime.Now) { strResult = "NOT"; } Response.Clear(); Response.Write(strResult); strValue = strValue + "检测安装的值:" + strCookie; } WriteLog(strValue); return null; } #endregion } }