PageRenderTime 85ms CodeModel.GetById 62ms app.highlight 18ms RepoModel.GetById 2ms app.codeStats 0ms

/CmsCheckin/StartUp.cs

https://bitbucket.org/mahalowe/bvcms
C# | 152 lines | 144 code | 8 blank | 0 comment | 12 complexity | 0bddaf85af0c1222070e1f186be3450a MD5 | raw file
  1using System;
  2using System.Collections.Generic;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Drawing;
  6using System.Linq;
  7using System.Text;
  8using System.Windows.Forms;
  9using System.Net;
 10using System.Xml.Linq;
 11using System.Drawing.Printing;
 12using System.Xml.Serialization;
 13using System.IO;
 14
 15namespace CmsCheckin
 16{
 17    public partial class StartUp : Form
 18    {
 19        public XDocument campuses { get; set; }
 20        public int CampusId
 21        {
 22            get
 23            {
 24                var c = cbCampusId.SelectedItem as Campus;
 25                if (c != null)
 26                    return c.Id;
 27                return 0;
 28            }
 29        }
 30        public string AdminPassword
 31        {
 32            get
 33            {
 34                var c = cbCampusId.SelectedItem as Campus;
 35                if (c != null)
 36                    return c.password;
 37                return "kio.";
 38            }
 39        }
 40        public int DayOfWeek
 41        {
 42            get
 43            {
 44                var d = cbDayOfWeek.SelectedItem as DayOfWeek;
 45                return d.Day;
 46            }
 47        }
 48        public StartUp()
 49        {
 50            InitializeComponent();
 51            cbDayOfWeek.Items.Add(new DayOfWeek { Day = 0, Text = "Sunday" });
 52            cbDayOfWeek.Items.Add(new DayOfWeek { Day = 1, Text = "Monday" });
 53            cbDayOfWeek.Items.Add(new DayOfWeek { Day = 2, Text = "Tuesday" });
 54            cbDayOfWeek.Items.Add(new DayOfWeek { Day = 3, Text = "Wednesday" });
 55            cbDayOfWeek.Items.Add(new DayOfWeek { Day = 4, Text = "Thursday" });
 56            cbDayOfWeek.Items.Add(new DayOfWeek { Day = 5, Text = "Friday" });
 57            cbDayOfWeek.Items.Add(new DayOfWeek { Day = 6, Text = "Saturday" });
 58            cbDayOfWeek.SelectedIndex = (int)DateTime.Now.DayOfWeek;
 59
 60        }
 61
 62        private void button1_Click(object sender, EventArgs e)
 63        {
 64            if (cbCampusId.Items.Count > 0)
 65                Settings1.Default.Campus = ((Campus)(cbCampusId.SelectedItem)).Name;
 66            Settings1.Default.AskChurch = AskChurch.Checked;
 67            Settings1.Default.AskChurchName = AskChurchName.Checked;
 68            Settings1.Default.AskEmFriend = AskEmFriend.Checked;
 69            Settings1.Default.AskGrade = AskGrade.Checked;
 70            Settings1.Default.KioskName = KioskName.Text;
 71            Settings1.Default.LateMinutes = LateMinutes.Text.ToInt();
 72            Settings1.Default.LeadHours = LeadHours.Text.ToInt();
 73            Settings1.Default.LateMinutes = LateMinutes.Text.ToInt();
 74            Settings1.Default.DisableJoin = DisableJoin.Checked;
 75            Settings1.Default.ExtraBlankLabel = ExtraBlankLabel.Checked;
 76            Settings1.Default.OldLabels = OldLabels.Checked;
 77            Settings1.Default.Save();
 78
 79            if (OldLabels.Checked) Program.UseNewLabels = false;
 80            else Program.UseNewLabels = true;
 81
 82            this.Hide();
 83        }
 84
 85        private void StartUp_Load(object sender, EventArgs e)
 86        {
 87#if DEBUG
 88            cbDayOfWeek.SelectedIndex = 0;
 89            HideCursor.Checked = false;
 90#endif
 91
 92            foreach (var i in campuses.Descendants("campus"))
 93                cbCampusId.Items.Add(new Campus
 94                {
 95                    Id = int.Parse(i.Attribute("id").Value),
 96                    Name = i.Attribute("name").Value,
 97                    password = i.Attribute("password").Value
 98                });
 99            if (cbCampusId.Items.Count > 0)
100                cbCampusId.SelectedIndex = 0;
101            var ii = cbCampusId.FindStringExact(Settings1.Default.Campus);
102            if (ii >= 0)
103                cbCampusId.SelectedIndex = ii;
104            ii = LeadHours.FindStringExact(Settings1.Default.LeadHours.ToString());
105            if (ii >= 0)
106                LeadHours.SelectedIndex = ii;
107            ii = LateMinutes.FindStringExact(Settings1.Default.LateMinutes.ToString());
108            if (ii >= 0)
109                LateMinutes.SelectedIndex = ii;
110            AskEmFriend.Checked = Settings1.Default.AskEmFriend;
111            AskGrade.Checked = Settings1.Default.AskGrade;
112            AskChurch.Checked = Settings1.Default.AskChurch;
113            AskChurchName.Checked = Settings1.Default.AskChurchName;
114            KioskName.Text = Settings1.Default.KioskName;
115            DisableJoin.Checked = Settings1.Default.DisableJoin;
116            ExtraBlankLabel.Checked = Settings1.Default.ExtraBlankLabel;
117            OldLabels.Checked = Settings1.Default.OldLabels;
118        }
119
120        private void OldLabels_CheckedChanged(object sender, EventArgs e)
121        {
122            if (OldLabels.Checked)
123            {
124                ExtraBlankLabel.Checked = false;
125                ExtraBlankLabel.Enabled = false;
126            }
127            else
128            {
129                ExtraBlankLabel.Enabled = true;
130            }
131        }
132    }
133    class DayOfWeek
134    {
135        public string Text { get; set; }
136        public int Day { get; set; }
137        public override string ToString()
138        {
139            return Text;
140        }
141    }
142    class Campus
143    {
144        public string Name { get; set; }
145        public int Id { get; set; }
146        public string password { get; set; }
147        public override string ToString()
148        {
149            return Name;
150        }
151    }
152}