PageRenderTime 55ms CodeModel.GetById 34ms RepoModel.GetById 1ms app.codeStats 0ms

/HSKCards/HSKCards/Words.cs

#
C# | 157 lines | 133 code | 22 blank | 2 comment | 22 complexity | f249252dc95f35fad1ac2f109d78e837 MD5 | raw file
  1. using System;
  2. using System.Drawing;
  3. using System.Data;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Data.SqlServerCe;
  7. namespace HSKCards
  8. {
  9. public partial class Words : Form
  10. {
  11. public SqlCeCommand comm;
  12. public SqlCeConnection conn;
  13. public SqlCeDataReader result;
  14. string traditional;
  15. string simplified;
  16. string pinyin;
  17. string english;
  18. string pos;
  19. int level;
  20. bool studylist;
  21. bool known;
  22. bool amend;
  23. short viewcount;
  24. bool trad;
  25. public string RemoveDuplicateCharacter(string temp)
  26. {
  27. StringBuilder a = new StringBuilder(temp);
  28. for (int i = 0; i < a.Length; i++)
  29. {
  30. for (int j = i + 1; j < a.Length; j++)
  31. {
  32. if (a[i] == a[j])
  33. a = a.Replace(a[i], (char)46, j, a.Length - j);
  34. }
  35. }
  36. for (int i = 0; i < a.Length; i++)
  37. {
  38. int x = Convert.ToInt32(a[i]);
  39. if (x < 10000 || x > 41000)
  40. {
  41. try
  42. {
  43. a = a.Remove(i, 1);
  44. }
  45. catch
  46. {
  47. }
  48. i--;
  49. }
  50. }
  51. return a.ToString();
  52. }
  53. public Words(int ID, SqlCeConnection connection, bool t)
  54. {
  55. trad = t;
  56. InitializeComponent();
  57. conn = connection;
  58. button1.Font = new Font("PMingLiUCustom", 36, FontStyle.Regular);
  59. button2.Font = new Font("PMingLiUCustom", 36, FontStyle.Regular);
  60. button3.Font = new Font("PMingLiUCustom", 36, FontStyle.Regular);
  61. button4.Font = new Font("PMingLiUCustom", 36, FontStyle.Regular);
  62. // get entry from Database
  63. comm = new System.Data.SqlServerCe.SqlCeCommand();
  64. comm.Connection = conn;
  65. comm.CommandText = "Select * from entries where ID = '" + ID.ToString() + "'";
  66. result = comm.ExecuteReader();
  67. result.Read();
  68. //ID = result.GetInt32(0);
  69. traditional = result.GetString(1);
  70. simplified = result.GetString(2);
  71. pinyin = result.GetString(3);
  72. english = result.GetString(4);
  73. pos = result.GetString(5);
  74. level = result.GetInt32(6);
  75. studylist = result.GetBoolean(7);
  76. known = result.GetBoolean(8);
  77. amend = result.GetBoolean(9);
  78. viewcount = result.GetInt16(10);
  79. int i = 1;
  80. string temp;
  81. if (trad) temp = RemoveDuplicateCharacter(traditional);
  82. else temp = RemoveDuplicateCharacter(simplified);
  83. foreach (char c in temp)
  84. {
  85. if (i == 1)
  86. {
  87. button1.Text = c.ToString();
  88. button1.Visible = true;
  89. i++;
  90. continue;
  91. }
  92. else if (i == 2)
  93. {
  94. button2.Text = c.ToString();
  95. button2.Visible = true;
  96. i++;
  97. continue;
  98. }
  99. else if (i == 3)
  100. {
  101. button3.Text = c.ToString();
  102. button3.Visible = true;
  103. i++;
  104. continue;
  105. }
  106. else if (i == 4)
  107. {
  108. button4.Text = c.ToString();
  109. button4.Visible = true;
  110. i++;
  111. continue;
  112. }
  113. else
  114. {
  115. MessageBox.Show("Word Overflow");
  116. continue;
  117. }
  118. }
  119. result.Close();
  120. comm.Dispose();
  121. if (temp.Length == 1)
  122. {
  123. button1_Click(button1, new EventArgs());
  124. this.Hide();
  125. }
  126. }
  127. private void button1_Click(object sender, EventArgs e)
  128. {
  129. Related related = new Related(((Button)sender).Text[0], conn,trad );
  130. related.ShowDialog();
  131. related.Close();
  132. return;
  133. }
  134. }
  135. }