PageRenderTime 2492ms CodeModel.GetById 23ms RepoModel.GetById 5ms app.codeStats 0ms

/src/M2008/csharp/UMAListView/MainForm.cs

http://libwp7n2012.googlecode.com/
C# | 387 lines | 360 code | 27 blank | 0 comment | 5 complexity | 1d2a06a431c889848938d3f86eeb1848 MD5 | raw file
Possible License(s): LGPL-3.0
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. using System.Collections;
  5. using System.Linq;
  6. namespace UMAListView
  7. {
  8. public partial class MainForm : Form
  9. {
  10. private ListViewItemComparer listView1_Sorter;
  11. private enum HorseType {
  12. CHILD,
  13. RACE,
  14. DAM,
  15. SIRE,
  16. UNKNOWN,
  17. }
  18. public MainForm()
  19. {
  20. this.InitializeComponent();
  21. this.ControlsSetup();
  22. }
  23. private void ControlsSetup()
  24. {
  25. this.listView1_Setup();
  26. foreach( var _column in this.listView1.Columns )
  27. {
  28. var column = (_column as ColumnHeader);
  29. var text = column.Text;
  30. var button = new ToolStripMenuItem() {
  31. Text = text,
  32. Checked = true,
  33. Tag = column.Name,
  34. };
  35. button.Click += ( obj, e )=> {
  36. var b = ( obj as ToolStripMenuItem );
  37. var c = this.listView1.Columns[ (String)b.Tag ];
  38. if( b.Checked ) {
  39. c.Width = 0;
  40. b.Checked = false;
  41. } else {
  42. c.Width = (int)c.Tag;
  43. b.Checked = true;
  44. }
  45. };
  46. contextMenuStrip1.Items.Add( button );
  47. column.Tag = column.Width;
  48. }
  49. this.radioButton1.Tag = HorseType.CHILD;
  50. this.radioButton2.Tag = HorseType.RACE;
  51. this.radioButton3.Tag = HorseType.DAM;
  52. this.radioButton4.Tag = HorseType.SIRE;
  53. this.checkBox1.Checked = true;
  54. this.checkBox2.Checked = true;
  55. this.checkBox3.Checked = true;
  56. this.checkBox4.Checked = true;
  57. this.checkBox5.Checked = true;
  58. this.checkBox6.Checked = true;
  59. this.checkBox7.Checked = true;
  60. this.checkBox8.Checked = true;
  61. this.checkBox9.Checked = true;
  62. this.checkBox10.Checked = true;
  63. this.radioButton2.Checked = true;
  64. this.toolStripStatusLabel1.Text = "";
  65. this.toolStripStatusLabel2.Text = "";
  66. this.toolStripStatusLabel3.Text = "";
  67. this.timer1.Tick += ( obj, e )=> {
  68. Invoke( (MethodInvoker)delegate {
  69. this.toolStripStatusLabel1.Text =
  70. String.Format( "{0:f2}(MB)", GC.GetTotalMemory( false ) / 1024.0 / 1024.0 );
  71. });
  72. };
  73. this.timer1.Interval = 1000;
  74. this.timer1.Start();
  75. }
  76. private void listView1_Setup()
  77. {
  78. this.listView1.Columns.Add( new ColumnHeader() {
  79. Text = "??",
  80. Name = "name",
  81. TextAlign = HorizontalAlignment.Left,
  82. Width = 200,
  83. Tag = ListViewItemComparer.ComparerMode.STRING,
  84. });
  85. this.listView1.Columns.Add( new ColumnHeader() {
  86. Text = "?",
  87. Name = "age",
  88. TextAlign = HorizontalAlignment.Right,
  89. Width = 30,
  90. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  91. });
  92. this.listView1.Columns.Add( new ColumnHeader() {
  93. Text = "?",
  94. Name = "gender",
  95. TextAlign = HorizontalAlignment.Right,
  96. Width = 30,
  97. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  98. });
  99. this.listView1.Columns.Add( new ColumnHeader() {
  100. Text = "SP",
  101. Name = "speed",
  102. TextAlign = HorizontalAlignment.Right,
  103. Width = 60,
  104. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  105. });
  106. this.listView1.Columns.Add( new ColumnHeader() {
  107. Text = "ST",
  108. Name = "stamina",
  109. TextAlign = HorizontalAlignment.Right,
  110. Width = 35,
  111. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  112. });
  113. this.listView1.Columns.Add( new ColumnHeader() {
  114. Text = "?",
  115. Name = "power",
  116. TextAlign = HorizontalAlignment.Right,
  117. Width = 45,
  118. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  119. });
  120. this.listView1.Columns.Add( new ColumnHeader() {
  121. Text = "?",
  122. Name = "syunpatsu",
  123. TextAlign = HorizontalAlignment.Right,
  124. Width = 45,
  125. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  126. });
  127. this.listView1.Columns.Add( new ColumnHeader() {
  128. Text = "?",
  129. Name = "konzyou",
  130. TextAlign = HorizontalAlignment.Right,
  131. Width = 45,
  132. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  133. });
  134. this.listView1.Columns.Add( new ColumnHeader() {
  135. Text = "?",
  136. Name = "zyuunan",
  137. TextAlign = HorizontalAlignment.Right,
  138. Width = 45,
  139. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  140. });
  141. this.listView1.Columns.Add( new ColumnHeader() {
  142. Text = "?",
  143. Name = "seishin",
  144. TextAlign = HorizontalAlignment.Right,
  145. Width = 45,
  146. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  147. });
  148. this.listView1.Columns.Add( new ColumnHeader() {
  149. Text = "?",
  150. Name = "kashikosa",
  151. TextAlign = HorizontalAlignment.Right,
  152. Width = 45,
  153. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  154. });
  155. this.listView1.Columns.Add( new ColumnHeader() {
  156. Text = "?",
  157. Name = "health",
  158. TextAlign = HorizontalAlignment.Right,
  159. Width = 45,
  160. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  161. });
  162. this.listView1.Columns.Add( new ColumnHeader() {
  163. Text = "?",
  164. Name = "subpara",
  165. TextAlign = HorizontalAlignment.Right,
  166. Width = 40,
  167. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  168. });
  169. this.listView1.Columns.Add( new ColumnHeader() {
  170. Text = "?",
  171. Name = "babatekisei",
  172. TextAlign = HorizontalAlignment.Left,
  173. Width = 30,
  174. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  175. });
  176. this.listView1.Columns.Add( new ColumnHeader() {
  177. Text = "??",
  178. Name = "seichougata",
  179. TextAlign = HorizontalAlignment.Left,
  180. Width = 40,
  181. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  182. });
  183. this.listView1.Columns.Add( new ColumnHeader() {
  184. Text = "??",
  185. Name = "seichouryoku",
  186. TextAlign = HorizontalAlignment.Left,
  187. Width = 40,
  188. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  189. });
  190. this.listView1.Columns.Add( new ColumnHeader() {
  191. Text = "??",
  192. Name = "seichou",
  193. TextAlign = HorizontalAlignment.Right,
  194. Width = 40,
  195. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  196. });
  197. this.listView1.Columns.Add( new ColumnHeader() {
  198. Text = "??",
  199. Name = "seigen",
  200. TextAlign = HorizontalAlignment.Right,
  201. Width = 40,
  202. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  203. });
  204. this.listView1.Columns.Add( new ColumnHeader() {
  205. Text = "??",
  206. Name = "zyumyou",
  207. TextAlign = HorizontalAlignment.Right,
  208. Width = 40,
  209. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  210. });
  211. this.listView1.Columns.Add( new ColumnHeader() {
  212. Text = "??",
  213. Name = "kodashi",
  214. TextAlign = HorizontalAlignment.Right,
  215. Width = 40,
  216. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  217. });
  218. this.listView1.Columns.Add( new ColumnHeader() {
  219. Text = "?",
  220. Name = "kisyou",
  221. TextAlign = HorizontalAlignment.Left,
  222. Width = 30,
  223. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  224. });
  225. this.listView1.Columns.Add( new ColumnHeader() {
  226. Text = "??",
  227. Name = "keiro",
  228. TextAlign = HorizontalAlignment.Left,
  229. Width = 60,
  230. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  231. });
  232. this.listView1.Columns.Add( new ColumnHeader() {
  233. Text = "?",
  234. Name = "komawari_X",
  235. TextAlign = HorizontalAlignment.Left,
  236. Width = 30,
  237. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  238. });
  239. this.listView1.Columns.Add( new ColumnHeader() {
  240. Text = "?",
  241. Name = "hidarimawari_X",
  242. TextAlign = HorizontalAlignment.Left,
  243. Width = 30,
  244. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  245. });
  246. this.listView1.Columns.Add( new ColumnHeader() {
  247. Text = "?",
  248. Name = "migimawari_X",
  249. TextAlign = HorizontalAlignment.Left,
  250. Width = 30,
  251. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  252. });
  253. this.listView1.Columns.Add( new ColumnHeader() {
  254. Text = "?",
  255. Name = "migimawari_X",
  256. TextAlign = HorizontalAlignment.Left,
  257. Width = 30,
  258. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  259. });
  260. this.listView1.Columns.Add( new ColumnHeader() {
  261. Text = "?",
  262. Name = "migimawari_X",
  263. TextAlign = HorizontalAlignment.Left,
  264. Width = 30,
  265. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  266. });
  267. this.listView1.Columns.Add( new ColumnHeader() {
  268. Text = "?",
  269. Name = "migimawari_X",
  270. TextAlign = HorizontalAlignment.Left,
  271. Width = 30,
  272. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  273. });
  274. this.listView1.Columns.Add( new ColumnHeader() {
  275. Text = "??",
  276. Name = "father",
  277. TextAlign = HorizontalAlignment.Left,
  278. Width = 200,
  279. Tag = ListViewItemComparer.ComparerMode.STRING,
  280. });
  281. this.listView1.Columns.Add( new ColumnHeader() {
  282. Text = "??",
  283. Name = "family_line",
  284. TextAlign = HorizontalAlignment.Left,
  285. Width = 200,
  286. Tag = ListViewItemComparer.ComparerMode.STRING,
  287. });
  288. this.listView1.Columns.Add( new ColumnHeader() {
  289. Text = "??",
  290. Name = "mother",
  291. TextAlign = HorizontalAlignment.Left,
  292. Width = 200,
  293. Tag = ListViewItemComparer.ComparerMode.STRING,
  294. });
  295. this.listView1.Columns.Add( new ColumnHeader() {
  296. Text = "?",
  297. Name = "sizitsu_num",
  298. TextAlign = HorizontalAlignment.Right,
  299. Width = 30,
  300. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  301. });
  302. this.listView1.Columns.Add( new ColumnHeader() {
  303. Text = "????",
  304. Name = "abl_num",
  305. TextAlign = HorizontalAlignment.Right,
  306. Width = 80,
  307. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  308. });
  309. this.listView1.Columns.Add( new ColumnHeader() {
  310. Text = "???",
  311. Name = "id",
  312. TextAlign = HorizontalAlignment.Right,
  313. Width = 80,
  314. Tag = ListViewItemComparer.ComparerMode.TAG_NUMERIC,
  315. });
  316. var list = new ListViewItemComparer.ComparerMode[ this.listView1.Columns.Count ];
  317. for( var i=0; i<list.Length; ++i ) {
  318. list[i] = (ListViewItemComparer.ComparerMode)this.listView1.Columns[i].Tag;
  319. }
  320. this.listView1_Sorter = new ListViewItemComparer() {
  321. ColumnModes = list,
  322. };
  323. this.listView1.ListViewItemSorter = this.listView1_Sorter;
  324. }
  325. private void button1_Click(object sender, EventArgs e)
  326. {
  327. var sw = new System.Diagnostics.Stopwatch();
  328. sw.Start();
  329. #if DEBUG
  330. this.CreateHorseList();
  331. #else
  332. try {
  333. this.CreateHorseList();
  334. } catch( Exception ex ) {
  335. MessageBox.Show( "?????????? - " + ex.Message );
  336. }
  337. #endif
  338. sw.Stop();
  339. this.toolStripStatusLabel2.Text = String.Format( "{0}(ms)", sw.ElapsedMilliseconds );
  340. this.toolStripStatusLabel3.Text = String.Format( "{0}(line)", this.listView1.Items.Count );
  341. GC.Collect();
  342. }
  343. private void listView1_OddColor()
  344. {
  345. for( var i=0; i<this.listView1.Items.Count; ++i ) {
  346. this.listView1.Items[i].BackColor = ( i % 2 == 1 )
  347. ? System.Drawing.Color.FromArgb( 0xef, 0xef, 0xff )
  348. : System.Drawing.Color.White;
  349. }
  350. }
  351. private void listView1_ColumnClick( object sender, ColumnClickEventArgs e )
  352. {
  353. this.listView1_ExecSort( e.Column );
  354. this.listView1_OddColor();
  355. }
  356. private void listView1_MouseClick(object sender, MouseEventArgs e)
  357. {
  358. }
  359. }
  360. }