/// <summary>Called after the user has selected a new met file.</summary> /// <param name="fileName">Name of the file.</param> public void OnBrowse(string fileName) { bool isCsv = Path.GetExtension(fileName) == ".csv"; this.weatherDataView.ShowConstantsFile(isCsv); if (this.weatherData.FullFileName != PathUtilities.GetAbsolutePath(fileName, this.explorerPresenter.ApsimXFile.FileName)) { if (ExcelUtilities.IsExcelFile(fileName)) { // Extend height of Browse Panel to show Drop Down for Sheet names this.weatherDataView.ShowExcelSheets(true); this.sheetNames = ExcelUtilities.GetWorkSheetNames(fileName); this.weatherDataView.PopulateDropDownData(this.sheetNames); // We want to attempt to update the table/summary now. This may fail if the // sheet name is incorrect/not set. this.WriteTableAndSummary(fileName); } else { // Shrink Browse Panel so that the sheet name dropdown doesn't show this.weatherDataView.ShowExcelSheets(false); // as a precaution, set this to nothing this.weatherData.ExcelWorkSheetName = string.Empty; this.WriteTableAndSummary(fileName); } } }
/// <summary>Called after the user has selected a new met file.</summary> /// <param name="fileName">Name of the file.</param> public void OnBrowse(string fileName) { if (this.weatherData.FullFileName != PathUtilities.GetAbsolutePath(fileName, this.explorerPresenter.ApsimXFile.FileName)) { if (Path.GetExtension(fileName) == ExcelUtilities.ExcelExtension) { //// Extend height of Browse Panel to show Drop Down for Sheet names this.weatherDataView.ShowExcelSheets(true); this.sheetNames = ExcelUtilities.GetWorkSheetNames(fileName); this.weatherDataView.PopulateDropDownData(this.sheetNames); // the following is not required here as it happens when the sheet name is changed // this.WriteTableAndSummary(fileName); } else { //// Shrink Browse Panel so that the sheet name dropdown doesn't show this.weatherDataView.ShowExcelSheets(false); // as a precaution, set this to nothing this.weatherData.ExcelWorkSheetName = string.Empty; this.WriteTableAndSummary(fileName); } } }
/// <summary> /// Get data from the weather file and present it to the view as both a table and a summary /// </summary> /// <param name="filename">The filename.</param> private void WriteTableAndSummary(string filename, string sheetName = "") { // Clear any previous summary this.weatherDataView.Summarylabel = string.Empty; this.weatherDataView.GraphSummary.Clear(); this.weatherDataView.GraphSummary.Refresh(); this.weatherDataView.GraphRainfall.Clear(); this.weatherDataView.GraphRainfall.Refresh(); this.weatherDataView.GraphMonthlyRainfall.Clear(); this.weatherDataView.GraphMonthlyRainfall.Refresh(); this.weatherDataView.GraphTemperature.Clear(); this.weatherDataView.GraphTemperature.Refresh(); this.weatherDataView.GraphRadiation.Clear(); this.weatherDataView.GraphRadiation.Refresh(); this.graphMetData = new DataTable(); if (filename != null) { try { if (Path.GetExtension(filename) == ExcelUtilities.ExcelExtension) { ////Extend height of Browse Panel to show Drop Down for Sheet names weatherDataView.BrowsePanelControlHeight = 76; if (sheetNames == null) { sheetNames = ExcelUtilities.GetWorkSheetNames(filename); this.weatherDataView.PopulateDropDownData(sheetNames); } } else { //Shrink Browse Panel so that the sheet name dropdown doesn't show weatherDataView.BrowsePanelControlHeight = 41; } this.weatherData.ExcelWorkSheetName = sheetName; this.weatherData.FullFileName = PathUtilities.GetAbsolutePath(filename, this.explorerPresenter.ApsimXFile.FileName); DataTable data = this.weatherData.GetAllData(); this.WriteTable(data); this.WriteSummary(data); this.DisplayDetailedGraphs(data); this.explorerPresenter.MainPresenter.ShowMessage(" ", DataStore.ErrorLevel.Information); } catch (Exception err) { string message = err.Message; message += "\r\n" + err.StackTrace; this.weatherDataView.Summarylabel = err.Message; this.explorerPresenter.MainPresenter.ShowMessage(message, DataStore.ErrorLevel.Error); } } this.weatherDataView.Filename = PathUtilities.GetRelativePath(filename, this.explorerPresenter.ApsimXFile.FileName); this.weatherDataView.ExcelWorkSheetName = sheetName; }
/// <summary>Called when [browse].</summary> /// <param name="fileName">Name of the file.</param> public void OnBrowse(string fileName) { if (this.weatherData.FullFileName != PathUtilities.GetAbsolutePath(fileName, this.explorerPresenter.ApsimXFile.FileName)) { if (Path.GetExtension(fileName) == ExcelUtilities.ExcelExtension) { //Extend height of Browse Panel to show Drop Down for Sheet names weatherDataView.BrowsePanelControlHeight = 76; sheetNames = ExcelUtilities.GetWorkSheetNames(fileName); this.weatherDataView.PopulateDropDownData(sheetNames); } else { //Shrink Browse Panel so that the sheet name dropdown doesn't show weatherDataView.BrowsePanelControlHeight = 41; //as a precaution, set this to nothing this.weatherData.ExcelWorkSheetName = string.Empty; this.WriteTableAndSummary(fileName); } } }
/// <summary> /// Get data from the weather file and present it to the view as both a table and a summary /// </summary> /// <param name="filename">The filename.</param> /// <param name="sheetName">The name of the sheet</param> private void WriteTableAndSummary(string filename, string sheetName = "") { // Clear any previos error message this.explorerPresenter.MainPresenter.ShowMessage(" ", Simulation.MessageType.Information); // Clear any previous summary this.weatherDataView.Summarylabel = string.Empty; this.weatherDataView.GraphSummary.Clear(); this.weatherDataView.GraphSummary.Refresh(); this.weatherDataView.GraphRainfall.Clear(); this.weatherDataView.GraphRainfall.Refresh(); this.weatherDataView.GraphMonthlyRainfall.Clear(); this.weatherDataView.GraphMonthlyRainfall.Refresh(); this.weatherDataView.GraphTemperature.Clear(); this.weatherDataView.GraphTemperature.Refresh(); this.weatherDataView.GraphRadiation.Clear(); this.weatherDataView.GraphRadiation.Refresh(); this.graphMetData = new DataTable(); if (filename != null) { this.weatherDataView.Filename = PathUtilities.GetAbsolutePath(filename, this.explorerPresenter.ApsimXFile.FileName); try { if (ExcelUtilities.IsExcelFile(filename)) { // Extend height of Browse Panel to show Drop Down for Sheet names this.weatherDataView.ShowExcelSheets(true); if (this.sheetNames == null) { this.sheetNames = ExcelUtilities.GetWorkSheetNames(filename); this.weatherDataView.ExcelSheetChangeClicked -= this.ExcelSheetValueChanged; this.weatherDataView.PopulateDropDownData(this.sheetNames); this.weatherDataView.ExcelSheetChangeClicked += this.ExcelSheetValueChanged; } } else { // Shrink Browse Panel so that the sheet name dropdown doesn't show this.weatherDataView.ShowExcelSheets(false); } ViewBase.MasterView.WaitCursor = true; try { this.weatherData.ExcelWorkSheetName = sheetName; string newFileName = PathUtilities.GetAbsolutePath(filename, this.explorerPresenter.ApsimXFile.FileName); var changes = new List <ChangeProperty.Property>(); if (weatherData.FullFileName != newFileName) { changes.Add(new ChangeProperty.Property(weatherData, nameof(weatherData.FullFileName), newFileName)); } // Set constants file name to null iff the new file name is not a csv file. if (Path.GetExtension(newFileName) != ".csv" && weatherData.ConstantsFile != null) { changes.Add(new ChangeProperty.Property(weatherData, nameof(weatherData.ConstantsFile), null)); } if (changes.Count > 0) { ICommand changeFileName = new ChangeProperty(changes); explorerPresenter.CommandHistory.Add(new ChangeProperty(changes)); } using (DataTable data = this.weatherData.GetAllData()) { this.dataStartDate = this.weatherData.StartDate; this.dataEndDate = this.weatherData.EndDate; this.WriteTable(data); this.WriteSummary(data); this.DisplayDetailedGraphs(data); } } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } finally { ViewBase.MasterView.WaitCursor = false; this.weatherData.CloseDataFile(); } } catch (Exception err) { string message = err.Message; message += "\r\n" + err.StackTrace; this.weatherDataView.Summarylabel = err.Message; this.explorerPresenter.MainPresenter.ShowError(err); } } // this.weatherDataView.Filename = PathUtilities.GetRelativePath(filename, this.explorerPresenter.ApsimXFile.FileName); this.weatherDataView.Filename = PathUtilities.GetAbsolutePath(filename, this.explorerPresenter.ApsimXFile.FileName); this.weatherDataView.ConstantsFileName = weatherData.ConstantsFile; this.weatherDataView.ExcelWorkSheetName = sheetName; }
/// <summary> /// Get data from the weather file and present it to the view as both a table and a summary /// </summary> /// <param name="filename">The filename.</param> private void WriteTableAndSummary(string filename, string sheetName = "") { // Clear any previous summary this.weatherDataView.Summarylabel = string.Empty; this.weatherDataView.GraphSummary.Clear(); this.weatherDataView.GraphSummary.Refresh(); this.weatherDataView.GraphRainfall.Clear(); this.weatherDataView.GraphRainfall.Refresh(); this.weatherDataView.GraphMonthlyRainfall.Clear(); this.weatherDataView.GraphMonthlyRainfall.Refresh(); this.weatherDataView.GraphTemperature.Clear(); this.weatherDataView.GraphTemperature.Refresh(); this.weatherDataView.GraphRadiation.Clear(); this.weatherDataView.GraphRadiation.Refresh(); this.graphMetData = new DataTable(); if (filename != null) { this.weatherDataView.Filename = PathUtilities.GetRelativePath(filename, this.explorerPresenter.ApsimXFile.FileName); try { if (Path.GetExtension(filename) == ExcelUtilities.ExcelExtension) { //Extend height of Browse Panel to show Drop Down for Sheet names weatherDataView.ShowExcelSheets(true); List <string> sheetNames = ExcelUtilities.GetWorkSheetNames(filename); this.weatherDataView.ExcelSheetChangeClicked -= this.ExcelSheetValueChanged; this.weatherDataView.PopulateDropDownData(sheetNames); this.weatherDataView.ExcelWorkSheetName = sheetName; this.weatherDataView.ExcelSheetChangeClicked += this.ExcelSheetValueChanged; this.weatherData.ExcelWorkSheetName = this.weatherDataView.ExcelWorkSheetName; } else { //Shrink Browse Panel so that the sheet name dropdown doesn't show weatherDataView.ShowExcelSheets(false); //as a precaution, set this to nothing this.weatherData.ExcelWorkSheetName = string.Empty; } (weatherDataView as TabbedMetDataView).WaitCursor = true; try { this.weatherData.FullFileName = PathUtilities.GetAbsolutePath(filename, this.explorerPresenter.ApsimXFile.FileName); DataTable data = this.weatherData.GetAllData(); this.WriteTable(data); this.WriteSummary(data); this.DisplayDetailedGraphs(data); this.explorerPresenter.ShowMessage(" ", DataStore.ErrorLevel.Information); } finally { (weatherDataView as TabbedMetDataView).WaitCursor = false; } } catch (Exception err) { string message = err.Message; message += "\r\n" + err.StackTrace; this.weatherDataView.Summarylabel = err.Message; this.explorerPresenter.ShowMessage(message, DataStore.ErrorLevel.Error); } } this.weatherDataView.Filename = PathUtilities.GetRelativePath(filename, this.explorerPresenter.ApsimXFile.FileName); }
/// <summary> /// Get data from the weather file and present it to the view as both a table and a summary /// </summary> /// <param name="filename">The filename.</param> /// <param name="sheetName">The name of the sheet</param> private void WriteTableAndSummary(string filename, string sheetName = "") { // Clear any previos error message this.explorerPresenter.MainPresenter.ShowMessage(" ", Simulation.MessageType.Information); // Clear any previous summary this.weatherDataView.Summarylabel = string.Empty; this.weatherDataView.GraphSummary.Clear(); this.weatherDataView.GraphSummary.Refresh(); this.weatherDataView.GraphRainfall.Clear(); this.weatherDataView.GraphRainfall.Refresh(); this.weatherDataView.GraphMonthlyRainfall.Clear(); this.weatherDataView.GraphMonthlyRainfall.Refresh(); this.weatherDataView.GraphTemperature.Clear(); this.weatherDataView.GraphTemperature.Refresh(); this.weatherDataView.GraphRadiation.Clear(); this.weatherDataView.GraphRadiation.Refresh(); this.graphMetData = new DataTable(); if (filename != null) { this.weatherDataView.Filename = PathUtilities.GetAbsolutePath(filename, this.explorerPresenter.ApsimXFile.FileName); try { if (Path.GetExtension(filename) == ExcelUtilities.ExcelExtension) { // Extend height of Browse Panel to show Drop Down for Sheet names this.weatherDataView.ShowExcelSheets(true); if (this.sheetNames == null) { this.sheetNames = ExcelUtilities.GetWorkSheetNames(filename); this.weatherDataView.ExcelSheetChangeClicked -= this.ExcelSheetValueChanged; this.weatherDataView.PopulateDropDownData(this.sheetNames); this.weatherDataView.ExcelSheetChangeClicked += this.ExcelSheetValueChanged; } } else { // Shrink Browse Panel so that the sheet name dropdown doesn't show this.weatherDataView.ShowExcelSheets(false); } (this.weatherDataView as TabbedMetDataView).WaitCursor = true; try { this.weatherData.ExcelWorkSheetName = sheetName; explorerPresenter.CommandHistory.Add(new Commands.ChangeProperty(weatherData, "FullFileName", PathUtilities.GetAbsolutePath(filename, this.explorerPresenter.ApsimXFile.FileName))); using (DataTable data = this.weatherData.GetAllData()) { this.dataStartDate = this.weatherData.StartDate; this.dataEndDate = this.weatherData.EndDate; this.WriteTable(data); this.WriteSummary(data); this.DisplayDetailedGraphs(data); } } finally { (this.weatherDataView as TabbedMetDataView).WaitCursor = false; this.weatherData.CloseDataFile(); } } catch (Exception err) { string message = err.Message; message += "\r\n" + err.StackTrace; this.weatherDataView.Summarylabel = err.Message; this.explorerPresenter.MainPresenter.ShowError(err); } } // this.weatherDataView.Filename = PathUtilities.GetRelativePath(filename, this.explorerPresenter.ApsimXFile.FileName); this.weatherDataView.Filename = PathUtilities.GetAbsolutePath(filename, this.explorerPresenter.ApsimXFile.FileName); this.weatherDataView.ExcelWorkSheetName = sheetName; }