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
| private void ImportCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
var matrixOccupanciesViewSource = ((CollectionViewSource)(this.FindResource("matrixOccupanciesViewSource")));
OpenFileDialog openDialog = new OpenFileDialog();
// Show open file dialog box
Nullable<bool> result = openDialog.ShowDialog();
if (result == true)
{
string path = System.IO.Path.GetFullPath(openDialog.FileName);
string query = "SELECT * FROM [A$]";
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;" +
@"Data Source=" + path +";" +
"Extended Properties=Excel 8.0;";
OleDbDataAdapter adapter = new OleDbDataAdapter(query, conn);
DataTable data = new DataTable();
adapter.Fill(data);
matrixOccupanciesViewSource.Source = data;
}
}
#endregion
private void matrixDataGrid_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
var selectedDate = (Matrix)e.AddedItems[0];
var occupenciesCollection = selectedDate.Occupancies;
var occupanciesViewSource = ((CollectionViewSource)(this.FindResource("matrixOccupanciesViewSource")));
occupanciesViewSource.Source = occupenciesCollection;
} |
Partager