소스 검색

New Product pricing editor

Kenric Nugteren 2 년 전
부모
커밋
877170559c

+ 0 - 5
prs.classes/Entities/Customer/CustomerProduct.cs

@@ -2,11 +2,6 @@
 
 namespace Comal.Classes
 {
-    public enum ProductPriceType
-    {
-        FixedPrice,
-        CostPlus
-    }
 
     [UserTracking(typeof(Product))]
     public class CustomerProduct : Entity, IPersistent, IRemotable, IManyToMany<Customer, Product>, ILicense<ProductManagementLicense>, IExportable,

+ 4 - 1
prs.classes/Entities/Product/ProductPrice.cs

@@ -8,8 +8,11 @@ namespace Comal.Classes
         CostPlus
     }
 
-    public class ProductPrice :  BaseObject, IEnclosedEntity
+    public class ProductPrice : BaseObject, IEnclosedEntity
     {
+        [CheckBoxEditor]
+        public bool Chargeable { get; set; }
+
         [EnumLookupEditor(typeof(ProductPriceType))]
         public ProductPriceType PriceType { get; set; }
         

+ 215 - 0
prs.shared/Editors/ProductPriceEditor.cs

@@ -0,0 +1,215 @@
+using Comal.Classes;
+using InABox.DynamicGrid;
+using Syncfusion.Windows.Shared;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Media;
+
+namespace PRS.Shared
+{
+    public class ProductPriceEditorControl : DynamicEnclosedEditorControl<ProductPrice, ProductPriceEditor>
+    {
+
+        private Grid Grid;
+        private CheckBox Chargeable;
+        private Label PriceLabel;
+        private ComboBox PriceType;
+        private DoubleTextBox Price;
+
+        private ProductPrice ProductPrice = new();
+
+        public override void Configure()
+        {
+        }
+
+        protected override FrameworkElement CreateEditor()
+        {
+            Grid = new Grid();
+
+            Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
+            Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
+            Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
+            Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
+            Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
+            Grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
+
+            var chargeableLabel = new Label
+            {
+                Content = "Chargeable",
+                Margin = new Thickness(0, 0, 0, 0)
+            };
+            chargeableLabel.SetValue(Grid.ColumnProperty, 1);
+
+            Chargeable = new CheckBox
+            {
+                VerticalAlignment = VerticalAlignment.Center
+            };
+            Chargeable.Checked += Chargeable_Checked;
+            Chargeable.Unchecked += Chargeable_Checked;
+            Chargeable.SetValue(Grid.ColumnProperty, 0);
+
+            var typeLabel = new Label
+            {
+                Content = "Type:",
+                Margin = new Thickness(5, 0, 0, 0)
+            };
+            typeLabel.SetValue(Grid.ColumnProperty, 2);
+            PriceType = new ComboBox
+            {
+            };
+            PriceType.ItemsSource = Enum.GetValues<ProductPriceType>();
+            PriceType.SelectedValue = ProductPrice.PriceType;
+            PriceType.SelectionChanged += PriceType_SelectionChanged;
+            PriceType.SetValue(Grid.ColumnProperty, 3);
+
+            PriceLabel = new Label
+            {
+                Content = "Price:",
+                Margin = new Thickness(5, 0, 0, 0)
+            };
+            PriceLabel.SetValue(Grid.ColumnProperty, 4);
+            Price = new DoubleTextBox
+            {
+                VerticalContentAlignment = VerticalAlignment.Center,
+                HorizontalContentAlignment = HorizontalAlignment.Center,
+                VerticalAlignment = VerticalAlignment.Stretch
+            };
+            Price.ValueChanged += Price_ValueChanged;
+            Price.SetValue(Grid.ColumnProperty, 5);
+
+            Grid.Children.Add(chargeableLabel);
+            Grid.Children.Add(Chargeable);
+            Grid.Children.Add(typeLabel);
+            Grid.Children.Add(PriceType);
+            Grid.Children.Add(PriceLabel);
+            Grid.Children.Add(Price);
+
+            return Grid;
+        }
+
+        public override void SetValue(string property, object? value)
+        {
+            if (!property.StartsWith($"{ColumnName}.")) return;
+            property = property[(ColumnName.Length + 1)..];
+
+            if (property == nameof(ProductPrice.Chargeable) && value is bool b)
+            {
+                ProductPrice.Chargeable = b;
+                Chargeable.IsChecked = b;
+            }
+            else if (property == nameof(ProductPrice.Markup) && value is double markup)
+            {
+                ProductPrice.Markup = markup;
+                if (ProductPrice.PriceType == ProductPriceType.CostPlus)
+                {
+                    Price.Value = markup;
+                }
+            }
+            else if (property == nameof(ProductPrice.Price) && value is double price)
+            {
+                ProductPrice.Price = price;
+                if(ProductPrice.PriceType == ProductPriceType.FixedPrice)
+                {
+                    Price.Value = price;
+                }
+            }
+            else if (property == nameof(ProductPrice.PriceType) && value is ProductPriceType priceType)
+            {
+                ProductPrice.PriceType = priceType;
+                PriceType.SelectedValue = priceType;
+            }
+        }
+
+        public override object? GetValue(string property)
+        {
+            if (!property.StartsWith($"{ColumnName}.")) return null;
+            property = property[(ColumnName.Length + 1)..];
+
+            if (property == nameof(ProductPrice.Chargeable)) return ProductPrice.Chargeable;
+            if (property == nameof(ProductPrice.Markup)) return ProductPrice.Markup;
+            if (property == nameof(ProductPrice.Price)) return ProductPrice.Price;
+            if (property == nameof(ProductPrice.PriceType)) return ProductPrice.PriceType;
+
+            return null;
+        }
+
+        public override Dictionary<string, object?> GetValues()
+        {
+            return new Dictionary<string, object?>
+            {
+                { $"{ColumnName}.{nameof(ProductPrice.Chargeable)}", ProductPrice.Chargeable },
+                { $"{ColumnName}.{nameof(ProductPrice.Markup)}", ProductPrice.Markup },
+                { $"{ColumnName}.{nameof(ProductPrice.Price)}", ProductPrice.Price },
+                { $"{ColumnName}.{nameof(ProductPrice.PriceType)}", ProductPrice.PriceType }
+            };
+        }
+
+        private void Price_ValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+        {
+            var price = Price.Value ?? 0.0;
+            switch (ProductPrice.PriceType)
+            {
+                case ProductPriceType.FixedPrice:
+                    ProductPrice.Price = price;
+                    break;
+                case ProductPriceType.CostPlus:
+                    ProductPrice.Markup = price;
+                    break;
+            }
+            CheckChanged();
+        }
+
+        private void PriceType_SelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            if(PriceType.SelectedValue is ProductPriceType priceType)
+            {
+                ProductPrice.PriceType = priceType;
+                switch (priceType)
+                {
+                    case ProductPriceType.FixedPrice:
+                        PriceLabel.Content = "Price:";
+                        Price.Value = ProductPrice.Price;
+                        break;
+                    case ProductPriceType.CostPlus:
+                        PriceLabel.Content = "Markup:";
+                        Price.Value = ProductPrice.Markup;
+                        break;
+                }
+            }
+
+            CheckChanged();
+        }
+
+        private void Chargeable_Checked(object sender, RoutedEventArgs e)
+        {
+            ProductPrice.Chargeable = Chargeable.IsChecked == true;
+            CheckChanged();
+        }
+
+        public override int DesiredHeight()
+        {
+            return 25;
+        }
+
+        public override int DesiredWidth()
+        {
+            return int.MaxValue;
+        }
+
+        public override void SetColor(System.Windows.Media.Color color)
+        {
+            Price.Background = new SolidColorBrush(color);
+        }
+
+        public override void SetFocus()
+        {
+            Price.Focus();
+        }
+    }
+}

+ 0 - 1
prs.shared/PRS.Shared.csproj

@@ -4,7 +4,6 @@
     <TargetFramework>net6.0-windows</TargetFramework>
     <ImplicitUsings>enable</ImplicitUsings>
     <Nullable>enable</Nullable>
-	  <UseWindowsForms>true</UseWindowsForms>
 	  <UseWpf>true</UseWpf>
 	  <LangVersion>default</LangVersion>
   </PropertyGroup>

+ 1 - 0
prs.shared/Update.cs

@@ -12,6 +12,7 @@ using System.Linq;
 using System.Reflection;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
 
 namespace PRS.Shared
 {