예제 #1
0
        private void OnListDoubleClick(object sender, MouseButtonEventArgs e)
        {
            switch (((ListBox)sender).Name)
            {
            case "listBoxBoats":
                EditSingleItemDialog esd = new EditSingleItemDialog();
                string copyOfItemToEdit  = listBoxBoats.SelectedItems[0].ToString();
                esd.ItemForEditing = listBoxBoats.SelectedItems[0].ToString();
                esd.ItemType       = "name of boat";
                if ((bool)esd.ShowDialog())
                {
                    foreach (var item in listBoxBoats.Items)
                    {
                        if (item.ToString() == copyOfItemToEdit)
                        {
                            listBoxBoats.Items.Remove(item);
                            break;
                        }
                    }
                    listBoxBoats.Items.Add(esd.ItemForEditing);
                }
                break;

            case "listBoxGears":

                break;
            }
        }
예제 #2
0
        private void OnButtonClick(object sender, RoutedEventArgs e)
        {
            switch (((Button)sender).Name)
            {
            case "buttonCancel":
                Close();
                //((MainWindow)Owner).ChildFormClosed();
                break;

            case "buttonOk":
                if (textFisherName.Text.Length > 0 &&
                    listBoxBoats.Items.Count > 0 &&
                    listBoxGears.Items.Count > 0 &&
                    cboLandingSite.Text.Length > 0)
                {
                    bool proceed = true;
                    if ((bool)rbPhone.IsChecked || (bool)rbGPS.IsChecked)
                    {
                        proceed = cboDevice.Text.Length > 0;
                    }

                    if (proceed)
                    {
                        if (IsNew)
                        {
                            Fisher f = new Fisher {
                                Name = textFisherName.Text, FisherID = Entities.FisherViewModel.NextRecordNumber()
                            };
                            f.Gears = _gears;
                            foreach (string item in listBoxBoats.Items)
                            {
                                f.Vessels.Add(item);
                            }
                            if (Entities.FisherViewModel.AddRecordToRepo(f))
                            {
                                Close();
                                //((MainWindow)Owner).ChildFormClosed();
                            }
                        }
                        else
                        {
                            _fisher.Name = textFisherName.Text;
                            _fisher.Vessels.Clear();
                            foreach (string item in listBoxBoats.Items)
                            {
                                _fisher.Vessels.Add(item);
                            }
                            if (Entities.FisherViewModel.UpdateRecordInRepo(_fisher))
                            {
                                Close();
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please provide identifier of device assigned to fisher", "GPX Manager", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                }
                else
                {
                    MessageBox.Show("Please provide all the information that are asked", "GPX Manager", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                break;

            case "buttonDeleteGears":
                if (listBoxGears.SelectedItems.Count == 1)
                {
                    var g = _gears.FirstOrDefault(t => t.ToString() == listBoxGears.SelectedItem.ToString());
                    _gears.Remove(g);
                    listBoxGears.Items.Remove(listBoxGears.SelectedItem);
                }
                break;

            case "buttonAddGears":
                EditFisherBoat(_gears);
                break;

            case "buttonDeleteBoat":
                break;

            case "buttonAddBoat":
                EditSingleItemDialog esd = new EditSingleItemDialog();
                esd.ItemType = "name of boat";
                if ((bool)esd.ShowDialog())
                {
                    listBoxBoats.Items.Add(esd.ItemForEditing);
                }
                break;
            }
        }