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