Пример #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();
        }