Pastebin: OmegaChart MY検索ワード SearchBrandDialog.cs 追加する部分には//☆MY検索ワード

Formato
Plain text
Post date
2018-11-10 18:30
Publication Period
Unlimited
  1. /*
  2. * Copyright (c) Daisuke OKAJIMA All rights reserved.
  3. *
  4. * $Id$
  5. */
  6. using System;
  7. using System.Drawing;
  8. using System.Collections;
  9. using System.ComponentModel;
  10. using System.Windows.Forms;
  11. using System.Globalization;
  12. using Zanetti.Data;
  13. using Zanetti.Commands;
  14. namespace Zanetti.Forms
  15. {
  16. /// <summary>
  17. /// SearchBrandDialog の概要の説明です。
  18. /// </summary>
  19. internal class SearchBrandDialog : System.Windows.Forms.Form
  20. {
  21. private static ArrayList _sortedBrands;
  22. private System.Windows.Forms.TextBox _textBox;
  23. private System.Windows.Forms.ListBox _listBox;
  24. private System.Windows.Forms.Button _okButton;
  25. private System.Windows.Forms.Button _cancelButton;
  26. /// <summary>
  27. /// 必要なデザイナ変数です。
  28. /// </summary>
  29. private System.ComponentModel.Container components = null;
  30. public SearchBrandDialog()
  31. {
  32. //
  33. // Windows フォーム デザイナ サポートに必要です。
  34. //
  35. InitializeComponent();
  36. //
  37. // TODO: InitializeComponent 呼び出しの後に、コンストラクタ コードを追加してください。
  38. //
  39. }
  40. protected override void OnLoad(EventArgs e)
  41. {
  42. base.OnLoad(e);
  43. _textBox.Focus();
  44. if (_sortedBrands == null) FillBrands();
  45. foreach (AbstractBrand br in _sortedBrands)
  46. AddBrand(br);
  47. }
  48. /// <summary>
  49. /// 使用されているリソースに後処理を実行します。
  50. /// </summary>
  51. protected override void Dispose(bool disposing)
  52. {
  53. if (disposing)
  54. {
  55. if (components != null)
  56. {
  57. components.Dispose();
  58. }
  59. }
  60. base.Dispose(disposing);
  61. }
  62. #region Windows フォーム デザイナで生成されたコード
  63. /// <summary>
  64. /// デザイナ サポートに必要なメソッドです。このメソッドの内容を
  65. /// コード エディタで変更しないでください。
  66. /// </summary>
  67. private void InitializeComponent()
  68. {
  69. this._textBox = new System.Windows.Forms.TextBox();
  70. this._listBox = new System.Windows.Forms.ListBox();
  71. this._okButton = new System.Windows.Forms.Button();
  72. this._cancelButton = new System.Windows.Forms.Button();
  73. this.SuspendLayout();
  74. //
  75. // _textBox
  76. //
  77. this._textBox.Location = new System.Drawing.Point(8, 8);
  78. this._textBox.Name = "_textBox";
  79. this._textBox.Size = new System.Drawing.Size(208, 19);
  80. this._textBox.TabIndex = 0;
  81. this._textBox.Text = "";
  82. this._textBox.TextChanged += new System.EventHandler(this.OnTextChanged);
  83. //
  84. // _listBox
  85. //
  86. this._listBox.ItemHeight = 12;
  87. this._listBox.Location = new System.Drawing.Point(8, 32);
  88. this._listBox.Name = "_listBox";
  89. this._listBox.Size = new System.Drawing.Size(208, 184);
  90. this._listBox.TabIndex = 1;
  91. this._listBox.DoubleClick += new System.EventHandler(this._listBox_DoubleClick);
  92. //
  93. // _okButton
  94. //
  95. this._okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  96. this._okButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
  97. this._okButton.Location = new System.Drawing.Point(64, 224);
  98. this._okButton.Name = "_okButton";
  99. this._okButton.TabIndex = 2;
  100. this._okButton.Text = "OK";
  101. this._okButton.Click += new System.EventHandler(this.OnOK);
  102. //
  103. // _cancelButton
  104. //
  105. this._cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  106. this._cancelButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
  107. this._cancelButton.Location = new System.Drawing.Point(144, 224);
  108. this._cancelButton.Name = "_cancelButton";
  109. this._cancelButton.TabIndex = 3;
  110. this._cancelButton.Text = "キャンセル";
  111. //
  112. // SearchBrandDialog
  113. //
  114. this.AcceptButton = this._okButton;
  115. this.AutoScaleBaseSize = new System.Drawing.Size(5, 12);
  116. this.CancelButton = this._cancelButton;
  117. this.ClientSize = new System.Drawing.Size(226, 256);
  118. this.Controls.Add(this._cancelButton);
  119. this.Controls.Add(this._okButton);
  120. this.Controls.Add(this._listBox);
  121. this.Controls.Add(this._textBox);
  122. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  123. this.MaximizeBox = false;
  124. this.MinimizeBox = false;
  125. this.Name = "SearchBrandDialog";
  126. this.ShowInTaskbar = false;
  127. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  128. this.Text = "名前から検索";
  129. this.ResumeLayout(false);
  130. }
  131. #endregion
  132. private static void FillBrands()
  133. {
  134. _sortedBrands = new ArrayList();
  135. //新方式ではコード順でまるでOKだった
  136. IDictionaryEnumerator ie = Env.BrandCollection.GetEnumerator();
  137. while (ie.MoveNext())
  138. {
  139. AbstractBrand br = ie.Value as AbstractBrand;
  140. if (br.Market != MarketType.B) _sortedBrands.Add(br);
  141. }
  142. _sortedBrands.Reverse();
  143. //_sortedBrands.Sort(new BrandComparer());
  144. }
  145. private class BrandComparer : IComparer
  146. {
  147. public int Compare(object x, object y)
  148. {
  149. return ((AbstractBrand)x).Name.CompareTo(((AbstractBrand)y).Name);
  150. }
  151. }
  152. private void OnTextChanged(object sender, EventArgs args)
  153. {
  154. string i = _textBox.Text;
  155. if (i.Length > 0)
  156. {
  157. _listBox.Items.Clear();
  158. Refill(i);
  159. }
  160. /*
  161. int i = FindNearest(_textBox.Text);
  162. if(i!=-1)
  163. _listBox.SelectedIndex = i;
  164. */
  165. }
  166. private void OnOK(object sender, EventArgs args)
  167. {
  168. ShowBrand();
  169. }
  170. private void ShowBrand()
  171. {
  172. if (_listBox.SelectedIndex != -1)
  173. {
  174. string sel = (string)_listBox.Items[_listBox.SelectedIndex];
  175. int sp = sel.IndexOf(' ');
  176. AbstractBrand br = Env.BrandCollection.FindBrand(Int32.Parse(sel.Substring(0, sp)));
  177. CommandExec.ShowBrand(br);
  178. }
  179. }
  180. private void Refill(string name)
  181. {
  182. CompareInfo ci = CompareInfo.GetCompareInfo("ja-JP");
  183. foreach (AbstractBrand br in _sortedBrands)
  184. {
  185. int c = ci.IndexOf(br.Name, name, CompareOptions.IgnoreCase | CompareOptions.IgnoreKanaType | CompareOptions.IgnoreNonSpace | CompareOptions.IgnoreWidth);
  186. if (c != -1) AddBrand(br);
  187. }
  188. //☆MY検索ワード ここから
  189. foreach (var e in Env.BrandCollection.HSearchWord)
  190. {
  191. var sw = (SearchWord)e;
  192. int c = ci.IndexOf(sw.name, name, CompareOptions.IgnoreWidth);
  193. BasicBrand br = (BasicBrand)Env.BrandCollection.FindBrand(sw.code);
  194. if (c != -1) AddBrand(br);
  195. }
  196. //ここまで
  197. }
  198. private void AddBrand(AbstractBrand br)
  199. {
  200. _listBox.Items.Add(String.Format("{0} {1}", br.CodeAsString, br.Name));
  201. }
  202. private static int FindNearest(string text)
  203. {
  204. if (text.Length == 0) return 0;
  205. else return FindNearest(text, 0, _sortedBrands.Count);
  206. }
  207. private void _listBox_DoubleClick(object sender, System.EventArgs e)
  208. {
  209. ShowBrand();
  210. this.Close();
  211. }
  212. private static int FindNearest(string text, int begin, int end)
  213. {
  214. if (end - begin <= 1)
  215. {
  216. if (end < _sortedBrands.Count) return end;
  217. else return _sortedBrands.Count - 1;
  218. }
  219. int m = (begin + end) / 2;
  220. string t = ((AbstractBrand)_sortedBrands[m]).Name;
  221. // 検索範囲を広げても現実的な銘柄名では二分探索に失敗しないという仮定あり
  222. int c = text.CompareTo(t);
  223. if (c < 0)
  224. return FindNearest(text, begin, m);
  225. else if (c > 0)
  226. return FindNearest(text, m, end);
  227. else
  228. return m;
  229. }
  230. }
  231. }
Download Printable view

URL of this paste

Embed with JavaScript

Embed with iframe

Raw text