コード例 #1
0
        private void AdditionalCrossWithGrooveCheckBox_Click(object sender, RoutedEventArgs e)
        {
            var checkedValue = ((CheckBox)sender).IsChecked;

            data = calculatorService.CheckExtraCrossProfileWithGroove(checkedValue.Value, data);
            RefreshFormValues();
        }
コード例 #2
0
        private OutputWpfData CalculateMounts(OutputWpfData notPricedOutputData)
        {
            var mountIm = notPricedOutputData.Mounts.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentMount.Name);

            mountIm = mountIm ?? notPricedOutputData.Mounts.FirstOrDefault();
            notPricedOutputData.CurrentMount.Name  = mountIm.Name;
            notPricedOutputData.CurrentMount.Count = mountIm.Count;
            notPricedOutputData.CurrentMount.Price = Math.Round(notPricedOutputData.CurrentMount.Count * mountIm.PricePerCount, 2);

            if (mountIm.ClincherCount != 0)
            {
                var clincher = inputData.PackageDetails[(int)PackageDetail.Clincher];
                notPricedOutputData.RequiredExtraDetails.Add(new CurrentExtraDetail
                {
                    Name  = clincher.Name + " (" + notPricedOutputData.CurrentMount.Name + ")",
                    Count = mountIm.ClincherCount,
                    Price = clincher.PricePerCount * mountIm.ClincherCount
                });
            }

            if (mountIm.Felt)
            {
                var felt      = inputData.PackageDetails[(int)PackageDetail.Felt];
                var feltCount = Math.Round(((notPricedOutputData.Width * notPricedOutputData.Height) / 1000000), 2);
                notPricedOutputData.RequiredExtraDetails.Add(new CurrentExtraDetail
                {
                    Name  = felt.Name + " (" + notPricedOutputData.CurrentMount.Name + ")",
                    Count = feltCount,
                    Price = feltCount * felt.PricePerCount
                });
            }

            return(notPricedOutputData);
        }
コード例 #3
0
 public OutputWpfData ChangeExtraCrossProfileWithGroove(string profileName, OutputWpfData oldData)
 {
     oldData.CurrentCrossProfileWithGroove = new CurrentCrossProfile
     {
         Name = profileName
     };
     return(Calculate(oldData));
 }
コード例 #4
0
 public OutputWpfData ChangeCord(string cordName, OutputWpfData oldData)
 {
     oldData.CurrentCord = new CurrentCord
     {
         Name = cordName
     };
     return(Calculate(oldData));
 }
コード例 #5
0
 public OutputWpfData ChangeNet(string netName, OutputWpfData oldData)
 {
     oldData.CurrentNet = new CurrentNet
     {
         Name = netName
     };
     return(Calculate(oldData));
 }
コード例 #6
0
 public OutputWpfData ChangeCrossProfile(string crossProfileName, OutputWpfData oldData)
 {
     oldData.CurrentCrossProfile = new CurrentCrossProfile
     {
         Name = crossProfileName
     };
     return(Calculate(oldData));
 }
コード例 #7
0
 public OutputWpfData ChangeSystem(string systemName, OutputWpfData oldData)
 {
     oldData.CurrentSystem = new CurrentSystem
     {
         Name = systemName
     };
     return(Calculate(oldData));
 }
