예제 #1
0
        private static ObservableCollection <SimpleRecord> GetSimpleDictionary(
            DictionaryKind dictionary)
        {
            using (var connection =
                       new NpgsqlConnection(Configuration.ConnectionString))
            {
                connection.Open();
                using (var command = new NpgsqlCommand(
                           Queries.Dictionaries.SelectAll(dictionary), connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        if (!reader.HasRows)
                        {
                            return(null);
                        }
                        ObservableCollection <SimpleRecord> collection =
                            new ObservableCollection <SimpleRecord>();
                        while (reader.Read())
                        {
                            int    id   = reader.GetInt32(0);
                            string name = reader.GetString(1).TrimEnd();

                            collection.Add(new SimpleRecord(id, name));
                        }

                        return(collection);
                    }
                }
            }
        }
예제 #2
0
        public static List <string> GetNameList(
            DictionaryKind dictionary)
        {
            using (var connection =
                       new NpgsqlConnection(Configuration.ConnectionString))
            {
                connection.Open();
                using (var command = new NpgsqlCommand(
                           Queries.Dictionaries.SelectNameView(dictionary),
                           connection))
                {
                    using (var reader = command.ExecuteReader())
                    {
                        if (!reader.HasRows)
                        {
                            return(null);
                        }
                        List <string> collection = new List <string>();
                        while (reader.Read())
                        {
                            collection.Add(reader.GetString(0).TrimEnd(' '));
                        }

                        return(collection);
                    }
                }
            }
        }
예제 #3
0
        public static ObservableCollection <SimpleRecord> GetDictionary(
            DictionaryKind dictionary)
        {
            switch (dictionary)
            {
            case DictionaryKind.Hotel: return(GetHotels());

            case DictionaryKind.Ticket: return(GetTickets());

            case DictionaryKind.Agency: return(GetAgencies());

            default: return(GetSimpleDictionary(dictionary));
            }
        }
        public DictionaryRecordDialog(DictionaryKind dictionary, SimpleRecord record)
        {
            InitializeComponent();

            DictionaryRecordViewModel viewModel =
                new DictionaryRecordViewModel(dictionary, this, record);

            InputBoxes.ItemsSource = GenerateContent(dictionary, record);
            viewModel.MessageBoxDisplayRequested += (sender, e) =>
            {
                CustomMessageBox.Show(e.Title, e.Text);
            };
            DataContext = viewModel;
        }
예제 #5
0
        public DictionaryViewModel(DictionaryKind dictionary)
        {
            Dictionary = dictionary;
            switch (Dictionary)
            {
            case DictionaryKind.Transport:
                Title             = "Вид транспорта";
                IconKind          = PackIconKind.Aeroplane;
                GenerateTitleFunc = SimpleRecord.GenerateTitle;
                break;

            case DictionaryKind.City:
                Title             = "Города";
                IconKind          = PackIconKind.City;
                GenerateTitleFunc = SimpleRecord.GenerateTitle;
                break;

            case DictionaryKind.Ownership:
                Title             = "Тип собственности";
                IconKind          = PackIconKind.SecurityHome;
                GenerateTitleFunc = SimpleRecord.GenerateTitle;
                break;

            case DictionaryKind.Status:
                Title             = "Социальное положение";
                IconKind          = PackIconKind.TicketUser;
                GenerateTitleFunc = SimpleRecord.GenerateTitle;
                break;

            case DictionaryKind.Hotel:
                Title             = "Отели";
                IconKind          = PackIconKind.Hotel;
                GenerateTitleFunc = Hotel.GenerateTitle;
                break;

            case DictionaryKind.Ticket:
                Title             = "Проездные билеты";
                IconKind          = PackIconKind.Cards;
                GenerateTitleFunc = Ticket.GenerateTitle;
                break;

            case DictionaryKind.Agency:
                Title             = "Агенства";
                IconKind          = PackIconKind.OfficeBuilding;
                GenerateTitleFunc = Agency.GenerateTitle;
                break;
            }

            UpdateCollection();
        }
예제 #6
0
 public static string Delete(DictionaryKind dictionary,
                             SimpleRecord record) =>
 $"select delete_{dictionary}({record.GetId()})";
예제 #7
0
 public static string Update(DictionaryKind dictionary,
                             SimpleRecord record) =>
 $"select update_{dictionary}" +
 $"({record.GetIdentifiedParameterList()})";
예제 #8
0
 public static string Insert(DictionaryKind dictionary,
                             SimpleRecord record) =>
 $"select insert_{dictionary}({record.GetParameterList()})";
