117 lines
3.5 KiB
C#
117 lines
3.5 KiB
C#
// Copyright (c) 2023 schick Informatik
|
|
// Description: Administration screen for ships
|
|
//
|
|
|
|
|
|
using BreCalClient.misc.Api;
|
|
using BreCalClient.misc.Model;
|
|
using System;
|
|
using System.Windows;
|
|
|
|
namespace BreCalClient
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ShipListDialog.xaml
|
|
/// </summary>
|
|
public partial class ShipListDialog : Window
|
|
{
|
|
public ShipListDialog()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#region Properties
|
|
|
|
public ShipApi? ShipApi { get; set; }
|
|
|
|
#endregion
|
|
|
|
#region Event handler
|
|
|
|
private void buttonClose_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
private void Window_Loaded(object sender, RoutedEventArgs e)
|
|
{
|
|
this.dataGridShips.Initialize();
|
|
this.dataGridShips.ItemsSource = BreCalLists.AllShips;
|
|
|
|
this.dataGridShips.CreateRequested += DataGridShips_CreateRequested; ;
|
|
this.dataGridShips.EditRequested += DataGridShips_EditRequested;
|
|
this.dataGridShips.DeleteRequested += DataGridShips_DeleteRequested;
|
|
}
|
|
|
|
private async void DataGridShips_DeleteRequested(object obj)
|
|
{
|
|
if (obj is ShipModel shipmodel)
|
|
{
|
|
if(this.ShipApi != null)
|
|
await this.ShipApi.ShipDeleteAsync(shipmodel.Ship.Id);
|
|
BreCalLists.Ships.Remove(shipmodel); // remove from "selectable" ships
|
|
shipmodel.Ship.Deleted = true; // set deleted marker on working instance
|
|
}
|
|
}
|
|
|
|
private async void DataGridShips_EditRequested(object obj)
|
|
{
|
|
if (obj is ShipModel shipmodel)
|
|
{
|
|
EditShipDialog esd = new()
|
|
{
|
|
Ship = shipmodel.Ship
|
|
};
|
|
esd.Participants.AddRange(BreCalLists.Participants_Tug);
|
|
|
|
if (esd.ShowDialog() ?? false)
|
|
{
|
|
try
|
|
{
|
|
if (this.ShipApi != null)
|
|
{
|
|
Id tmpId = await this.ShipApi.ShipUpdateAsync(shipmodel.Ship);
|
|
}
|
|
this.dataGridShips.ItemsSource = null;
|
|
this.dataGridShips.ItemsSource = BreCalLists.AllShips;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void DataGridShips_CreateRequested()
|
|
{
|
|
ShipModel shipModel = new ShipModel(new Ship());
|
|
EditShipDialog esd = new()
|
|
{
|
|
Ship = shipModel.Ship
|
|
};
|
|
esd.Participants.AddRange(BreCalLists.Participants_Tug);
|
|
|
|
if(esd.ShowDialog() ?? false)
|
|
{
|
|
try
|
|
{
|
|
this.ShipApi?.ShipsCreateAsync(shipModel.Ship);
|
|
this.dataGridShips.ItemsSource = null;
|
|
BreCalLists.AllShips.Add(shipModel);
|
|
BreCalLists.Ships.Add(shipModel);
|
|
this.dataGridShips.ItemsSource = BreCalLists.AllShips;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
}
|