コード例 #8
0
        private OutputWpfData Calculate(OutputWpfData notPricedOutputData)
        {
            notPricedOutputData = SetAllowedImProductsBySystem(notPricedOutputData);

            notPricedOutputData = CalculateAngles(notPricedOutputData);
            notPricedOutputData = CalculateProfile(notPricedOutputData);
            notPricedOutputData = CalculateCrossProfiles(notPricedOutputData);
            notPricedOutputData = CalculateNet(notPricedOutputData);

            var cordIm = notPricedOutputData.Cords.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentCord.Name);

            cordIm = cordIm ?? notPricedOutputData.Cords.FirstOrDefault();
            notPricedOutputData.CurrentCord.Name  = cordIm.Name;
            notPricedOutputData.CurrentCord.Count = Math.Round((notPricedOutputData.Width + notPricedOutputData.Height - (2 * notPricedOutputData.ProfileTolerance)) / 500, 2);
            notPricedOutputData.CurrentCord.Price = Math.Round(notPricedOutputData.CurrentCord.Count * cordIm.PricePerCount, 2);

            notPricedOutputData = CalculateMounts(notPricedOutputData);
            notPricedOutputData = CalculateExtraMounts(notPricedOutputData);
            notPricedOutputData = CalculateCrossMounts(notPricedOutputData);
            notPricedOutputData = CalculateKnobs(notPricedOutputData);

            foreach (var currentExtraDetail in notPricedOutputData.CurrentExtraDetails)
            {
                var detailIm = notPricedOutputData.ExtraDetails.FirstOrDefault(im => im.Name == currentExtraDetail.Name);
                if (detailIm == null)
                {
                    continue;
                }
                currentExtraDetail.Price = Math.Round(currentExtraDetail.Count * detailIm.PricePerCount, 2);
            }

            var gLuePrice = Math.Round(notPricedOutputData.GluePrice / notPricedOutputData.AmountNetsOnTheOneGlue, 2);

            notPricedOutputData.TrashPrice = Math.Round(((notPricedOutputData.CurrentProfile.Price + notPricedOutputData.CurrentCrossProfile.Price + notPricedOutputData.CurrentNet.Price + notPricedOutputData.CurrentCord.Price) * notPricedOutputData.TrashPercent / 100), 2);

            var currentsSum = notPricedOutputData.CurrentProfile.Price +
                              notPricedOutputData.CurrentCrossProfile.Price +
                              notPricedOutputData.CurrentNet.Price +
                              notPricedOutputData.CurrentCord.Price +
                              notPricedOutputData.CurrentAngle.Price +
                              notPricedOutputData.CurrentMount.Price +
                              notPricedOutputData.CurrentCrossMount.Price +
                              notPricedOutputData.CurrentKnob.Price +
                              notPricedOutputData.CurrentExtraDetails.Select(detail => detail.Price).Sum() +
                              notPricedOutputData.RequiredExtraDetails.Select(detail => detail.Price).Sum() +
                              notPricedOutputData.TrashPrice +
                              notPricedOutputData.WorkPrice +
                              notPricedOutputData.OtherSpendingPrice +
                              gLuePrice;

            currentsSum += notPricedOutputData.CurrentExtraCrossProfile.Price;
            currentsSum += notPricedOutputData.CurrentCrossProfileWithGroove.Price;
            currentsSum += notPricedOutputData.CurrentExtraMount.Price;

            notPricedOutputData.TotalPrice = currentsSum;

            return(notPricedOutputData);
        }
コード例 #9
0
        public OutputWpfData UpdateExtraDetailCount(Guid id, decimal newCount, OutputWpfData oldData)
        {
            foreach (var extraDetail in oldData.CurrentExtraDetails.Where(extraDetail => extraDetail.Id == id))
            {
                extraDetail.Count = newCount;
            }

            return(Calculate(oldData));
        }
コード例 #10
0
        public OutputWpfData UpdateExtraDetailName(Guid id, string newName, OutputWpfData oldData)
        {
            foreach (var extraDetail in oldData.CurrentExtraDetails.Where(extraDetail => extraDetail.Id == id))
            {
                extraDetail.Name = newName;
            }

            return(Calculate(oldData));
        }
コード例 #11
0
 private void AddExtraDetailButton_Click(object sender, RoutedEventArgs e)
 {
     if (data == null)
     {
         return;
     }
     data = calculatorService.AddExtraDetail(data);
     RefreshFormValues();
 }
コード例 #12
0
        public OutputWpfData CheckExtraCrossProfileWithGroove(bool enabled, OutputWpfData oldData)
        {
            oldData.ExtraCrossProfileWithGrooveEnabled = enabled;

            if (oldData.ExtraCrossProfileWithGrooveEnabled)
            {
                oldData.ExtraCrossProfileEnabled = false;
            }

            return(Calculate(oldData));
        }
