StatTradeCheckService.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. using System;
  2. using System.Collections.Generic;
  3. using Library;
  4. using LitJson;
  5. using System.Linq;
  6. using System.Data;
  7. using System.Threading;
  8. using MySystem.PxcModels;
  9. namespace MySystem
  10. {
  11. public class StatTradeCheckService
  12. {
  13. public readonly static StatTradeCheckService Instance = new StatTradeCheckService();
  14. private StatTradeCheckService()
  15. { }
  16. // 统计交易额V2
  17. public void Start()
  18. {
  19. Thread th = new Thread(StartDo);
  20. th.IsBackground = true;
  21. th.Start();
  22. }
  23. public void StartDo()
  24. {
  25. while (true)
  26. {
  27. string content = RedisDbconn.Instance.RPop<string>("StatTradeCheckQueue");
  28. if(!string.IsNullOrEmpty(content))
  29. {
  30. StatTradeAmountDo(content);
  31. Thread.Sleep(1);
  32. }
  33. else
  34. {
  35. Thread.Sleep(10000);
  36. }
  37. }
  38. }
  39. public void StatTradeAmountDo(string date)
  40. {
  41. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  42. try
  43. {
  44. int pageNum = 0;
  45. bool check = true;
  46. while(check)
  47. {
  48. string sql = "";
  49. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "---" + pageNum + "----start", "统计交易额日志");
  50. DataTable dt = CustomerSqlConn.dtable("select UserId,ParentNav,BrandId,BankCardType,QrPayFlag,MerHelpFlag,Version,CapFlag,VipFlag,PayType,DATE_FORMAT(CreateDate,'%Y%m%d'),sum(TradeAmount),count(Id),SnNo,TradeDate from TradeRecord where Id>20000000 and ActStatus=1 and BrandId!=14 and UserId>0 and CreateDate>='" + date + " 00:00:00' and CreateDate<='" + date + " 23:59:59' group by UserId,ParentNav,BrandId,BankCardType,QrPayFlag,MerHelpFlag,Version,CapFlag,VipFlag,PayType,DATE_FORMAT(CreateDate,'%Y%m%d'),SnNo,TradeDate order by UserId limit " + pageNum + ",500", AppConfig.Base.TmpReadSqlConn);
  51. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "---" + pageNum + "----query", "统计交易额日志");
  52. if(dt.Rows.Count > 0)
  53. {
  54. foreach (DataRow dr in dt.Rows)
  55. {
  56. int UserId = int.Parse(dr["UserId"].ToString());
  57. string SnNo = dr["SnNo"].ToString();
  58. string BindingTime = dr["TradeDate"].ToString();
  59. string ParentNav = dr["ParentNav"].ToString();
  60. int BrandId = int.Parse(dr["BrandId"].ToString());
  61. int BankCardType = int.Parse(dr["BankCardType"].ToString());
  62. int QrPayFlag = int.Parse(dr["QrPayFlag"].ToString());
  63. int MerHelpFlag = int.Parse(dr["MerHelpFlag"].ToString());
  64. int Version = int.Parse(dr["Version"].ToString());
  65. int CapFlag = int.Parse(dr["CapFlag"].ToString());
  66. int VipFlag = int.Parse(dr["VipFlag"].ToString());
  67. int PayType = int.Parse(dr["PayType"].ToString());
  68. string TradeDate = dr[10].ToString();
  69. decimal TradeAmount = decimal.Parse(dr[11].ToString());
  70. int TradeCount = 1;
  71. string TradeMonth = TradeDate.Substring(0, 6);
  72. ParentNav += "," + UserId + ",";
  73. string ParentNavString = ParentNav.Trim(',').Replace(",,", ",");
  74. string[] UserIdList = ParentNavString.Split(',');
  75. if(Version < 2)
  76. {
  77. //个人业绩
  78. decimal ProfitDirectDebitTradeAmt = 0;
  79. decimal ProfitDirectDebitCapTradeAmt = 0;
  80. decimal ProfitDirectDebitCapNum = 0;
  81. decimal HelpDirectDebitTradeAmt = 0;
  82. decimal HelpDirectDebitCapTradeAmt = 0;
  83. decimal HelpDirectDebitCapNum = 0;
  84. decimal NotHelpDirectDebitTradeAmt = 0;
  85. decimal NotHelpDirectDebitCapTradeAmt = 0;
  86. decimal NotHelpDirectDebitCapNum = 0;
  87. decimal ProfitDirectTradeAmt = 0;
  88. decimal HelpDirectTradeAmt = 0;
  89. decimal NotHelpDirectTradeAmt = 0;
  90. if (BankCardType == 0)
  91. {
  92. if (Version == 1)
  93. {
  94. ProfitDirectDebitTradeAmt += TradeAmount;
  95. if (CapFlag == 1)
  96. {
  97. ProfitDirectDebitCapTradeAmt += TradeAmount;
  98. ProfitDirectDebitCapNum += TradeCount;
  99. }
  100. }
  101. else if (MerHelpFlag == 1)
  102. {
  103. HelpDirectDebitTradeAmt += TradeAmount;
  104. if (CapFlag == 1)
  105. {
  106. HelpDirectDebitCapTradeAmt += TradeAmount;
  107. HelpDirectDebitCapNum += TradeCount;
  108. }
  109. }
  110. else
  111. {
  112. NotHelpDirectDebitTradeAmt += TradeAmount;
  113. if (CapFlag == 1)
  114. {
  115. NotHelpDirectDebitCapTradeAmt += TradeAmount;
  116. NotHelpDirectDebitCapNum += TradeCount;
  117. }
  118. }
  119. }
  120. else if (BankCardType != 0)
  121. {
  122. if (Version == 1)
  123. {
  124. ProfitDirectTradeAmt += TradeAmount;
  125. }
  126. else if (MerHelpFlag == 1)
  127. {
  128. HelpDirectTradeAmt += TradeAmount;
  129. }
  130. else
  131. {
  132. NotHelpDirectTradeAmt += TradeAmount;
  133. }
  134. }
  135. sql += InsertOrUpdate("TradeDaySummary", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  136. if (DateTime.Parse(BindingTime) < DateTime.Parse("2023-07-01 00:00:00"))
  137. {
  138. sql += InsertOrUpdate("TradeDaySummaryBefore", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  139. }
  140. else
  141. {
  142. sql += InsertOrUpdate("TradeDaySummaryAfter", "ProfitDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitDirectTradeAmt,HelpDirectTradeAmt,NotHelpDirectTradeAmt", ProfitDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitDirectTradeAmt + "," + HelpDirectTradeAmt + "," + NotHelpDirectTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  143. }
  144. //团队业绩
  145. foreach(string SubUserId in UserIdList)
  146. {
  147. decimal ProfitNonDirectDebitTradeAmt = 0;
  148. ProfitDirectDebitCapTradeAmt = 0;
  149. ProfitDirectDebitCapNum = 0;
  150. decimal HelpNonDirectDebitTradeAmt = 0;
  151. HelpDirectDebitCapTradeAmt = 0;
  152. HelpDirectDebitCapNum = 0;
  153. decimal NotHelpNonDirectDebitTradeAmt = 0;
  154. NotHelpDirectDebitCapTradeAmt = 0;
  155. NotHelpDirectDebitCapNum = 0;
  156. decimal ProfitNonDirectTradeAmt = 0;
  157. decimal HelpNonDirectTradeAmt = 0;
  158. decimal NotHelpNonDirectTradeAmt = 0;
  159. if (BankCardType == 0)
  160. {
  161. if (Version == 1)
  162. {
  163. ProfitNonDirectDebitTradeAmt += TradeAmount;
  164. if (CapFlag == 1)
  165. {
  166. ProfitDirectDebitCapTradeAmt += TradeAmount;
  167. ProfitDirectDebitCapNum += TradeCount;
  168. }
  169. }
  170. else if (MerHelpFlag == 1)
  171. {
  172. HelpNonDirectDebitTradeAmt += TradeAmount;
  173. if (CapFlag == 1)
  174. {
  175. HelpDirectDebitCapTradeAmt += TradeAmount;
  176. HelpDirectDebitCapNum += TradeCount;
  177. }
  178. }
  179. else
  180. {
  181. NotHelpNonDirectDebitTradeAmt += TradeAmount;
  182. if (CapFlag == 1)
  183. {
  184. NotHelpDirectDebitCapTradeAmt += TradeAmount;
  185. NotHelpDirectDebitCapNum += TradeCount;
  186. }
  187. }
  188. }
  189. else if (BankCardType != 0)
  190. {
  191. if (Version == 1)
  192. {
  193. ProfitNonDirectTradeAmt += TradeAmount;
  194. }
  195. else if (MerHelpFlag == 1)
  196. {
  197. HelpNonDirectTradeAmt += TradeAmount;
  198. }
  199. else
  200. {
  201. NotHelpNonDirectTradeAmt += TradeAmount;
  202. }
  203. }
  204. sql += InsertOrUpdate("TradeDaySummary", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  205. if (DateTime.Parse(BindingTime) < DateTime.Parse("2023-07-01 00:00:00"))
  206. {
  207. sql += InsertOrUpdate("TradeDaySummaryBefore", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  208. }
  209. else
  210. {
  211. sql += InsertOrUpdate("TradeDaySummaryAfter", "ProfitNonDirectDebitTradeAmt,ProfitDirectDebitCapTradeAmt,ProfitDirectDebitCapNum,HelpNonDirectDebitTradeAmt,HelpDirectDebitCapTradeAmt,HelpDirectDebitCapNum,NotHelpNonDirectDebitTradeAmt,NotHelpDirectDebitCapTradeAmt,NotHelpDirectDebitCapNum,ProfitNonDirectTradeAmt,HelpNonDirectTradeAmt,NotHelpNonDirectTradeAmt", ProfitNonDirectDebitTradeAmt + "," + ProfitDirectDebitCapTradeAmt + "," + ProfitDirectDebitCapNum + "," + HelpNonDirectDebitTradeAmt + "," + HelpDirectDebitCapTradeAmt + "," + HelpDirectDebitCapNum + "," + NotHelpNonDirectDebitTradeAmt + "," + NotHelpDirectDebitCapTradeAmt + "," + NotHelpDirectDebitCapNum + "," + ProfitNonDirectTradeAmt + "," + HelpNonDirectTradeAmt + "," + NotHelpNonDirectTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  212. }
  213. }
  214. }
  215. else
  216. {
  217. decimal ProfitDebitTradeAmt = 0;
  218. decimal ProfitDebitCapTradeAmt = 0;
  219. decimal ProfitDebitCapNum = 0;
  220. decimal ProfitTradeAmt = 0;
  221. if (BankCardType == 0)
  222. {
  223. if (Version == 2)
  224. {
  225. ProfitDebitTradeAmt += TradeAmount;
  226. if (CapFlag == 1)
  227. {
  228. ProfitDebitCapTradeAmt += TradeAmount;
  229. ProfitDebitCapNum += TradeCount;
  230. }
  231. }
  232. }
  233. else if (BankCardType != 0)
  234. {
  235. if (Version == 2)
  236. {
  237. ProfitTradeAmt += TradeAmount;
  238. }
  239. }
  240. sql += InsertOrUpdate("TradeDaySummary2", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  241. if (DateTime.Parse(BindingTime) < DateTime.Parse("2023-07-01 00:00:00"))
  242. {
  243. sql += InsertOrUpdate("TradeDaySummary2Before", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  244. }
  245. else
  246. {
  247. sql += InsertOrUpdate("TradeDaySummary2After", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + UserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='self'");
  248. }
  249. foreach(string SubUserId in UserIdList)
  250. {
  251. sql += InsertOrUpdate("TradeDaySummary2", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  252. if (DateTime.Parse(BindingTime) < DateTime.Parse("2023-07-01 00:00:00"))
  253. {
  254. sql += InsertOrUpdate("TradeDaySummary2Before", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  255. }
  256. else
  257. {
  258. sql += InsertOrUpdate("TradeDaySummary2After", "ProfitDebitTradeAmt,ProfitDebitCapTradeAmt,ProfitDebitCapNum,ProfitTradeAmt", ProfitDebitTradeAmt + "," + ProfitDebitCapTradeAmt + "," + ProfitDebitCapNum + "," + ProfitTradeAmt, "UserId=" + SubUserId + " and TradeMonth='" + TradeMonth + "' and TradeDate='" + TradeDate + "' and BrandId=" + BrandId + " and QueryCount=" + QrPayFlag + " and VipFlag=" + VipFlag + " and PayType=" + PayType + " and SeoTitle='team'");
  259. }
  260. }
  261. }
  262. }
  263. pageNum += 1;
  264. }
  265. else
  266. {
  267. check = false;
  268. }
  269. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "---" + pageNum + "----end", "统计交易额日志");
  270. // function.WriteLog(sql, "SQL脚本");
  271. CustomerSqlConn.op(sql, AppConfig.Base.SqlConn);
  272. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "---" + pageNum + "----fiinsh\n\n", "统计交易额日志");
  273. }
  274. }
  275. catch (Exception ex)
  276. {
  277. function.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "统计交易额异常");
  278. }
  279. function.WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), "统计交易额日志");
  280. }
  281. List<string> rediskeys = new List<string>();
  282. public string InsertOrUpdate(string table, string fields, string vals, string condition)
  283. {
  284. string sql = "";
  285. // string check = RedisDbconn.Instance.Get<string>("statreset:" + table + ":" + function.MD5_16(condition));
  286. // if(string.IsNullOrEmpty(check))
  287. if(!rediskeys.Contains(table + ":" + function.MD5_16(condition)))
  288. {
  289. rediskeys.Add(table + ":" + function.MD5_16(condition));
  290. // RedisDbconn.Instance.Set("statreset:" + table + ":" + function.MD5_16(condition), fields + "#cut#" + vals);
  291. // RedisDbconn.Instance.SetExpire("statreset:" + table + ":" + function.MD5_16(condition), 3600);
  292. string[] conditionList = condition.Split(new string[]{ " and " }, StringSplitOptions.None);
  293. foreach(string sub in conditionList)
  294. {
  295. string[] subCondition = sub.Split('=');
  296. fields += "," + subCondition[0];
  297. vals += "," + subCondition[1];
  298. }
  299. sql = "insert into " + table + " (" + fields + ") values (" + vals + ");\n";
  300. }
  301. else
  302. {
  303. string setVals = "";
  304. string[] fieldList = fields.Split(',');
  305. string[] valList = vals.Split(',');
  306. for (int i = 0; i < fieldList.Length; i++)
  307. {
  308. setVals += fieldList[i] + "=" + fieldList[i] + "+" + valList[i] + ",";
  309. }
  310. sql = "update " + table + " set " + setVals.TrimEnd(',') + " where " + condition + ";\n";
  311. }
  312. return sql;
  313. }
  314. }
  315. }