PageRenderTime 84ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/SqlServer_20110520/Soccer Score Forecast/Soccer Score Forecast/UI_TreeChart/ProgressBarDelegate.cs

http://htmlconvertsql.googlecode.com/
C# | 148 lines | 125 code | 4 blank | 19 comment | 17 complexity | 00cb69606fd12f19cf74333115c76ea6 MD5 | raw file
  1. using System.Windows.Forms;
  2. using System.Data.SqlServerCe;
  3. using System.IO;
  4. using SoccerScore.Compact.Linq;
  5. using System.Data.Linq;
  6. using System.Reflection;
  7. using System;
  8. using System.Linq;
  9. using System.Data;
  10. using System.Collections.Generic;
  11. namespace Soccer_Score_Forecast
  12. {
  13. public static class ProgressBarDelegate
  14. {
  15. //???
  16. public delegate void SendPMessage(int i);
  17. public static event SendPMessage sendPEvent;
  18. public static void DoSendPMessage(int i)
  19. {
  20. sendPEvent(i);
  21. }
  22. public static DataTable ToDataTable<T>(this IEnumerable<T> varlist)
  23. {
  24. DataTable dtReturn = new DataTable();
  25. PropertyInfo[] oProps = null;
  26. if (varlist == null) return dtReturn;
  27. foreach (T rec in varlist)
  28. {
  29. if (oProps == null)
  30. {
  31. oProps = ((Type)rec.GetType()).GetProperties();
  32. foreach (PropertyInfo pi in oProps)
  33. {
  34. Type colType = pi.PropertyType;
  35. if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition() == typeof(Nullable<>))) colType = colType.GetGenericArguments()[0];
  36. dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
  37. }
  38. }
  39. DataRow dr = dtReturn.NewRow();
  40. foreach (PropertyInfo pi in oProps) dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue(rec, null);
  41. dtReturn.Rows.Add(dr);
  42. }
  43. return dtReturn;
  44. }
  45. }
  46. // public static class Conn
  47. // {
  48. // private static string connStr = "Data Source=SoccerScoreSqlite.db;FailIfMissing=false;";
  49. // public static System.Data.SQLite.SQLiteConnection cnn = new SQLiteConnection(connStr);
  50. // }
  51. public static class Conn
  52. {
  53. private static string dbpath = Application.StartupPath + @"\SyncSoccerScore.sdf";
  54. private static string updatepath = Application.StartupPath + @"\UpdateList.xml";
  55. public static SqlCeConnection conn = new SqlCeConnection(@"Data Source='" + dbpath + "'");
  56. public static void CompressCompact()
  57. {
  58. SqlCeEngine engine = new SqlCeEngine(@"Data Source='" + dbpath + "'");
  59. //Specifynulldestinationconnectionstringforin-placecompaction
  60. //
  61. engine.Shrink();
  62. //Specifyconnectionstringfornewdatabaseoptions.Thefollowing
  63. //tokensarevalid:
  64. //-Password
  65. //-LCID
  66. //-Encrypt
  67. //
  68. //AllotherSqlCeConnection.ConnectionStringtokensareignored
  69. //
  70. //engine.Compact("DataSource=;Password=a@3!7f$dQ;");
  71. }
  72. public static bool CreateTable(Type linqTableClass)
  73. {
  74. bool suc = true;
  75. string createtable = linqTableClass.Name;
  76. //MessageBox.Show(createtable);
  77. //???????????????
  78. using (DataClassesMatchDataContext match = new DataClassesMatchDataContext(Conn.conn))
  79. {
  80. try
  81. {
  82. var metaTable = match.Mapping.GetTable(linqTableClass);
  83. var typeName = "System.Data.Linq.SqlClient.SqlBuilder";
  84. var type = typeof(DataContext).Assembly.GetType(typeName);
  85. var bf = BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.InvokeMethod;
  86. var sql = type.InvokeMember("GetCreateTableCommand", bf, null, null, new[] { metaTable });
  87. #region //???sql2008??
  88. var sqlAsString = sql.ToString().Replace("(MAX)", "");
  89. string querytable = @"SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='"
  90. + createtable + @"' AND TABLE_TYPE='TABLE'";
  91. int exists = match.ExecuteQuery<int>(querytable).First();
  92. if (exists > 0)
  93. match.ExecuteCommand("drop table " + createtable);
  94. #endregion
  95. match.ExecuteCommand(sqlAsString);
  96. }
  97. catch (Exception ex)
  98. {
  99. suc = false;
  100. MessageBox.Show(ex.ToString());
  101. }
  102. }
  103. return suc;
  104. }
  105. public static void ImportSdfFile()
  106. {
  107. OpenFileDialog dlgOpenfile = new OpenFileDialog();
  108. string strFileFullName = null;
  109. dlgOpenfile.Filter = "Sql Compact File|*.sdf";
  110. dlgOpenfile.Title = "Open";
  111. dlgOpenfile.ShowDialog();
  112. dlgOpenfile.RestoreDirectory = true;
  113. if (!string.IsNullOrEmpty(dlgOpenfile.FileName))
  114. {
  115. strFileFullName = dlgOpenfile.FileName;
  116. if (strFileFullName.IndexOf("SyncSoccerScore.sdf") != -1)
  117. {
  118. if (File.Exists(dbpath)) File.Delete(dbpath);
  119. File.Copy(strFileFullName, dbpath);
  120. MessageBox.Show("sdf????");
  121. }
  122. }
  123. }
  124. public static void ImportUpdateFile()
  125. {
  126. OpenFileDialog dlgOpenfile = new OpenFileDialog();
  127. string strFileFullName = null;
  128. dlgOpenfile.Filter = "Update Xml File|*.xml";
  129. dlgOpenfile.Title = "Open";
  130. dlgOpenfile.ShowDialog();
  131. dlgOpenfile.RestoreDirectory = true;
  132. if (!string.IsNullOrEmpty(dlgOpenfile.FileName))
  133. {
  134. strFileFullName = dlgOpenfile.FileName;
  135. if (strFileFullName.IndexOf("UpdateList.xml") != -1)
  136. {
  137. if (File.Exists(updatepath)) File.Delete(updatepath);
  138. File.Copy(strFileFullName, updatepath);
  139. MessageBox.Show("xml????");
  140. }
  141. }
  142. }
  143. }
  144. }