using System; using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Data; using Tango.PPC.Common.Build; namespace Tango.PPC.UI.Converters { public class ProgressWeightSpoolConverter : IMultiValueConverter { private static IBuildProvider _buildProvider; public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) { try { if (_buildProvider == null) { _buildProvider = Core.DI.TangoIOC.Default.GetInstance(); } if (values.Count() == 4) { double length = System.Convert.ToDouble(values[0]); bool forOneSpool = System.Convert.ToBoolean(values[1]); double coef = System.Convert.ToDouble(values[2]); int number_of_spools = System.Convert.ToInt16(values[3]); if (_buildProvider.MachineType == BL.Enumerations.MachineTypes.Eureka) { var totalBy4Spools = (double)length * number_of_spools; var weight = ((double)totalBy4Spools * coef) / (1000);//(g) if (forOneSpool) { return (double)weight / number_of_spools; } return weight; } else { double weight = ((double)length * coef) / (1000);//(g) if (forOneSpool) { weight = ((double)length / (double)number_of_spools * coef) / (1000);//(g) } return weight; } } if (values.Count() == 5) { double length = System.Convert.ToDouble(values[0]); bool forOneSpool = System.Convert.ToBoolean(values[1]); double currentProgresslength = System.Convert.ToDouble(values[2]); double coef = System.Convert.ToDouble(values[3]); int number_of_spools = System.Convert.ToInt16(values[4]); if (_buildProvider.MachineType == BL.Enumerations.MachineTypes.Eureka) { var totalBy4Spools = (double)length * number_of_spools; var currentProgressBy4Spools = (double)currentProgresslength * number_of_spools; int coeff = (int)currentProgressBy4Spools / (int)totalBy4Spools; var progressCurrent = (coeff == 0 || coeff == 1) ? currentProgressBy4Spools : currentProgressBy4Spools % (coeff * totalBy4Spools);//show for progress var weight = ((double)progressCurrent * coef) / (1000);//(g) if (forOneSpool) { return (double)weight / number_of_spools; } return weight; } else { double weight = 0; if (forOneSpool) { double lengthPerSpool = length / number_of_spools; // Get the current spool int currentSpool = (int)(Math.Floor(currentProgresslength / lengthPerSpool)) + 1; // Calculate progress on the current spool double spoolProgress = currentProgresslength % lengthPerSpool; if (currentSpool > number_of_spools) { currentSpool = number_of_spools; spoolProgress = lengthPerSpool; } weight = ((double)spoolProgress * coef) / (1000);//(g) } else { weight = ((double)currentProgresslength * coef) / (1000);//(g) } return weight; } } return "-"; } catch { return "-"; } } public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) { throw new NotImplementedException(); } } }