forked from silahian/VisualHFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathucPositions.xaml.cs
138 lines (127 loc) · 5.33 KB
/
ucPositions.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Microsoft.Win32;
using VisualHFT.Model;
namespace VisualHFT.View
{
/// <summary>
/// Interaction logic for ucPositions.xaml
/// </summary>
public partial class ucPositions : UserControl
{
public ucPositions()
{
InitializeComponent();
}
private void butLoadFile_Click(object sender, RoutedEventArgs e)
{
try
{
// Create OpenFileDialog
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".pos";
dlg.Filter = "POS Positions (*.pos)|*.pos|All (*.*)|*.*";
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
/*if (result == true)
{
// Open document
string filename = dlg.FileName;
if (filename != "")
{
using (Stream stream = File.Open(filename, FileMode.Open))
{
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
List<Position> tmpList = new List<Position>();
while (stream.Position != stream.Length)
{
tmpList.Add((Position)bformatter.Deserialize(stream));
}
//Helpers.HelperCommon.AllPositions = new ObservableCollection<Position>(tmpList);
}
}
}*/
MessageBox.Show("File has been succesfuly loaded.", "", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void butSaveFile_Click(object sender, RoutedEventArgs e)
{
try
{
// Create OpenFileDialog
Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".pos";
dlg.Filter = "POS Positions (*.pos)|*.pos|All (*.*)|*.*";
// Display OpenFileDialog by calling ShowDialog method
Nullable<bool> result = dlg.ShowDialog();
if (result == true)
{
// Open document
string filename = dlg.FileName;
/*if (filename != "")
{
ObservableCollection<OrderVM> _positions = ((VisualHFT.ViewModel.vmPosition)this.DataContext).AllOrders;
if (_positions != null && _positions.Count > 0)
{
//serialize
string dir = Environment.CurrentDirectory;
using (Stream stream = File.Open(filename, FileMode.Create))
{
var bformatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bformatter.Serialize(stream, _positions.ToList());
}
}
}*/
}
MessageBox.Show("File has been succesfuly saved.", "", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void butExportCsv_Click(object sender, RoutedEventArgs e)
{
string extension = "csv";
SaveFileDialog dialog = new SaveFileDialog()
{
DefaultExt = extension,
Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "CSV File"),
FilterIndex = 1
};
if (dialog.ShowDialog() == true)
{
try
{
using (Stream stream = dialog.OpenFile())
{
/*grdExecutions.Export(stream,
new GridViewExportOptions()
{
Format = ExportFormat.Csv,
ShowColumnHeaders = true,
ShowColumnFooters = true,
ShowGroupFooters = false,
});*/
}
MessageBox.Show("File has been succesfuly saved.", "", MessageBoxButton.OK, MessageBoxImage.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
}
}
}