diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2021-08-13 19:10:11 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2021-08-13 19:10:11 +0300 |
| commit | b59b10c6b53f75fd9564662f6c198e794456d47b (patch) | |
| tree | 9766c225ae3c92947af41167972e0c69ff9b9d87 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs | |
| parent | e6a1c01dc220ef50be61b72037e982e20011983e (diff) | |
| parent | 5514eac5e2eb031380b74cf2ec1c697d0d47067e (diff) | |
| download | Tango-b59b10c6b53f75fd9564662f6c198e794456d47b.tar.gz Tango-b59b10c6b53f75fd9564662f6c198e794456d47b.zip | |
Merged RML Extensions feature !!!!
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs | 201 |
1 files changed, 201 insertions, 0 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs new file mode 100644 index 000000000..4e7d84e7f --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ThreadExtensions/ViewModels/TestResultViewVM.cs @@ -0,0 +1,201 @@ +using Microsoft.Win32; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.BL; +using Tango.BL.ActionLogs; +using Tango.BL.DTO; +using Tango.BL.Entities; +using Tango.BL.Enumerations; +using Tango.Core.Commands; +using Tango.MachineStudio.Common.Notifications; +using Tango.SharedUI; + +namespace Tango.MachineStudio.ThreadExtensions.ViewModels +{ + public class TestResultViewVM : ViewModel + { + private INotificationProvider _notification; + private IActionLogManager _actionLogManager; + + #region Properties + + private string _threadName; + /// <summary> + /// Gets or sets the name of the thread. Using in print + /// </summary> + /// <value> + /// The name of the thread. + /// </value> + public string ThreadName + { + get { return _threadName; } + set + { + _threadName = value; + RaisePropertyChangedAuto(); + } + } + + + private bool _isSelected; + /// <summary> + /// Gets or sets a value indicating whether this instance is selected. + /// </summary> + public bool IsSelected + { + get { return _isSelected; } + set { _isSelected = value; RaisePropertyChangedAuto(); } + } + + private RmlExtensionTestResult _testResult; + + public RmlExtensionTestResult TestResult + { + get { return _testResult; } + set { _testResult = value; + RaisePropertyChangedAuto(); + } + } + + + #endregion + public RelayCommand ExportToFileCommand { get; set; } + + public TestResultViewVM(INotificationProvider notification, IActionLogManager actionLogManager) + { + _notification = notification; + _actionLogManager = actionLogManager; + ExportToFileCommand = new RelayCommand(ExportToFile); + } + + #region save + // public void Save(ObservablesContext active_context) + //{ + // try + // { + // IsFree = false; + + // TestResult.LastUpdated = DateTime.UtcNow; + + // var RmlExtensionTestResultAfterChange = RmlExtensionTestResultDTO.FromObservable(TestResult); + + // active_context.SaveChanges(); + // } + // catch (Exception ex) + // { + // LogManager.Log(ex, "Could not update RmlExtension TestResult."); + // _notification.ShowError($"An error occurred while trying to save RmlExtension TestResult.\n{ex.Message}"); + // } + // finally + // { + // IsFree = true; + // } + //} + #endregion + + private void ExportToFile() + { + SaveFileDialog dlg = new SaveFileDialog(); + try + { + dlg.Title = $"Export excel calibration file for {TestResult.Name}"; + dlg.Filter = "Text Files|*.txt"; + dlg.DefaultExt = ".txt"; + dlg.FileName = $"RML_EXTENSION_{TestResult.Name}.txt"; + if (dlg.ShowDialog().Value) + { + using (StreamWriter outputFile = new StreamWriter(dlg.FileName)) + { + outputFile.WriteLine(String.Format($" {TestResult.Name.ToUpper()} ")); + outputFile.WriteLine(""); + outputFile.WriteLine(""); + outputFile.WriteLine(" Dryer temperature"); + outputFile.WriteLine(""); + outputFile.WriteLine(String.Format($" Dryer temperature : {TestResult.DryerTemperature.ToString()}")); + outputFile.WriteLine(String.Format($" Tunnel temperature : {TestResult.TunnelTemperature.ToString()}")); + outputFile.WriteLine(String.Format($" Tunnel flow : {TestResult.TunnelFlow.ToString()}")); + outputFile.WriteLine(String.Format($" Tunnel AVG temperature : {TestResult.TunnelAvgTemperature.ToString()}")); + outputFile.WriteLine(""); + outputFile.WriteLine(""); + outputFile.WriteLine(" Tension through the thread path"); + outputFile.WriteLine(""); + outputFile.WriteLine(String.Format($" Head : {TestResult.TensionHeadMin.ToString()} - {TestResult.TensionHeadMax.ToString()}")); + outputFile.WriteLine(String.Format($" After dryer : {TestResult.TensionAfterDryerMin.ToString()} - {TestResult.TensioinAfterDryerMax.ToString()}")); + outputFile.WriteLine(String.Format($" Winder : {TestResult.BtsrMin.ToString()} - {TestResult.BtsrMax.ToString()}")); + outputFile.WriteLine(String.Format($" BTSR : {TestResult.TensionHeadMin.ToString()} - {TestResult.TensionHeadMax.ToString()}")); + outputFile.WriteLine(String.Format($" Puller tension : {TestResult.PullerTensionMin.ToString()} - {TestResult.PullerTensionMax.ToString()}")); + outputFile.WriteLine(String.Format($" Winder exit tension: {TestResult.ExitTensionMin.ToString()} - {TestResult.ExitTensionMax.ToString()}")); + + outputFile.WriteLine(""); + outputFile.WriteLine(" Rubbing results"); + outputFile.WriteLine(""); + outputFile.WriteLine(" Color DeltaE CIE 100 % GS 100% DeltaETestResult CIE 200 % GS 200% "); + foreach (var rubbingResult in TestResult.RubbingResults) + { + StringBuilder sb = new StringBuilder(); + //sb.Append(" Color: "); + sb.Append($" { rubbingResult.TestResultColor.ToString()} "); + //sb.Append(" DeltaE CIE 100 % : "); + sb.Append($" { rubbingResult.DeltaeCie100.ToString()} "); + //sb.Append(" GS 100% : "); + sb.Append($" { rubbingResult.Gs100Min.ToString()}-{rubbingResult.Gs100Max.ToString()} "); + //sb.Append(" DeltaE CIE 200 % : "); + sb.Append($" { rubbingResult.DeltaeCie200.ToString()} "); + //sb.Append(" GS 200% : "); + sb.Append($" { rubbingResult.Gs200Min.ToString()}-{rubbingResult.Gs200Max.ToString()} "); + outputFile.WriteLine(sb); + } + outputFile.WriteLine(""); + outputFile.WriteLine(" Mechanical properties"); + outputFile.WriteLine(""); + outputFile.WriteLine(" %Color Color Load at Maximum Load(N) STDEV Percentage Strain at Maximum Load STDEV "); + foreach (var result in TestResult.TensileResults) + { + StringBuilder sb = new StringBuilder(); + //sb.Append(" % Color: "); + sb.Append($" { result.ColorPercent.ToString()}"); + //sb.Append(" Color : "); + sb.Append($" { result.TestResultColor.ToString()}"); + //sb.Append(" Load at Maximum Load(N) : "); + sb.Append($" { result.MaxLoad.ToString()}"); + //sb.Append(" STDEV : "); + sb.Append($" { result.StdevMaxLoad.ToString()}"); + //sb.Append(" Percentage Strain at Maximum Load: "); + sb.Append($" {result.StrainMaxLoad.ToString()}"); + //sb.Append(" STDEV : "); + sb.Append($" { result.StdevStrainMaxLoad.ToString()}"); + outputFile.WriteLine(sb); + } + outputFile.WriteLine(""); + outputFile.WriteLine(" Uniformity"); + outputFile.WriteLine(""); + outputFile.WriteLine(String.Format($" Zone1 : {TestResult.SeverityZone1Min.ToString()} - {TestResult.SeverityZone1Max.ToString()}")); + outputFile.WriteLine(String.Format($" Zone2 : {TestResult.SeverityZone2Min.ToString()} - {TestResult.SeverityZone2Max.ToString()}")); + outputFile.WriteLine(""); + outputFile.WriteLine(" COF"); + outputFile.WriteLine(""); + outputFile.WriteLine(" Thread name Lub Version COF Lub amount "); + outputFile.WriteLine(String.Format($" REF {TestResult.RefLubVersion} {TestResult.RefCof.ToString()} {TestResult.RefLub.ToString()}")); + outputFile.WriteLine(String.Format($" {ThreadName} {TestResult.ThreadLubVersion} {TestResult.ThreadCof.ToString()} {TestResult.ThreadLub.ToString()}")); + + outputFile.WriteLine(""); + outputFile.WriteLine(String.Format($" Comments: {TestResult.Comment}")); + outputFile.WriteLine(String.Format($" Conclusion: {TestResult.Conclusions}")); + outputFile.WriteLine(""); + outputFile.Flush(); + } + + } + } + catch (Exception ex) + { + LogManager.Log(ex, "Error exporting excel file " + dlg.FileName); + _notification.ShowError("An error occurred while trying to export the test result data."); + } + } + } +} |
