/
MainWindow.xaml.cs
71 lines (64 loc) · 2.43 KB
/
MainWindow.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using DevExpress.Xpf.Scheduling.iCalendar;
using Microsoft.Win32;
using System.IO;
using System.Windows;
namespace WpfApplication1 {
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
}
#region #Import_Button
private void Import_Button_Click(object sender, RoutedEventArgs e) {
OpenFileDialog dialog = new OpenFileDialog();
dialog.Filter = "iCalendar files (*.ics)|*.ics";
dialog.FilterIndex = 1;
if (dialog.ShowDialog() != true)
return;
using (Stream stream = dialog.OpenFile()) {
ImportAppointments(stream);
}
}
#endregion #Import_Button
#region #Import_Drop
private void schedulerControl1_Drop(object sender, DragEventArgs e) {
string[] fileNames = e.Data.GetData(DataFormats.FileDrop) as string[];
if (fileNames == null || fileNames.Length == 0)
return;
foreach (string fileName in fileNames) {
if (File.Exists(fileName)) {
using (Stream stream = File.Open(fileName, FileMode.Open)) {
ImportAppointments(stream);
}
}
}
}
#endregion #Import_Drop
#region #Import
private void ImportAppointments(Stream stream) {
if (stream == null)
return;
ICalendarImporter importer = new ICalendarImporter(schedulerControl1);
importer.Import(stream);
}
#endregion #Import
#region #Export
private void Export_Button_Click(object sender, RoutedEventArgs e) {
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "iCalendar files (*.ics)|*.ics";
dialog.FilterIndex = 1;
if (dialog.ShowDialog() == true) {
using (Stream stream = dialog.OpenFile()) {
ExportAppointments(stream);
}
}
}
void ExportAppointments(Stream stream) {
if (stream == null)
return;
ICalendarExporter exporter = new ICalendarExporter(schedulerControl1);
exporter.ProductIdentifier = "-//Developer Express Inc.//DXScheduler iCalendarExchange Example//EN";
exporter.Export(stream);
}
#endregion #Export
}
}