예제 #9
0
 public static string SelectAll(DictionaryKind dictionary) =>
 $"select * from {dictionary}_view";
예제 #10
0
 public static string SelectNameView(DictionaryKind dictionary) =>
 $"select * from {dictionary}_name_view";
        private UIElement[] GenerateContent(DictionaryKind dictionary, SimpleRecord record)
        {
            List <UIElement> inputs = new List <UIElement>();
            TextBox          textBox;
            ComboBox         comboBox;
            Grid             content;

            switch (dictionary)
            {
            case DictionaryKind.Hotel:
                textBox = new TextBox();
                textBox.SetBinding(TextBox.TextProperty,
                                   new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(Hotel.Name))
                {
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(textBox, Hotel.GenerateTitle(nameof(Hotel.Name)));
                inputs.Add(textBox);

                comboBox = new ComboBox {
                    Margin = new Thickness(0, 10, 0, 0)
                };

                comboBox.SetBinding(Selector.SelectedItemProperty,
                                    new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(Hotel.City))
                {
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(comboBox, Hotel.GenerateTitle(nameof(Hotel.City)));
                comboBox.ItemsSource = Hotel.Empty.Equals(record)
                        ? Dictionaries.GetNameList(DictionaryKind.City)
                        : new List <string> {
                    ((Hotel)record).City
                };
                inputs.Add(comboBox);

                var stackPanel = new StackPanel
                {
                    Orientation = Orientation.Horizontal,
                    Margin      = new Thickness(0, 20, 0, 0)
                };
                stackPanel.Children.Add(new TextBlock
                {
                    Text   = Hotel.GenerateTitle(nameof(Hotel.Type)) + ":",
                    Margin = new Thickness(0, 0, 10, 0)
                });
                RatingBar ratingBar = new RatingBar {
                    Max = 5
                };
                ratingBar.SetBinding(RatingBar.ValueProperty,
                                     new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(Hotel.Type))
                {
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                stackPanel.Children.Add(ratingBar);
                inputs.Add(stackPanel);
                break;

            case DictionaryKind.Ticket:
                comboBox = new ComboBox();
                comboBox.SetBinding(Selector.SelectedItemProperty,
                                    new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(Ticket.Name))
                {
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(comboBox, Ticket.GenerateTitle(nameof(Ticket.Name)));
                comboBox.ItemsSource = Ticket.Empty.Equals(record)
                        ? Dictionaries.GetNameList(DictionaryKind.Transport)
                        : new List <string> {
                    ((Ticket)record).Name
                };
                inputs.Add(comboBox);

                content = new Grid {
                    Margin = new Thickness(0, 10, 0, 0)
                };
                content.ColumnDefinitions.Add(new ColumnDefinition());
                content.ColumnDefinitions.Add(new ColumnDefinition
                {
                    Width = GridLength.Auto
                });
                content.ColumnDefinitions.Add(new ColumnDefinition());

                comboBox = new ComboBox();
                comboBox.SetBinding(Selector.SelectedItemProperty,
                                    new Binding(nameof(DictionaryRecordViewModel.Record) +
                                                '.' + nameof(Ticket.From))
                {
                    UpdateSourceTrigger =
                        UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(comboBox,
                                   Ticket.GenerateTitle(nameof(Ticket.From)));
                comboBox.ItemsSource = Ticket.Empty.Equals(record)
                        ? Dictionaries.GetNameList(DictionaryKind.City)
                        : new List <string> {
                    ((Ticket)record).From
                };
                comboBox.SetValue(Grid.ColumnProperty, 0);
                content.Children.Add(comboBox);

                TextBlock textBlock = new TextBlock {
                    Width = 10
                };
                textBlock.SetValue(Grid.ColumnProperty, 1);
                content.Children.Add(textBlock);

                comboBox = new ComboBox();
                comboBox.SetBinding(Selector.SelectedItemProperty,
                                    new Binding(nameof(DictionaryRecordViewModel.Record) +
                                                '.' + nameof(Ticket.To))
                {
                    UpdateSourceTrigger =
                        UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(comboBox,
                                   Ticket.GenerateTitle(nameof(Ticket.To)));
                comboBox.ItemsSource = Ticket.Empty.Equals(record)
                        ? Dictionaries.GetNameList(DictionaryKind.City)
                        : new List <string> {
                    ((Ticket)record).To
                };
                comboBox.SetValue(Grid.ColumnProperty, 2);
                content.Children.Add(comboBox);
                inputs.Add(content);

                textBox = new TextBox {
                    Margin = new Thickness(0, 10, 0, 0)
                };
                textBox.SetBinding(TextBox.TextProperty,
                                   new Binding(nameof(DictionaryRecordViewModel.Record) +
                                               '.' + nameof(Ticket.Cost))
                {
                    UpdateSourceTrigger =
                        UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(textBox,
                                   Ticket.GenerateTitle(nameof(Ticket.Cost)));
                inputs.Add(textBox);
                break;

            case DictionaryKind.Agency:
                textBox = new TextBox();
                textBox.SetBinding(TextBox.TextProperty,
                                   new Binding(nameof(DictionaryRecordViewModel.Record) +
                                               '.' + nameof(Agency.Name))
                {
                    UpdateSourceTrigger =
                        UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(textBox,
                                   Agency.GenerateTitle(nameof(Agency.Name)));
                inputs.Add(textBox);

                content = new Grid {
                    Margin = new Thickness(0, 10, 0, 0)
                };
                content.ColumnDefinitions.Add(new ColumnDefinition());
                content.ColumnDefinitions.Add(new ColumnDefinition
                {
                    Width = GridLength.Auto
                });

                textBox = new TextBox();
                textBox.SetBinding(TextBox.TextProperty,
                                   new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(Agency.Registration))
                {
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(textBox,
                                   Agency.GenerateTitle(nameof(Agency.Registration)));
                textBox.SetValue(Grid.ColumnProperty, 0);
                content.Children.Add(textBox);

                DatePicker datePicker = new DatePicker
                {
                    Margin = new Thickness(10, 0, 0, 0)
                };
                datePicker.SetBinding(DatePicker.SelectedDateProperty,
                                      new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(Agency.Date))
                {
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(datePicker,
                                   Agency.GenerateTitle(nameof(Agency.Date)));
                datePicker.SetValue(Grid.ColumnProperty, 1);
                content.Children.Add(datePicker);
                inputs.Add(content);

                content = new Grid {
                    Margin = new Thickness(0, 10, 0, 0)
                };
                content.ColumnDefinitions.Add(new ColumnDefinition
                {
                    Width = GridLength.Auto
                });
                content.ColumnDefinitions.Add(new ColumnDefinition());

                comboBox = new ComboBox {
                    Margin = new Thickness(0, 0, 10, 0), MinWidth = 60
                };
                comboBox.SetBinding(Selector.SelectedItemProperty,
                                    new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(Agency.City))
                {
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(comboBox, Agency.GenerateTitle(nameof(Agency.City)));
                comboBox.ItemsSource = Dictionaries.GetNameList(DictionaryKind.City);
                comboBox.SetValue(Grid.ColumnProperty, 0);
                content.Children.Add(comboBox);

                textBox = new TextBox();
                textBox.SetBinding(TextBox.TextProperty,
                                   new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(Agency.Address))
                {
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(textBox,
                                   Agency.GenerateTitle(nameof(Agency.Address)));
                textBox.SetValue(Grid.ColumnProperty, 1);
                content.Children.Add(textBox);
                inputs.Add(content);

                comboBox = new ComboBox {
                    Margin = new Thickness(0, 10, 0, 0)
                };
                comboBox.SetBinding(Selector.SelectedItemProperty,
                                    new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(Agency.Ownership))
                {
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(comboBox, Agency.GenerateTitle(nameof(Agency.Ownership)));
                comboBox.ItemsSource = Dictionaries.GetNameList(DictionaryKind.Ownership);
                inputs.Add(comboBox);

                textBox = new TextBox {
                    Margin = new Thickness(0, 10, 0, 0), MaxLength = 12
                };
                textBox.SetBinding(TextBox.TextProperty,
                                   new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(Agency.Phone))
                {
                    UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                    Mode = BindingMode.TwoWay
                });
                HintAssist.SetHint(textBox,
                                   Agency.GenerateTitle(nameof(Agency.Phone)));
                inputs.Add(textBox);
                break;

            default:
            {
                textBox = new TextBox();
                textBox.SetBinding(TextBox.TextProperty,
                                   new Binding(nameof(DictionaryRecordViewModel.Record) + '.' + nameof(DictionaryRecordViewModel.Record.Name))
                    {
                        UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged,
                        Mode = BindingMode.TwoWay
                    });
                HintAssist.SetHint(textBox, SimpleRecord.GenerateTitle());
                inputs.Add(textBox);
                break;
            }
            }

            return(inputs.ToArray());
        }