SQLHelperParametric.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  1. using Newtonsoft.Json.Linq;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Text.Json;
  8. using TEAMModelOS.SDK.Context.Exception;
  9. namespace TEAMModelOS.SDK.Module.AzureCosmosDBV3
  10. {
  11. public class SQLHelperParametric
  12. {
  13. static readonly string[] LogicOpers = new string[] { " and ", " or " };
  14. static readonly string[] CompareOpers = new string[] { " > ", " < ", " <= ", " >= ", " = ", " != ", " like ", " not like ", " in " };
  15. public static void ReplaceKeyWords(ref StringBuilder sql)
  16. {
  17. sql.Replace(".order.", "['order'].");
  18. sql.Replace(".order ", "['order'] ");
  19. sql.Replace(".group.", "['group'].");
  20. sql.Replace(".group ", "['group'] ");
  21. sql.Replace(".end.", "['end'].");
  22. sql.Replace(".end ", "['end'] ");
  23. sql.Replace(".having.", "['having'].");
  24. sql.Replace(".having ", "['having'] ");
  25. }
  26. public static CosmosDbQuery GetSQL(Dictionary<string, object> dict, StringBuilder sql)
  27. {
  28. if (dict != null)
  29. {
  30. Dictionary<string, object> parmeters = new Dictionary<string, object>();
  31. int offsetNum = 0;
  32. int limitNum = 0;
  33. bool pageBool = false;
  34. GetPageNum(dict, ref offsetNum, ref limitNum, ref pageBool);
  35. //处理顺序
  36. Stack<KeyValuePair<string, object>> stack = new Stack<KeyValuePair<string, object>>();
  37. foreach (string item in dict.Keys)
  38. {
  39. if (item.EndsWith(".|"))
  40. {
  41. stack.Push(new KeyValuePair<string, object>(item, dict[item]));
  42. }
  43. }
  44. foreach (string item in dict.Keys)
  45. {
  46. if (!item.EndsWith(".|"))
  47. {
  48. stack.Push(new KeyValuePair<string, object>(item, dict[item]));
  49. }
  50. }
  51. string Join = " join ";
  52. string instring = " in ";
  53. Dictionary<string, string> keyValues = new Dictionary<string, string>();
  54. StringBuilder WhereString = new StringBuilder();
  55. int heada = 0;
  56. string[] sqlHead = new string[] { "A", "B", "C", "D", "E", "F" };
  57. int kslength = 0;
  58. int logicOperNum = 0;
  59. bool keyListValueList = true;
  60. int keyListValueListNum = 0;
  61. int stackCount = stack.Count;
  62. for (int k = 0; k < stackCount; k++)
  63. {
  64. KeyValuePair<string, object> item = stack.Pop();
  65. bool isLikeSQL = false;
  66. if (item.Key.StartsWith("$.") || item.Key.StartsWith("!$."))
  67. {
  68. isLikeSQL = true;
  69. }
  70. string key = item.Key;
  71. string[] keyHead = key.Split(".");
  72. int index = 0;
  73. int compareOper = 4;
  74. int logicOper = 0;
  75. if (key.EndsWith(".&"))
  76. {
  77. logicOper = (int)LogicOper.and;
  78. key = key.Replace(".&", "");
  79. }
  80. else if (key.EndsWith(".|"))
  81. {
  82. logicOper = (int)LogicOper.or;
  83. key = key.Replace(".|", "");
  84. }
  85. CompareOperSwitch(keyHead[0], ref key, ref compareOper);
  86. string[] keyBody = key.Split("[*]");
  87. if (keyBody.Length > 1)
  88. {
  89. key = key.Replace("[*]", "");
  90. key = key.Replace(".", "");
  91. kslength += keyBody.Length;
  92. if (kslength < (7 + heada))
  93. {
  94. StringBuilder sqlitem = new StringBuilder();
  95. for (int i = 0; i < keyBody.Length - 1; i++)
  96. {
  97. //Console.WriteLine(ks[i]);
  98. if (i == 0)
  99. {
  100. sqlitem.Append(Join);
  101. string a = sqlHead[heada] + index;
  102. sqlitem.Append(a + " ");
  103. //keyValues.Add(ks[i], a);
  104. keyValues[keyBody[i]] = a;
  105. sqlitem.Append(instring);
  106. sqlitem.Append("c.");
  107. sqlitem.Append(keyBody[i]);
  108. }
  109. else
  110. {
  111. sqlitem.Append(Join);
  112. string a = sqlHead[heada] + index;
  113. sqlitem.Append(a + " ");
  114. //keyValues.Add(ks[i], a);
  115. keyValues[keyBody[i]] = a;
  116. sqlitem.Append(instring);
  117. sqlitem.Append(keyValues[keyBody[i - 1]]);
  118. sqlitem.Append(keyBody[i]);
  119. }
  120. index += 1;
  121. }
  122. sql.Append(sqlitem);
  123. string s = "";
  124. if (isLikeSQL)
  125. {
  126. s = ValueIsLike(sqlHead[heada] + (keyBody.Length - 2) + keyBody[index] + "", key, item.Value, LogicOpers[logicOper], logicOperNum, compareOper, ref keyListValueList);
  127. }
  128. else
  129. {
  130. s = ValueNotLike(sqlHead[heada] + (keyBody.Length - 2) + keyBody[index] + "", key, item.Value, LogicOpers[logicOper], logicOperNum, compareOper, ref keyListValueList);
  131. }
  132. WhereString.Append(s);
  133. if (keyListValueList && keyListValueListNum == 0)
  134. {
  135. sql = sql.Replace("select ", "select distinct ");
  136. keyListValueList = false;
  137. keyListValueListNum++;
  138. }
  139. }
  140. else
  141. {
  142. throw new BizException("数组总共深度不能超过5层", ResponseCode.PARAMS_ERROR);
  143. }
  144. heada += 1;
  145. }
  146. else
  147. {
  148. string itemKey = key.Replace(".", "");
  149. WhereString.Append(KeyNotElement(dict[item.Key], item.Key, itemKey, LogicOpers[logicOper], logicOperNum, compareOper));
  150. }
  151. logicOperNum += 1;
  152. }
  153. sql.Append(" where 1=1 ").Append(WhereString);
  154. if (pageBool)
  155. {
  156. sql.Append(" OFFSET " + offsetNum + " LIMIT " + limitNum);
  157. }
  158. ReplaceKeyWords(ref sql);
  159. parmeters = GetParmeter(dict, parmeters);
  160. CosmosDbQuery cosmosDbQuery = new CosmosDbQuery
  161. {
  162. QueryText = sql.ToString(),
  163. Parameters = parmeters
  164. };
  165. return cosmosDbQuery;
  166. }
  167. return null;
  168. }
  169. private static void GetPageNum(Dictionary<string, object> dict, ref int offsetNum, ref int limitNum, ref bool pageBool)
  170. {
  171. dict.TryGetValue("OFFSET", out object offset);
  172. dict.Remove("OFFSET");
  173. dict.TryGetValue("LIMIT", out object limit);
  174. dict.Remove("LIMIT");
  175. if (offset != null && limit != null)
  176. {
  177. pageBool = true;
  178. offsetNum = int.Parse(offset.ToString());
  179. limitNum = int.Parse(limit.ToString());
  180. }
  181. }
  182. private static void CompareOperSwitch(string keyHead, ref string key, ref int compareOper)
  183. {
  184. switch (keyHead)
  185. {
  186. case ">":
  187. compareOper = (int)CompareOper.moreThan;
  188. key = key.Replace(">.", "");
  189. break;
  190. case "<":
  191. compareOper = (int)CompareOper.lessThan;
  192. key = key.Replace("<.", "");
  193. break;
  194. case "<=":
  195. compareOper = (int)CompareOper.notMoreThan;
  196. key = key.Replace("<=.", "");
  197. break;
  198. case ">=":
  199. compareOper = (int)CompareOper.notLessThan;
  200. key = key.Replace(">=.", "");
  201. break;
  202. case "=":
  203. compareOper = (int)CompareOper.equal;
  204. key = key.Replace("=.", "");
  205. break;
  206. case "!=":
  207. compareOper = (int)CompareOper.notEqual;
  208. key = key.Replace("!=.", "");
  209. break;
  210. case "$":
  211. compareOper = (int)CompareOper.like;
  212. key = key.Replace("$.", "");
  213. break;
  214. case "!$":
  215. compareOper = (int)CompareOper.notLike;
  216. key = key.Replace("!$.", "");
  217. break;
  218. default:
  219. compareOper = 4;
  220. break;
  221. }
  222. }
  223. private static string ValueNotLike(string key, string key1, object value, string logicOperParams, int logicOperNum, int compareOperNum, ref bool keyListValueList)
  224. {
  225. string logicOper = " and ";
  226. string compareOper = " = ";
  227. if (compareOperNum != 4) compareOper = CompareOpers[compareOperNum];
  228. if (logicOperNum != 0) logicOper = logicOperParams;
  229. StringBuilder sql = new StringBuilder(logicOper + key + " in (");
  230. if (value is JArray array)
  231. {
  232. int aa = 0;
  233. foreach (JValue obja in array)
  234. {
  235. sql.Append(" @" + key1 + aa + " ,");
  236. aa++;
  237. }
  238. string sqls = sql.ToString().Substring(0, sql.Length - 1);
  239. sqls += " ) ";
  240. return sqls;
  241. }
  242. else if (value is IEnumerable enumerable && !(value is String))
  243. {
  244. int aa = 0;
  245. foreach (object obja in enumerable)
  246. {
  247. sql.Append(" @" + key1 + aa + " ,");
  248. aa++;
  249. }
  250. string sqls = sql.ToString().Substring(0, sql.Length - 1);
  251. sqls += ") ";
  252. return sqls;
  253. }
  254. else if (value is JsonElement jsonElement)
  255. {
  256. if (jsonElement.ValueKind is JsonValueKind.Array)
  257. {
  258. int aa = 0;
  259. foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
  260. {
  261. sql.Append(" @" + key1 + aa + " ,");
  262. aa++;
  263. }
  264. }
  265. else
  266. {
  267. if (compareOperNum == 4) keyListValueList = false;
  268. return logicOper + key + compareOper + " @" + key1 + " ";
  269. }
  270. string sqls = sql.ToString().Substring(0, sql.Length - 1);
  271. sqls += " ) ";
  272. return sqls;
  273. }
  274. else
  275. {
  276. Type s = value.GetType();
  277. TypeCode typeCode = Type.GetTypeCode(s);
  278. if (compareOperNum == 4) keyListValueList = false;
  279. return logicOper + key + compareOper + " @" + key1 + " ";
  280. }
  281. }
  282. private static string ValueIsLike(string key, string key1, object value, string logicOperParams, int logicOperNum, int compareOperNum, ref bool keyListValueList)
  283. {
  284. string compareOperBool = " true ";
  285. compareOperBool = CompareBoolSwitch(compareOperNum);
  286. string logicOper = " and ";
  287. if (logicOperNum != 0) logicOper = logicOperParams;
  288. StringBuilder s = new StringBuilder(logicOper + " ( Contains( ");
  289. if (value is JArray array)
  290. {
  291. int aa = 0;
  292. foreach (JValue obja in array)
  293. {
  294. if (aa != 0) s.Append("or Contains(");
  295. s.Append(key + "," + " @" + key1 + aa + " ) = " + compareOperBool + " ");
  296. if (obja.Value is string)
  297. {
  298. s.Append(key + "," + " @" + key1 + aa + " ) = " + compareOperBool + " ");
  299. }
  300. else
  301. {
  302. s.Append("ToString( " + key + " )," + " \'@" + key1 + aa + "\' ) = " + compareOperBool + " ");
  303. }
  304. aa++;
  305. }
  306. }
  307. else if (value is IEnumerable enumerable && !(value is String))
  308. {
  309. int aa = 0;
  310. foreach (object obja in enumerable)
  311. {
  312. if (aa != 0) s.Append("or Contains(");
  313. if (obja is string)
  314. {
  315. s.Append(key + "," + " @" + key1 + aa + " ) = " + compareOperBool + " ");
  316. }
  317. else
  318. {
  319. s.Append("ToString( " + key + " )," + " \'@" + key1 + aa + "\' ) = " + compareOperBool + " ");
  320. }
  321. aa++;
  322. }
  323. }
  324. else if (value is JsonElement jsonElement && jsonElement.ValueKind is JsonValueKind.Array)
  325. {
  326. int aa = 0;
  327. foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
  328. {
  329. if (aa != 0) s.Append("or Contains(");
  330. if (obja.ValueKind is JsonValueKind.String)
  331. {
  332. s.Append(key + "," + " @" + key1 + aa + " ) = " + compareOperBool + " ");
  333. }
  334. else
  335. {
  336. s.Append("ToString( " + key + " )," + " \'@" + key1 + aa + "\' ) = " + compareOperBool + " ");
  337. }
  338. aa++;
  339. }
  340. }
  341. else
  342. {
  343. Type stype = value.GetType();
  344. TypeCode typeCode = Type.GetTypeCode(stype);
  345. keyListValueList = false;
  346. string sql = "";
  347. if (value is string)
  348. {
  349. sql = logicOper + "Contains( " + key + " , @" + key1 + " ) = " + compareOperBool + " ";
  350. }
  351. else if (value is JsonElement jsonElement1 && jsonElement1.ValueKind is JsonValueKind.String)
  352. {
  353. sql = logicOper + "Contains( " + key + " , @" + key1 + " ) = " + compareOperBool + " ";
  354. }
  355. else
  356. {
  357. sql = logicOper + "Contains( ToString(" + key + " ), \'@" + key1 + "\' ) = " + compareOperBool + " ";
  358. }
  359. return sql;
  360. }
  361. s.Append(" )");
  362. return s.ToString();
  363. }
  364. private static string CompareBoolSwitch(int compareOperNum)
  365. {
  366. return compareOperNum switch
  367. {
  368. 6 => " true ",
  369. 7 => " false ",
  370. _ => " true ",
  371. };
  372. }
  373. private static string KeyNotElement(object value, string key, string key1, string logicOperParams, int logicOperNum, int compareOperNum)
  374. {
  375. string compareOperBool = " true ";
  376. compareOperBool = CompareBoolSwitch(compareOperNum);
  377. string logicOper = " and ";
  378. int compareOper = 4;
  379. if (logicOperNum != 0) logicOper = logicOperParams;
  380. if (key.EndsWith(".&"))
  381. {
  382. key = key.Replace(".&", "");
  383. }
  384. else if (key.EndsWith(".|"))
  385. {
  386. key = key.Replace(".|", "");
  387. }
  388. string[] keyHead = key.Split(".");
  389. CompareOperSwitch(keyHead[0], ref key, ref compareOper);
  390. if (compareOper == 6 || compareOper == 7)
  391. {
  392. StringBuilder sql = new StringBuilder(logicOper + " ( Contains( ");
  393. if (value is JArray jarray)
  394. {
  395. int aa = 0;
  396. foreach (JValue obja in jarray)
  397. {
  398. if (aa != 0) sql.Append("or Contains(");
  399. if (obja.Value is string)
  400. {
  401. sql.Append(" c." + key + "," + " @" + key1 + aa + " ) = " + compareOperBool + " ");
  402. }
  403. else
  404. {
  405. sql.Append("ToString( c." + key + " )," + " \'@" + key1 + aa + "\' ) = " + compareOperBool + " ");
  406. }
  407. sql.Append(" c." + key + ", @" + key1 + aa + " )= " + compareOperBool + " ");
  408. aa++;
  409. }
  410. }
  411. else if (value is IEnumerable enumerable && !(value is String))
  412. {
  413. int aa = 0;
  414. foreach (object obja in enumerable)
  415. {
  416. if (aa != 0) sql.Append("or Contains(");
  417. if (obja is string)
  418. {
  419. sql.Append(" c." + key + "," + " @" + key1 + aa + " ) = " + compareOperBool + " ");
  420. }
  421. else
  422. {
  423. sql.Append("ToString( c." + key + " )," + " \'@" + key1 + aa + "\' ) = " + compareOperBool + " ");
  424. }
  425. aa++;
  426. }
  427. }
  428. else if (value is JsonElement jsonElement && jsonElement.ValueKind! is JsonValueKind.Array)
  429. {
  430. int aa = 0;
  431. foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
  432. {
  433. if (aa != 0) sql.Append("or Contains(");
  434. if (obja.ValueKind is JsonValueKind.String)
  435. {
  436. sql.Append(" c." + key + "," + " @" + key1 + aa + " ) = " + compareOperBool + " ");
  437. }
  438. else
  439. {
  440. sql.Append("ToString( c." + key + " )," + " \'@" + key1 + aa + "\' ) = " + compareOperBool + " ");
  441. }
  442. aa++;
  443. }
  444. }
  445. else
  446. {
  447. Type s = value.GetType();
  448. TypeCode typeCode = Type.GetTypeCode(s);
  449. string sql1 = "";
  450. if (value is string)
  451. {
  452. sql1 = logicOper + "Contains( c." + key + " , @" + key1 + " ) = " + compareOperBool + " ";
  453. }
  454. else
  455. {
  456. sql1 = logicOper + "Contains( ToString( c." + key + " ), \'@" + key1 + "\' ) = " + compareOperBool + " ";
  457. }
  458. return sql1;
  459. }
  460. sql.Append(")");
  461. return sql.ToString();
  462. }
  463. else
  464. {
  465. StringBuilder sql = new StringBuilder(logicOper + " c." + key + " in (");
  466. if (value is JArray array)
  467. {
  468. int aa = 0;
  469. foreach (JValue obja in array)
  470. {
  471. sql.Append(" @" + key1 + aa + " ,");
  472. aa++;
  473. }
  474. string sqls = sql.ToString().Substring(0, sql.Length - 1);
  475. sqls += " ) ";
  476. return sqls;
  477. }
  478. else if (value is IEnumerable enumerable && !(value is String))
  479. {
  480. int aa = 0;
  481. foreach (object obja in enumerable)
  482. {
  483. sql.Append(" @" + key1 + aa + " ,");
  484. aa++;
  485. }
  486. string sqls = sql.ToString().Substring(0, sql.Length - 1);
  487. sqls += " ) ";
  488. return sqls;
  489. }
  490. else if (value is JsonElement jsonElement)
  491. {
  492. if (jsonElement.ValueKind is JsonValueKind.Array)
  493. {
  494. int aa = 0;
  495. foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
  496. {
  497. sql.Append(" @" + key1 + aa + " ,");
  498. aa++;
  499. }
  500. }
  501. else
  502. {
  503. return logicOper + " c." + key + CompareOpers[compareOperNum] + " @" + key1;
  504. }
  505. string sqls = sql.ToString().Substring(0, sql.Length - 1);
  506. sqls += " ) ";
  507. return sqls;
  508. }
  509. else
  510. {
  511. Type s = value.GetType();
  512. TypeCode typeCode = Type.GetTypeCode(s);
  513. return typeCode switch
  514. {
  515. TypeCode.String => logicOper + " c." + key + CompareOpers[compareOperNum] + " @" + key1,// + "\'" + value.ToString() + "\'",
  516. TypeCode.Char => logicOper + " c." + key + CompareOpers[compareOperNum] + " @" + key1,// + "\'" + value.ToString() + "\'",
  517. TypeCode.Int32 => logicOper + " c." + key + CompareOpers[compareOperNum] + " @" + key1,// + int.Parse(value.ToString()),
  518. TypeCode.Double => logicOper + " c." + key + CompareOpers[compareOperNum] + " @" + key1,// + double.Parse(value.ToString()),
  519. TypeCode.Boolean => logicOper + " c." + key + CompareOpers[compareOperNum] + " @" + key1,// + bool.Parse(value.ToString()),
  520. TypeCode.DateTime => logicOper + " c." + key + CompareOpers[compareOperNum] + " @" + key1,// + (DateTime)value,
  521. TypeCode.Int64 => logicOper + " c." + key + CompareOpers[compareOperNum] + " @" + key1,// + long.Parse(value.ToString()),
  522. _ => null,
  523. };
  524. }
  525. }
  526. }
  527. public enum LogicOper : int
  528. {
  529. and = 0, or = 1
  530. }
  531. public enum CompareOper : int
  532. {
  533. moreThan = 0, lessThan = 1, notMoreThan = 2, notLessThan = 3, equal = 4, notEqual = 5, like = 6, notLike = 7, IN = 8
  534. }
  535. private static Dictionary<string, object> GetParmeter(Dictionary<string, object> dict, Dictionary<string, object> parmeters)
  536. {
  537. foreach (KeyValuePair<string, object> keyValue in dict)
  538. {
  539. string key = "";
  540. string[] keyHead = keyValue.Key.Split(".");
  541. switch (keyHead[0])
  542. {
  543. case ">":
  544. key = keyValue.Key.Replace(">.", "");
  545. break;
  546. case "<":
  547. key = keyValue.Key.Replace("<.", "");
  548. break;
  549. case "<=":
  550. key = keyValue.Key.Replace("<=.", "");
  551. break;
  552. case ">=":
  553. key = keyValue.Key.Replace(">=.", "");
  554. break;
  555. case "=":
  556. key = keyValue.Key.Replace("=.", "");
  557. break;
  558. case "!=":
  559. key = keyValue.Key.Replace("!=.", "");
  560. break;
  561. case "$":
  562. key = keyValue.Key.Replace("$.", "");
  563. break;
  564. case "!$":
  565. key = keyValue.Key.Replace("!$.", "");
  566. break;
  567. default:
  568. key = keyValue.Key;
  569. break;
  570. }
  571. if (key.EndsWith(".&"))
  572. {
  573. key = key.Replace(".&", "");
  574. }
  575. else if (key.EndsWith(".|"))
  576. {
  577. key = key.Replace(".|", "");
  578. }
  579. key = key.Replace("[*]", "");
  580. key = key.Replace(".", "");
  581. if (keyValue.Value is JArray array)
  582. {
  583. int aa = 0;
  584. foreach (JValue obja in array)
  585. {
  586. parmeters.Add("@" + key + aa, obja);
  587. aa++;
  588. }
  589. }
  590. else if (keyValue.Value is JsonElement jsonElement)
  591. {
  592. if (jsonElement.ValueKind is JsonValueKind.Array)
  593. {
  594. int aa = 0;
  595. foreach (JsonElement obja in jsonElement.EnumerateArray().ToArray())
  596. {
  597. if (obja.ValueKind is JsonValueKind.String)
  598. {
  599. parmeters.Add("@" + key + aa, obja.ToString());
  600. }
  601. if (obja.ValueKind is JsonValueKind.Number)
  602. {
  603. parmeters.Add("@" + key + aa, double.Parse(obja.ToString()));
  604. }
  605. if (obja.ValueKind is JsonValueKind.True)
  606. {
  607. parmeters.Add("@" + key + aa, bool.Parse(obja.ToString()));
  608. }
  609. if (obja.ValueKind is JsonValueKind.False)
  610. {
  611. parmeters.Add("@" + key + aa, bool.Parse(obja.ToString()));
  612. }
  613. aa++;
  614. }
  615. }
  616. else
  617. {
  618. if (jsonElement.ValueKind is JsonValueKind.String)
  619. {
  620. parmeters.Add("@" + key, keyValue.Value.ToString());
  621. }
  622. else if (jsonElement.ValueKind is JsonValueKind.Number)
  623. {
  624. parmeters.Add("@" + key, double.Parse(keyValue.Value.ToString()));
  625. }
  626. else if (jsonElement.ValueKind is JsonValueKind.True)
  627. {
  628. parmeters.Add("@" + key, bool.Parse(keyValue.Value.ToString()));
  629. }
  630. else if (jsonElement.ValueKind is JsonValueKind.False)
  631. {
  632. parmeters.Add("@" + key, bool.Parse(keyValue.Value.ToString()));
  633. }
  634. else
  635. {
  636. parmeters.Add("@" + key, keyValue.Value.ToString());
  637. }
  638. }
  639. }
  640. else if (keyValue.Value is IEnumerable enumerable)
  641. {
  642. int aa = 0;
  643. foreach (object obja in enumerable)
  644. {
  645. parmeters.Add("@" + key + aa, obja);
  646. aa++;
  647. }
  648. }
  649. else
  650. {
  651. parmeters.Add("@" + key, keyValue.Value);
  652. }
  653. }
  654. return parmeters;
  655. }
  656. }
  657. }