/// <summary> /// 輸出按鈕 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonImport_Click(object sender, EventArgs e) { try { OpenFileDialog fileDialog = new OpenFileDialog(); //File type fileDialog.Filter = "csv files(*.csv)|*.csv"; if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { String[] headers = OutputFile.CSV.ReadHeaders(fileDialog.FileName); if (headers == null) { MessageBox.Show(String.Format("該{0}檔案不存在數據"), fileDialog.FileName); } else { var names = OutputFile.Config.GetNames(); var rules = OutputFile.Config.GetRules(); var selectForm = new SelectForm(headers, names); selectForm.ShowDialog(); headers = selectForm.GetHeaders(); var selectNumber = selectForm.GetSelect(); for (int point = 0; point < selectNumber.Length; point++) { Console.WriteLine(selectNumber[point]); } var series = GetSeries(headers, selectNumber); var seriesAvg = GetSeries(headers, selectNumber); CleanArray(); CleanAvgArray(); CleanChart(ref _chart, true); CleanChart(ref _chartAvg, true); foreach (Series s in series) { try { _chart.Series.Add(s); } catch (ArgumentException ex) { } } foreach (Series s in seriesAvg) { try { _chartAvg.Series.Add(s); } catch (ArgumentException ex) { } } DrawCSV(fileDialog.FileName, rules, selectNumber); if (OutputFile.CSV.OldToNewCSV(fileDialog.FileName, OutputFile.Config.GetRules(), _listHeader.ToArray()) == true) { MessageBox.Show("檔案輸出成功"); } else { MessageBox.Show("檔案輸出失敗"); } } } else { MessageBox.Show("請選擇正確檔案"); } } catch (IOException ex) { MessageBox.Show("請先關閉該檔案"); } catch (NullReferenceException ex) { MessageBox.Show("請確認檔案是否存在"); } }