コード例 #13
0
        private void AdditionalCrossWithGrooveComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (data == null || e.AddedItems.Count == 0)
            {
                return;
            }
            var newValue = e.AddedItems[0] as string;

            data = calculatorService.ChangeExtraCrossProfileWithGroove(newValue, data);
            RefreshFormValues();
        }
コード例 #14
0
        private void ExtraMountComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (data == null || e.AddedItems.Count == 0)
            {
                return;
            }
            var newValue = e.AddedItems[0] as string;

            data = calculatorService.ChangeExtraMount(newValue, data);
            RefreshFormValues();
        }
コード例 #15
0
        private OutputWpfData CalculateKnobs(OutputWpfData notPricedOutputData)
        {
            var knobIm = notPricedOutputData.Knobs.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentKnob.Name);

            knobIm = knobIm ?? notPricedOutputData.Knobs.FirstOrDefault();
            notPricedOutputData.CurrentKnob.Name  = knobIm.Name;
            notPricedOutputData.CurrentKnob.Count = knobIm.Count;
            notPricedOutputData.CurrentKnob.Price = Math.Round(notPricedOutputData.CurrentKnob.Count * knobIm.PricePerCount, 2);

            return(notPricedOutputData);
        }
コード例 #16
0
        private void ExtraMountCountSingleUpDown_ValueChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            if (data == null)
            {
                return;
            }

            var newValue = e.NewValue;

            data = calculatorService.ChangeExtraMountCount(decimal.Parse(newValue.ToString()), data);
            RefreshFormValues();
        }
コード例 #17
0
        private void RemoveExtraDetailButton_Click(object sender, RoutedEventArgs e)
        {
            if (data == null)
            {
                return;
            }

            var button = (GridRowButton)sender;
            var itemId = button.ItemId;

            data = calculatorService.RemoveExtraDetail(itemId, data);
            RefreshFormValues();
        }
コード例 #18
0
        public OutputWpfData AddExtraDetail(OutputWpfData oldData)
        {
            var newExtraDetail = new CurrentExtraDetail
            {
                Id    = Guid.NewGuid(),
                Name  = oldData.ExtraDetails.Select(im => im.Name).FirstOrDefault(),
                Count = 1
            };

            oldData.CurrentExtraDetails.Add(newExtraDetail);

            return(Calculate(oldData));
        }
コード例 #19
0
        private OutputWpfData CalculateProfile(OutputWpfData notPricedOutputData)
        {
            var profileIm = notPricedOutputData.Profiles.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentProfile.Name);

            profileIm = profileIm ?? notPricedOutputData.Profiles.FirstOrDefault();
            notPricedOutputData.CurrentProfile.Name = profileIm.Name;
            var profileTolerance = notPricedOutputData.CurrentAngle.Inner ? 0 : notPricedOutputData.ProfileTolerance;

            notPricedOutputData.CurrentProfile.Count = Math.Round((notPricedOutputData.Width + notPricedOutputData.Height - (2 * profileTolerance)) / 500, 2);
            notPricedOutputData.CurrentProfile.Price = Math.Round(notPricedOutputData.CurrentProfile.Count * profileIm.PricePerCount, 2);

            return(notPricedOutputData);
        }
