/// <summary> /// 保存数据前检查指定业数据是否符合条件(事务前) /// </summary> /// <param name="drsr"></param> /// <param name="bdo"></param> /// <returns></returns> protected void DataSave_BeforeCheckBDO(DataRowSaveResult drsr, BDO bdo) { drsr.DataRow = null; bf_Busi_Field[] bbf_List = (bf_Busi_Field[])bdo.Business.Fields.Select("m_ValueControl>0"); foreach (BRO bro in bdo.Rows) { if (bro.RowState == DataRowState.Detached) { continue; } //if (drData.RowState == DataRowState.Unchanged) continue; drsr.DataRow = bro; bro.ValidFieldValues(drsr, bbf_List); if (drsr.Success == false) { return; } // this.OnDataSave_BeforeCheckRow(drsr); if (drsr.Success == false) { return; } } this.DataSave_BeforeCheckBDOUnique(drsr, bdo); if (drsr.Success == false) { return; } }
public static string BDOsToJSON(BDOs bdos) { DataSetModel dsMd = new DataSetModel(); dsMd.name = bdos.DataSetName; BDO mbdo = bdos.MasterBDO; dsMd.dataModel.Add(new DataTableModel { name = mbdo.BusiNo, data = mbdo, queryno = mbdo.Business.QueryNo }); AddChildBDOData(dsMd, mbdo); StringBuilder sbd = new StringBuilder(); sbd.Append("{ \"name\":\""); sbd.Append(dsMd.name); sbd.Append("\",\"datas\":["); foreach (var v in dsMd.dataModel) { sbd.Append("{\"busiName\":\""); sbd.Append(v.name); sbd.Append("\",\"busiQueryno\":\""); sbd.Append(v.queryno); sbd.Append("\",\"busiData\":"); string str = JsonConvert.SerializeObject(v.data); sbd.Append(str); sbd.Append("},"); } sbd.Remove(sbd.Length - 1, 1); sbd.Append("],\"relations\":"); sbd.Append(JsonConvert.SerializeObject(dsMd.relations)); sbd.Append("}"); return(sbd.ToString()); }
public void UpdateAthelete(BDO.Athlete athlete) { using (var unitOfWork = DAL.UnitOfWork.Create()) { unitOfWork.AthleteRepository.Update(athlete); unitOfWork.Commit(); } }
public void UpdateTraining(BDO.Training training) { using (var unitOfWork = DAL.UnitOfWork.Create()) { unitOfWork.TrainingRepository.Update(training); unitOfWork.Commit(); } }
public void UpdateCompetition(BDO.Competition competition) { using (var unitOfWork = DAL.UnitOfWork.Create()) { unitOfWork.CompetitionRepository.Update(competition); unitOfWork.Commit(); } }
/// <summary> /// BDO模型转DataTable /// </summary> /// <param name="bdo"></param> /// <returns></returns> public static DataTable ToDataTableDTO(BDO bdo) { DataView dv = bdo.DefaultView; DataTable dt = dv.ToTable(); dt.AcceptChanges(); dt.TableName = bdo.TableName; return(dt); }
public ActionResult Create(BDO.Athlete athlete) { try { athleteManager.AddAthlete(athlete); return RedirectToAction("Index"); } catch { return View(); } }
public static string BDOToJSON(BDO bdoData) { StringBuilder sbd = new StringBuilder(); sbd.Append("{\"busiName\":\""); sbd.Append(bdoData.BusiNo); sbd.Append("\",\"busiQueryno\":\""); sbd.Append(bdoData.Business.QueryNo); sbd.Append("\",\"busiData\":"); string str = JsonConvert.SerializeObject(bdoData); sbd.Append(str); sbd.Append("}"); return(sbd.ToString()); }
private void OnSave_AfterTransaction(DataRowSaveResult drsr, BDO bdo) { drsr.DataRow = null; if (bdo == null) { return; } DataRow dr = bdo.CurrentDataRow; if (dr == null) { return; } //if (Save_AfterTransaction == null) return; //DataRowSaveEventArgs drse = new DataRowSaveEventArgs(drsr, dr.RowState); //Save_AfterTransaction(bdo, drse); }
static void AddChildBDOData(DataSetModel dsMd, BDO mbdo) { foreach (var bdo in mbdo.Children) { dsMd.dataModel.Add(new DataTableModel { name = bdo.BusiNo, queryno = bdo.Business.QueryNo, data = bdo }); dsMd.relations.Add(new RelationDTO() { name = bdo.BusiNo, parentBusiNo = mbdo.Business.No, parentCols = new List <string> { bdo.ParentRelations[0].ParentColumns[0].ColumnName }, childCols = new List <string> { bdo.ParentRelations[0].ChildColumns[0].ColumnName } }); if (bdo.Children.Count > 0) { AddChildBDOData(dsMd, bdo); } } }
/// <summary> /// 实时接口 POST请求 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="interfaceCode"></param> /// <param name="interfaceName"></param> /// <param name="PostObj"></param> /// <returns></returns> public static IRestResponse <T> PostExcute <T>(DataRow InterfaceURLRow, string interfaceName, object PostObj) where T : class, new() { //BDOs tmpInterFaceConfig = new BDOs("SYS_InterfaceURL", "INTERFACECODE = '"+ interfaceCode+"'"); if (InterfaceURLRow == null) { throw new ApplicationException("接口地址未配置!"); } string InterfaceURL = InterfaceURLRow["URL"].ToString(); if (string.IsNullOrEmpty(InterfaceURL)) { throw new ApplicationException("接口地址未配置!"); } string interfaceCode = InterfaceURLRow["INTERFACECODE"].ToString(); var client = new RestClient(InterfaceURL); var request = new RestRequest(Method.POST) { RequestFormat = DataFormat.Json }; request.AddJsonBody(PostObj); request.AddHeader("Content-Type", "application/json; charset=utf-8"); var content = client.Execute <T>(request); string requestBody = JsonConvert.SerializeObject(PostObj); requestBody = requestBody.Replace("\\\\", "\\"); string responseBody = content.Content; StackTrace trace = new StackTrace(); StackFrame frame = trace.GetFrame(1); MethodBase method = frame.GetMethod(); //String className = method.ReflectedType.Name; if (content.StatusCode != System.Net.HttpStatusCode.OK) { var hi = AppCache.GetCache <RequestHeaderInfo>(Thread.CurrentThread.ManagedThreadId); Task task1 = new Task(() => { var ai = new RequestHeaderInfo(hi.LangNo, hi.DBNo, hi.MenuNo, hi.UserNo, hi.UserName, ""); AppCache.Add(Thread.CurrentThread.ManagedThreadId, ai); BDO bd1 = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat1 = bd1.NewRow(); drBat1["IsIn"] = 1; drBat1["SerialNo"] = Guid.NewGuid(); drBat1["FunctionName"] = method.Name; drBat1["InterfaceName"] = interfaceName; drBat1["interfaceCode"] = interfaceCode; drBat1["RequestBody"] = requestBody; drBat1["ResponseBody"] = responseBody; drBat1["ResponseCode"] = "E"; drBat1["ResponseMessage"] = content.Content; drBat1["CREATETIME"] = DateTime.Now; bd1.Rows.Add(drBat1); DataRowsSaveResult drsr1 = bd1.SaveToDB(); if (!drsr1.Success) { throw new Exception(drsr1.ErrorText); } }); task1.Start(); task1.Wait(); } else { var ResponseCode = string.Empty; var ResponseMessage = string.Empty; var ZGUID = string.Empty; try { T model = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(responseBody); if (model == null) { throw new ApplicationException("返回信息解析失败:" + InterfaceURL + "->" + responseBody); } if (content.Data == null) { content.Data = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(responseBody); } } catch (Exception ex) { ResponseCode = "N/A"; ResponseMessage = string.IsNullOrEmpty(responseBody) ? ex.Message : responseBody; } var hi = AppCache.GetCache <RequestHeaderInfo>(Thread.CurrentThread.ManagedThreadId); Task task1 = new Task(() => { var ai = new RequestHeaderInfo(hi.LangNo, hi.DBNo, hi.MenuNo, hi.UserNo, hi.UserName, ""); AppCache.Add(Thread.CurrentThread.ManagedThreadId, ai); BDO bd1 = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat1 = bd1.NewRow(); drBat1["IsIn"] = 1; drBat1["SerialNo"] = Guid.NewGuid(); drBat1["FunctionName"] = method.Name; drBat1["InterfaceName"] = interfaceName; drBat1["interfaceCode"] = interfaceCode; drBat1["RequestBody"] = requestBody; drBat1["ResponseBody"] = responseBody; drBat1["ResponseCode"] = ResponseCode; drBat1["ResponseMessage"] = string.IsNullOrEmpty(ResponseMessage) ? "" : ResponseMessage; drBat1["CREATETIME"] = DateTime.Now; bd1.Rows.Add(drBat1); DataRowsSaveResult drsr1 = bd1.SaveToDB(); if (!drsr1.Success) { throw new Exception(drsr1.ErrorText); } }); task1.Start(); task1.Wait(); } return(content); }
public static List <BDOs> ToBDOsModel(PostData postData) { //取真实表名 for (int i = 0; i < postData.BusiDatas.Length; i++) { bf_Busi busi = bf_Busis.GetItem(postData.BusiDatas[i].BusiNo); if (busi == null) { continue; } postData.BusiDatas[i].TableName = busi.TableName; busi = bf_Busis.GetItem(postData.BusiDatas[i].ParentBusiNo); if (busi == null) { continue; } postData.BusiDatas[i].ParentTableName = busi.TableName; } //按照表关系转换 List <BDOs> lstDs = new List <BDOs>(); List <string> lstTbInBdos = new List <string>(); for (int i = 0; i < postData.relations.Length; i++) { RelationDTO rel = postData.relations[i]; BDOs BDOS = lstDs.Find((b) => b.DataSetName == rel.parentBusiNo); if (BDOS == null) { BDOs bdos = null; BDO bdoParent = null; foreach (BDOs bds in lstDs) { bdoParent = bds[rel.parentBusiNo]; if (bdoParent != null) { bdos = bds; break; } } if (bdoParent == null) { bdos = new BDOs(rel.parentBusiNo); bdoParent = JsonToBDO(bdos, null, rel.parentBusiNo, postData.BusiDatas.AsEnumerable().FirstOrDefault(f => f.BusiNo.Equals(rel.parentBusiNo)).JsonData); CheckNullValue(bdoParent); bdos.DataSetName = rel.parentBusiNo; } BDO bdoChild = JsonToBDO(bdos, null, rel.name, postData.BusiDatas.AsEnumerable().FirstOrDefault(f => f.BusiNo.ToUpper().Equals(rel.name.ToUpper())).JsonData); if (bdoParent.Rows.Count == 0) { foreach (DataRow row in bdoChild.Rows) { if (bdoParent.AsEnumerable().FirstOrDefault(f => f[rel.parentCols[0]].Equals(row[rel.childCols[0]])) != null) { continue; } DataRow nr = bdoParent.NewRow(); nr[rel.parentCols[0]] = row.RowState == DataRowState.Deleted?row[rel.childCols[0], DataRowVersion.Original]: row[rel.childCols[0]]; bdoParent.Rows.Add(nr); } bdoParent.AcceptChanges(); } bdoParent.AddChildren(rel.name, bdoChild, rel.parentCols[0], rel.childCols[0]); //CopyRelation(bdos, rel); if (!lstDs.Contains(bdos)) { lstDs.Add(bdos); lstTbInBdos.Add(rel.parentBusiNo); } lstTbInBdos.Add(rel.name); } else { BDO bdo = JsonToBDO(BDOS, null, rel.name, postData.BusiDatas.AsEnumerable().FirstOrDefault(f => f.BusiNo.Equals(rel.name)).JsonData); CheckNullValue(bdo); if (BDOS.MasterBDO.Rows.Count == 0) { foreach (DataRow row in bdo.Rows) { if (BDOS.MasterBDO.AsEnumerable().FirstOrDefault(f => f[rel.parentCols[0]].Equals(row[rel.childCols[0]])) != null) { continue; } DataRow nr = BDOS.MasterBDO.NewRow(); nr[rel.parentCols[0]] = row[rel.childCols[0]]; BDOS.MasterBDO.Rows.Add(nr); } BDOS.MasterBDO.AcceptChanges(); } BDOS.MasterBDO.AddChildren(rel.name, bdo, rel.parentCols[0], rel.childCols[0]); //CopyRelation(BDOS, rel); lstTbInBdos.Add(rel.name); } } //无表关系的单表 foreach (BusiData bd in postData.BusiDatas) { if (!lstTbInBdos.Exists((name) => name == bd.BusiNo)) { BDOs singleBDOs = new BDOs(bd.BusiNo); BDO bdo = JsonToBDO(singleBDOs, null, bd.BusiNo, postData.BusiDatas.AsEnumerable().FirstOrDefault(f => f.BusiNo.Equals(bd.BusiNo)).JsonData); CheckNullValue(bdo); singleBDOs.DataSetName = bd.BusiNo; lstDs.Add(singleBDOs); } } return(lstDs); }
// 记录接口日志 public static IRestResponse <T> PostExcute <T>(DataRow InterfaceURL, DataRow InterfaceQueue, object PostObj) where T : class, new() { if (string.IsNullOrEmpty(InterfaceURL["Url"].ToString())) { throw new ApplicationException("接口地址未配置!"); } var client = new RestClient(InterfaceURL["Url"].ToString()); var request = new RestRequest(Method.POST) { RequestFormat = DataFormat.Json }; request.AddJsonBody(PostObj); request.AddHeader("Content-Type", "application/json; charset=utf-8"); var content = client.Execute <T>(request); var interfaceCode = string.Empty; if (InterfaceURL["Url"].ToString().Contains("=")) { interfaceCode = InterfaceURL["Url"].ToString().Split('=')[1]; } string requestBody = content.Request.JsonSerializer.Serialize(PostObj); string responseBody = content.Content; if (content.StatusCode != System.Net.HttpStatusCode.OK) { BDO bd = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat = bd.NewRow(); drBat["IsIn"] = 0; drBat["LogTime"] = DateTime.Now; drBat["SerialNo"] = InterfaceQueue["SerialNo"]; drBat["FunctionName"] = InterfaceQueue["FunctionName"]; drBat["InterfaceName"] = InterfaceQueue["InterfaceName"]; drBat["interfaceCode"] = interfaceCode; drBat["RequestBody"] = requestBody; drBat["ResponseBody"] = responseBody; drBat["ResponseCode"] = "E"; drBat["ResponseMessage"] = content.Content; bd.Rows.Add(drBat); DataRowsSaveResult drsr = bd.SaveToDB(null, null); } else { var ResponseCode = string.Empty; var ResponseMessage = string.Empty; var ZGUID = string.Empty; var isSendMialToSAP = false;//是否发送邮件 added by haijun 2018-4-18 try { BaseReturnModel model = Newtonsoft.Json.JsonConvert.DeserializeObject <BaseReturnModel>(responseBody); if (model == null) { throw new ApplicationException("返回信息解析失败:" + InterfaceURL["Url"].ToString() + "->" + responseBody); } if (content.Data == null) { content.Data = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(responseBody); } //added by haijun if (model.HEAD != null) { if (!String.IsNullOrEmpty(model.HEAD.ZTYPE)) { if (model.HEAD.ZTYPE == "E") { isSendMialToSAP = true; } } } if (model.ITEM != null && model.ITEM.Count > 0 && !isSendMialToSAP) { var items = model.ITEM.Where(i => i.ZTYPE == "E"); if (items.Any()) { isSendMialToSAP = true; } } if (model.HEAD != null && !string.IsNullOrEmpty(model.HEAD.ZTYPE)) { ResponseCode = model.HEAD.ZTYPE; ResponseMessage = model.HEAD.ZMESSAGE; ZGUID = model.HEAD.ZGUID; } else if (model.ITEM != null && model.ITEM.Count > 0) { var items = model.ITEM.Where(i => i.ZTYPE == "E"); ResponseCode = items.Any() ? "E" : "S"; if (items.Any()) { ResponseMessage = string.Join(";", items.Select(s => s.ZMESSAGE).ToList()); } else { ResponseMessage = model.ITEM.First().ZMESSAGE; } ZGUID = model.ITEM.First().ZGUID; } } catch (Exception ex) { ResponseCode = "N/A"; ResponseMessage = string.IsNullOrEmpty(responseBody) ? ex.Message : responseBody; } BDO bd = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat = bd.NewRow(); drBat["IsIn"] = 0; drBat["LogTime"] = DateTime.Now; drBat["SerialNo"] = InterfaceQueue["SerialNo"]; drBat["FunctionName"] = InterfaceQueue["FunctionName"]; drBat["InterfaceName"] = InterfaceQueue["InterfaceName"]; drBat["interfaceCode"] = interfaceCode; drBat["RequestBody"] = requestBody; drBat["ResponseBody"] = responseBody; drBat["ResponseCode"] = ResponseCode; drBat["ResponseMessage"] = string.IsNullOrEmpty(ResponseMessage) ? "" : ResponseMessage; bd.Rows.Add(drBat); DataRowsSaveResult drsr = bd.SaveToDB(null, null); } return(content); }
/// <summary> /// 实时接口 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="interfaceCode"></param> /// <param name="interfaceName"></param> /// <param name="PostObj"></param> /// <returns></returns> public static IRestResponse <T> PostExcute <T>(DataRow InterfaceURLRow, string interfaceName, object PostObj) where T : class, new() { //BDOs tmpInterFaceConfig = new BDOs("SYS_InterfaceURL", "INTERFACECODE = '"+ interfaceCode+"'"); if (InterfaceURLRow == null) { throw new ApplicationException("接口地址未配置!"); } string InterfaceURL = InterfaceURLRow["URL"].ToString(); if (string.IsNullOrEmpty(InterfaceURL)) { throw new ApplicationException("接口地址未配置!"); } string interfaceCode = InterfaceURLRow["INTERFACECODE"].ToString(); var client = new RestClient(InterfaceURL); var request = new RestRequest(Method.POST) { RequestFormat = DataFormat.Json }; request.AddJsonBody(PostObj); request.AddHeader("Content-Type", "application/json; charset=utf-8"); var content = client.Execute <T>(request); string requestBody = content.Request.JsonSerializer.Serialize(PostObj); requestBody = requestBody.Replace("\\\\", "\\"); string responseBody = content.Content; StackTrace trace = new StackTrace(); StackFrame frame = trace.GetFrame(1); MethodBase method = frame.GetMethod(); //String className = method.ReflectedType.Name; if (content.StatusCode != System.Net.HttpStatusCode.OK) { BDO bd = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat = bd.NewRow(); drBat["IsIn"] = 1; drBat["LogTime"] = DateTime.Now; drBat["SerialNo"] = Guid.NewGuid(); drBat["FunctionName"] = method.Name; drBat["InterfaceName"] = interfaceName; drBat["interfaceCode"] = interfaceCode; drBat["RequestBody"] = requestBody; drBat["ResponseBody"] = responseBody; drBat["ResponseCode"] = "E"; if (string.IsNullOrEmpty(content.Content)) { content.Content = "接口未联通"; } drBat["ResponseMessage"] = content.Content; bd.Rows.Add(drBat); DataRowsSaveResult drsr = bd.SaveToDB(null, null); } else { var ResponseCode = string.Empty; var ResponseMessage = string.Empty; var ZGUID = string.Empty; try { responseBody = responseBody.Substring(6, responseBody.Length - 8); responseBody = responseBody.Replace("\\", ""); responseBody = responseBody.Replace("/Date(", ""); responseBody = responseBody.Replace(")/", ""); responseBody = responseBody.Insert(1, "\"ZINT_ID\":\"" + interfaceCode + "\","); BaseModel model = Newtonsoft.Json.JsonConvert.DeserializeObject <BaseModel>(responseBody); if (model == null) { throw new ApplicationException("返回信息解析失败:" + InterfaceURL + "->" + responseBody); } if (content.Data == null) { content.Data = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(responseBody); } //added by haijun if (model != null && !string.IsNullOrEmpty(model.ZTYPE)) { ResponseCode = model.ZTYPE; ResponseMessage = model.ZMESSAGE; ZGUID = model.ZGUID; } //else if (model != null && model.Count > 0) //{ // //var items = model.ITEM.Where(i => i.ZTYPE == "E"); // //ResponseCode = items.Any() ? "E" : "S"; // //if (items.Any()) // //{ // // ResponseMessage = string.Join(";", items.Select(s => s.ZMESSAGE).ToList()); // //} // //else // //{ // ResponseMessage = model.ITEM.First().ZMESSAGE; // //} // ZGUID = model.ITEM.First().ZGUID; //} } catch (Exception ex) { ResponseCode = "N/A"; ResponseMessage = string.IsNullOrEmpty(responseBody) ? ex.Message : responseBody; } BDO bd = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat = bd.NewRow(); drBat["IsIn"] = 1; drBat["SerialNo"] = Guid.NewGuid(); drBat["FunctionName"] = method.Name; drBat["InterfaceName"] = interfaceName; drBat["interfaceCode"] = interfaceCode; drBat["RequestBody"] = requestBody; drBat["ResponseBody"] = responseBody; drBat["ResponseCode"] = ResponseCode; drBat["ResponseMessage"] = string.IsNullOrEmpty(ResponseMessage) ? "" : ResponseMessage; bd.Rows.Add(drBat); DataRowsSaveResult drsr = bd.SaveToDB(null, null); } return(content); }
// 记录接口日志 public static IRestResponse <T> PostExcute <T>(DataRow InterfaceURL, DataRow InterfaceQueue, object PostObj) where T : class, new() { if (string.IsNullOrEmpty(InterfaceURL["Url"].ToString())) { throw new ApplicationException("接口地址未配置!"); } var client = new RestClient(InterfaceURL["Url"].ToString()); var request = new RestRequest(Method.POST) { RequestFormat = DataFormat.Json }; request.AddJsonBody(PostObj); request.AddHeader("Content-Type", "application/json; charset=utf-8"); var content = client.Execute <T>(request); var interfaceCode = string.Empty; if (InterfaceURL["Url"].ToString().Contains("=")) { interfaceCode = InterfaceURL["Url"].ToString().Split('=')[1]; } string requestBody = JsonConvert.SerializeObject(PostObj); string responseBody = content.Content; if (content.StatusCode != System.Net.HttpStatusCode.OK) { BDO bd = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat = bd.NewRow(); drBat["IsIn"] = 0; drBat["LogTime"] = DateTime.Now; drBat["SerialNo"] = InterfaceQueue["SerialNo"]; drBat["FunctionName"] = InterfaceQueue["FunctionName"]; drBat["InterfaceName"] = InterfaceQueue["InterfaceName"]; drBat["interfaceCode"] = interfaceCode; drBat["RequestBody"] = requestBody; drBat["ResponseBody"] = responseBody; drBat["ResponseCode"] = "E"; drBat["ResponseMessage"] = content.Content; bd.Rows.Add(drBat); DataRowsSaveResult drsr = bd.SaveToDB(null, null); } else { var ResponseCode = string.Empty; var ResponseMessage = string.Empty; var ZGUID = string.Empty; var isSendMialToSAP = false;//是否发送邮件 added by haijun 2018-4-18 try { MES2ERPResult model = Newtonsoft.Json.JsonConvert.DeserializeObject <MES2ERPResult>(responseBody); if (model == null) { throw new ApplicationException("返回信息解析失败:" + InterfaceURL["Url"].ToString() + "->" + responseBody); } if (content.Data == null) { content.Data = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(responseBody); } } catch (Exception ex) { ResponseCode = "N/A"; ResponseMessage = string.IsNullOrEmpty(responseBody) ? ex.Message : responseBody; } BDO bd = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat = bd.NewRow(); drBat["IsIn"] = 0; drBat["LogTime"] = DateTime.Now; drBat["SerialNo"] = InterfaceQueue["SerialNo"]; drBat["FunctionName"] = InterfaceQueue["FunctionName"]; drBat["InterfaceName"] = InterfaceQueue["InterfaceName"]; drBat["interfaceCode"] = interfaceCode; drBat["RequestBody"] = requestBody; drBat["ResponseBody"] = responseBody; drBat["ResponseCode"] = ResponseCode; drBat["ResponseMessage"] = string.IsNullOrEmpty(ResponseMessage) ? "" : ResponseMessage; bd.Rows.Add(drBat); DataRowsSaveResult drsr = bd.SaveToDB(null, null); } return(content); }
/// <summary> /// 实时接口 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="interfaceCode"></param> /// <param name="interfaceName"></param> /// <param name="PostObj"></param> /// <returns></returns> public static IRestResponse <T> PostExcute <T>(DataRow InterfaceURLRow, string interfaceName, object PostObj) where T : class, new() { //BDOs tmpInterFaceConfig = new BDOs("SYS_InterfaceURL", "INTERFACECODE = '"+ interfaceCode+"'"); if (InterfaceURLRow == null) { throw new ApplicationException("接口地址未配置!"); } string InterfaceURL = InterfaceURLRow["URL"].ToString(); if (string.IsNullOrEmpty(InterfaceURL)) { throw new ApplicationException("接口地址未配置!"); } string interfaceCode = InterfaceURLRow["INTERFACECODE"].ToString(); ///////////////////////////////// //using (var tmpClient = new HttpClient()) //{ // try // { // var str = JsonConvert.SerializeObject(PostObj); // str = str.Replace("STD_IN_Origin", "STD_IN Origin").Replace("Service_Name", "Service Name"); // HttpContent tmpContent = new StringContent(str); // tmpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json"); // HttpResponseMessage response = tmpClient.PostAsync(InterfaceURL, tmpContent).Result;//改成自己的 // response.EnsureSuccessStatusCode();//用来抛异常的 // string tmpResponseBody= response.Content.ReadAsStringAsync().Result; // } // catch (Exception e) // { // string msg = e.Message; // } //} /////////////////////////////////// var str = JsonConvert.SerializeObject(PostObj); str = str.Replace("STD_IN_Origin", "STD_IN Origin").Replace("Service_Name", "Service Name"); var client = new RestClient(InterfaceURL); var request = new RestRequest(); request.Method = Method.POST; request.AddHeader("Accept", "application/json"); request.Parameters.Clear(); request.AddParameter("application/json", str, ParameterType.RequestBody); //var content = response.Content; // 返回的网页内容 //var client = new RestClient(InterfaceURL); //var request = new RestRequest(Method.POST) { RequestFormat = DataFormat.Json }; //request.AddJsonBody(PostObj); //request.AddHeader("Content-Type", "application/json; charset=utf-8"); var content = client.Execute <T>(request); //string requestBody = JsonConvert.SerializeObject(PostObj); string requestBody = str; requestBody = requestBody.Replace("\\\\", "\\"); string responseBody = content.Content; StackTrace trace = new StackTrace(); StackFrame frame = trace.GetFrame(1); MethodBase method = frame.GetMethod(); String className = method.ReflectedType.Name; if (content.StatusCode != System.Net.HttpStatusCode.OK) { var hi = AppCache.GetCache <RequestHeaderInfo>(Thread.CurrentThread.ManagedThreadId); Task task1 = new Task(() => { var ai = new RequestHeaderInfo(hi.LangNo, hi.DBNo, hi.MenuNo, hi.UserNo, hi.UserName, ""); AppCache.Add(Thread.CurrentThread.ManagedThreadId, ai); BDO bd1 = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat1 = bd1.NewRow(); drBat1["IsIn"] = 1; drBat1["SerialNo"] = Guid.NewGuid(); drBat1["FunctionName"] = method.Name; drBat1["InterfaceName"] = interfaceName; drBat1["interfaceCode"] = interfaceCode; drBat1["RequestBody"] = requestBody; drBat1["ResponseBody"] = responseBody; drBat1["ResponseCode"] = "E"; drBat1["ResponseMessage"] = content.Content; drBat1["CREATETIME"] = DateTime.Now; bd1.Rows.Add(drBat1); DataRowsSaveResult drsr1 = bd1.SaveToDB(); if (!drsr1.Success) { throw new Exception(drsr1.ErrorText); } }); task1.Start(); task1.Wait(); } else { var ResponseCode = string.Empty; var ResponseMessage = string.Empty; var ZGUID = string.Empty; try { //responseBody=responseBody.Replace("单别-单号", "Message").Replace("错误原因", "Message").Replace("处理结果", "Message"); //MES2ERPResult model = Newtonsoft.Json.JsonConvert.DeserializeObject<MES2ERPResult>(responseBody); //if (model == null) // throw new ApplicationException("返回信息解析失败:" + InterfaceURL + "->" + responseBody); if (content.Data == null) { content.Data = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(responseBody); } } catch (Exception ex) { ResponseCode = "N/A"; ResponseMessage = string.IsNullOrEmpty(responseBody) ? ex.Message : responseBody; } var hi = AppCache.GetCache <RequestHeaderInfo>(Thread.CurrentThread.ManagedThreadId); Task task1 = new Task(() => { var ai = new RequestHeaderInfo(hi.LangNo, hi.DBNo, hi.MenuNo, hi.UserNo, hi.UserName, ""); AppCache.Add(Thread.CurrentThread.ManagedThreadId, ai); BDO bd1 = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat1 = bd1.NewRow(); drBat1["IsIn"] = 1; drBat1["SerialNo"] = Guid.NewGuid(); drBat1["FunctionName"] = method.Name; drBat1["InterfaceName"] = interfaceName; drBat1["interfaceCode"] = interfaceCode; drBat1["RequestBody"] = requestBody; drBat1["ResponseBody"] = responseBody; drBat1["ResponseCode"] = ResponseCode; drBat1["ResponseMessage"] = string.IsNullOrEmpty(ResponseMessage) ? "" : ResponseMessage; drBat1["CREATETIME"] = DateTime.Now; bd1.Rows.Add(drBat1); DataRowsSaveResult drsr1 = bd1.SaveToDB(); if (!drsr1.Success) { throw new Exception(drsr1.ErrorText); } }); task1.Start(); task1.Wait(); } return(content); }
public SessionImplObject GetData(out object DataStream, SessionQuery query) { try { // Init session objects if (this.SessionObj == null) { this.SessionObj = new SessionImplObject(); this.SessionObj.SdmxObject = new SdmxObjectsImpl(); } if (BDO == null || GetSDMXObject == null) { throw new Exception(Messages.label_error_network + " " + DataObj.Configuration.Title); } codemapWidget = new CodemapWidget(new GetCodemapObject() { Configuration = this.DataObj.Configuration, Dataflow = this.DataObj.Dataflow, PreviusCostraint = this.DataObj.Criteria }, this.SessionObj, query); //ISdmxObjects structure = codemapWidget.GetDsd(); ISdmxObjects structure = query.Structure; IDataflowObject df = structure.Dataflows.FirstOrDefault(); IDataStructureObject kf = structure.DataStructures.First(); if (df == null) { throw new InvalidOperationException("Dataflow is not set"); } /****************/ // Get all codelist /****************/ //Dictionary<string, ICodelistObject> ConceptCodelists = codemapWidget.GetCodelistMap(df, kf, true); Dictionary <string, ICodelistObject> ConceptCodelists = codemapWidget.GetCodelistMap(query, false); ComponentCodeDescriptionDictionary codemap = new ComponentCodeDescriptionDictionary(); foreach (string ConceptId in ConceptCodelists.Keys) { ICodelistObject codelist = ConceptCodelists[ConceptId]; Dictionary <string, string> codes = new Dictionary <string, string>(); foreach (ICode codeItem in codelist.Items) { codes.Add(codeItem.Id, TextTypeHelper.GetText(codeItem.Names, this.DataObj.Configuration.Locale)); } codemap.Add(ConceptId, codes); } /****************/ //codemapWidget.GetCodeListCostraint(df,kf,component) this.SessionObj.MergeObject(codemapWidget.SessionObj); int num1; #region Gestione last period if (this.DataObj.Criteria.ContainsKey(kf.TimeDimension.Id) && this.DataObj.Criteria[kf.TimeDimension.Id].Count == 1 && int.TryParse(this.DataObj.Criteria[kf.TimeDimension.Id].First(), out num1) && !this.DataObj.Layout.axis_z.Contains(kf.TimeDimension.Id)) { int offsetTime = int.Parse(this.DataObj.Criteria[kf.TimeDimension.Id].First()); var codMap = codemap; int lengthTime = codMap[kf.TimeDimension.Id].Count; if ((lengthTime - offsetTime) >= 0) { var codes = codMap[kf.TimeDimension.Id].Reverse().Take(offsetTime); List <string> _criteriaTime = (from c in codes select c.Key).ToList <string>(); this.DataObj.Criteria[kf.TimeDimension.Id] = new List <string>(); this.DataObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.Last()); this.DataObj.Criteria[kf.TimeDimension.Id].Add(_criteriaTime.First()); } else { this.DataObj.Criteria[kf.TimeDimension.Id] = new List <string>(); this.DataObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].First().Key); this.DataObj.Criteria[kf.TimeDimension.Id].Add(codemap[kf.TimeDimension.Id].Last().Key); } } #endregion LayoutObj layObj = InitLayout(df, kf); List <DataCriteria> Criterias = BDO.InitCriteria(kf, this.DataObj.Criteria); //query.GetCriteria(); Dictionary <string, List <DataChacheObject> > DataCache = SessionObj.DataCache; List <string> ret = null; List <DataCriteria> QueryCriterias = new List <DataCriteria>(); if (query.Criteria != null) //criteri nulli se proviene da un template { if (query._store != null) //.Count == 1) { query.SetCriteriaTime(this.DataObj.Criteria[kf.TimeDimension.Id]); } if (query.Criteria.TryGetValue(kf.TimeDimension.Id, out ret)) { if (ret.Count == 1) { query.SetCriteriaTime(this.DataObj.Criteria[kf.TimeDimension.Id]); } } QueryCriterias = query.GetCriteria(); /*if (query._store == null) //.Count == 1) * { QueryCriterias = Criterias; } * else * { QueryCriterias = query.GetCriteria(); }*/ } else { QueryCriterias = Criterias; } //aggiunta da fabio IDataSetStore store; if (query._store != null) { store = query._store; } else { //store = BDO.GetDataset(df, kf, Criterias, ref DataCache, _useAttr); store = BDO.GetDataset(df, kf, QueryCriterias, ref DataCache, _useAttr, query); query._store = store; } //fine nuovo SessionObj.DataCache = DataCache; DataStream = new DataObjectForStreaming() { Configuration = this.DataObj.Configuration, store = store, layObj = layObj, Criterias = Criterias, structure = structure, codemap = codemap }; return(this.SessionObj); } catch (Exception ex) { Logger.Warn(ex.Message, ex); throw ex; } }
/// <summary> /// 检查本表数据是否违反唯一性策略 /// </summary> /// <param name="drsr"></param> /// <param name="bdo"></param> /// <returns></returns> private void DataSave_BeforeCheckBDOUnique(DataRowSaveResult drsr, BDO bdo) { drsr.DataRow = null; DataRow[] drschanged = bdo.Select(null, null, DataViewRowState.Added | DataViewRowState.ModifiedCurrent); if (drschanged.Length == 0) { return; } bf_Busi busi = bdo.Business; db_Object so = busi.db_Object; foreach (string gno in busi.UniqueGroupNos) { List <bf_Busi_Field> bbflist = busi.UniqueFields(gno); if (bbflist.Count == 0) { continue; } string ufText = "", ufText2 = ""; List <string> ufList = new List <string>(); foreach (bf_Busi_Field bbf in bbflist) { if (bbf.DbType == DbType.Binary) { continue; } ufList.Add(bbf.m_Name); ufText += string.Format("+[{0}]", bbf.Caption); if (bbf.VisibleType > 0) { ufText2 += string.Format("+[{0}]", bbf.Caption); } } if (string.IsNullOrEmpty(ufText2) == false) { ufText = ufText2; } ufText = ufText.Substring(1); foreach (DataRow dr in drschanged) { drsr.DataRow = dr; string filter = ""; foreach (bf_Busi_Field bbf in bbflist) { object cellValue = dr[bbf.m_Name]; string compareString = " is null"; if (cellValue != DBNull.Value) { compareString = string.Format("='{0}'", cellValue); } filter += string.Format("and {0}{1} ", bbf.m_Name, compareString); } filter = filter.Substring(4); int cnt = (int)bdo.Compute("Count(ID)", filter); if (cnt == 1) { continue; } string error = string.Format("表[{0}]中\r\n字段{1}违反数据唯一性策略。", busi.Caption, ufText); drsr.ErrorText = error; drsr.Fields = ufList; return; } } }
public static BDO JsonToBDO(BDOs owner, BDO parentBDO, string busino, string jsonData) { BDO bdo = new BDO(owner, parentBDO, busino, "1<>1", false, -1, -1, false); try { ArrayList arrayList = JsonConvert.DeserializeObject <ArrayList>(jsonData); foreach (var v in arrayList) { Newtonsoft.Json.Linq.JObject jobj = v as Newtonsoft.Json.Linq.JObject; string dataState = "0"; //0-unchange,1-add,2-modify,3-delete Newtonsoft.Json.Linq.JToken token; if (jobj.TryGetValue("dataState", out token)) { dataState = token.ToString(); } //if (dataState == "0") continue; DataRow nr = bdo.NewRow(); bdo.Rows.Add(nr); if (dataState == "2") { foreach (var vv in jobj) { if (!vv.Key.EndsWith("_old")) { continue; } string filedName = vv.Key.Substring(0, vv.Key.Length - 4); if (!bdo.Columns.Contains(filedName)) { continue; } if (vv.Value.GetType() == typeof(Newtonsoft.Json.Linq.JObject) || vv.Value.GetType() == typeof(Newtonsoft.Json.Linq.JArray)) { if (bdo.Columns[filedName].DataType != typeof(string)) { continue; } nr[filedName] = vv.Value.ToString(); } else { if (((Newtonsoft.Json.Linq.JValue)vv.Value).Value == null && !bdo.Columns[filedName].AllowDBNull) { continue; } if (((Newtonsoft.Json.Linq.JValue)vv.Value).Type == Newtonsoft.Json.Linq.JTokenType.Boolean) { nr[filedName] = (bool)((Newtonsoft.Json.Linq.JValue)vv.Value).Value ? 1 : 0; } else { nr[filedName] = ((Newtonsoft.Json.Linq.JValue)vv.Value).Value == null || ((Newtonsoft.Json.Linq.JValue)vv.Value).Value.Equals("") || ((Newtonsoft.Json.Linq.JValue)vv.Value).Value.Equals("null") ? DBNull.Value : vv.Value.ToObject(bdo.Columns[filedName].DataType); } } } nr.AcceptChanges(); } bool flg = true; foreach (var vv in jobj) { if (!bdo.Columns.Contains(vv.Key)) { continue; } if (vv.Key.EndsWith("_old")) { continue; } if (vv.Value.GetType() == typeof(Newtonsoft.Json.Linq.JObject)) { continue; } var vl = (Newtonsoft.Json.Linq.JValue)vv.Value; if ((vl.Value == null || vl.Value.ToString().ToUpper() == "NULL") && !bdo.Columns[vv.Key].AllowDBNull) { continue; } if (dataState == "1" && bdo.Columns[vv.Key].DataType == typeof(Guid)) { ((BRO)nr).OldID = vl.Value; continue; } if (!nr[vv.Key].Equals(vl.Value)) { flg = flg & false; } if (vl.Value == null || vl.Value.ToString().ToUpper() == "NULL") { nr[vv.Key] = DBNull.Value; } else if (vl.Type == Newtonsoft.Json.Linq.JTokenType.String && (bdo.Columns[vv.Key].DataType == typeof(Boolean) || bdo.Columns[vv.Key].DataType == typeof(Int32)) && (vl.Value.ToString().ToUpper() == "TRUE" || vl.Value.ToString().ToUpper() == "FALSE")) { nr[vv.Key] = vl.Value.ToString().ToUpper() == "TRUE" ? 1 : 0; } else if (vv.Value.Type == Newtonsoft.Json.Linq.JTokenType.Boolean) { nr[vv.Key] = (vv.Value.HasValues || vl.Value.ToString().ToUpper() == "TRUE") ? 1 : 0; } else { //if (!nr[vv.Key].Equals(vl.Value)) // flg = flg & false; object objValue = ((Newtonsoft.Json.Linq.JValue)vv.Value).Value; nr[vv.Key] = objValue == null || string.IsNullOrEmpty(objValue.ToString().Trim()) ? DBNull.Value : vv.Value.ToObject(bdo.Columns[vv.Key].DataType); } } if (dataState == "2" && flg) { nr.AcceptChanges(); } if (dataState == "3") { nr.AcceptChanges(); nr.Delete(); } else if (dataState == "0") { nr.AcceptChanges(); } } } catch (Exception ex) { if (ex.Message == "Input string was not in a correct format.") { throw new ApplicationException("数据类型转换错误, 请删除后再输入重试."); } else { throw ex; } } return(bdo); }
/// <summary> /// 实时接口 PUT请求 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="InterfaceURLRow"></param> /// <param name="interfaceName"></param> /// <param name="PostObj"></param> /// <returns></returns> public static IRestResponse <T> PutExcute <T>(DataRow InterfaceURLRow, string interfaceName, object PostObj) where T : class, new() { //BDOs tmpInterFaceConfig = new BDOs("SYS_InterfaceURL", "INTERFACECODE = '"+ interfaceCode+"'"); if (InterfaceURLRow == null) { throw new ApplicationException("接口地址未配置!"); } string InterfaceURL = InterfaceURLRow["URL"].ToString(); if (string.IsNullOrEmpty(InterfaceURL)) { throw new ApplicationException("接口地址未配置!"); } string interfaceCode = InterfaceURLRow["INTERFACECODE"].ToString(); var client = new RestClient(InterfaceURL); var request = new RestRequest(Method.PUT) { RequestFormat = DataFormat.Json }; request.AddJsonBody(PostObj); request.AddHeader("Content-Type", "application/json; charset=utf-8"); var content = client.Execute <T>(request); string requestBody = JsonConvert.SerializeObject(PostObj); requestBody = requestBody.Replace("\\\\", "\\"); string responseBody = content.Content; StackTrace trace = new StackTrace(); StackFrame frame = trace.GetFrame(1); MethodBase method = frame.GetMethod(); //String className = method.ReflectedType.Name; if (content.StatusCode != System.Net.HttpStatusCode.OK) { BDO bd = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat = bd.NewRow(); drBat["IsIn"] = 1; drBat["LogTime"] = DateTime.Now; drBat["SerialNo"] = Guid.NewGuid(); drBat["FunctionName"] = method.Name; drBat["InterfaceName"] = interfaceName; drBat["interfaceCode"] = interfaceCode; drBat["RequestBody"] = requestBody; drBat["ResponseBody"] = responseBody; drBat["ResponseCode"] = "E"; if (string.IsNullOrEmpty(content.Content)) { content.Content = "接口未联通"; } drBat["ResponseMessage"] = content.Content; bd.Rows.Add(drBat); DataRowsSaveResult drsr = bd.SaveToDB(null, null); } else { var ResponseCode = string.Empty; var ResponseMessage = string.Empty; var ZGUID = string.Empty; try { MES2ERPResult model = Newtonsoft.Json.JsonConvert.DeserializeObject <MES2ERPResult>(responseBody); if (model == null) { throw new ApplicationException("返回信息解析失败:" + InterfaceURL + "->" + responseBody); } if (content.Data == null) { content.Data = Newtonsoft.Json.JsonConvert.DeserializeObject <T>(responseBody); } } catch (Exception ex) { ResponseCode = "N/A"; ResponseMessage = string.IsNullOrEmpty(responseBody) ? ex.Message : responseBody; } BDO bd = new BDO(null, null, "SYS_InterfaceLog", "1<>1"); DataRow drBat = bd.NewRow(); drBat["IsIn"] = 1; drBat["SerialNo"] = Guid.NewGuid(); drBat["FunctionName"] = method.Name; drBat["InterfaceName"] = interfaceName; drBat["interfaceCode"] = interfaceCode; drBat["RequestBody"] = requestBody; drBat["ResponseBody"] = responseBody; drBat["ResponseCode"] = ResponseCode; drBat["ResponseMessage"] = string.IsNullOrEmpty(ResponseMessage) ? "" : ResponseMessage; bd.Rows.Add(drBat); DataRowsSaveResult drsr = bd.SaveToDB(null, null); } return(content); }
/// <summary> /// DataSet转BDOs模型 /// </summary> /// <param name="ds"></param> /// <returns></returns> public static List <BDOs> ToBDOsModel(DataSet ds) { List <BDOs> lstDs = new List <BDOs>(); List <string> lstTbInBdos = new List <string>(); foreach (DataRelation v in ds.Relations) { BDOs BDOS = lstDs.Find((b) => { DataTable dt = v.ParentTable; while (dt.ParentRelations.Count > 0) { dt = dt.ParentRelations[0].ParentTable; } return(b.DataSetName == dt.TableName); }); if (BDOS == null) { BDOs bdos = new BDOs(); //新建DS if (v.ParentTable.ParentRelations.Count == 0) { bdos.DataSetName = v.ParentTable.TableName; CheckNullValue(v.ParentTable); BDO bdo = new BDO(bdos, null, v.ParentTable.Copy()); bdo.TableName = v.ParentTable.TableName; bdos.Tables.Add(bdo); //添加MasterBDO bdo = new BDO(bdos, bdos.MasterBDO, v.ChildTable.Copy()); bdo.TableName = v.ChildTable.TableName; bdos.Tables.Add(bdo); CopyRelation(bdos, v); bdos.MasterBDO.Children.Add(bdo); lstDs.Add(bdos); lstTbInBdos.Add(v.ParentTable.TableName); lstTbInBdos.Add(v.ChildTable.TableName); } else { DataTable dt = v.ParentTable; while (dt.ParentRelations.Count > 0) { dt = dt.ParentRelations[0].ParentTable; } bdos.DataSetName = dt.TableName; CheckNullValue(dt); BDO bdo = new BDO(bdos, null, dt.Copy()); bdo.TableName = dt.TableName; bdos.Tables.Add(bdo); //添加MasterBDO lstDs.Add(bdos); lstTbInBdos.Add(dt.TableName); while (dt.ChildRelations.Count > 0) { for (int i = 0; i < dt.ChildRelations.Count; i++) { bdo = new BDO(bdos, bdos.MasterBDO, dt.ChildRelations[i].ChildTable.Copy()); bdo.TableName = dt.ChildRelations[i].ChildTable.TableName; bdos.Tables.Add(bdo); CopyRelation(bdos, dt.ChildRelations[i]); bdos.MasterBDO.Children.Add(bdo); lstTbInBdos.Add(dt.ChildRelations[i].ChildTable.TableName); } dt = dt.ChildRelations[0].ChildTable; } } } else if (!BDOS.Tables.Contains(v.ChildTable.TableName)) { CheckNullValue(v.ChildTable); BDO bdo = new BDO(BDOS, BDOS.MasterBDO, v.ChildTable.Copy()); bdo.TableName = v.ChildTable.TableName; BDOS.Tables.Add(bdo); CopyRelation(BDOS, v); BDOS.MasterBDO.Children.Add(bdo); lstTbInBdos.Add(v.ChildTable.TableName); } } //无表关系的单表 foreach (DataTable dt in ds.Tables) { if (!lstTbInBdos.Exists((name) => name == dt.TableName)) { CheckNullValue(dt); BDOs singleBDOs = new BDOs(); singleBDOs.DataSetName = dt.TableName; BDO bdo = new BDO(singleBDOs, null, dt.Copy()); bdo.TableName = dt.TableName; singleBDOs.Tables.Add(bdo); lstDs.Add(singleBDOs); } } return(lstDs); }