/// <summary> /// 登录MES系统 /// </summary> /// <returns></returns> public MesLoginResult LoginMes() { MesLoginResult loginResult = new MesLoginResult(); string loginUrl = MESUrl + "/GTHINKING/AjaxService/N_MISPRO/100208057.ashx/Login"; MESLoginDto mESLogin = new MESLoginDto() { userId = UserName, password = PassWord, clientType = "s", epId = "" }; string postData = JsonConvert.SerializeObject(mESLogin); Tuple <bool, CookieContainer, string> returnData = PostData.PostLogin(postData, loginUrl); if (returnData.Item1 == true) { loginResult = JsonConvert.DeserializeObject <MesLoginResult>(returnData.Item3); if (loginResult.Success) { DateTime expireTime = DateTime.Now.AddMinutes(210); CacheHelper.Add("MESUser", returnData.Item2, expireTime); } else { CacheHelper.Remove("MESUser"); } } else { loginResult = new MesLoginResult() { ErrorMessage = returnData.Item3, Success = returnData.Item1 }; } return(loginResult); }
public void Execute() { lock (_lockMin) { if (_shuttingDown) { return; } List <LogDetail> logDetails = new List <LogDetail>(); Config _config = new Config(); string interfaceUrl = _config.MESUrl + "/GTHINKING/AjaxService/U20201652_N_XL/100892099.ashx/NewWL"; try { Dictionary <string, string> dic = SQLBusiness.GetBusinessInfo("Inventory"); busId = dic["id"]; upTime = dic["value"]; string newid = Guid.NewGuid().ToString(); string SqlText = string.Empty; DataTable dt = new DataTable(); string SelSql = string.Empty; SQLHelper dbTplus = new SQLHelper("Tplusconn"); SQLHelper dbSysConn = new SQLHelper("DefaultConnection"); string url = string.Empty; string StrSql = string.Empty; object mesCookie = CacheHelper.Get("MESUser"); if (mesCookie == null) { MesLoginResult mesLogin = _config.LoginMes(); if (!mesLogin.Success) { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = $"Mes系统登录请求失败,请求信息(用户:{_config.UserName},密码:{_config.PassWord})", postType = "Post", returnData = mesLogin.ErrorMessage, result = "失败", description = "Mes系统登录请求" }); SQLBusiness.WriteDetailLog(logDetails); return; } else { mesCookie = CacheHelper.Get("MESUser"); } } CookieContainer cookie = mesCookie as CookieContainer; SelSql = string.Format(@"select TOP 10 A.code,A.name,specification,B.code inventoryclass,C.name unit,idinvlocation,idSubUnitByReport isPurchase,isMadeSelf,isMaterial,IsWeigh,Creater,A.updatedBy,A.updated,E.name saleUnit, priuserdefnvc2,C.Gcode,C.Gname,G.name subUnit,CASE A.disabled WHEN 1 THEN 'Y' ELSE 'N' END AS TYBZ, A.priuserdefnvc1 AS COLOR from AA_Inventory A LEFT JOIN AA_InventoryClass B ON A.idinventoryclass=B.id LEFT JOIN V_Gunit C ON A.idunit=C.id LEFT JOIN V_Gunit E ON A.idUnitBySale=E.id LEFT JOIN V_Gunit G ON A.idSubUnitByReport =G.id WHERE NOT EXISTS(SELECT TOP 1 1 FROM MESTIMEAPI.dbo.[tb_Inventory] where code= A.code )" ); SqlText = string.Format(@"select A.code,A.name,specification,B.code inventoryclass,C.name unit,idinvlocation,idSubUnitByReport isPurchase,isMadeSelf,isMaterial,IsWeigh,Creater,A.updatedBy,A.updated,E.name saleUnit, priuserdefnvc2,C.Gcode,C.Gname,G.name subUnit,CASE A.disabled WHEN 1 THEN 'Y' ELSE 'N' END AS TYBZ, A.priuserdefnvc1 AS COLOR from AA_Inventory A LEFT JOIN AA_InventoryClass B ON A.idinventoryclass=B.id LEFT JOIN V_Gunit C ON A.idunit=C.id LEFT JOIN V_Gunit E ON A.idUnitBySale=E.id LEFT JOIN V_Gunit G ON A.idSubUnitByReport =G.id WHERE EXISTS(SELECT TOP 1 1 FROM MESTIMEAPI.dbo.tb_Inventory where code= A.code AND CONVERT(varchar(100), updated, 120)<> CONVERT(varchar(100), A.updated, 120) ) "); DataTable TPlusAddDt = dbTplus.GetDataTable(CommandType.Text, SelSql, null); DataTable TPlusUpDt = dbTplus.GetDataTable(CommandType.Text, SqlText, null); if (TPlusAddDt != null) { List <string> InsertSql = new List <string>(); IEnumerable <InventoryDto> query = from a in TPlusAddDt.AsEnumerable() select new InventoryDto() { WLID = a.Field <string>("code"), OLDWLID = a.Field <string>("code"), PIID = a.Field <string>("inventoryclass"), WLMC = a.Field <string>("name"), GG = a.Field <string>("specification"), XH = "", DYDJ = "", COLOR = a.Field <string>("COLOR"), TZ = "", CL = "", WLXT = "K", JLDW = a.Field <string>("unit"), FJLDW = a.Field <string>("subUnit"), CWJLDW = a.Field <string>("unit"), XSJLDW = a.Field <string>("saleUnit"), ZZSL = 0, PHKZ = "N", TYBZ = a.Field <string>("TYBZ") }; if (query != null && query.Count() > 0) { var postObject = new { CZLX = "I", DATA = query }; string postData = JsonConvert.SerializeObject(postObject); Tuple <bool, string> returnData = PostData.PostDataWithCokie(postData, interfaceUrl, cookie); if (returnData.Item1) { Result result = JsonConvert.DeserializeObject <Result>(returnData.Item2); if (result.Success) { foreach (DataRow data in TPlusAddDt.Rows) { InsertSql.Add(string.Format(@"INSERT INTO [dbo].[tb_Inventory]([code],[updated]) values('{0}','{1}')", data["code"], data["updated"])); sucsum = sucsum + 1; } logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = returnData.Item2, result = "成功", description = "物料同步" }); } else { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = result.Message, result = "失败", description = "物料同步" }); } } else { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = returnData.Item2, result = "失败", description = "物料同步" }); } } if (InsertSql.Count > 0) { dbSysConn.ExecuteSqlTran(InsertSql); } } if (TPlusUpDt != null) { List <string> UpSql = new List <string>(); IEnumerable <InventoryDto> query = from a in TPlusUpDt.AsEnumerable() select new InventoryDto() { WLID = a.Field <string>("code"), OLDWLID = a.Field <string>("code"), PIID = a.Field <string>("inventoryclass"), WLMC = a.Field <string>("name"), GG = a.Field <string>("specification"), XH = "", DYDJ = "", COLOR = "", TZ = "", CL = "", WLXT = "K", JLDW = a.Field <string>("unit"), FJLDW = a.Field <string>("subUnit"), CWJLDW = a.Field <string>("unit"), XSJLDW = a.Field <string>("saleUnit"), ZZSL = 0, PHKZ = "N", TYBZ = a.Field <string>("TYBZ") }; if (query != null && query.Count() > 0) { var postObject = new { CZLX = "U", DATA = query }; string postData = JsonConvert.SerializeObject(postObject); Tuple <bool, string> returnData = PostData.PostDataWithCokie(postData, interfaceUrl, cookie); if (returnData.Item1) { Result result = JsonConvert.DeserializeObject <Result>(returnData.Item2); if (result.Success) { foreach (DataRow data in TPlusUpDt.Rows) { UpSql.Add(string.Format(@"UPDATE [dbo].[tb_Inventory] SET updated='{1}' WHERE code='{0}'", data["code"], data["updated"])); sucsum = sucsum + 1; } logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = returnData.Item2, result = "成功", description = "物料同步" }); } else { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = result.Message, result = "失败", description = "物料同步" }); } } else { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = returnData.Item2, result = "失败", description = "物料同步" }); } } if (UpSql.Count > 0) { dbSysConn.ExecuteSqlTran(UpSql); } } SQLBusiness.WriteDetailLog(logDetails); } catch (Exception ex) { failsum += 1; logDetails.Add(new LogDetail() { busId = busId, code = ex.HResult.ToString(), date = DateTime.Now, url = interfaceUrl, postData = ex.Source.Replace("'", ""), postType = "", returnData = ex.Message.Replace("'", "''"), result = "系统错误", description = "同步物料" }); SQLBusiness.WriteDetailLog(logDetails); } finally { SQLBusiness.WriteCountLog(new CountDto() { BusId = busId, sucsum = sucsum, failsum = failsum, latTime = DateTime.Now.AddMinutes(Convert.ToInt32(upTime)).ToString() }); } } }
public void Execute() { lock (_lockMin) { if (_shuttingDown) { return; } List <LogDetail> logDetails = new List <LogDetail>(); Config _config = new Config(); string interfaceUrl = _config.MESUrl + "/GTHINKING/AjaxService/U20201652_N_XL/100892099.ashx/NewPL"; try { Dictionary <string, string> dic = SQLBusiness.GetBusinessInfo("InventoryClass"); busId = dic["id"]; upTime = dic["value"]; string newid = Guid.NewGuid().ToString(); string SqlText = string.Empty; DataTable dt = new DataTable(); string SelSql = string.Empty; SQLHelper dbTplus = new SQLHelper("Tplusconn"); SQLHelper dbSysConn = new SQLHelper("DefaultConnection"); string url = string.Empty; string StrSql = string.Empty; object mesCookie = CacheHelper.Get("MESUser"); if (mesCookie == null) { MesLoginResult mesLogin = _config.LoginMes(); if (!mesLogin.Success) { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = $"Mes系统登录请求失败,请求信息(用户:{_config.UserName},密码:{_config.PassWord})", postType = "Post", returnData = mesLogin.ErrorMessage, result = "失败", description = "Mes系统登录请求" }); SQLBusiness.WriteDetailLog(logDetails); return; } else { mesCookie = CacheHelper.Get("MESUser"); } } CookieContainer cookie = mesCookie as CookieContainer; SelSql = string.Format(@"SELECT code,name,CASE isEndNode WHEN 1 THEN 'Y' ELSE 'N' END AS MJBZ, CASE disabled WHEN 1 THEN 'Y' ELSE 'N' END AS TYBZ,A.updated FROM dbo.AA_InventoryClass A WHERE NOT EXISTS(SELECT TOP 1 1 FROM MESTIMEAPI.dbo.tb_InventoryClass where code= A.code ) "); SqlText = string.Format(@"SELECT code,name,CASE isEndNode WHEN 1 THEN 'Y' ELSE 'N' END AS MJBZ, CASE disabled WHEN 1 THEN 'Y' ELSE 'N' END AS TYBZ,A.updated FROM dbo.AA_InventoryClass A WHERE EXISTS(SELECT TOP 1 1 FROM MESTIMEAPI.dbo.tb_InventoryClass where code= A.code AND CONVERT(varchar(100), updated, 120)<> CONVERT(varchar(100), A.updated, 120) ) "); DataTable TPlusAddDt = dbTplus.GetDataTable(CommandType.Text, SelSql, null); DataTable TPlusUpDt = dbTplus.GetDataTable(CommandType.Text, SqlText, null); if (TPlusAddDt != null) { List <string> InsertSql = new List <string>(); IEnumerable <ClassDto> query = from a in TPlusAddDt.AsEnumerable() select new ClassDto() { MJBZ = a.Field <string>("MJBZ"), OLDPLID = a.Field <string>("code"), PIID = a.Field <string>("code"), PLMC = a.Field <string>("name"), TYBZ = a.Field <string>("TYBZ") }; if (query != null && query.Count() > 0) { var postObject = new { CZLX = "I", DATA = query }; string postData = JsonConvert.SerializeObject(postObject); Tuple <bool, string> returnData = PostData.PostDataWithCokie(postData, interfaceUrl, cookie); if (returnData.Item1) { Result result = JsonConvert.DeserializeObject <Result>(returnData.Item2); if (result.Success) { foreach (DataRow data in TPlusAddDt.Rows) { InsertSql.Add(string.Format(@"INSERT INTO [dbo].[tb_InventoryClass]([code],[updated]) values('{0}','{1}')", data["code"], data["updated"])); sucsum = sucsum + 1; } logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = returnData.Item2, result = "成功", description = "物料类别同步" }); } else { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = result.Message, result = "失败", description = "物料类别同步" }); } } else { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = returnData.Item2, result = "失败", description = "物料类别同步" }); } } if (InsertSql.Count > 0) { dbSysConn.ExecuteSqlTran(InsertSql); } } if (TPlusUpDt != null) { List <string> UpSql = new List <string>(); IEnumerable <ClassDto> query = from a in TPlusUpDt.AsEnumerable() select new ClassDto() { MJBZ = a.Field <string>("MJBZ"), OLDPLID = a.Field <string>("code"), PIID = a.Field <string>("code"), PLMC = a.Field <string>("name"), TYBZ = a.Field <string>("TYBZ") }; if (query != null && query.Count() > 0) { var postObject = new { CZLX = "U", DATA = query }; string postData = JsonConvert.SerializeObject(postObject); Tuple <bool, string> returnData = PostData.PostDataWithCokie(postData, interfaceUrl, cookie); if (returnData.Item1) { Result result = JsonConvert.DeserializeObject <Result>(returnData.Item2); if (result.Success) { foreach (DataRow data in TPlusUpDt.Rows) { UpSql.Add(string.Format(@"UPDATE [dbo].[tb_InventoryClass] SET updated='{1}' WHERE code='{0}'", data["code"], data["updated"])); sucsum = sucsum + 1; } logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = returnData.Item2, result = "成功", description = "物料类别同步" }); } else { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = result.Message, result = "失败", description = "物料类别同步" }); } } else { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = returnData.Item2, result = "失败", description = "物料类别同步" }); } } if (UpSql.Count > 0) { dbSysConn.ExecuteSqlTran(UpSql); } } SQLBusiness.WriteDetailLog(logDetails); } catch (Exception ex) { failsum += 1; logDetails.Add(new LogDetail() { busId = busId, code = ex.HResult.ToString(), date = DateTime.Now, url = interfaceUrl, postData = ex.Source.Replace("'", ""), postType = "", returnData = ex.Message.Replace("'", "''"), result = "系统错误", description = "同步物料类别" }); SQLBusiness.WriteDetailLog(logDetails); } finally { SQLBusiness.WriteCountLog(new CountDto() { BusId = busId, sucsum = sucsum, failsum = failsum, latTime = DateTime.Now.AddMinutes(Convert.ToInt32(upTime)).ToString() }); } } }
public void Execute() { lock (_lockMin) { if (_shuttingDown) { return; } List <LogDetail> logDetails = new List <LogDetail>(); Config _config = new Config(); string interfaceUrl = _config.MESUrl + "/GTHINKING/AjaxService/U20201652_N_XL/100892099.ashx/NewSO"; try { Dictionary <string, string> dic = SQLBusiness.GetBusinessInfo("SaleOrder"); busId = dic["id"]; upTime = dic["value"]; string newid = Guid.NewGuid().ToString(); string SqlText = string.Empty; DataTable dt = new DataTable(); string SelSql = string.Empty; SQLHelper dbTplus = new SQLHelper("Tplusconn"); SQLHelper dbSysConn = new SQLHelper("DefaultConnection"); string url = string.Empty; string StrSql = string.Empty; object mesCookie = CacheHelper.Get("MESUser"); if (mesCookie == null) { MesLoginResult mesLogin = _config.LoginMes(); if (!mesLogin.Success) { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = "", date = DateTime.Now, url = interfaceUrl, postData = $"Mes系统登录请求失败,请求信息(用户:{_config.UserName},密码:{_config.PassWord})", postType = "Post", returnData = mesLogin.ErrorMessage, result = "失败", description = "Mes系统登录请求" }); SQLBusiness.WriteDetailLog(logDetails); return; } else { mesCookie = CacheHelper.Get("MESUser"); } } CookieContainer cookie = mesCookie as CookieContainer; SelSql = string.Format(@"SELECT TOP 10 A.id, A.voucherdate AS DDRQ, A.code AS SOID,'ljxk' KHID,ISNULL(C.code,'') BMID, ISNULL(C.name,'') deptName,ISNULL(D.name,'') TXY,left(A.linkMan,4) AS LXR,A.acceptDate AS XQRQ,ISNULL(A.memo,'') BZ FROM PU_PurchaseOrder A LEFT JOIN AA_Partner B ON A.idpartner =B.id LEFT JOIN AA_Department C ON A.iddepartment =C.id LEFT JOIN AA_Person D ON A.idclerk=D.id WHERE NOT EXISTS(SELECT TOP 1 1 FROM MESTIMEAPI.dbo.tb_PurchaseOrder WHERE A.code=code)"); DataTable TPlusAddDt = dbTplus.GetDataTable(CommandType.Text, SelSql, null); if (TPlusAddDt != null && TPlusAddDt.Rows.Count > 0) { List <string> InsertSql = new List <string>(); foreach (DataRow orderHead in TPlusAddDt.Rows) { SqlText = string.Format($@"SELECT A.id AS SOXH,'{orderHead["SOID"].ToString()}' AS SOID,B.code AS WLID,C.name AS JLDW,A.acceptDate AS XQRQ, A.quantity AS XQSL,A.origTaxPrice AS JG,A.origTaxAmount AS JE,A.origPrice AS WSJG, (A.origTaxAmount-A.origTax) WSJE,A.origTax,A.pubuserdefnvc2 AS BZ,A.saleOrderCode FROM PU_PurchaseOrder_b A LEFT JOIN dbo.AA_Inventory B ON A.idinventory=B.id LEFT JOIN dbo.AA_Unit C ON A.idunit=C.id WHERE A.idPurchaseOrderDTO='{orderHead["id"].ToString()}'"); DataTable orderBodyDt = dbTplus.GetDataTable(CommandType.Text, SqlText, null); IEnumerable <SaleOrderDetailDto> query = from a in orderBodyDt.AsEnumerable() select new SaleOrderDetailDto() { WLID = a.Field <string>("WLID"), BZ = a.Field <string>("BZ"), JE = a.Field <decimal>("JE"), JG = a.Field <decimal>("JG"), JHFHRQ = null, SOID = a.Field <string>("SOID"), SOXH = a.Field <int>("SOXH"), WSJE = a.Field <decimal>("WSJE"), WSJG = a.Field <decimal>("WSJG"), XQRQ = a.Field <DateTime?>("XQRQ"), XQSL = a.Field <decimal>("XQSL"), JLDW = a.Field <string>("JLDW") }; SaleOrderDto saleOrder = new SaleOrderDto() { BMID = orderHead["BMID"].ToString(), BZ = orderHead["BZ"].ToString(), DDRQ = orderHead["DDRQ"] != null?Convert.ToDateTime(orderHead["DDRQ"]) : DateTime.Now, KHID = orderHead["KHID"].ToString(), LXR = orderHead["LXR"].ToString(), SOID = orderHead["SOID"].ToString(), TXY = orderHead["TXY"].ToString(), XQRQ = orderHead["XQRQ"] != null?Convert.ToDateTime(orderHead["XQRQ"]) : DateTime.Now }; if (query != null && query.Count() > 0) { saleOrder.DETAILS = query.ToList(); var postObject = new { CZLX = "I", DATA = saleOrder }; string postData = JsonConvert.SerializeObject(postObject); Tuple <bool, string> returnData = PostData.PostDataWithCokie(postData, interfaceUrl, cookie); if (returnData.Item1) { Result result = JsonConvert.DeserializeObject <Result>(returnData.Item2); if (result.Success) { InsertSql.Add(string.Format(@"INSERT INTO [dbo].[tb_PurchaseOrder]([code]) values('{0}')", orderHead["SOID"])); sucsum = sucsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = orderHead["SOID"].ToString(), date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = returnData.Item2, result = "成功", description = "销售订单同步" }); } else { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = orderHead["SOID"].ToString(), date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = result.Message, result = "失败", description = "销售订单同步" }); } } else { failsum = failsum + 1; logDetails.Add(new LogDetail() { busId = busId, code = orderHead["SOID"].ToString(), date = DateTime.Now, url = interfaceUrl, postData = postData, postType = "Post", returnData = returnData.Item2, result = "失败", description = "销售订单同步" }); } } } if (InsertSql.Count > 0) { dbSysConn.ExecuteSqlTran(InsertSql); } } SQLBusiness.WriteDetailLog(logDetails); } catch (Exception ex) { failsum += 1; logDetails.Add(new LogDetail() { busId = busId, code = ex.HResult.ToString(), date = DateTime.Now, url = interfaceUrl, postData = ex.Source.Replace("'", ""), postType = "", returnData = ex.Message.Replace("'", "''"), result = "系统错误", description = "同步销售订单" }); SQLBusiness.WriteDetailLog(logDetails); } finally { SQLBusiness.WriteCountLog(new CountDto() { BusId = busId, sucsum = sucsum, failsum = failsum, latTime = DateTime.Now.AddMinutes(Convert.ToInt32(upTime)).ToString() }); } } }