PageRenderTime 46ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/SqlServer.v.2011.10.31/Soccer Score Forecast/Soccer Score Forecast/UI_Command/AuditLiveTable.cs

http://htmlconvertsql.googlecode.com/
C# | 286 lines | 194 code | 49 blank | 43 comment | 14 complexity | f0681e2f46ea20f0c14fcfae80274cdd MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.IO;
  5. using System.Text;
  6. using System.Threading;
  7. using System.Windows.Forms;
  8. using System.Net;
  9. using SoccerScore.Compact.Linq;
  10. using System.Linq;
  11. using System.Data.SqlServerCe;
  12. using HtmlAgilityPack;
  13. using System.Data.SqlClient;
  14. using Soccer_Score_Forecast.BulkSql;
  15. namespace Soccer_Score_Forecast
  16. {
  17. //??2????
  18. //1.??????
  19. //2.????????
  20. //???????class ????
  21. public partial class Form1 : Form
  22. {
  23. private DateTime? UpdateResultDateTime;
  24. private void UpateResult()
  25. {
  26. int overday = 0;
  27. DeleteLiveData();
  28. UpdateResultData();
  29. ForecastAlgorithm();
  30. if (UpdateResultDateTime.Value.Day == DateTime.Now.Day)
  31. {
  32. overday = -1;
  33. }
  34. else
  35. {
  36. TimeSpan ts = DateTime.Now.Subtract(UpdateResultDateTime.Value);
  37. overday = -1 * ts.Days - 1;//?????
  38. }
  39. AuditForecastAlgorithm(overday);
  40. BatchExcuteSim(overday);
  41. UpdateAnalysisResult();
  42. }
  43. private void ReleaseMemory()
  44. {
  45. GC.Collect();
  46. GC.Collect();
  47. Application.DoEvents();
  48. }
  49. //1.?????live_id????????live_id,??analysis_id.?? ??
  50. //Full_home_goals?? Full_away_goals?? Half_home_goals?? Half_away_goals is null
  51. private void DeleteLiveData()
  52. {
  53. using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext(Conn.conn))
  54. {
  55. int deleteid = 0;
  56. var ltls = matches.Live_Table_lib.Where(e => e.Full_home_goals == null);
  57. if (ltls.FirstOrDefault() != null)
  58. deleteid = matches.Live_Table_lib.Where(e => e.Full_home_goals == null).Min(e => e.Live_table_lib_id);
  59. else
  60. deleteid = matches.Live_Table_lib.Max(e => e.Live_table_lib_id);
  61. matches.ExecuteCommand("delete from Live_Table_lib where Live_table_lib_id>=" + deleteid);
  62. matches.ExecuteCommand("delete from Match_analysis_result where Live_table_lib_id>=" + deleteid);
  63. }
  64. /*
  65. if (Conn.CreateTable(typeof(Match_analysis_result))
  66. && Conn.CreateTable(typeof(Live_Table_lib)))
  67. { }
  68. * */
  69. }
  70. //2.?? live_id to Live_Table_lib
  71. private void UpdateResultData()
  72. {
  73. DateTime? dt = DateTime.Now;
  74. using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext(Conn.conn))
  75. {
  76. dt = matches.Live_Table_lib.Max(e => e.Match_time);
  77. }
  78. //???????
  79. //DateTime dt = DateTime.Now.AddYears(-1);
  80. UpdateResultDateTime = dt;
  81. List<Live_Table_lib> ltls = new List<Live_Table_lib>();
  82. using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext(Conn.conn))
  83. {
  84. var result_tb = matches.Result_tb_lib.Where(e => e.Match_time > dt).OrderBy(e => e.Match_time);
  85. foreach (var r in result_tb)
  86. {
  87. Live_Table_lib ltl = new Live_Table_lib();
  88. ltl.Match_time = r.Match_time;
  89. ltl.Html_position = r.Html_position;
  90. ltl.Match_type = r.Match_type;
  91. ltl.Home_team_big = r.Home_team_big;
  92. ltl.Home_team = r.Home_team;
  93. ltl.Away_red_card = r.Away_red_card;
  94. ltl.Away_team_big = r.Away_team_big;
  95. ltl.Away_team = r.Away_team;
  96. ltl.Away_red_card = r.Away_red_card;
  97. ltl.Full_home_goals = r.Full_home_goals;
  98. ltl.Full_away_goals = r.Full_away_goals;
  99. ltl.Half_home_goals = r.Half_home_goals;
  100. ltl.Half_away_goals = r.Half_away_goals;
  101. ltl.Status = r.Odds;
  102. //matches.Live_Table_lib.InsertOnSubmit(ltl);
  103. ltls.Add(ltl);
  104. }
  105. //matches.SubmitChanges();
  106. }
  107. using (SqlConnection con = new SqlConnection(Conn.conn))
  108. {
  109. con.Open();
  110. using (SqlTransaction tran = con.BeginTransaction())
  111. {
  112. var newOrders = ltls;
  113. SqlBulkCopy bc = new SqlBulkCopy(con,
  114. //SqlBulkCopyOptions.CheckConstraints |
  115. //SqlBulkCopyOptions.FireTriggers |
  116. SqlBulkCopyOptions.KeepNulls, tran);
  117. bc.BulkCopyTimeout = 36000;
  118. bc.BatchSize = 10000;
  119. bc.DestinationTableName = "Live_Table_lib";
  120. bc.WriteToServer(newOrders.AsDataReader());
  121. tran.Commit();
  122. }
  123. con.Close();
  124. }
  125. //MessageBox.Show("UpdateResultData...OK");
  126. toolStripLabel2.Text = "UpdateResultData...OK"; Thread.Sleep(1);
  127. }
  128. //3.?? live_id to Match_analysis_result
  129. private void ForecastAlgorithm()
  130. {
  131. try
  132. {
  133. //dMatch.dNew = false;
  134. //dMatch.LoadMatchData(true);
  135. ForecastAlgorithm f = new ForecastAlgorithm();
  136. //f.DeleteRedundancy();
  137. int pb = f.idExc.Count();
  138. //MessageBox.Show(pb.ToString());
  139. toolStripLabel2.Text = pb.ToString(); Thread.Sleep(1);
  140. if (pb != 0)
  141. {
  142. toolStripProgressBar1.Maximum = pb;
  143. f.top20Algorithm();
  144. }
  145. }
  146. catch (Exception ex)
  147. {
  148. MessageBox.Show(ex.ToString());
  149. }
  150. //MessageBox.Show("ForecastAlgorithm...OK");
  151. toolStripLabel2.Text = "ForecastAlgorithm...OK"; Thread.Sleep(1);
  152. }
  153. //4.???? Match_analysis_result
  154. private void AuditForecastAlgorithm(int overday)
  155. {
  156. //int overday = -370;
  157. try
  158. {
  159. //dMatch.dNew = false;
  160. //dMatch.LoadMatchData(true);
  161. //MessageBox.Show(overday.ToString());
  162. toolStripLabel2.Text = overday.ToString(); Thread.Sleep(1);
  163. AuditForecastAlgorithm f = new AuditForecastAlgorithm(overday);
  164. int pb = f.idExc.Count();
  165. //MessageBox.Show(pb.ToString());
  166. toolStripLabel2.Text = pb.ToString(); Thread.Sleep(1);
  167. if (pb != 0)
  168. {
  169. toolStripProgressBar1.Maximum = pb;
  170. f.top20Algorithm();
  171. }
  172. }
  173. catch (Exception ex)
  174. {
  175. MessageBox.Show(ex.ToString());
  176. }
  177. //MessageBox.Show("AuditForecastAlgorithm...OK");
  178. toolStripLabel2.Text = "AuditForecastAlgorithm...OK"; Thread.Sleep(1);
  179. }
  180. //5.??
  181. private void BatchExcuteSim(int overday)
  182. {
  183. //???????????? 2011.11.29
  184. this.tabControl1.SelectedTab = this.tabPage3;
  185. Application.DoEvents();
  186. //BatchExcuteSim();
  187. List<string> mtlist = new List<string>();
  188. //???????????????????????
  189. RowNumberTable rnt = new RowNumberTable();
  190. using (DataClassesMatchDataContext matches = new DataClassesMatchDataContext(Conn.conn))
  191. {
  192. mtlist = matches.Live_Table_lib.Where(m => m.Match_time.Value.Date >= DateTime.Now.AddDays(overday).Date)
  193. .Select(e => e.Match_type).Distinct().ToList();
  194. }
  195. toolStripProgressBar1.Maximum = mtlist.Count();
  196. int i = 0;
  197. foreach (string matchtype in mtlist)
  198. {
  199. i++;
  200. ProgressBarDelegate.DoSendPMessage(i);
  201. label9.Text = matchtype;
  202. Application.DoEvents();
  203. if (OutToMatlab(matchtype, 1) == false) continue;
  204. Application.DoEvents();
  205. SimulinkGRNN();
  206. Application.DoEvents();
  207. SimulinkPNN();
  208. //Application.DoEvents();
  209. //GC.Collect(); GC.Collect(); Application.DoEvents();
  210. }
  211. }
  212. //6.??????
  213. //?? Match_analysis_result
  214. private void UpdateAnalysisResult()
  215. {
  216. //int overday = -370;
  217. try
  218. {
  219. UpdateAnalysisResult u = new UpdateAnalysisResult();
  220. int pb = u.ExecUpateCount;
  221. //MessageBox.Show(pb.ToString());
  222. toolStripLabel2.Text = pb.ToString(); Thread.Sleep(1);
  223. if (pb != 0)
  224. {
  225. toolStripProgressBar1.Maximum = pb;
  226. u.ExecUpdate();
  227. }
  228. }
  229. catch (Exception ex)
  230. {
  231. MessageBox.Show(ex.ToString());
  232. }
  233. //MessageBox.Show("UpdateAnalysisResult...OK");
  234. toolStripLabel2.Text = "UpdateAnalysisResult...OK"; Thread.Sleep(1);
  235. }
  236. }
  237. }