Beispiel #1
0
        private void ButtonAdd_OnClick(object sender, RoutedEventArgs e)
        {
            var transports = new List <Transport>();

            for (int i = 1; i <= GridTransports.RowDefinitions.Count; i++)
            {
                string note = (WindowCosts.FindName("ComboBoxNotes_" + i) as ComboBox).Text;

                DirectoryNote directoryNote = null;

                if (!_bc.IsDirectoryNote(note))
                {
                    directoryNote = _bc.AddDirectoryNote(note);
                }
                else
                {
                    directoryNote = _bc.GetDirectoryNote(note);
                }

                string weightText = (WindowCosts.FindName("TextBoxWeight_" + i) as TextBox).Text;

                var transport = new Transport();

                transport.DirectoryRC   = (WindowCosts.FindName("ComboBoxRCs_" + i) as ComboBox).SelectedItem as DirectoryRC;
                transport.DirectoryNote = directoryNote;
                transport.Weight        = string.IsNullOrWhiteSpace(weightText) ? 0 : double.Parse(weightText);

                transports.Add(transport);
            }
            var currency = (Currency)Enum.Parse(typeof(Currency), ComboBoxCurrencies.SelectedItem.ToString());

            Date = DatePickerDate.SelectedDate.Value;

            if (!_isEdit)
            {
                _bc.AddInfoCosts(DatePickerDate.SelectedDate.Value, ComboBoxCostItems.SelectedItem as DirectoryCostItem,
                                 RadioButtonIncoming.IsChecked.Value,
                                 ComboBoxTransportCompanies.SelectedItem as DirectoryTransportCompany, double.Parse(TextBoxSumm.Text), currency,
                                 transports);

                ComboBoxNotes_1.ItemsSource = null;
                ComboBoxNotes_1.ItemsSource = _bc.GetDirectoryNotes().ToList();

                ClearForm();
                InitializeValidation(GridCosts.Children);
            }
            else
            {
                _bc.RemoveInfoCost(_infoCost);
                _bc.AddInfoCosts(DatePickerDate.SelectedDate.Value, ComboBoxCostItems.SelectedItem as DirectoryCostItem,
                                 RadioButtonIncoming.IsChecked.Value,
                                 ComboBoxTransportCompanies.SelectedItem as DirectoryTransportCompany, double.Parse(TextBoxSumm.Text), currency,
                                 transports);
            }

            this.Close();
        }
Beispiel #2
0
        private void RefreshFilters()
        {
            if (RCs == null || InOuts == null || TransportCompanies == null || Notes == null)
            {
                return;
            }

            SelectedRC               = RCs.First();
            SelectedInOut            = InOuts.First();
            SelectedTransportCompany = TransportCompanies.First();
            SelectedNote             = Notes.First();

            Filter();

            BC.DataContext.Configuration.AutoDetectChangesEnabled = false;

            RCs.Clear();
            var rcEmpty = new DirectoryRC {
                Name = null
            };

            RCs.Add(rcEmpty);

            foreach (var rc in Costs.Select(c => c.DirectoryRC).Distinct())
            {
                RCs.Add(rc);
            }

            InOuts.Clear();
            InOuts.Add("");

            if (Costs.Any(c => c.IsIncoming))
            {
                InOuts.Add("Приход");
            }

            if (Costs.Any(c => !c.IsIncoming))
            {
                InOuts.Add("Расход");
            }


            TransportCompanies.Clear();
            var transportCompanyEmpty = new DirectoryTransportCompany {
                Name = null
            };

            TransportCompanies.Add(transportCompanyEmpty);

            foreach (var transportCompany in Costs.Select(c => c.DirectoryTransportCompany).Where(t => t != null).Distinct())
            {
                TransportCompanies.Add(transportCompany);
            }


            Notes.Clear();
            var noteEmpty = new DirectoryNote {
                Description = null
            };

            Notes.Add(noteEmpty);

            foreach (var masNotes in Costs.Select(c => c.CurrentNotes.Select(n => n.DirectoryNote)))
            {
                foreach (var note in masNotes)
                {
                    if (!Notes.Contains(note))
                    {
                        Notes.Add(note);
                    }
                }
            }

            OrderNotes();

            BC.DataContext.Configuration.AutoDetectChangesEnabled = true;
        }
Beispiel #3
0
        public MonthCostsViewModel()
        {
            var firstWorkingArea = Screen.AllScreens[0].WorkingArea;

            MaxHeightForm = firstWorkingArea.Height - 100;

            _isNotTransportOnly = Privileges.HasAccess(UserPrivileges.CostsVisibility_IsNotTransportOnly);

            Costs = new ObservableCollection <InfoCost>();

            Years = new ObservableCollection <int>(BC.GetInfoCostYears());
            if (Years.Any())
            {
                SelectedYear = Years.Last();
            }

            IncomingsAndExpenses = new ObservableCollection <IncomingAndExpense>();
            IncomingsAndExpenses.Add(new IncomingAndExpense());

            ShowDayCostsCommand = new RelayCommand(ShowDayCosts);
            FilterCommand       = new RelayCommand(FilterShow);
            ReturnCommand       = new RelayCommand(Return);

            ReturnName       = "Компенсация";
            ReturnVisibility = Visibility.Collapsed;

            ReturnButtonVisibility = _isNotTransportOnly ? Visibility.Visible : Visibility.Collapsed;

            VisibilityCash = _isNotTransportOnly ? Visibility.Visible : Visibility.Collapsed;


            BC.DataContext.Configuration.AutoDetectChangesEnabled = false;

            CostItems = new ObservableCollection <DirectoryCostItem>(BC.GetDirectoryCostItems());
            var costItemEmpty = new DirectoryCostItem {
                Name = null
            };

            CostItems.Insert(0, costItemEmpty);

            InOuts = new ObservableCollection <string>
            {
                "",
                "Приход",
                "Расход"
            };
            SelectedInOut = InOuts.First();

            TransportCompanies = new ObservableCollection <DirectoryTransportCompany>(BC.GetDirectoryTransportCompanies());
            var transportCompanyEmpty = new DirectoryTransportCompany {
                Name = null
            };

            TransportCompanies.Insert(0, transportCompanyEmpty);
            SelectedTransportCompany = TransportCompanies.First();

            Notes = new ObservableCollection <DirectoryNote>(BC.GetDirectoryNotes().ToList());
            var noteEmpty = new DirectoryNote {
                Description = null
            };

            Notes.Insert(0, noteEmpty);

            SelectedNote = Notes.First();

            SelectedCostItem = CostItems.First();

            BC.DataContext.Configuration.AutoDetectChangesEnabled = true;

            InfoCost.OnChangeIsReturn += InfoCost_OnChangeIsReturn;
        }