PageRenderTime 49ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/CmsCheckin/ListFamily.cs

https://bitbucket.org/mahalowe/bvcms
C# | 1000 lines | 895 code | 90 blank | 15 comment | 109 complexity | f789c5c28c61289a4837ff01d825a461 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. using System.Xml.Serialization;
  15. using CmsCheckin.Classes;
  16. namespace CmsCheckin
  17. {
  18. public partial class ListFamily : UserControl
  19. {
  20. private const int ExtraPixelsName = 15;
  21. private const string STR_CheckMark = "ΓΌ";
  22. public ListFamily()
  23. {
  24. InitializeComponent();
  25. }
  26. protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
  27. {
  28. const int WM_KEYDOWN = 0x100;
  29. const int WM_SYSKEYDOWN = 0x104;
  30. if ((msg.Msg == WM_KEYDOWN) || (msg.Msg == WM_SYSKEYDOWN))
  31. {
  32. switch (keyData)
  33. {
  34. case Keys.PageUp:
  35. if (pgup.Visible)
  36. ShowPage(page - 1);
  37. return true;
  38. case Keys.PageDown:
  39. if (pgdn.Visible)
  40. ShowPage(page + 1);
  41. return true;
  42. case Keys.Escape:
  43. Program.TimerStop();
  44. this.GoHome(string.Empty);
  45. return true;
  46. case Keys.Return:
  47. Program.TimerStop();
  48. DoPrinting(null, null);
  49. this.GoHome(string.Empty);
  50. return true;
  51. case Keys.S | Keys.Alt:
  52. Program.TimerReset();
  53. Program.CursorShow();
  54. foreach (var c in sucontrols)
  55. {
  56. c.Enabled = true;
  57. c.BackColor = Color.Coral;
  58. }
  59. return true;
  60. }
  61. }
  62. return base.ProcessCmdKey(ref msg, keyData);
  63. }
  64. private bool hasprinter;
  65. DoPrinting doprint = new DoPrinting();
  66. List<AttendLabel> list;
  67. int page = 1;
  68. List<Control> controls = new List<Control>();
  69. List<Control> sucontrols = new List<Control>();
  70. XDocument xdoc;
  71. const string Verdana = "Verdana";
  72. Font pfont = new Font(Verdana, 14f, FontStyle.Regular, GraphicsUnit.Point, ((byte)(0)));
  73. public void ShowFamily(int fid)
  74. {
  75. page = 1;
  76. xdoc = this.GetDocument("Checkin2/Family/" + fid + Program.QueryString);
  77. ShowFamily(xdoc);
  78. }
  79. public void ShowFamily(XDocument x)
  80. {
  81. xdoc = x;
  82. hasprinter = PrintRawHelper.HasPrinter(Program.Printer);
  83. this.Focus();
  84. Program.FamilyId = x.Root.Attribute("familyid").Value.ToInt();
  85. if (!Program.SecurityCode.HasValue())
  86. Program.SecurityCode = x.Root.Attribute("securitycode").Value;
  87. label3.Text = Program.SecurityCode;
  88. Program.MaxLabels = x.Root.Attribute("maxlabels").Value.ToInt();
  89. list = new List<AttendLabel>();
  90. if (x.Descendants("attendee").Count() == 0)
  91. {
  92. ClearControls();
  93. var lab = new Label();
  94. lab.Font = pfont;
  95. lab.Location = new Point(15, 200);
  96. lab.AutoSize = true;
  97. PrintAll.Visible = false;
  98. PrintAll1.Visible = false;
  99. PrintAll2.Visible = false;
  100. pgup.Visible = false;
  101. pgdn.Visible = false;
  102. lab.Text = "Not Found, try another phone number?";
  103. this.Controls.Add(lab);
  104. Return.Text = "Try again";
  105. controls.Add(lab);
  106. return;
  107. }
  108. foreach (var e in x.Descendants("attendee"))
  109. {
  110. var a = new AttendLabel
  111. {
  112. cinfo = new ClassInfo
  113. {
  114. oid = e.Attribute("orgid").Value.ToInt(),
  115. pid = e.Attribute("id").Value.ToInt(),
  116. mv = e.Attribute("mv").Value,
  117. },
  118. name = e.Attribute("name").Value,
  119. first = e.Attribute("first").Value,
  120. last = e.Attribute("last").Value,
  121. dob = e.Attribute("dob").Value,
  122. church = e.Attribute("church").Value,
  123. preferredname = e.Attribute("preferredname").Value,
  124. goesby = e.Attribute("goesby").Value,
  125. email = e.Attribute("email").Value,
  126. addr = e.Attribute("addr").Value,
  127. zip = e.Attribute("zip").Value,
  128. home = e.Attribute("home").Value.FmtFone(),
  129. cell = e.Attribute("cell").Value.FmtFone(),
  130. gender = e.Attribute("gender").Value.ToInt(),
  131. marital = e.Attribute("marital").Value.ToInt(),
  132. emphone = e.Attribute("emphone").Value.FmtFone(),
  133. emfriend = e.Attribute("emfriend").Value,
  134. allergies = e.Attribute("allergies").Value,
  135. grade = e.Attribute("grade").Value,
  136. activeother = e.Attribute("activeother").Value,
  137. parent = e.Attribute("parent").Value,
  138. org = e.Attribute("org").Value,
  139. orgname = e.Attribute("orgname").Value,
  140. custody = bool.Parse(e.Attribute("custody").Value),
  141. transport = bool.Parse(e.Attribute("transport").Value),
  142. location = e.Attribute("loc").Value,
  143. leader = e.Attribute("leader").Value,
  144. NumLabels = int.Parse(e.Attribute("numlabels").Value),
  145. Row = list.Count,
  146. CheckedIn = bool.Parse(e.Attribute("checkedin").Value),
  147. HasPicture = bool.Parse(e.Attribute("haspicture").Value),
  148. RequiresSecurityLabel = bool.Parse(e.Attribute("requiressecuritylabel").Value),
  149. leadtime = double.Parse(e.Attribute("leadtime").Value),
  150. };
  151. DateTime dt;
  152. if (DateTime.TryParse(e.Attribute("hour").Value, out dt))
  153. a.cinfo.hour = dt;
  154. list.Add(a);
  155. }
  156. ShowPage(1);
  157. }
  158. public void ShowPage(int page)
  159. {
  160. ClearControls();
  161. this.page = page;
  162. const int sep = 10;
  163. const int rowheight = 50;
  164. int top = 50;
  165. const int bsize = 45;
  166. const int bwid = 65;
  167. const int mwid = 80;
  168. var points = 14F;
  169. var g = this.CreateGraphics();
  170. Font font;
  171. Font labfont;
  172. string Present = "Attend";
  173. string Labels = "Labels";
  174. Return.Text = "Print Labels, Return";
  175. var cols = new int[6];
  176. const int PageSize = 10;
  177. int srow = (page - 1) * PageSize;
  178. int erow = srow + PageSize;
  179. if (erow > list.Count)
  180. erow = list.Count;
  181. pgdn.Visible = list.Count > erow;
  182. pgup.Visible = srow > 0;
  183. int maxheight;
  184. int twidab, widname, widorg, twidlb;
  185. int totalwid;
  186. while (true)
  187. {
  188. twidab = widname = widorg = twidlb = maxheight = 0;
  189. font = new Font(Verdana, points, FontStyle.Regular,
  190. GraphicsUnit.Point, ((byte)(0)));
  191. labfont = new Font(Verdana, points,
  192. ((FontStyle)((FontStyle.Italic | FontStyle.Underline))),
  193. GraphicsUnit.Point, ((byte)(0)));
  194. maxheight = 0;
  195. foreach (var c in list)
  196. {
  197. var size = g.MeasureString(Present, labfont);
  198. twidab = Math.Max(twidab, (int)Math.Ceiling(size.Width));
  199. twidab = Math.Max(twidab, bwid);
  200. size = g.MeasureString(c.name, font);
  201. widname = Math.Max(widname, (int)Math.Ceiling(size.Width) + ExtraPixelsName);
  202. size = g.MeasureString(Labels, labfont);
  203. twidlb = Math.Max(twidlb, (int)Math.Ceiling(size.Width));
  204. twidlb = Math.Max(twidlb, mwid);
  205. size = g.MeasureString("{0:h:mm tt} {1}".Fmt(c.cinfo.hour, c.org), font);
  206. widorg = Math.Max(widorg, (int)Math.Ceiling(size.Width));
  207. size = g.MeasureString("|", labfont);
  208. maxheight = Math.Max(maxheight, (int)Math.Ceiling(size.Height));
  209. }
  210. totalwid = sep + twidab + sep + widname + sep + widorg
  211. + sep + twidlb + sep;
  212. if (totalwid > 1024)
  213. {
  214. points -= 1F;
  215. continue;
  216. }
  217. break;
  218. }
  219. var labtop = top - rowheight;
  220. var LeftEdge = (1024 - totalwid) / 2;
  221. var head = new Label();
  222. LeftEdge += sep;
  223. head.Location = new Point(LeftEdge, labtop);
  224. head.Size = new Size(twidab + 5, maxheight);
  225. head.Font = labfont;
  226. head.Text = Present;
  227. this.Controls.Add(head);
  228. controls.Add(head);
  229. head = new Label();
  230. LeftEdge += twidab + sep;
  231. head.Location = new Point(LeftEdge, labtop);
  232. head.Size = new Size(widname + 5, maxheight);
  233. head.Font = labfont;
  234. head.Text = "Name";
  235. this.Controls.Add(head);
  236. controls.Add(head);
  237. head = new Label();
  238. LeftEdge += mwid + sep + widname + sep;
  239. head.Location = new Point(LeftEdge, labtop);
  240. head.Size = new Size(widorg + 5, maxheight);
  241. head.Font = labfont;
  242. head.Text = "Meeting";
  243. this.Controls.Add(head);
  244. controls.Add(head);
  245. for (var r = srow; r < erow; r++)
  246. {
  247. var c = list[r];
  248. if (c.cinfo.mv == "V")
  249. c.cinfo.mv = "G";
  250. if (classlist.Count > 0)
  251. {
  252. var q = from cl in classlist
  253. where cl.oid == c.cinfo.oid && cl.pid == c.cinfo.pid
  254. select cl;
  255. if (q.Count() > 0 && c.CheckedIn)
  256. c.WasChecked = true;
  257. }
  258. LeftEdge = (1024 - totalwid) / 2;
  259. top += rowheight;
  260. var ab = new Button();
  261. LeftEdge += sep;
  262. ab.Location = new Point(LeftEdge, top - 5);
  263. ab.Size = new Size(bwid, bsize);
  264. ab.FlatStyle = FlatStyle.Flat;
  265. ab.FlatAppearance.BorderSize = 1;
  266. ab.BackColor = Color.CornflowerBlue;
  267. ab.FlatAppearance.BorderColor = Color.Black;
  268. double howlate = -(Program.EarlyCheckin / 60d);
  269. if (c.cinfo.oid == 0
  270. || c.leadtime > Program.LeadTime
  271. || c.leadtime < howlate)
  272. {
  273. ab.Enabled = false;
  274. ab.BackColor = SystemColors.Control;
  275. ab.FlatAppearance.BorderColor = SystemColors.ButtonShadow;
  276. }
  277. ab.ForeColor = Color.White;
  278. ab.Font = new Font("Wingdings", 24, FontStyle.Bold,
  279. GraphicsUnit.Point, ((byte)(2)));
  280. ab.Name = "attend" + c.Row;
  281. ab.TextAlign = ContentAlignment.TopCenter;
  282. ab.UseVisualStyleBackColor = false;
  283. this.Controls.Add(ab);
  284. ab.KeyDown += new KeyEventHandler(AttendButton_KeyDown);
  285. ab.Click += new EventHandler(Attend_Click);
  286. ab.Text = c.CheckedIn ? STR_CheckMark : String.Empty;
  287. ab.Tag = c.Row;
  288. controls.Add(ab);
  289. var nam = new Button();
  290. LeftEdge += twidab + sep;
  291. nam.UseVisualStyleBackColor = false;
  292. nam.FlatStyle = FlatStyle.Flat;
  293. nam.FlatAppearance.BorderSize = 1;
  294. nam.FlatAppearance.BorderColor = Color.Black;
  295. if (c.HasPicture)
  296. nam.BackColor = Color.FromArgb(0xFF, 0xCC, 0x99);
  297. else
  298. nam.BackColor = Color.White;
  299. nam.Location = new Point(LeftEdge, top - 5);
  300. nam.Size = new Size(widname, bsize);
  301. nam.Font = font;
  302. nam.UseMnemonic = false;
  303. nam.Text = c.name;
  304. nam.Name = "name" + c.Row;
  305. nam.TextAlign = ContentAlignment.MiddleLeft;
  306. if (c.cinfo.oid != 0)
  307. if (c.cinfo.mv == "M")
  308. nam.ForeColor = Color.Blue;
  309. else
  310. nam.ForeColor = Color.DarkGreen;
  311. nam.Click += new EventHandler(ShowPic_Click);
  312. nam.Enabled = false;
  313. nam.Tag = c.Row;
  314. this.Controls.Add(nam);
  315. controls.Add(nam);
  316. sucontrols.Add(nam);
  317. var menu = new Button();
  318. LeftEdge += widname + 5 + sep;
  319. menu.Location = new Point(LeftEdge, top - 5);
  320. menu.Size = new Size(mwid, bsize);
  321. menu.Text = "menu";
  322. menu.BackColor = SystemColors.Control;
  323. menu.Enabled = false;
  324. menu.Font = pfont;
  325. menu.Name = "menu" + c.Row;
  326. menu.Tag = c.Row;
  327. menu.TextAlign = ContentAlignment.TopCenter;
  328. menu.UseVisualStyleBackColor = false;
  329. this.Controls.Add(menu);
  330. menu.Click += new EventHandler(Menu_Click);
  331. controls.Add(menu);
  332. sucontrols.Add(menu);
  333. var org = new Label();
  334. LeftEdge += mwid + 5 + sep;
  335. org.Location = new Point(LeftEdge, top);
  336. org.Size = new Size(widorg + 5, maxheight);
  337. org.Font = font;
  338. org.UseMnemonic = false;
  339. org.Text = "{0:h:mm tt} {1}".Fmt(c.cinfo.hour, c.org);
  340. org.TextAlign = ContentAlignment.MiddleLeft;
  341. org.Name = "org" + c.Row;
  342. if (c.cinfo.oid != 0)
  343. if (c.cinfo.mv == "M")
  344. org.ForeColor = Color.Blue;
  345. else
  346. org.ForeColor = Color.DarkGreen;
  347. this.Controls.Add(org);
  348. controls.Add(org);
  349. }
  350. Program.TimerStart(timer1_Tick);
  351. ComputeLabels();
  352. }
  353. void timer1_Tick(object sender, EventArgs e)
  354. {
  355. Program.TimerStop();
  356. Util.UnLockFamily();
  357. Program.ClearFields();
  358. this.GoHome("");
  359. }
  360. void AttendButton_KeyDown(object sender, KeyEventArgs e)
  361. {
  362. Program.TimerReset();
  363. if (e.KeyValue == 27)
  364. {
  365. Program.TimerStop();
  366. Util.UnLockFamily();
  367. this.GoHome(string.Empty);
  368. }
  369. }
  370. void PrintLabel_Click(object sender, EventArgs e)
  371. {
  372. Program.TimerReset();
  373. var c = list[(int)menu.Tag];
  374. var li = new LabelInfo
  375. {
  376. allergies = c.allergies,
  377. pid = c.cinfo.pid,
  378. mv = c.cinfo.mv,
  379. n = c.NumLabels,
  380. first = c.first,
  381. last = c.last,
  382. location = c.location,
  383. hour = c.cinfo.hour,
  384. org = c.org,
  385. custody = c.custody,
  386. transport = c.transport,
  387. requiressecuritylabel = c.RequiresSecurityLabel,
  388. securitycode = Program.SecurityCode,
  389. };
  390. if (Program.UseNewLabels)
  391. {
  392. IEnumerable<LabelInfo> liList = new[] { li };
  393. PrinterHelper.doPrinting(liList, true);
  394. }
  395. else
  396. {
  397. int iLabelSize = PrinterHelper.getPageHeight(Program.Printer);
  398. using (var ms = new MemoryStream())
  399. {
  400. if ( iLabelSize >= 170 && iLabelSize <= 230 )
  401. ms.LabelKiosk2(li);
  402. else
  403. ms.LabelKiosk(li);
  404. PrintRawHelper.SendDocToPrinter(Program.Printer, ms);
  405. }
  406. }
  407. RemoveMenu();
  408. }
  409. void Attend_Click(object sender, EventArgs e)
  410. {
  411. Attend_Click((Button)sender);
  412. }
  413. public void Attend_Click(Button ab)
  414. {
  415. Program.TimerReset();
  416. var c = list[(int)ab.Tag];
  417. if (c.lastpress.HasValue && DateTime.Now.Subtract(c.lastpress.Value).TotalSeconds < 1)
  418. return;
  419. if (c.cinfo.oid == 0)
  420. return;
  421. Cursor.Current = Cursors.WaitCursor;
  422. Program.CursorShow();
  423. if (ab.Text == String.Empty)
  424. {
  425. ab.Text = STR_CheckMark;
  426. c.CheckedIn = true;
  427. c.WasChecked = true;
  428. }
  429. else
  430. {
  431. ab.Text = String.Empty;
  432. c.CheckedIn = false;
  433. c.WasChecked = false;
  434. }
  435. var info = new Util.ClassCheckedInfo { c = c.cinfo, ischecked = c.CheckedIn };
  436. c.lastpress = DateTime.Now;
  437. ComputeLabels();
  438. var bw = new BackgroundWorker();
  439. bw.DoWork += CheckUnCheckDoWork;
  440. bw.RunWorkerCompleted += CheckUncheckCompleted;
  441. bw.RunWorkerAsync(info);
  442. }
  443. void ShowPic_Click(object sender, EventArgs e)
  444. {
  445. Program.TimerReset();
  446. var eb = sender as Button;
  447. var ab = this.Controls[this.Controls.IndexOfKey("attend" + eb.Tag.ToString())] as Button;
  448. var c = list[(int)ab.Tag];
  449. Program.PeopleId = c.cinfo.pid;
  450. var f = new Picture();
  451. f.ShowDialog();
  452. }
  453. public List<ClassInfo> classlist = new List<ClassInfo>();
  454. private Label mask;
  455. private Menu menu;
  456. void Menu_Click(object sender, EventArgs e)
  457. {
  458. Program.TimerReset();
  459. var MenuButton = sender as Button;
  460. menu = new Menu();
  461. menu.Tag = MenuButton.Tag;
  462. menu.Parent = this;
  463. menu.Location = new Point(MenuButton.Location.X - 100, MenuButton.Location.Y + MenuButton.Height);
  464. mask = new Label();
  465. mask.BackColor = this.BackColor;
  466. mask.Size = this.Size;
  467. //mask.Location = this.Location;
  468. mask.Parent = this;
  469. mask.BringToFront();
  470. var nam = this.Controls[this.Controls.IndexOfKey("name" + menu.Tag.ToString())] as Button;
  471. var org = this.Controls[this.Controls.IndexOfKey("org" + menu.Tag.ToString())] as Label;
  472. nam.BringToFront();
  473. org.BringToFront();
  474. mask.Show();
  475. menu.VisitClass += Visit_Click;
  476. var c = list[(int)menu.Tag];
  477. nam.Enabled = false;
  478. menu.EditRecord += EditRecord_Click;
  479. menu.PrintLabel += PrintLabel_Click;
  480. menu.AddFamily += AddToFamily_Click;
  481. menu.JoinClass += Join_Click;
  482. if (c.cinfo.oid != 0)
  483. {
  484. menu.DropJoin.Visible = true;
  485. if (c.cinfo.mv == "M")
  486. {
  487. menu.DropJoinClass += DropThis_Click;
  488. menu.DropJoin.Text = "Drop This Class";
  489. }
  490. else
  491. {
  492. menu.DropJoinClass += JoinThis_Click;
  493. menu.DropJoin.Text = "Join This Class";
  494. }
  495. }
  496. else
  497. menu.DropJoin.Visible = false;
  498. menu.CancelMenu += new EventHandler(CancelMenu_Click);
  499. menu.Show();
  500. menu.BringToFront();
  501. }
  502. void Join_Click(object sender, EventArgs e)
  503. {
  504. var c = list[(int)menu.Tag];
  505. SaveClasses();
  506. RemoveMenu();
  507. this.Swap(Program.home.classes);
  508. Program.home.classes.JoiningNotAttending = true;
  509. Program.home.classes.ShowResults(c.cinfo.pid);
  510. }
  511. void DropThis_Click(object sender, EventArgs e)
  512. {
  513. var c = list[(int)menu.Tag];
  514. var org = this.Controls[this.Controls.IndexOfKey("org" + menu.Tag.ToString())] as Label;
  515. SaveClasses();
  516. Util.JoinUnJoin(c.cinfo, false);
  517. RemoveMenu();
  518. if (Program.baseform.textbox.Parent is Home)
  519. Program.home.family.ShowFamily(Program.FamilyId);
  520. else if (Program.baseform.textbox.Parent is Home2)
  521. Program.home2.family.ShowFamily(Program.FamilyId);
  522. }
  523. void JoinThis_Click(object sender, EventArgs e)
  524. {
  525. var c = list[(int)menu.Tag];
  526. var org = this.Controls[this.Controls.IndexOfKey("org" + menu.Tag.ToString())] as Label;
  527. SaveClasses();
  528. Util.JoinUnJoin(c.cinfo, true);
  529. RemoveMenu();
  530. if (Program.baseform.textbox.Parent is Home)
  531. Program.home.family.ShowFamily(Program.FamilyId);
  532. else if (Program.baseform.textbox.Parent is Home2)
  533. Program.home2.family.ShowFamily(Program.FamilyId);
  534. }
  535. void CancelMenu_Click(object sender, EventArgs e)
  536. {
  537. RemoveMenu();
  538. }
  539. void Visit_Click(object sender, EventArgs e)
  540. {
  541. var c = list[(int)menu.Tag];
  542. SaveClasses();
  543. RemoveMenu();
  544. this.Swap(Program.home.classes);
  545. Program.home.classes.ShowResults(c.cinfo.pid);
  546. }
  547. private void SaveClasses()
  548. {
  549. classlist = new List<ClassInfo>();
  550. for (var r = 0; r < list.Count; r++)
  551. {
  552. var cc = list[r];
  553. if (cc.WasChecked)
  554. {
  555. cc.cinfo.nlabels = cc.NumLabels;
  556. classlist.Add(cc.cinfo);
  557. }
  558. }
  559. }
  560. private void ComputeLabels()
  561. {
  562. int canprint;
  563. int willprint;
  564. var can = list.Where(c => c.CheckedIn && c.NumLabels > 0);
  565. var will = can.Where(c => c.WasChecked);
  566. canprint = can.Count();
  567. willprint = will.Count();
  568. var show = canprint > willprint;
  569. PrintAll.Visible = show;
  570. PrintAll1.Visible = show;
  571. PrintAll2.Visible = show;
  572. if (PrintAll.Text.HasValue() || willprint > 0)
  573. Return.Text = "Print Labels, Return";
  574. else
  575. Return.Text = "Return";
  576. }
  577. void EditRecord_Click(object sender, EventArgs e)
  578. {
  579. var c = list[(int)menu.Tag];
  580. var home = Program.home;
  581. Program.PeopleId = c.cinfo.pid;
  582. home.SetFields(c.last, c.email, c.addr, c.zip, c.home, c.parent, c.emfriend, c.emphone, c.activeother, c.church);
  583. home.first.textBox1.Text = c.first;
  584. home.goesby.textBox1.Text = c.goesby;
  585. home.dob.textBox1.Text = c.dob;
  586. home.cellphone.textBox1.Text = c.cell.FmtFone();
  587. home.gendermarital.Marital = c.marital;
  588. home.gendermarital.Gender = c.gender;
  589. if (Program.AskChurch)
  590. home.gendermarital.ActiveOther.CheckState =
  591. c.activeother == bool.TrueString ? CheckState.Checked :
  592. c.activeother == bool.FalseString ? CheckState.Unchecked : CheckState.Indeterminate;
  593. if (Program.AskGrade)
  594. home.grade.textBox1.Text = c.grade;
  595. home.allergy.textBox1.Text = c.allergies;
  596. if (Program.AskEmFriend)
  597. {
  598. home.parent.textBox1.Text = c.parent;
  599. home.emfriend.textBox1.Text = c.emfriend;
  600. home.emphone.textBox1.Text = c.emphone.FmtFone();
  601. }
  602. Util.UnLockFamily();
  603. SaveClasses();
  604. Program.editing = true;
  605. RemoveMenu();
  606. this.Swap(home.first);
  607. }
  608. private void RemoveMenu()
  609. {
  610. var nam = this.Controls[this.Controls.IndexOfKey("name" + menu.Tag.ToString())] as Button;
  611. nam.Enabled = true;
  612. this.Controls.Remove(menu);
  613. this.Controls.Remove(mask);
  614. menu.Dispose();
  615. mask.Dispose();
  616. }
  617. PleaseWait PleaseWaitForm = null;
  618. private void DoPrinting(object sender, DoWorkEventArgs e)
  619. {
  620. if (list == null)
  621. return;
  622. var qlist = list.Where(c => c.CheckedIn && c.NumLabels > 0);
  623. if (!PrintAll.Text.HasValue()) qlist = qlist.Where(c => c.WasChecked);
  624. var q = from c in qlist
  625. select new LabelInfo
  626. {
  627. allergies = c.allergies,
  628. pid = c.cinfo.pid,
  629. mv = c.cinfo.mv,
  630. n = c.NumLabels,
  631. first = c.preferredname,
  632. last = c.last,
  633. location = c.location,
  634. hour = c.cinfo.hour,
  635. org = c.orgname,
  636. custody = c.custody,
  637. transport = c.transport,
  638. requiressecuritylabel = c.RequiresSecurityLabel,
  639. securitycode = Program.SecurityCode,
  640. dob = ( c.dob != null && c.dob.Length > 0 ? DateTime.Parse( c.dob ) : DateTime.Now ),
  641. };
  642. Util.UnLockFamily();
  643. if (Program.PrintMode == "Print To Server")
  644. {
  645. PrintServerLabels(q);
  646. return;
  647. }
  648. if (Program.UseNewLabels)
  649. {
  650. PrinterHelper.doPrinting(q);
  651. }
  652. else
  653. {
  654. int iLabelSize = PrinterHelper.getPageHeight(Program.Printer);
  655. using (var ms = new MemoryStream())
  656. {
  657. if (iLabelSize >= 170 && iLabelSize <= 230)
  658. doprint.PrintLabels2(ms, q);
  659. else
  660. doprint.PrintLabels(ms, q);
  661. doprint.FinishUp(ms);
  662. }
  663. /*
  664. using (var ms = new MemoryStream())
  665. {
  666. //if (Program.TwoInchLabel)
  667. //else doprint.PrintLabels(ms, q);
  668. doprint.PrintLabels(ms, q);
  669. doprint.FinishUp(ms);
  670. }
  671. */
  672. }
  673. }
  674. private void PrintingCompleted(object sender, RunWorkerCompletedEventArgs e)
  675. {
  676. PleaseWaitForm.Hide();
  677. PleaseWaitForm.Dispose();
  678. PleaseWaitForm = null;
  679. Program.FamilyId = 0;
  680. classlist = new List<ClassInfo>();
  681. PrintAll.Text = string.Empty;
  682. if (Program.AskLabels)
  683. {
  684. var f = new DidItWork();
  685. var ret = f.ShowDialog();
  686. f.Hide();
  687. f.Dispose();
  688. if (ret == DialogResult.No)
  689. {
  690. Util.ReportPrinterProblem();
  691. var fa = new AdminLogin();
  692. fa.ShowDialog();
  693. }
  694. }
  695. this.GoHome(string.Empty);
  696. }
  697. private void PrintServerLabels(IEnumerable<LabelInfo> q)
  698. {
  699. if (list == null)
  700. return;
  701. Util.UploadPrintJob(q);
  702. }
  703. private void ClearControls()
  704. {
  705. foreach (var c in controls)
  706. {
  707. this.Controls.Remove(c);
  708. c.Dispose();
  709. }
  710. controls.Clear();
  711. doprint.LabelsPrinted = 0;
  712. sucontrols.Clear();
  713. }
  714. private void MagicButton_Click(object sender, EventArgs e)
  715. {
  716. Program.TimerStop();
  717. if (list.Count == 0)
  718. {
  719. if (Program.baseform.textbox.Parent is Home)
  720. this.Swap(Program.home.namesearch);
  721. else if (Program.baseform.textbox.Parent is Home2)
  722. this.Swap(Program.home2.namesearch);
  723. return;
  724. }
  725. foreach (var c in sucontrols)
  726. {
  727. c.Enabled = true;
  728. if (c.BackColor == SystemColors.Control)
  729. c.BackColor = Color.Coral;
  730. }
  731. }
  732. private void pgup_Click(object sender, EventArgs e)
  733. {
  734. ShowPage(page - 1);
  735. }
  736. private void pgdn_Click(object sender, EventArgs e)
  737. {
  738. ShowPage(page + 1);
  739. }
  740. private void AddToFamily_Click(object sender, EventArgs e)
  741. {
  742. var c = list[(int)menu.Tag];
  743. Program.editing = false;
  744. SaveClasses();
  745. Util.UnLockFamily();
  746. RemoveMenu();
  747. Program.home.SetFields(c.last, c.email, c.addr, c.zip, c.home, c.parent, c.emfriend, c.emphone, c.activeother, c.church);
  748. this.Swap(Program.home.first);
  749. }
  750. private void CheckUnCheckDoWork(object sender, DoWorkEventArgs e)
  751. {
  752. var info = e.Argument as Util.ClassCheckedInfo;
  753. Util.AttendUnAttend(info);
  754. }
  755. private void CheckUncheckCompleted(object sender, RunWorkerCompletedEventArgs e)
  756. {
  757. Cursor.Current = Cursors.Default;
  758. Program.CursorHide();
  759. }
  760. private void Return_Click(object sender, EventArgs e)
  761. {
  762. Program.TimerStop();
  763. if (Return.Text.Contains("Try Again"))
  764. {
  765. this.GoHome(string.Empty);
  766. return;
  767. }
  768. PleaseWaitForm = new PleaseWait();
  769. PleaseWaitForm.Show();
  770. var bw = new BackgroundWorker();
  771. bw.DoWork += DoPrinting;
  772. bw.RunWorkerCompleted += PrintingCompleted;
  773. bw.RunWorkerAsync();
  774. }
  775. private void PrintAll_Click(object sender, EventArgs e)
  776. {
  777. PrintAll.Text = PrintAll.Text.HasValue() ? String.Empty : STR_CheckMark;
  778. ComputeLabels();
  779. }
  780. }
  781. public class AttendLabel
  782. {
  783. public DateTime? lastpress { get; set; }
  784. public ClassInfo cinfo { get; set; }
  785. public string name { get; set; }
  786. public string first { get; set; }
  787. public string last { get; set; }
  788. public string dob { get; set; }
  789. public string church { get; set; }
  790. public string preferredname { get; set; }
  791. public string goesby { get; set; }
  792. public string email { get; set; }
  793. public string addr { get; set; }
  794. public string zip { get; set; }
  795. public string home { get; set; }
  796. public string cell { get; set; }
  797. public string emfriend { get; set; }
  798. public string emphone { get; set; }
  799. public string allergies { get; set; }
  800. public string grade { get; set; }
  801. public string activeother { get; set; }
  802. public string parent { get; set; }
  803. public bool custody { get; set; }
  804. public bool transport { get; set; }
  805. public int gender { get; set; }
  806. public int marital { get; set; }
  807. public string orgname { get; set; }
  808. public string leader { get; set; }
  809. public string org { get; set; }
  810. public string location { get; set; }
  811. public int NumLabels { get; set; }
  812. public int Row { get; set; }
  813. public bool CheckedIn { get; set; }
  814. public bool WasChecked { get; set; }
  815. public bool HasPicture { get; set; }
  816. public bool RequiresSecurityLabel { get; set; }
  817. public double leadtime { get; set; }
  818. }
  819. // all of these come from the attribtues on the attendee element
  820. // attributes have the same name unless noted otherwise
  821. [Serializable]
  822. public class LabelInfo
  823. {
  824. public int n { get; set; } // numlabels attribute
  825. public DateTime dob { get; set; } // dob
  826. public string location { get; set; } // loc attribute
  827. public string allergies { get; set; }
  828. public string org { get; set; } // orgname attribute
  829. public DateTime? hour { get; set; }
  830. public int age
  831. {
  832. get
  833. {
  834. DateTime now = DateTime.Now;
  835. int age = now.Year - dob.Year;
  836. if (now < dob.AddYears(age)) age--;
  837. return age;
  838. }
  839. }
  840. public string date
  841. {
  842. get
  843. {
  844. if (hour != null) return hour.Value.ToString("d");
  845. else return "";
  846. }
  847. }
  848. public string time
  849. {
  850. get
  851. {
  852. if (hour != null) return hour.Value.ToString("t");
  853. else return "";
  854. }
  855. }
  856. public string extra
  857. {
  858. get
  859. {
  860. if (custody || transport || allergies.Length > 0) return ("Extra - " + (allergies.Length > 0 ? "A|" : "") + (custody ? "C|" : "") + (transport ? "T" : "")).TrimEnd( new char[] { '|' } );
  861. else return "Extra";
  862. }
  863. }
  864. public string guest
  865. {
  866. get
  867. {
  868. if (custody || transport || allergies.Length > 0) return ("Guest - " + (allergies.Length > 0 ? "A|" : "") + (custody ? "C|" : "") + (transport ? "T" : "")).TrimEnd(new char[] { '|' });
  869. else return "Guest";
  870. }
  871. }
  872. public string guestoption
  873. {
  874. get
  875. {
  876. if (mv == "M") return "";
  877. else return "Guest";
  878. }
  879. }
  880. public string info
  881. {
  882. get
  883. {
  884. return ((allergies.Length > 0 ? "A|" : "") + (custody ? "C|" : "") + (transport ? "T" : "")).TrimEnd(new char[] { '|' });
  885. }
  886. }
  887. public int pid { get; set; } // id attribute
  888. public string mv { get; set; }
  889. public string first { get; set; }
  890. public string last { get; set; }
  891. public bool transport { get; set; }
  892. public bool custody { get; set; }
  893. public bool requiressecuritylabel { get; set; }
  894. public string securitycode { get; set; }
  895. }
  896. [Serializable]
  897. public class PrintJob
  898. {
  899. // securitycode comes from the attribute on the root element (Attendees)
  900. public string securitycode { get; set; }
  901. // the following is a list of each person/class that was checked present
  902. public List<LabelInfo> list { get; set; }
  903. }
  904. [Serializable]
  905. public class PrintJobs
  906. {
  907. public List<PrintJob> jobs { get; set; }
  908. }
  909. }