using System; using System.Diagnostics; using System.Drawing; using System.IO; using System.Windows.Forms; using Deltares.Dam.Data; using Deltares.Standard; using Deltares.Standard.Attributes; using Deltares.Standard.EventPublisher; using Deltares.Standard.Forms; using Deltares.Standard.Forms.DExpress; namespace Deltares.Dam.Forms { public partial class ScenarioCalculationPropertyControl : UserControl, IPropertyControl { private RWScenarioProfileResult result; private ScenarioType scenarioType = ScenarioType.Scenario01; private string soilProfileName; public ScenarioCalculationPropertyControl() { InitializeComponent(); this.Name = "Calculation"; BindSupport.BindTextAndValue(this, this.LocationLabel, this.LocationEdit, typeof(RWScenarioProfileResult), "LocationName"); BindSupport.BindTextAndValue(this, this.ProfileLabel, this.ProfileEdit, typeof(RWScenarioProfileResult), "SoilProfileName"); BindSupport.BindTextAndValue(this, this.LoadSituationLabel, this.LoadSituationComboBox, typeof(RWScenarioProfileResult), "LoadSituation"); BindSupport.BindTextAndValue(this, this.DikeSensitivityLabel, this.DikeSensitivityComboBox, typeof(RWScenarioProfileResult), "DikeDrySensitivity"); BindSupport.BindTextAndValue(this, this.HydraulicShortcutLabel, this.HydraulicShortcutComboBox, typeof(RWScenarioProfileResult), "HydraulicShortcutType"); BindSupport.BindTextAndValue(this, this.UpliftLabel, this.UpliftComboBox, typeof(RWScenarioProfileResult), "UpliftType"); BindSupport.BindTextAndValue(this, this.ModelLabel, this.ModelComboBox, typeof(RWScenarioProfileResult), "MstabModelOption"); BindSupport.BindTextAndValue(this, this.ModelPipingLabel, this.ModelPipingComboBox, typeof(RWScenarioProfileResult), "PipingModelOption"); BindSupport.BindTextAndValue(this, this.ScenarioLabel, this.ScenarioComboBox, typeof(RWScenarioProfileResult), "ScenarioType"); BindSupport.BindTextValueAndUnit(this, this.SafetyFactorLabel, this.SafetyFactorEdit, typeof(RWScenarioProfileResult), "SafetyFactor"); BindSupport.BindTextAndValue(this, this.CalculationLabel, this.CalculationComboBox, typeof(RWScenarioProfileResult), "CalculationResult"); BindSupport.Bind(this, this.AcceptedCheckEdit, typeof(RWScenarioProfileResult), "ResultEvaluation", ResultEvaluation.Accepted); BindSupport.Bind(this, this.RejectedCheckEdit, typeof(RWScenarioProfileResult), "ResultEvaluation", ResultEvaluation.Rejected); BindSupport.Bind(this, this.NotEvaluatedCheckEdit, typeof(RWScenarioProfileResult), "ResultEvaluation", ResultEvaluation.NotEvaluated); //#Best name in edits added LocalizationSupport.Register(typeof(RWScenarioProfileResult), this.AcceptedCheckEdit, this.RejectedCheckEdit, this.NotEvaluatedCheckEdit, this.groupControl1, this.groupControl2, this.EvaluationGroupControl); BindSupport.BindTextAndValue(this, this.NotesLabel, this.NotesEdit, typeof(RWScenarioProfileResult), "Notes"); BindSupport.Bind(this.EvaluationGroupControl, OpenFileButton, this.GetType(), "OpenFile"); BindSupport.Assign(this.EvaluationGroupControl, this); FormsSupport.RepairRightAnchoredControls(this); DataEventPublisher.OnAfterChange += DataEventPublisher_OnAfterChange; } private void DataEventPublisher_OnAfterChange(object sender, PublishEventArgs e) { if (sender is LocationJobSymbol) { this.scenarioType = ((LocationJobSymbol) sender).CurrentScenarioType; soilProfileName = ((LocationJobSymbol)sender).CurrentProfileName; } } #region IPropertyControl Members public object SelectedObject { get { return result; } set { if (value is RWScenarioProfileResult) { result = value as RWScenarioProfileResult; BindSupport.Assign(this, result); } else if (value is LocationJob) { if (result == null || result.Location != ((LocationJob)value).Location || ((LocationJob)value).HasRWScenarioResults == false || result.ScenarioType != scenarioType || result.SoilProfileName != soilProfileName) { // Note: if no results for this locationjob (the third condition) the result will be set to null, so dialog will be hidden result = ((LocationJob) value).GetAssesmentResultByProfile(scenarioType, soilProfileName); BindSupport.Assign(this, result); // AcceptedCheckEdit.Visible = true; // AcceptedCheckEdit.ForeColor = Color.Black; // RejectedCheckEdit.Visible = true; // NotEvaluatedCheckEdit.Visible = true; // tableLayoutPanel1.Visible = true; // tableLayoutPanel1.Enabled = true; // EvaluationGroupControl.Enabled = true; // EvaluationGroupControl.Visible = true; } } } } public bool IsVisible { get { return this.result != null; } } #endregion [Label("Open calculation")] public void OpenFile() { if (File.Exists(result.InputFile)) { string copyFile = Path.GetDirectoryName(result.InputFile) + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(result.InputFile) + " (copy)" + Path.GetExtension(result.InputFile); File.Copy(result.InputFile, copyFile, true); // Copy dump file too string orgDumpFile = Path.ChangeExtension(result.InputFile, ".std"); if (File.Exists(orgDumpFile)) { string copyDumpFile = Path.ChangeExtension(copyFile, ".std"); File.Copy(orgDumpFile, copyDumpFile, true); } // Copy output file too string orgOutputFile = Path.ChangeExtension(result.InputFile, ".sto"); if (File.Exists(orgOutputFile)) { string copyOutputFile = Path.ChangeExtension(copyFile, ".sto"); File.Copy(orgOutputFile, copyOutputFile, true); } Process process = new Process(); process.StartInfo.RedirectStandardOutput = false; process.StartInfo.FileName = DamHelperFunctions.MStabExePath; process.StartInfo.Arguments = " \"" + copyFile + "\""; process.StartInfo.UseShellExecute = false; process.StartInfo.WindowStyle = ProcessWindowStyle.Normal; process.Start(); } else { if (File.Exists(result.PipingResultFile)) { string copyFile = Path.GetTempPath() + Path.DirectorySeparatorChar + Path.GetFileNameWithoutExtension(result.PipingResultFile) + " (copy)" + Path.GetExtension(result.PipingResultFile); File.Copy(result.PipingResultFile, copyFile, true); System.Diagnostics.Process.Start(copyFile); } } } } }