public DataCollection DoOperate(ParameterStd p) { string flag = p.GetValue <string>("_unit_action_flag_"); UnitParameter up = (UnitParameter)p; T t = (T)Activator.CreateInstance(typeof(T), true); var sqlobj = t.GetSqlFunc(flag)(up); if (!(sqlobj is FrameDLRObject)) { throw new TypeRequiredException("需要的动态数据对象类型应该为FrameDLRObject"); } IDBAccessInfo dba = up.Dao; DBOParameterCollection dbc = up.SPParameter; UnitDataCollection rtn = new UnitDataCollection(); if (dba is ADBAccess) { bool isrturnds = sqlobj.isreturnds != null ? sqlobj.isreturnds : false; DBDataCollection dbrtn = ((ADBAccess)dba).ExcuteProcedure(ComFunc.nvl(sqlobj.spname), isrturnds, ref dbc); if (dbrtn.IsSuccess) { foreach (string s in dbrtn.Keys) { if (dbrtn[s] is DataSetStd) { rtn.QueryDatas = dbrtn.ReturnDataSet; } else { rtn.SetValue(s, dbrtn[s]); } } } } return(rtn); }
public DataCollection DoOperate(ParameterStd p) { string flag = p.GetValue <string>("_unit_action_flag_"); //预执行 T t = (T)Activator.CreateInstance(typeof(T), true); UnitParameter up = (UnitParameter)p; UnitDataCollection rtn = new UnitDataCollection(); if (up.Dao is ADBAccess) { var sqlobj = t.GetSqlFunc(flag)(up); ADBAccess dba = (ADBAccess)up.Dao; string regstr = ""; string regexpress = @"(?isx) (') #开始标记“<tag...>” (?> #分组构造,用来限定量词“*”修饰范围 \1 (?<Open>) #命名捕获组,遇到开始标记,入栈,Open计数加1 |\1 (?<-Open>) #狭义平衡组,遇到结束标记,出栈,Open计数减1 |[^']* #右侧不为开始或结束标记的任意字符 ) (?(Open)(?!)) #判断是否还有'OPEN',有则说明不配对,什么都不匹配 \1 #结束标记“</tag>” "; string tmpsql = ""; if (dba is OracleAccess) { regstr = @"(?<=:)[a-zA-Z0-9_]*\d*"; } else { regstr = @"(?<=@)[A-Za-z0-9_]+\d*"; } Regex re = new Regex(regstr); Regex re2 = new Regex(regexpress); try { if (!(sqlobj is FrameDLRObject)) { throw new TypeRequiredException("需要指定的动态数据对象:FrameDLRObject"); } string presql = sqlobj.presql; DBAPageP dbc = new DBAPageP(); dba.BeginTransaction(); if (!string.IsNullOrEmpty(presql)) { tmpsql = presql.Replace("''", "#sp#"); foreach (Match m in re2.Matches(tmpsql)) { tmpsql = tmpsql.Replace(m.Value, "#sp#"); } foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql)) { dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString())); } dba.ExecuteNoQuery(presql, dbc.SQL_Parameters); } //执行翻页查询 string sql = sqlobj.sql; string orderby = sqlobj.orderby; if (!string.IsNullOrEmpty(sql)) { tmpsql = sql.Replace("''", "#sp#"); foreach (Match m in re2.Matches(tmpsql)) { tmpsql = tmpsql.Replace(m.Value, "#sp#"); } dbc.SQL_Parameters.Clear(); foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql)) { if (up.GetValue(m.ToString()) is byte[]) { dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Binary); } else { dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString())); } } dbc.SQL = sql; dbc.OrderBy = orderby; dbc.Count_of_OnePage = up.Count_Of_OnePage; dbc.CurrentPage = up.CurrentPage; dba.StartPageByCondition(dbc); rtn.QueryTable = dba.GoToPage(up.ToPage); rtn.Count_Of_OnePage = up.Count_Of_OnePage; rtn.CurrentPage = dba.CurrentPage; rtn.TotalPage = dba.TotalPage; rtn.TotalRow = dba.TotalRow; } //收尾处理 string aftersql = sqlobj.aftersql; if (!string.IsNullOrEmpty(aftersql)) { tmpsql = aftersql.Replace("''", "#sp#"); foreach (Match m in re2.Matches(tmpsql)) { tmpsql = tmpsql.Replace(m.Value, "#sp#"); } dbc.SQL_Parameters.Clear(); foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql)) { dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString())); } dba.ExecuteNoQuery(aftersql, dbc.SQL_Parameters); } dba.CommitTransaction(); } catch { if (dba != null) { dba.RollbackTransaction(); } throw; } } return(rtn); }
public DataCollection DoOperate(ParameterStd p) { UnitDataCollection rtn = new UnitDataCollection(); string flag = p.GetValue <string>("_unit_action_flag_"); UnitParameter up = (UnitParameter)p; if (up.Dao is ADBAccess) { T t = (T)Activator.CreateInstance(typeof(T), true); var sqlobj = t.GetSqlFunc(flag)(up); if (!(sqlobj is FrameDLRObject)) { throw new TypeRequiredException("需要指定的动态数据对象:FrameDLRObject"); } string sql = sqlobj.sql; ADBAccess dba = (ADBAccess)up.Dao; DBOParameterCollection dbc = new DBOParameterCollection(); if (!string.IsNullOrEmpty(sql)) { string regstr = ""; regstr = @"(?<=" + (dba.ParameterFlagChar == "$"?"\\$": dba.ParameterFlagChar) + @")[A-Za-z0-9_]+\d*"; string regexpress = @"(?isx) (') #开始标记“<tag...>” (?> #分组构造,用来限定量词“*”修饰范围 \1 (?<Open>) #命名捕获组,遇到开始标记,入栈,Open计数加1 |\1 (?<-Open>) #狭义平衡组,遇到结束标记,出栈,Open计数减1 |[^']* #右侧不为开始或结束标记的任意字符 ) (?(Open)(?!)) #判断是否还有'OPEN',有则说明不配对,什么都不匹配 \1 #结束标记“</tag>” "; Regex re = new Regex(regstr); string tmpsql = ""; Regex re2 = new Regex(regexpress); tmpsql = sql.Replace("''", "#sp#"); foreach (Match m in re2.Matches(tmpsql)) { tmpsql = tmpsql.Replace(m.Value, "#sp#"); } foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql)) { if (up.GetValue(m.ToString()) is byte[]) { dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Binary); } else if (up.GetValue(m.ToString()) is DateTime) { dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.DateTime); } else if (up.GetValue(m.ToString()) is int) { dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Int32); } else if (up.GetValue(m.ToString()) is double) { dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Double); } else { dbc.Add(m.ToString(), up.GetValue(m.ToString())); } } } try { rtn.QueryDatas = dba.Query(sql, dbc); }catch (Exception ex) { FrameDLRObject dp = FrameDLRObject.CreateInstance(Base.Constants.FrameDLRFlags.SensitiveCase); foreach (var item in dbc) { if (item.Value.ParameterValue is DateTime) { dp.SetValue(item.Key, DateTimeStd.IsDateTimeThen(item.Value.ParameterValue, "yyyy-MM-dd HH:mm:ss")); } else if (item.Value.ParameterValue is DBNull) { dp.SetValue(item.Key, null); } else { dp.SetValue(item.Key, item.Value.ParameterValue); } } GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.ERROR, $"QuerySql={sql};\nParameters={dp.ToJSONString()}"); throw ex; } if (rtn.QueryDatas != null && rtn.QueryDatas.Tables.Count > 0) { rtn.QueryTable = rtn.QueryDatas[0]; } } return(rtn); }
protected override void OnError(Exception ex, ParameterStd p, DataCollection d) { //GlobalCommon.ExceptionProcessor.ProcessException(this, ex, p, d); string errorCode = "E-" + ComFunc.nvl(p[DomainKey.CONFIG, "Machine_No"]) + "-" + DateTime.Now.ToString("yyyyMMddHHmmssfff"); string errlog = ""; if (ex.InnerException != null) { errlog = string.Format("错误编号:{0},\n{1}\n{2}\nInnerException:{3}\n{4}", errorCode, ex.Message, ex.StackTrace, ex.InnerException.Message, ex.InnerException.StackTrace); } else { errlog = string.Format("错误编号:{0},\n{1}\n{2}", errorCode, ex.Message, ex.StackTrace); } GlobalCommon.Logger.WriteLog(LoggerLevel.ERROR, errlog); var errormsg = ""; var isdebug = p[DomainKey.CONFIG, "DebugMode"] == null ? false : (bool)p[DomainKey.CONFIG, "DebugMode"]; if (isdebug) { errormsg = string.Format("出错了,{0}", errlog);; } else { errormsg = string.Format("系统出错了,亲,请将错误编号({0})告知我们,我们会帮亲处理的哦!", errorCode); } var logkey = ComFunc.nvl(p.GetValue("logkey")); if (logmsg.ContainsKey(logkey)) { var msgobj = (FrameDLRObject)logmsg[logkey]; DebugLog(string.Format("标号{0}微信请求处理记录:\n{1}", logkey, msgobj.ToJSONString()), (WebParameter)p); } p.Resources.RollbackTransaction(p.CurrentTransToken); p.Resources.ReleaseAll(); var dobj = FrameDLRObject.CreateInstance(FrameDLRFlags.SensitiveCase); dobj.ToUserName = p[DomainKey.POST_DATA, "FromUserName"]; dobj.FromUserName = p[DomainKey.POST_DATA, "ToUserName"]; dobj.CreateTime = DateTime.Now; dobj.MsgType = "text"; dobj.Content = errormsg; dobj.FuncFlag = 0; var content = ToXml(dobj); //如果内容为aes加密 if (p.ExtentionObj.weixin.encrypt_type == "aes") { DateTime createTime = dobj.CreateTime; int timeStamp = ToWeixinTime(createTime); Random random = new Random(); string nonce = random.Next().ToString(); WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(p.ExtentionObj.weixin.token, p.ExtentionObj.weixin.encrypt_key, p.ExtentionObj.weixin.appid); string xmlEncrypt = ""; //加密消息 if (wxcpt.EncryptMsg(content, timeStamp.ToString(), nonce, ref xmlEncrypt) == WXBizMsgCrypt.WXBizMsgCryptErrorCode.WXBizMsgCrypt_OK) { content = xmlEncrypt; } } var msgbytelength = Encoding.UTF8.GetByteCount(content); CurrentContext.Response.Headers.Add("Content-Length", new Microsoft.Extensions.Primitives.StringValues(msgbytelength + "")); CurrentContext.Response.ContentType = ResponseHeader_ContentType.xml + ";charset=utf-8"; CurrentContext.Response.WriteAsync((string)content); }
public DataCollection DoOperate(ParameterStd p) { string flag = p.GetValue <string>("_unit_action_flag_"); //预执行 T t = (T)Activator.CreateInstance(typeof(T), true); UnitParameter up = (UnitParameter)p; UnitDataCollection rtn = new UnitDataCollection(); if (up.Dao is ADBAccess) { var sqlobj = t.GetSqlFunc(flag)(up); ADBAccess dba = (ADBAccess)up.Dao; string regstr = ""; string regexpress = @"(?isx) (') #开始标记“<tag...>” (?> #分组构造,用来限定量词“*”修饰范围 \1 (?<Open>) #命名捕获组,遇到开始标记,入栈,Open计数加1 |\1 (?<-Open>) #狭义平衡组,遇到结束标记,出栈,Open计数减1 |[^']* #右侧不为开始或结束标记的任意字符 ) (?(Open)(?!)) #判断是否还有'OPEN',有则说明不配对,什么都不匹配 \1 #结束标记“</tag>” "; string tmpsql = ""; regstr = @"(?<=" + (dba.ParameterFlagChar == "$" ? "\\$" : dba.ParameterFlagChar) + @")[A-Za-z0-9_]+\d*"; Regex re = new Regex(regstr); Regex re2 = new Regex(regexpress); try { if (!(sqlobj is FrameDLRObject)) { throw new TypeRequiredException("需要指定的动态数据对象:FrameDLRObject"); } string presql = sqlobj.presql; DBAPageP dbc = new DBAPageP(); //dba.BeginTransaction(); if (!string.IsNullOrEmpty(presql)) { tmpsql = presql.Replace("''", "#sp#"); foreach (Match m in re2.Matches(tmpsql)) { tmpsql = tmpsql.Replace(m.Value, "#sp#"); } foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql)) { dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString())); } try { dba.ExecuteNoQuery(presql, dbc.SQL_Parameters); } catch (Exception ex) { FrameDLRObject dp = FrameDLRObject.CreateInstance(Base.Constants.FrameDLRFlags.SensitiveCase); foreach (var item in dbc.SQL_Parameters) { if (item.Value.ParameterValue is DateTime) { dp.SetValue(item.Key, DateTimeStd.IsDateTimeThen(item.Value.ParameterValue, "yyyy-MM-dd HH:mm:ss")); } else if (item.Value.ParameterValue is DBNull) { dp.SetValue(item.Key, null); } else { dp.SetValue(item.Key, item.Value.ParameterValue); } } GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.ERROR, $"QueryByPage PreSql={presql};\nParameters={dp.ToJSONString()}"); throw ex; } } //执行翻页查询 string sql = sqlobj.sql; string orderby = sqlobj.orderby; if (!string.IsNullOrEmpty(sql)) { tmpsql = sql.Replace("''", "#sp#"); foreach (Match m in re2.Matches(tmpsql)) { tmpsql = tmpsql.Replace(m.Value, "#sp#"); } dbc.SQL_Parameters.Clear(); foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql)) { if (up.GetValue(m.ToString()) is byte[]) { dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Binary); } else { dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString())); } } try { dbc.SQL = sql; dbc.OrderBy = orderby; dbc.Count_of_OnePage = up.Count_Of_OnePage; dbc.CurrentPage = up.CurrentPage; dba.StartPageByCondition(dbc); rtn.QueryTable = dba.GoToPage(up.ToPage); rtn.QueryDatas = new DataSetStd(); rtn.QueryDatas.Tables.Add(rtn.QueryTable); rtn.Count_Of_OnePage = up.Count_Of_OnePage; rtn.CurrentPage = dba.CurrentPage; rtn.TotalPage = dba.TotalPage; rtn.TotalRow = dba.TotalRow; } catch (Exception ex) { FrameDLRObject dp = FrameDLRObject.CreateInstance(Base.Constants.FrameDLRFlags.SensitiveCase); foreach (var item in dbc.SQL_Parameters) { if (item.Value.ParameterValue is DateTime) { dp.SetValue(item.Key, DateTimeStd.IsDateTimeThen(item.Value.ParameterValue, "yyyy-MM-dd HH:mm:ss")); } else if (item.Value.ParameterValue is DBNull) { dp.SetValue(item.Key, null); } else { dp.SetValue(item.Key, item.Value.ParameterValue); } } GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.ERROR, $"QueryByPage sql={sql};\n order by={orderby};\nParameters={dp.ToJSONString()}"); throw ex; } } //收尾处理 string aftersql = sqlobj.aftersql; if (!string.IsNullOrEmpty(aftersql)) { tmpsql = aftersql.Replace("''", "#sp#"); foreach (Match m in re2.Matches(tmpsql)) { tmpsql = tmpsql.Replace(m.Value, "#sp#"); } dbc.SQL_Parameters.Clear(); foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql)) { dbc.SQL_Parameters.Add(m.ToString(), up.GetValue(m.ToString())); } try { dba.ExecuteNoQuery(aftersql, dbc.SQL_Parameters); }catch (Exception ex) { FrameDLRObject dp = FrameDLRObject.CreateInstance(Base.Constants.FrameDLRFlags.SensitiveCase); foreach (var item in dbc.SQL_Parameters) { if (item.Value.ParameterValue is DateTime) { dp.SetValue(item.Key, DateTimeStd.IsDateTimeThen(item.Value.ParameterValue, "yyyy-MM-dd HH:mm:ss")); } else if (item.Value.ParameterValue is DBNull) { dp.SetValue(item.Key, null); } else { dp.SetValue(item.Key, item.Value.ParameterValue); } } GlobalCommon.Logger.WriteLog(Base.Constants.LoggerLevel.ERROR, $"QueryByPage AfterSql={aftersql};\nParameters={dp.ToJSONString()}"); throw ex; } } //dba.CommitTransaction(); } catch { //if (dba != null) // dba.RollbackTransaction(); throw; } } return(rtn); }
public DataCollection DoOperate(ParameterStd p) { UnitDataCollection rtn = new UnitDataCollection(); string flag = p.GetValue <string>("_unit_action_flag_"); UnitParameter up = (UnitParameter)p; if (up.Dao is ADBAccess) { T t = (T)Activator.CreateInstance(typeof(T), true); var sqlobj = t.GetSqlFunc(flag)(up); if (!(sqlobj is FrameDLRObject)) { throw new TypeRequiredException("需要指定的动态数据对象:FrameDLRObject"); } string sql = sqlobj.sql; ADBAccess dba = (ADBAccess)up.Dao; DBOParameterCollection dbc = new DBOParameterCollection(); if (!string.IsNullOrEmpty(sql)) { string regstr = ""; if (dba is OracleAccess) { regstr = @"(?<=:)[a-zA-Z0-9_]*\d*"; } else { regstr = @"(?<=@)[A-Za-z0-9_]+\d*"; } string regexpress = @"(?isx) (') #开始标记“<tag...>” (?> #分组构造,用来限定量词“*”修饰范围 \1 (?<Open>) #命名捕获组,遇到开始标记,入栈,Open计数加1 |\1 (?<-Open>) #狭义平衡组,遇到结束标记,出栈,Open计数减1 |[^']* #右侧不为开始或结束标记的任意字符 ) (?(Open)(?!)) #判断是否还有'OPEN',有则说明不配对,什么都不匹配 \1 #结束标记“</tag>” "; Regex re = new Regex(regstr); string tmpsql = ""; Regex re2 = new Regex(regexpress); tmpsql = sql.Replace("''", "#sp#"); foreach (Match m in re2.Matches(tmpsql)) { tmpsql = tmpsql.Replace(m.Value, "#sp#"); } foreach (System.Text.RegularExpressions.Match m in re.Matches(tmpsql)) { if (up.GetValue(m.ToString()) is byte[]) { dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Binary); } else if (up.GetValue(m.ToString()) is DateTime) { dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.DateTime); } else if (up.GetValue(m.ToString()) is int) { dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Int32); } else if (up.GetValue(m.ToString()) is double) { dbc.Add(m.ToString(), up.GetValue(m.ToString()), System.Data.DbType.Double); } else { dbc.Add(m.ToString(), up.GetValue(m.ToString())); } } } rtn.QueryDatas = dba.Query(sql, dbc); if (rtn.QueryDatas != null && rtn.QueryDatas.Tables.Count > 0) { rtn.QueryTable = rtn.QueryDatas[0]; } } return(rtn); }