コード例 #20
0
        private OutputWpfData CalculateCrossProfiles(OutputWpfData notPricedOutputData)
        {
            var systemIm             = inputData.Systems.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentSystem.Name);
            var allowedCrossProfiles = inputData.CrossProfiles.Where(im => im.Systems.Contains(systemIm.Id)).ToList();

            notPricedOutputData.CrossProfiles           = allowedCrossProfiles.Where(im => !im.JointExists).ToList();
            notPricedOutputData.CrossProfilesWithGroove = allowedCrossProfiles.Where(im => im.JointExists).ToList();

            var crossProfileIm = notPricedOutputData.CrossProfiles.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentCrossProfile.Name);

            crossProfileIm = crossProfileIm ?? notPricedOutputData.CrossProfiles.FirstOrDefault();
            notPricedOutputData.CurrentCrossProfile.Name  = crossProfileIm.Name;
            notPricedOutputData.CurrentCrossProfile.Count = Math.Round((notPricedOutputData.Height - notPricedOutputData.CrossProfileTolerance) / 1000, 2);
            notPricedOutputData.CurrentCrossProfile.Price = Math.Round(notPricedOutputData.CurrentCrossProfile.Count * crossProfileIm.PricePerCount, 2);

            notPricedOutputData.CurrentExtraCrossProfile.Name  = notPricedOutputData.CurrentCrossProfile.Name;
            notPricedOutputData.CurrentExtraCrossProfile.Count = notPricedOutputData.CurrentCrossProfile.Count; // todo: move 4 to settings
            notPricedOutputData.CurrentExtraCrossProfile.Price = notPricedOutputData.CurrentCrossProfile.Price;
            if (!notPricedOutputData.ExtraCrossProfileEnabled)
            {
                notPricedOutputData.CurrentExtraCrossProfile.Price = 0;
            }

            var crossProfileWithGrooveIm = notPricedOutputData.CrossProfilesWithGroove.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentCrossProfileWithGroove.Name);

            crossProfileWithGrooveIm = crossProfileWithGrooveIm ?? notPricedOutputData.CrossProfilesWithGroove.FirstOrDefault();
            notPricedOutputData.CurrentCrossProfileWithGroove.Name  = crossProfileWithGrooveIm.Name;
            notPricedOutputData.CurrentCrossProfileWithGroove.Count = Math.Round((notPricedOutputData.Height - notPricedOutputData.CrossProfileTolerance + 4) / 1000, 2); // todo: move 4 to settings
            notPricedOutputData.CurrentCrossProfileWithGroove.Price = Math.Round(notPricedOutputData.CurrentCrossProfileWithGroove.Count * crossProfileWithGrooveIm.PricePerCount, 2);
            if (!notPricedOutputData.ExtraCrossProfileWithGrooveEnabled)
            {
                notPricedOutputData.CurrentCrossProfileWithGroove.Price = 0;
            }

            notPricedOutputData.ExtraCrossProfileAllowed           = notPricedOutputData.Width > 1600;  //todo: move to settings
            notPricedOutputData.ExtraCrossProfileWithGrooveAllowed = notPricedOutputData.Height > 1000; //todo: move to settings

            if (!notPricedOutputData.ExtraCrossProfileAllowed)
            {
                notPricedOutputData.ExtraCrossProfileEnabled = false;
            }

            if (!notPricedOutputData.ExtraCrossProfileWithGrooveAllowed)
            {
                notPricedOutputData.ExtraCrossProfileWithGrooveEnabled = false;
            }

            return(notPricedOutputData);
        }
コード例 #21
0
 public MainWindow()
 {
     calculatorService = new CalculatorService(new InputDataProvider("mosdb.xlsx"));
     InitializeComponent();
     try
     {
         data = calculatorService.GetDefault();
         RefreshFormValues();
     }
     catch (Exception)
     {
         MessageBox.Show("Something went wrong. Check you excel file");
         Close();
     }
 }
