internal object ExecuteQuery(Query query, QueryReturn returnType) { // EXCEPTION: if (query.Connection != null && query.Connection != this) { throw new Exception("The query being executed is attached to a different connection."); } object val; switch (returnType) { case QueryReturn.Nothing: this.ExecuteQueryNoReturn(query); val = null; break; case QueryReturn.Value: val = this.ExecuteQueryAsValue(query); break; case QueryReturn.Array: val = this.ExecuteQueryAsArray(query); break; case QueryReturn.Reader: val = this.ExecuteQueryAsReader(query); break; default: throw new NotSupportedException("Query return type not supported."); } return(val); }
public async Task <QueryReturn> Query(string mchid, string orderid, string sign) { QueryReturn r = new QueryReturn(); SortedDictionary <string, string> para = new SortedDictionary <string, string>(); para.Add("mchid", mchid); para.Add("orderid", orderid); string temp = string.Format("{0}&key={1}", OnlineSettle.GetParamSrc(para), DB.MchKey); Dos.Common.LogHelper.Debug(temp); if (mchid != DB.MchId) { r.ReturnMsg = "商户号不存在"; return(r); } temp = Dos.Common.EncryptHelper.MD5EncryptWeChat(temp, "utf-8"); if (temp != sign) { r.ReturnMsg = "签名错误"; return(r); } return(await Settle_OrderBll.Instance.Query(mchid, orderid)); }
private object Execute(QueryReturn returnType, Dictionary <QueryParameter, object> parameterValues) { Query queryToRun; if (parameterValues != null && parameterValues.Count > 0) { queryToRun = this.Clone(); // Merge object-scope parameter values with method-scope values foreach (KeyValuePair <QueryParameter, object> localParam in parameterValues) { _parameters[localParam.Key] = localParam.Value; } } else { queryToRun = this; } return((_connection ?? Persistence.Persistence.Current).ExecuteQuery(queryToRun, returnType)); }
internal void SendNotifcations() { RecipientsType.ForEach(item => { item.FilttersRecipient.ForEach(r => { QueryReturn = ""; ParamsDynamicTableDataEvent.ForEach(d => { QueryReturn = r.Filtter.Replace(d.IdParam, d.ValueParam); }); using (Connection = new SqlConnection(ConectionString)) { Connection.Open(); #pragma warning disable S3649 // User-provided values should be sanitized before use in SQL statements using (Command = new SqlCommand(QueryReturn, Connection)) #pragma warning restore S3649 // User-provided values should be sanitized before use in SQL statements { MessageBase = item.Message.Message; TitleMessage = item.Message.TitleMessage; DataAdapter = new SqlDataAdapter(Command); DataTable = new DataTable(); DataAdapter.Fill(DataTable); String table = QueryReturn.ToUpper(); if (table.Contains("FROM")) { table = table.Substring(table.LastIndexOf("FROM")); } if (table.Contains("WHERE")) { table = table.Substring(0, table.LastIndexOf("WHERE")); } table = table.Replace("FROM", "").Replace("WHERE", ""); String[] items; if (table.Contains(",")) { items = table.Split(','); table = items[0].Trim(); } else { table = table.Trim(); } if (table.Contains(" ")) { int index = QueryReturn.IndexOf(" "); table = table.Substring(0, index + 1); } String valueReplace = ""; foreach (DataRow dtRow in DataTable.Rows) { IdTables = SchemaTables.GetColumKeys(ConectionString, Connection.Database, table); JsonRow = JsonConvert.SerializeObject(dtRow.Table).Replace("[", "").Replace("]", ""); ObjectJson = (JObject)JsonConvert.DeserializeObject(JsonRow); IdTables.ForEach(i => { ObjectJson.Property(i)?.Remove(); }); JsonRow = ObjectJson.ToString(); item.Message.ConfigMessage.ForEach(c => { valueReplace = ""; if (String.IsNullOrEmpty(c.DefinitiveValue)) { c.NameColum.ForEach(d => { foreach (var prop in ObjectJson) { if (prop.Key.ToUpper().Contains(d.ToUpper())) { valueReplace = prop.Value?.ToString(); break; } } }); if (String.IsNullOrEmpty(valueReplace)) { c.ExpressionRegular.ForEach(f => { Regex = new Regex(f); MachtExpression = Regex.Match(JsonRow); if (MachtExpression.Groups.Count > 0) { valueReplace = MachtExpression.Groups[0].Value; } Regex = null; MachtExpression = null; }); } } else { valueReplace = c.DefinitiveValue; } if (!String.IsNullOrEmpty(valueReplace)) { MessageBase = MessageBase.Replace(c.DinamycParam, valueReplace); } }); r.TypeNotification.ForEach(t => { string errorMessage = "Type Notification not support"; bool sendNotification = false; Regex = new Regex(t.ExpressionRegularMach); MachtExpression = Regex.Match(JsonRow); if (Enum.TryParse(t.TypeNotification, out TypeNotification typeNotification) && !String.IsNullOrEmpty(MachtExpression.Value)) { sendNotification = Notification.Send(MachtExpression.Value, TitleMessage, MessageBase, t.JsonNotificationConfig, typeNotification, t.Provaider, out errorMessage); } if (sendNotification) { errorMessage = "message send"; } else if (String.IsNullOrEmpty(MachtExpression.Value)) { errorMessage = "no se encontro en la consulta un destinatario"; } Connection.Insert(new NotificationLog() { Destination = MachtExpression.Groups[0].Value, MessageErrorProvaider = errorMessage, CreatedById = "NotifyDll", MessageSend = MessageBase, NotificationName = NotficationName, NameRecipientsType = item.RecipientName, FillterRecipenttype = QueryReturn, Provaider = t.Provaider, TypeNotification = t.TypeNotification, TitleMessage = TitleMessage, CreatedAt = DateTime.Now, IsSend = sendNotification }); //debe enviarse a grabar a la base de datos esta informacion }); } MessageBase = null; TitleMessage = null; } } }); }); }
private void ExecuteQuery(WebSocketMessage p_response, WebSocketSession p_webSocketSession, string p_query_data, Session v_httpSession) { WebSocketMessage v_response = p_response; QueryData v_query_data = JsonConvert.DeserializeObject <QueryData>(p_query_data); v_response.v_code = (int)response.QueryResult; QueryReturn v_g1 = new QueryReturn(); System.Collections.Generic.List <System.Collections.Generic.List <string> > v_table = new System.Collections.Generic.List <System.Collections.Generic.List <string> >(); OmniDatabase.Generic v_database2 = v_httpSession.v_databases[v_query_data.v_db_index]; OmniDatabase.Generic v_database = OmniDatabase.Generic.InstantiateDatabase( v_database2.v_alias, v_database2.v_conn_id, v_database2.v_db_type, v_database2.v_server, v_database2.v_port, v_database2.v_service, v_database2.v_user, v_database2.v_connection.v_password, v_database2.v_schema ); v_database.v_connection.SetTimeout(0); if (v_query_data.v_cmd_type == -2) { try { v_httpSession.Execute(v_database, v_query_data.v_sql_cmd, true, true); } catch (Spartacus.Database.Exception e) { v_response.v_error = true; v_response.v_data = e.v_message.Replace("<", "<").Replace(">", ">").Replace(System.Environment.NewLine, "<br/>"); SendToClient(p_webSocketSession, v_response); return; } catch (System.InvalidOperationException e) { v_response.v_error = true; v_response.v_data = e.Message.Replace("<", "<").Replace(">", ">").Replace(System.Environment.NewLine, "<br/>"); SendToClient(p_webSocketSession, v_response); return; } } else if (v_query_data.v_cmd_type == -3) { string[] v_commands = v_query_data.v_sql_cmd.Split(';'); string v_return_html = ""; int v_num_success_commands = 0; int v_num_error_commands = 0; v_database.v_connection.Open(); foreach (string v_command in v_commands) { if (v_command.Trim() != "") { try { v_httpSession.Execute(v_database, v_command, true, true); v_num_success_commands++; } catch (Spartacus.Database.Exception e) { v_num_error_commands++; v_return_html += "<b>Command:</b> " + v_command + "<br/><br/><b>Message:</b> " + e.v_message.Replace("<", "<").Replace(">", ">").Replace(System.Environment.NewLine, "<br/>") + "<br/><br/>"; } } } v_response.v_data = "<b>Successful commands:</b> " + v_num_success_commands + "<br/>"; v_response.v_data += "<b>Errors: </b> " + v_num_error_commands + "<br/><br/>"; if (v_num_error_commands > 0) { v_response.v_data += "<b>Errors details:</b><br/><br/>" + v_return_html; } v_database.v_connection.Close(); } else { try { System.Collections.Generic.List <string> v_columns; if (v_query_data.v_cmd_type == -1) { v_table = v_httpSession.QueryList(v_database, v_query_data.v_sql_cmd, true, true, out v_columns); } else { v_table = v_httpSession.QueryListLimited(v_database, v_query_data.v_sql_cmd, v_query_data.v_cmd_type, true, false, out v_columns); } v_g1.v_query_info = "Number of records: " + v_table.Count.ToString(); v_g1.v_data = v_table; v_g1.v_col_names = v_columns; v_response.v_data = v_g1; } catch (Spartacus.Database.Exception e) { v_response.v_error = true; v_response.v_data = e.v_message.Replace("<", "<").Replace(">", ">").Replace(System.Environment.NewLine, "<br/>"); SendToClient(p_webSocketSession, v_response); return; } catch (System.InvalidOperationException e) { v_response.v_error = true; v_response.v_data = e.Message.Replace("<", "<").Replace(">", ">").Replace(System.Environment.NewLine, "<br/>"); SendToClient(p_webSocketSession, v_response); return; } catch (System.Data.DuplicateNameException e) { v_response.v_error = true; v_response.v_data = e.Message.Replace("<", "<").Replace(">", ">").Replace(System.Environment.NewLine, "<br/>"); SendToClient(p_webSocketSession, v_response); return; } } SendToClient(p_webSocketSession, v_response); }
/// <summary> /// 查询接口 /// </summary> /// <param name="mchid"></param> /// <param name="orderid"></param> /// <param name="sign"></param> /// <returns></returns> public async Task <QueryReturn> Query(string mchid, string orderid) { QueryReturn r = new QueryReturn(); if (mchid != DB.MchId) { r.ReturnMsg = "商户号不存在"; return(r); } Pay_order order = DB.Context.From <Pay_order>().Where(p => p.Order_id == orderid).ToFirstDefault(); if (order == null || string.IsNullOrEmpty(order.Order_id)) { r.ReturnMsg = "订单不存在"; return(r); } if (order.Status == 1) { r.ReturnMsg = "ok"; r.IsPay = true; r.OrderNumber = order.Order_id; r.SerialNumber = order.Plat_order_id; r.Totalfee = order.Pay_amount; r.Attach = order.Attach; return(r); } else { Pay_mch mch = OnlinePay.GetMch(order.Mch_id); if (mch == null) { r.ReturnMsg = "平台商户信息错误"; return(r); } Pay_plat plat = OnlinePay.GetPlat(mch.Plat_id); if (plat == null) { r.ReturnMsg = "平台渠道信息错误"; return(r); } OnlinePay onlinepay = (OnlinePay)Activator.CreateInstance(Type.GetType(plat.Plat_class), plat, mch); r = await onlinepay.OrderQuery(order.Order_id); if (r.ReturnMsg == "ok" && r.IsPay) { order.Status = 1; if (r.Totalfee > 0) { order.Pay_amount = r.Totalfee; } order.Finish_time = DateTime.Now.ToTimeStamp(); DB.Context.Save(order); } return(r); } }