132 lines
3.6 KiB
C#
132 lines
3.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Navigation;
|
|
using System.Windows.Shapes;
|
|
using WpfApp1.Obsluga;
|
|
|
|
namespace WpfApp1
|
|
{
|
|
/// <summary>
|
|
/// Logika interakcji dla klasy MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
Zapas zapas = new Zapas();
|
|
Magazyn magazyn = new Magazyn();
|
|
int id_Pracownik = 0;
|
|
DateTime dateTime = DateTime.Now;
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
{
|
|
InitializeComponent();
|
|
wybor.Text = "1";
|
|
ZaladujListe(zapas.produkts);
|
|
|
|
}
|
|
|
|
private void ZaladujListe(List<Produkt> produkts)
|
|
{
|
|
lista.Items.Clear();
|
|
foreach (Produkt produkt in produkts)
|
|
{
|
|
lista.Items.Add(produkt.Nazwa + " " + produkt.Id + " " + produkt.Cena + " " + "Ilość produktu w automacie: " + produkt.Ilosc + " (ta wartość jest podana roboczo)");
|
|
}
|
|
|
|
}
|
|
|
|
private void Ok_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
ZmiejszZapas(Convert.ToInt32(wybor.Text));
|
|
}
|
|
|
|
private void Panel_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
void ZmiejszZapas(int id)
|
|
{
|
|
foreach (Produkt aprodukt in zapas.produkts)
|
|
{
|
|
if (aprodukt.Id == id)
|
|
{
|
|
if (aprodukt.Ilosc >= 1)
|
|
{
|
|
aprodukt.Ilosc = aprodukt.Ilosc-1;
|
|
}
|
|
else
|
|
{
|
|
dateTime = DateTime.Now;
|
|
Dostawa(dateTime, aprodukt.Id);
|
|
}
|
|
}
|
|
}
|
|
ZaladujListe(zapas.produkts);
|
|
}
|
|
|
|
void Dostawa(DateTime dateTime, int id_towar)
|
|
{
|
|
//int id_Pracownik = 0;
|
|
|
|
if(dateTime.TimeOfDay.CompareTo(magazyn.Edmund.Koniec_pracy.TimeOfDay) <0)
|
|
{
|
|
id_Pracownik = magazyn.Edmund.Id;
|
|
}
|
|
else if(dateTime.TimeOfDay.CompareTo(magazyn.Maja.Koniec_pracy.TimeOfDay) < 0)
|
|
{
|
|
id_Pracownik = magazyn.Maja.Id;
|
|
}
|
|
|
|
if(id_Pracownik == 1)
|
|
{
|
|
Thread.Sleep(magazyn.Edmund.Czas);
|
|
foreach (Produkt aprodukt in zapas.produkts)
|
|
{
|
|
if (aprodukt.Id == id_towar)
|
|
{
|
|
{
|
|
aprodukt.Ilosc = 5;
|
|
}
|
|
}
|
|
}
|
|
ZaladujListe(zapas.produkts);
|
|
}
|
|
|
|
else
|
|
{
|
|
Thread.Sleep(magazyn.Maja.Czas);
|
|
foreach (Produkt aprodukt in zapas.produkts)
|
|
{
|
|
if (aprodukt.Id == id_towar)
|
|
{
|
|
{
|
|
aprodukt.Ilosc = 5;
|
|
}
|
|
}
|
|
}
|
|
ZaladujListe(zapas.produkts);
|
|
}
|
|
}
|
|
|
|
private void Wybor_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|