private void AddFieldsBy(TradePointRequest request)
        {
            List <TradePoint> tradePoints = TradePointsController.GetInstance().GetTradePoints();
            TradePoint        currTradePoint;

            try
            {
                currTradePoint = request.TradePoint == null?tradePoints.First() : tradePoints.Find(x => x.Id == request.TradePoint.Id);
            }
            catch (Exception ex)
            {
                currTradePoint = null;
            }
            ComboBox tradePointCB = GetComboBoxOnData(tradePoints.ToList <object>(), currTradePoint, "FullName");

            List <Product> products = ProductsController.GetInstance().GetProducts();
            Product        currProduct;

            try
            {
                currProduct = request.Product == null || request.Product.Product == null?products.First() : products.Find(x => x.Id == request.Product.Product.Id);
            }
            catch (Exception ex)
            {
                currProduct = null;
            }
            ComboBox productCB = GetComboBoxOnData(products.ToList <object>(), currProduct, "Name");

            List <Supplier> suppliers = SuppliersController.GetInstance().GetSuppliers();
            Supplier        currSupplier;

            try
            {
                currSupplier = request.Product == null || request.Product.Supplier == null?suppliers.First() : suppliers.Find(x => x.Id == request.Product.Supplier.Id);
            }
            catch (Exception ex)
            {
                currSupplier = null;
            }
            ComboBox supplierCB = GetComboBoxOnData(suppliers.ToList <object>(), currSupplier, "Name");

            int     count   = request.Product == null ? 0 : request.Product.Count;
            TextBox countTB = new TextBox()
            {
                Text = count.ToString(), Margin = new Thickness(5, 5, 5, 5), Width = 200
            };

            countTB.PreviewTextInput += NumberValidationTextBox;

            Elements.Children.Add(supplierCB);
            Elements.Children.Add(productCB);
            Elements.Children.Add(countTB);
            Elements.Children.Add(tradePointCB);

            comboBoxes.Add(supplierCB);
            comboBoxes.Add(productCB);
            comboBoxes.Add(tradePointCB);
            textBoxes.Add(countTB);
        }
Exemplo n.º 2
0
        public void UpdateList()
        {
            List <Supplier> suppliersList = SuppliersController.GetInstance().GetSuppliers();

            suppliersList.Sort((x, y) => x.Name.CompareTo(y.Name));
            suppliers = new ObservableCollection <Supplier>(suppliersList);

            SuppliersList.ItemsSource = suppliers;
            SuppliersList.Items.Refresh();
            SuppliersList.UpdateLayout();
        }
Exemplo n.º 3
0
        public SuppliesUC()
        {
            InitializeComponent();

            List <TradePoint> tradePointsList = TradePointsController.GetInstance().GetTradePoints();

            tradePointsList.Sort((x, y) => x.FullName.CompareTo(y.FullName));
            TradePoints = new ObservableCollection <TradePoint>(tradePointsList);

            Binding bind1 = new Binding();

            bind1.Source = TradePoints;
            TradePointComboBox.DisplayMemberPath = "FullName";
            TradePointComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind1);
            TradePoint = TradePoints.FirstOrDefault();
            TradePointComboBox.SelectedItem = TradePoint;

            List <Product> productsList = ProductsController.GetInstance().GetProducts();

            Products = new ObservableCollection <Product>(productsList);

            Binding bind2 = new Binding();

            bind2.Source = Products;
            ProductComboBox.DisplayMemberPath = "Name";
            ProductComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind2);
            Product = Products.FirstOrDefault();
            ProductComboBox.SelectedItem = Product;

            List <Supplier> suppliersList = SuppliersController.GetInstance().GetSuppliers();

            Suppliers = new ObservableCollection <Supplier>(suppliersList);

            Binding bind3 = new Binding();

            bind3.Source = Suppliers;
            SupplierComboBox.DisplayMemberPath = "Name";
            SupplierComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind3);
            Supplier = Suppliers.FirstOrDefault();
            SupplierComboBox.SelectedItem = Supplier;

            List <Order> ordersList = OrdersController.GetInstance().GetOrders();

            Orders = new ObservableCollection <Order>(ordersList);

            Binding bind4 = new Binding();

            bind4.Source = Orders;
            OrderComboBox.DisplayMemberPath = "Id";
            OrderComboBox.SetBinding(ComboBox.ItemsSourceProperty, bind4);
            Order = Orders.FirstOrDefault();
            OrderComboBox.SelectedItem = Order;
        }
        private void ApplyChangesBy(Supplier supplier)
        {
            supplier.Name = textBoxes[0].Text;

            if (supplier.Id < 0)
            {
                SuppliersController.GetInstance().AddSupplier(supplier);
            }
            else
            {
                SuppliersController.GetInstance().EditSupplier(supplier);
            }
        }
        private void AddFieldsBy(Order order)
        {
            DatePicker datePicker = new DatePicker()
            {
                SelectedDate = order.Date, IsDropDownOpen = false, Margin = new Thickness(5, 5, 5, 5), Width = 200
            };

            List <Product> products = ProductsController.GetInstance().GetProducts();
            Product        currProduct;

            try
            {
                currProduct = order.Product.Product == null?products.First() : products.Find(x => x.Id == order.Product.Product.Id);
            }
            catch (Exception ex)
            {
                currProduct = null;
            }
            ComboBox productCB = GetComboBoxOnData(products.ToList <object>(), currProduct, "Name");

            List <Supplier> suppliers = SuppliersController.GetInstance().GetSuppliers();
            Supplier        currSupplier;

            try
            {
                currSupplier = order.Product.Supplier == null?suppliers.First() : suppliers.Find(x => x.Id == order.Product.Supplier.Id);
            }
            catch (Exception ex)
            {
                currSupplier = null;
            }
            ComboBox supplierCB = GetComboBoxOnData(suppliers.ToList <object>(), currSupplier, "Name");

            TextBox countTB = new TextBox()
            {
                Text = order.Product.Count.ToString(), Margin = new Thickness(5, 5, 5, 5), Width = 200
            };

            countTB.PreviewTextInput += NumberValidationTextBox;

            Elements.Children.Add(datePicker);
            Elements.Children.Add(productCB);
            Elements.Children.Add(supplierCB);
            Elements.Children.Add(countTB);

            datePickers.Add(datePicker);
            comboBoxes.Add(productCB);
            comboBoxes.Add(supplierCB);
            textBoxes.Add(countTB);
        }
Exemplo n.º 6
0
 private void DeleteButton_Click(object sender, RoutedEventArgs e)
 {
     SuppliersController.GetInstance().DeleteSupplier(GetSupplierByButton(sender as Button));
     UpdateList();
 }