private void buttonOpenDBC_Click(object sender, RoutedEventArgs e) { //init all controls to empty treeView.ItemsSource = null; OpenFileDialog openDBC = new OpenFileDialog(); openDBC.FileName = "DBC File"; openDBC.DefaultExt = ".dbc"; openDBC.Filter = "CAN db files (*.dbc)|*.dbc"; if (openDBC.ShowDialog() == System.Windows.Forms.DialogResult.OK) { ObservableCollection <DbcMessage> AllMsg; dbcParser = new DBCReader(openDBC.FileName); AllMsg = dbcParser.ExtGetAllMessages(); ConfManager.ProjectDBC = openDBC.FileName; ConfManager.AllMessages = AllMsg; ConfManager.SelectedNode = "All"; //binding to controls treeView.ItemsSource = null; treeView.Items.Clear(); treeView.ItemsSource = ConfManager.Messages; } }
private void btnSaveDBC_Click(object sender, RoutedEventArgs e) { if (dbcParser == null) { System.Windows.Forms.MessageBox.Show("Please load DBC before save!\n", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SaveFileDialog saveDBC = new SaveFileDialog(); saveDBC.FileName = "DBC File"; saveDBC.DefaultExt = ".dbc"; saveDBC.Filter = "CAN db files (.dbc)|*.dbc"; if (saveDBC.ShowDialog() == System.Windows.Forms.DialogResult.OK) { try { DBCWriter dbcWriter = new DBCWriter(saveDBC.FileName); dbcWriter.writeDBC(dbcParser.DbVersion, dbcParser.DbCustomer, dbcParser.DbName, String.IsNullOrEmpty(dbcParser.DbBaudrate) ? "500000" : dbcParser.DbBaudrate, dbcParser.ExtGetAllMessages()); dbcWriter.close(); System.Windows.Forms.MessageBox.Show("DBC File Saved successfully!", "OK", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception exp) { System.Windows.Forms.MessageBox.Show("Cannot save dbc file\n" + exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }