/CmsCheckin/ListNames.cs
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
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Net;
- using System.Xml.Linq;
- using System.Configuration;
- using System.IO;
- using System.Collections.Specialized;
-
- namespace CmsCheckin
- {
- public partial class ListNames : UserControl
- {
- UserControl nextcontrol;
- public ListNames(UserControl next)
- {
- InitializeComponent();
- this.nextcontrol = next;
- }
-
- protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
- {
- const int WM_KEYDOWN = 0x100;
- const int WM_SYSKEYDOWN = 0x104;
-
- if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
- {
- switch (keyData)
- {
- case Keys.PageUp:
- if (pgup.Visible)
- ShowResults(name, prev.Value);
- return true;
- case Keys.PageDown:
- if (pgdn.Visible)
- ShowResults(name, next.Value);
- return true;
- case Keys.Escape:
- Program.TimerStop();
- if (Program.HideCursor)
- Cursor.Hide();
- this.GoHome(string.Empty);
- return true;
- case Keys.S | Keys.Alt:
- Program.TimerReset();
- Program.CursorShow();
- foreach (var c in sucontrols)
- {
- c.Enabled = true;
- c.BackColor = Color.Coral;
- }
- return true;
- }
- }
- return base.ProcessCmdKey(ref msg, keyData);
- }
-
- int? next, prev;
- string name;
- List<Control> controls = new List<Control>();
- List<Control> sucontrols = new List<Control>();
-
- public void ShowResults(string match, int page)
- {
- ClearControls();
-
- name = match;
- var x = this.GetDocument("Checkin2/NameSearch/" + name + "?page=" + page);
-
- var points = 14F;
-
- string Verdana = "Verdana";
- Font labfont;
- var g = this.CreateGraphics();
-
- name = x.Root.Attribute("name").Value;
- next = x.Root.Attribute("next").Value.ToInt2();
- prev = x.Root.Attribute("prev").Value.ToInt2();
- pgdn.Visible = next.HasValue;
- pgup.Visible = prev.HasValue;
-
- if (x.Descendants("person").Count() == 0)
- {
- var lab = new Label();
- lab.Font = new Font(Verdana, points, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
- lab.Location = new Point(15, 200);
- lab.AutoSize = true;
- lab.Text = "Not Found, try another name?";
- this.Controls.Add(lab);
- controls.Add(lab);
- GoBackButton.Text = "Try again";
- return;
- }
-
- const int WidName = 890;
- while (true)
- {
- var wid = 0;
- labfont = new Font(Verdana, points, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
- foreach (var e in x.Descendants("person"))
- {
- var s = e.Attribute("display").Value;
- var size = g.MeasureString(s, labfont);
- wid = Math.Max(wid, (int)size.Width);
- }
- if (wid > WidName)
- {
- points -= 1F;
- continue;
- }
- break;
- }
- var row = 0;
- foreach (var e in x.Descendants("person"))
- {
- var ab = new Button();
- ab.BackColor = SystemColors.ControlLight;
- ab.Font = labfont;
- const int Gutter = 10;
- ab.Location = new Point(Gutter, 100 + (row * 50));
- ab.Tag = e.Attribute("fid").Value.ToInt();
- var homephone = e.Attribute("home").Value;
- var cellphone = e.Attribute("cell").Value;
- var ph = homephone.HasValue() ? homephone : cellphone.HasValue() ? cellphone : "";
- if (!ph.HasValue())
- ab.BackColor = Color.LightPink;
-
- ab.Size = new Size(WidName, 45);
- ab.TextAlign = ContentAlignment.MiddleLeft;
- ab.UseVisualStyleBackColor = false;
- ab.Text = e.Attribute("display").Value;
- this.Controls.Add(ab);
- ab.Click += new EventHandler(ab_Click);
- controls.Add(ab);
-
- row++;
- }
- Program.TimerStart(timer1_Tick);
- this.Focus();
- }
-
- void timer1_Tick(object sender, EventArgs e)
- {
- Program.TimerStop();
- Program.ClearFields();
- this.GoHome("");
- }
-
- void ab_Click(object sender, EventArgs e)
- {
- Program.TimerStop();
- var ab = sender as Button;
- this.Swap(nextcontrol);
- if (nextcontrol is ListFamily)
- ((ListFamily)nextcontrol).ShowFamily((int)ab.Tag);
- else if (nextcontrol is ListFamily2)
- ((ListFamily2)nextcontrol).ShowFamily((int)ab.Tag);
- }
-
- private void GoBack_Click(object sender, EventArgs e)
- {
- if (Program.baseform.textbox.Parent is Home)
- {
- Program.home.textBox1.Text = name;
- this.Swap(Program.home.namesearch);
- }
- else if (Program.baseform.textbox.Parent is Home2)
- {
- Program.home2.namesearch.textBox1.Text = name;
- this.Swap(Program.home2.namesearch);
- }
- }
-
- private void AddNewFamily_Click(object sender, EventArgs e)
- {
- Program.FamilyId = 0;
- Program.editing = false;
- if (Program.baseform.textbox.Parent is Home)
- this.Swap(Program.home.first);
- else if (Program.baseform.textbox.Parent is Home2)
- this.Swap(Program.home2.first);
- }
-
- private void ClearControls()
- {
- foreach (var c in controls)
- {
- this.Controls.Remove(c);
- c.Dispose();
- }
- controls.Clear();
- sucontrols.Clear();
- sucontrols.Add(bAddNewFamily);
- bAddNewFamily.BackColor = SystemColors.Control;
- bAddNewFamily.Enabled = false;
- }
- private void pgdn_Click(object sender, EventArgs e)
- {
- ShowResults(name, next.Value);
- }
-
- private void pgup_Click(object sender, EventArgs e)
- {
- ShowResults(name, prev.Value);
- }
-
- private void button2_Click(object sender, EventArgs e)
- {
- Program.TimerReset();
- foreach (var c in sucontrols)
- {
- c.Enabled = true;
- c.BackColor = Color.Coral;
- }
- }
- }
- }