Winify – Blame information for rev 15

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 using System;
4 office 2 using System.Linq;
1 office 3 using System.Windows.Forms;
15 office 4 using Announcements;
6 office 5 using Servers;
1 office 6 using Winify.Properties;
7 using Winify.Utilities;
8  
9 namespace Winify
10 {
11 public partial class SettingsForm : Form
12 {
4 office 13 #region Private Delegates, Events, Enums, Properties, Indexers and Fields
14  
15 office 15 private readonly Announcements.Announcements _notifications;
16  
8 office 17 private readonly global::Servers.Servers _servers;
4 office 18  
19 #endregion
20  
1 office 21 #region Constructors, Destructors and Finalizers
22  
4 office 23 private SettingsForm()
1 office 24 {
25 InitializeComponent();
26 }
27  
15 office 28 public SettingsForm(global::Servers.Servers servers, Announcements.Announcements notifications) : this()
4 office 29 {
30 _servers = servers;
7 office 31  
32 listBox1.DataSource = _servers.Server;
33 listBox1.DisplayMember = "Name";
34 listBox1.DataBindings.Add(new Binding("Text", _servers.Server, "Name", true,
35 DataSourceUpdateMode.OnPropertyChanged));
15 office 36  
37 _notifications = notifications;
38 listBox2.DataSource = _notifications.Announcement;
39 listBox2.DisplayMember = "Id";
40 listBox2.DataBindings.Add(new Binding("Text", _notifications.Announcement, "Id", true,
41 DataSourceUpdateMode.OnPropertyChanged));
4 office 42 }
43  
1 office 44 #endregion
45  
46 #region Event Handlers
47  
48 private void CheckBox1_CheckedChanged(object sender, EventArgs e)
49 {
50 Settings.Default.LaunchOnBoot = ((CheckBox) sender).Checked;
51  
52 Miscellaneous.LaunchOnBootSet(Settings.Default.LaunchOnBoot);
53 }
54  
4 office 55 private void Button1_Click(object sender, EventArgs e)
56 {
57 var name = serverNameTextBox.Text;
12 office 58 var url = serverUrlTextBox.Text;
4 office 59 var username = serverUsernameTextBox.Text;
60 var password = serverPasswordTextBox.Text;
61  
62 if (string.IsNullOrEmpty(name) ||
12 office 63 string.IsNullOrEmpty(url) ||
4 office 64 string.IsNullOrEmpty(username) ||
65 string.IsNullOrEmpty(password))
66 {
67 return;
68 }
69  
12 office 70 var server = new Server(name, url, username, password);
4 office 71  
14 office 72 var update = _servers.Server.FirstOrDefault(select => select.Name == server.Name);
73 switch (update)
4 office 74 {
14 office 75 default:
76 _servers.Server.Remove(update);
77 update.Url = server.Url;
78 update.Username = server.Username;
79 update.Password = server.Password;
80 _servers.Server.Add(update);
81 break;
82 case null:
83 _servers.Server.Add(server);
84 break;
4 office 85 }
86 }
87  
88 private void Button2_Click(object sender, EventArgs e)
89 {
90 listBox1.InvokeIfRequired(listBox =>
91 {
92 var item = listBox.SelectedItem;
93  
94 _servers.Server.Remove((Server) item);
95 });
96 }
97  
98 private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
99 {
100 var listBox = (ListBox) sender;
101  
102 if (listBox.SelectedIndex == -1)
103 {
104 serverNameTextBox.Text = string.Empty;
12 office 105 serverUrlTextBox.Text = string.Empty;
4 office 106 serverUsernameTextBox.Text = string.Empty;
107 serverPasswordTextBox.Text = string.Empty;
108  
109 return;
110 }
111  
112 var server = (Server) listBox.SelectedItem;
113  
114 serverNameTextBox.Text = server.Name;
12 office 115 serverUrlTextBox.Text = server.Url;
4 office 116 serverUsernameTextBox.Text = server.Username;
117 serverPasswordTextBox.Text = server.Password;
118 }
119  
15 office 120 private void Button3_Click(object sender, EventArgs e)
121 {
122 listBox2.InvokeIfRequired(listbox =>
123 {
124 var item = listbox.SelectedItem;
125  
126 _notifications.Announcement.Remove((Announcement) item);
127 });
128 }
129  
130 private void Button4_Click(object sender, EventArgs e)
131 {
132 var appId = appIdTextBox.Text;
133 var lingerTime = lingerTimeTextBox.Text;
134 var speak = speakTextBox.Text;
135  
136 if (string.IsNullOrEmpty(appId) ||
137 !int.TryParse(appId, out var numAppId) ||
138 string.IsNullOrEmpty(lingerTime) ||
139 !int.TryParse(lingerTime, out var numLingerTime) ||
140 string.IsNullOrEmpty(speak))
141 {
142 return;
143 }
144  
145 var notification = new Announcement(numAppId, numLingerTime, speak);
146  
147 var update = _notifications.Announcement.FirstOrDefault(select => select.Id == notification.Id);
148 switch (update)
149 {
150 default:
151 _notifications.Announcement.Remove(update);
152 update.AppId = numAppId;
153 update.LingerTime = numLingerTime;
154 update.Speak = speak;
155 _notifications.Announcement.Add(update);
156 break;
157 case null:
158 _notifications.Announcement.Add(notification);
159 break;
160 }
161 }
162  
163 private void ListBox2_SelectedIndexChanged(object sender, EventArgs e)
164 {
165 var listBox = (ListBox) sender;
166  
167 if (listBox.SelectedIndex == -1)
168 {
169 appIdTextBox.Text = string.Empty;
170 lingerTimeTextBox.Text = string.Empty;
171 speakTextBox.Text = string.Empty;
172  
173 return;
174 }
175  
176 var notification = (Announcement) listBox.SelectedItem;
177  
178 appIdTextBox.Text = notification.AppId.ToString();
179 lingerTimeTextBox.Text = notification.LingerTime.ToString();
180 speakTextBox.Text = notification.Speak;
181 }
182  
1 office 183 #endregion
184 }
185 }