/trunk/Winify/SettingsForm.cs |
@@ -1,6 +1,7 @@ |
using System; |
using System.Linq; |
using System.Windows.Forms; |
using Announcements; |
using Servers; |
using Winify.Properties; |
using Winify.Utilities; |
@@ -11,6 +12,8 @@ |
{ |
#region Private Delegates, Events, Enums, Properties, Indexers and Fields |
|
private readonly Announcements.Announcements _notifications; |
|
private readonly global::Servers.Servers _servers; |
|
#endregion |
@@ -22,7 +25,7 @@ |
InitializeComponent(); |
} |
|
public SettingsForm(global::Servers.Servers servers) : this() |
public SettingsForm(global::Servers.Servers servers, Announcements.Announcements notifications) : this() |
{ |
_servers = servers; |
|
@@ -30,6 +33,12 @@ |
listBox1.DisplayMember = "Name"; |
listBox1.DataBindings.Add(new Binding("Text", _servers.Server, "Name", true, |
DataSourceUpdateMode.OnPropertyChanged)); |
|
_notifications = notifications; |
listBox2.DataSource = _notifications.Announcement; |
listBox2.DisplayMember = "Id"; |
listBox2.DataBindings.Add(new Binding("Text", _notifications.Announcement, "Id", true, |
DataSourceUpdateMode.OnPropertyChanged)); |
} |
|
#endregion |
@@ -108,6 +117,69 @@ |
serverPasswordTextBox.Text = server.Password; |
} |
|
private void Button3_Click(object sender, EventArgs e) |
{ |
listBox2.InvokeIfRequired(listbox => |
{ |
var item = listbox.SelectedItem; |
|
_notifications.Announcement.Remove((Announcement) item); |
}); |
} |
|
private void Button4_Click(object sender, EventArgs e) |
{ |
var appId = appIdTextBox.Text; |
var lingerTime = lingerTimeTextBox.Text; |
var speak = speakTextBox.Text; |
|
if (string.IsNullOrEmpty(appId) || |
!int.TryParse(appId, out var numAppId) || |
string.IsNullOrEmpty(lingerTime) || |
!int.TryParse(lingerTime, out var numLingerTime) || |
string.IsNullOrEmpty(speak)) |
{ |
return; |
} |
|
var notification = new Announcement(numAppId, numLingerTime, speak); |
|
var update = _notifications.Announcement.FirstOrDefault(select => select.Id == notification.Id); |
switch (update) |
{ |
default: |
_notifications.Announcement.Remove(update); |
update.AppId = numAppId; |
update.LingerTime = numLingerTime; |
update.Speak = speak; |
_notifications.Announcement.Add(update); |
break; |
case null: |
_notifications.Announcement.Add(notification); |
break; |
} |
} |
|
private void ListBox2_SelectedIndexChanged(object sender, EventArgs e) |
{ |
var listBox = (ListBox) sender; |
|
if (listBox.SelectedIndex == -1) |
{ |
appIdTextBox.Text = string.Empty; |
lingerTimeTextBox.Text = string.Empty; |
speakTextBox.Text = string.Empty; |
|
return; |
} |
|
var notification = (Announcement) listBox.SelectedItem; |
|
appIdTextBox.Text = notification.AppId.ToString(); |
lingerTimeTextBox.Text = notification.LingerTime.ToString(); |
speakTextBox.Text = notification.Speak; |
} |
|
#endregion |
} |
} |