コード例 #22
0
        private OutputWpfData SetAllowedImProductsBySystem(OutputWpfData notPricedOutputData)
        {
            var systemIm = inputData.Systems.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentSystem.Name);

            notPricedOutputData.Angles               = inputData.Angles.Where(im => im.Systems.Contains(systemIm.Id)).ToList();
            notPricedOutputData.Cords                = inputData.Cords.Where(im => im.Systems.Contains(systemIm.Id)).ToList();
            notPricedOutputData.CrossProfiles        = inputData.CrossProfiles.Where(im => im.Systems.Contains(systemIm.Id)).ToList();
            notPricedOutputData.ExtraDetails         = inputData.ExtraDetails.Where(im => im.Systems.Contains(systemIm.Id)).ToList();
            notPricedOutputData.Mounts               = inputData.Mounts.Where(im => im.Systems.Contains(systemIm.Id)).ToList();
            notPricedOutputData.CrossMounts          = inputData.CrossMounts.Where(im => im.Systems.Contains(systemIm.Id)).ToList();
            notPricedOutputData.Knobs                = inputData.Knobs.Where(im => im.Systems.Contains(systemIm.Id)).ToList();
            notPricedOutputData.Nets                 = inputData.Nets.Where(im => im.Systems.Contains(systemIm.Id)).ToList();
            notPricedOutputData.Profiles             = inputData.Profiles.Where(im => im.Systems.Contains(systemIm.Id)).ToList();
            notPricedOutputData.ExtraMounts          = inputData.ExtraMounts.Where(im => im.Systems.Contains(systemIm.Id)).ToList();
            notPricedOutputData.RequiredExtraDetails = new List <CurrentExtraDetail>();

            return(notPricedOutputData);
        }
コード例 #23
0
        private void ExtraDetailName_ValueChanged(object sender, SelectionChangedEventArgs e)
        {
            if (data == null || e.AddedItems.Count == 0)
            {
                return;
            }

            var newValue = e.AddedItems[0] as string;
            var element  = (GridRowComboBox)sender;
            var itemId   = element.ItemId;

            if (itemId == Guid.Empty)
            {
                return;
            }

            data = calculatorService.UpdateExtraDetailName(itemId, newValue, data);
            RefreshFormValues();
        }
コード例 #24
0
        private void ExtraDetailCount_ValueChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            if (data == null)
            {
                return;
            }

            var newValue = e.NewValue;
            var element  = (GridRowSingleUpDown)sender;
            var itemId   = element.ItemId;

            if (itemId == Guid.Empty)
            {
                return;
            }

            data = calculatorService.UpdateExtraDetailCount(itemId, decimal.Parse(newValue.ToString()), data);
            RefreshFormValues();
        }
コード例 #25
0
        private OutputWpfData CalculateNet(OutputWpfData notPricedOutputData)
        {
            var netIm = notPricedOutputData.Nets.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentNet.Name);
            var netId = netIm == null?notPricedOutputData.Nets.FirstOrDefault().Id : netIm.Id;

            notPricedOutputData.Nets = notPricedOutputData.Nets
                                       .GroupBy(im => im.Id)
                                       .Select(ims => CalculateTheBestNetSize(ims.ToList(), notPricedOutputData.Width, notPricedOutputData.Height))
                                       .ToList();

            netIm = notPricedOutputData.Nets.FirstOrDefault(im => im.Id == netId);
            netIm = netIm ?? notPricedOutputData.Nets.FirstOrDefault();

            notPricedOutputData.CurrentNet.Name  = netIm.Name;
            notPricedOutputData.CurrentNet.Count = Math.Round(((notPricedOutputData.Width * notPricedOutputData.Height) / 1000000), 2);
            notPricedOutputData.CurrentNet.Price = Math.Round(notPricedOutputData.CurrentNet.Count * netIm.PricePerCount, 2);

            return(notPricedOutputData);
        }
