PageRenderTime 44ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/CmsCheckin/ListNames.cs

https://bitbucket.org/mahalowe/bvcms
C# | 222 lines | 202 code | 20 blank | 0 comment | 22 complexity | 9a1a2dcac9bdbc172433e1ed9486360f MD5 | raw file
Possible License(s): CC-BY-SA-3.0, Apache-2.0, BSD-3-Clause, LGPL-2.1, MPL-2.0-no-copyleft-exception, AGPL-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using System.Net;
  10. using System.Xml.Linq;
  11. using System.Configuration;
  12. using System.IO;
  13. using System.Collections.Specialized;
  14. namespace CmsCheckin
  15. {
  16. public partial class ListNames : UserControl
  17. {
  18. UserControl nextcontrol;
  19. public ListNames(UserControl next)
  20. {
  21. InitializeComponent();
  22. this.nextcontrol = next;
  23. }
  24. protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  25. {
  26. const int WM_KEYDOWN = 0x100;
  27. const int WM_SYSKEYDOWN = 0x104;
  28. if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
  29. {
  30. switch (keyData)
  31. {
  32. case Keys.PageUp:
  33. if (pgup.Visible)
  34. ShowResults(name, prev.Value);
  35. return true;
  36. case Keys.PageDown:
  37. if (pgdn.Visible)
  38. ShowResults(name, next.Value);
  39. return true;
  40. case Keys.Escape:
  41. Program.TimerStop();
  42. if (Program.HideCursor)
  43. Cursor.Hide();
  44. this.GoHome(string.Empty);
  45. return true;
  46. case Keys.S | Keys.Alt:
  47. Program.TimerReset();
  48. Program.CursorShow();
  49. foreach (var c in sucontrols)
  50. {
  51. c.Enabled = true;
  52. c.BackColor = Color.Coral;
  53. }
  54. return true;
  55. }
  56. }
  57. return base.ProcessCmdKey(ref msg, keyData);
  58. }
  59. int? next, prev;
  60. string name;
  61. List<Control> controls = new List<Control>();
  62. List<Control> sucontrols = new List<Control>();
  63. public void ShowResults(string match, int page)
  64. {
  65. ClearControls();
  66. name = match;
  67. var x = this.GetDocument("Checkin2/NameSearch/" + name + "?page=" + page);
  68. var points = 14F;
  69. string Verdana = "Verdana";
  70. Font labfont;
  71. var g = this.CreateGraphics();
  72. name = x.Root.Attribute("name").Value;
  73. next = x.Root.Attribute("next").Value.ToInt2();
  74. prev = x.Root.Attribute("prev").Value.ToInt2();
  75. pgdn.Visible = next.HasValue;
  76. pgup.Visible = prev.HasValue;
  77. if (x.Descendants("person").Count() == 0)
  78. {
  79. var lab = new Label();
  80. lab.Font = new Font(Verdana, points, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
  81. lab.Location = new Point(15, 200);
  82. lab.AutoSize = true;
  83. lab.Text = "Not Found, try another name?";
  84. this.Controls.Add(lab);
  85. controls.Add(lab);
  86. GoBackButton.Text = "Try again";
  87. return;
  88. }
  89. const int WidName = 890;
  90. while (true)
  91. {
  92. var wid = 0;
  93. labfont = new Font(Verdana, points, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
  94. foreach (var e in x.Descendants("person"))
  95. {
  96. var s = e.Attribute("display").Value;
  97. var size = g.MeasureString(s, labfont);
  98. wid = Math.Max(wid, (int)size.Width);
  99. }
  100. if (wid > WidName)
  101. {
  102. points -= 1F;
  103. continue;
  104. }
  105. break;
  106. }
  107. var row = 0;
  108. foreach (var e in x.Descendants("person"))
  109. {
  110. var ab = new Button();
  111. ab.BackColor = SystemColors.ControlLight;
  112. ab.Font = labfont;
  113. const int Gutter = 10;
  114. ab.Location = new Point(Gutter, 100 + (row * 50));
  115. ab.Tag = e.Attribute("fid").Value.ToInt();
  116. var homephone = e.Attribute("home").Value;
  117. var cellphone = e.Attribute("cell").Value;
  118. var ph = homephone.HasValue() ? homephone : cellphone.HasValue() ? cellphone : "";
  119. if (!ph.HasValue())
  120. ab.BackColor = Color.LightPink;
  121. ab.Size = new Size(WidName, 45);
  122. ab.TextAlign = ContentAlignment.MiddleLeft;
  123. ab.UseVisualStyleBackColor = false;
  124. ab.Text = e.Attribute("display").Value;
  125. this.Controls.Add(ab);
  126. ab.Click += new EventHandler(ab_Click);
  127. controls.Add(ab);
  128. row++;
  129. }
  130. Program.TimerStart(timer1_Tick);
  131. this.Focus();
  132. }
  133. void timer1_Tick(object sender, EventArgs e)
  134. {
  135. Program.TimerStop();
  136. Program.ClearFields();
  137. this.GoHome("");
  138. }
  139. void ab_Click(object sender, EventArgs e)
  140. {
  141. Program.TimerStop();
  142. var ab = sender as Button;
  143. this.Swap(nextcontrol);
  144. if (nextcontrol is ListFamily)
  145. ((ListFamily)nextcontrol).ShowFamily((int)ab.Tag);
  146. else if (nextcontrol is ListFamily2)
  147. ((ListFamily2)nextcontrol).ShowFamily((int)ab.Tag);
  148. }
  149. private void GoBack_Click(object sender, EventArgs e)
  150. {
  151. if (Program.baseform.textbox.Parent is Home)
  152. {
  153. Program.home.textBox1.Text = name;
  154. this.Swap(Program.home.namesearch);
  155. }
  156. else if (Program.baseform.textbox.Parent is Home2)
  157. {
  158. Program.home2.namesearch.textBox1.Text = name;
  159. this.Swap(Program.home2.namesearch);
  160. }
  161. }
  162. private void AddNewFamily_Click(object sender, EventArgs e)
  163. {
  164. Program.FamilyId = 0;
  165. Program.editing = false;
  166. if (Program.baseform.textbox.Parent is Home)
  167. this.Swap(Program.home.first);
  168. else if (Program.baseform.textbox.Parent is Home2)
  169. this.Swap(Program.home2.first);
  170. }
  171. private void ClearControls()
  172. {
  173. foreach (var c in controls)
  174. {
  175. this.Controls.Remove(c);
  176. c.Dispose();
  177. }
  178. controls.Clear();
  179. sucontrols.Clear();
  180. sucontrols.Add(bAddNewFamily);
  181. bAddNewFamily.BackColor = SystemColors.Control;
  182. bAddNewFamily.Enabled = false;
  183. }
  184. private void pgdn_Click(object sender, EventArgs e)
  185. {
  186. ShowResults(name, next.Value);
  187. }
  188. private void pgup_Click(object sender, EventArgs e)
  189. {
  190. ShowResults(name, prev.Value);
  191. }
  192. private void button2_Click(object sender, EventArgs e)
  193. {
  194. Program.TimerReset();
  195. foreach (var c in sucontrols)
  196. {
  197. c.Enabled = true;
  198. c.BackColor = Color.Coral;
  199. }
  200. }
  201. }
  202. }