コード例 #26
0
        private OutputWpfData CalculateExtraMounts(OutputWpfData notPricedOutputData)
        {
            var currentMountId = notPricedOutputData.Mounts.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentMount.Name).Id;

            notPricedOutputData.ExtraMounts = notPricedOutputData.ExtraMounts.Where(im => im.AllowedMounts.Contains(currentMountId)).ToList();

            int crossProfilesCount = 1;

            if (notPricedOutputData.ExtraCrossProfileEnabled)
            {
                crossProfilesCount = 2;
            }

            if (notPricedOutputData.ExtraCrossProfileWithGrooveEnabled)
            {
                crossProfilesCount = 3;
            }

            var extraMountIm = notPricedOutputData.ExtraMounts.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentExtraMount.Name);

            extraMountIm = extraMountIm ?? notPricedOutputData.ExtraMounts.FirstOrDefault();
            notPricedOutputData.CurrentExtraMount.Name  = extraMountIm.Name;
            notPricedOutputData.CurrentExtraMount.Count = extraMountIm.Count * crossProfilesCount;
            notPricedOutputData.CurrentExtraMount.Price = Math.Round(notPricedOutputData.CurrentExtraMount.Count * extraMountIm.PricePerCount, 2);

            if (extraMountIm.ClincherCount != 0)
            {
                var clincher = inputData.PackageDetails[(int)PackageDetail.Clincher];
                var count    = extraMountIm.ClincherCount * crossProfilesCount;
                notPricedOutputData.RequiredExtraDetails.Add(new CurrentExtraDetail
                {
                    Name  = clincher.Name + " (" + extraMountIm.Name + ")",
                    Count = count,
                    Price = clincher.PricePerCount * count
                });
            }

            return(notPricedOutputData);
        }
コード例 #27
0
        private OutputWpfData CalculateCrossMounts(OutputWpfData notPricedOutputData)
        {
            int crossProfilesCount = 1;

            if (notPricedOutputData.ExtraCrossProfileEnabled)
            {
                crossProfilesCount = 2;
            }

            if (notPricedOutputData.ExtraCrossProfileWithGrooveEnabled)
            {
                crossProfilesCount = 3;
            }

            var crossMountIm = notPricedOutputData.CrossMounts.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentCrossMount.Name);

            crossMountIm = crossMountIm ?? notPricedOutputData.CrossMounts.FirstOrDefault();
            notPricedOutputData.CurrentCrossMount.Name  = crossMountIm.Name;
            notPricedOutputData.CurrentCrossMount.Count = crossMountIm.Count * crossProfilesCount;
            notPricedOutputData.CurrentCrossMount.Price = Math.Round(notPricedOutputData.CurrentCrossMount.Count * crossMountIm.PricePerCount, 2);

            return(notPricedOutputData);
        }
コード例 #28
0
        private OutputWpfData CalculateAngles(OutputWpfData notPricedOutputData)
        {
            var angleIm = notPricedOutputData.Angles.FirstOrDefault(im => im.Name == notPricedOutputData.CurrentAngle.Name);

            angleIm = angleIm ?? notPricedOutputData.Angles.FirstOrDefault();
            notPricedOutputData.CurrentAngle.Name          = angleIm.Name;
            notPricedOutputData.CurrentAngle.Inner         = angleIm.Inner;
            notPricedOutputData.CurrentAngle.ClincherCount = angleIm.ClincherCount;
            notPricedOutputData.CurrentAngle.Count         = angleIm.Count;
            notPricedOutputData.CurrentAngle.Price         = Math.Round(notPricedOutputData.CurrentAngle.Count * angleIm.PricePerCount, 2);

            if (angleIm.ClincherCount != 0)
            {
                var clincher = inputData.PackageDetails[(int)PackageDetail.Clincher];
                notPricedOutputData.RequiredExtraDetails.Add(new CurrentExtraDetail
                {
                    Name  = clincher.Name + " (" + notPricedOutputData.CurrentAngle.Name + ")",
                    Count = angleIm.ClincherCount,
                    Price = clincher.PricePerCount * angleIm.ClincherCount
                });
            }

            return(notPricedOutputData);
        }
コード例 #29
0
        public OutputWpfData RemoveExtraDetail(Guid id, OutputWpfData oldData)
        {
            oldData.CurrentExtraDetails.Remove(oldData.CurrentExtraDetails.FirstOrDefault(detail => detail.Id == id));

            return(Calculate(oldData));
        }
コード例 #30
0
 public OutputWpfData ChangeWidth(decimal width, OutputWpfData oldData)
 {
     oldData.Width = width;
     return(Calculate(oldData));
 }