private void buttonEditStorage_Click(object sender, EventArgs e)
        {
            try
            {
                Button button = sender as Button;

                EditBox editStorage = new EditBox(button?.Text, _storage);

                editStorage.ShowDialog();

                if (editStorage.X < 0 || editStorage.Y < 0 || editStorage.Z < 0)
                {
                    throw new Exception(ErrorConstants.WRONG_STORAGE_SIZE);
                }

                if (editStorage.X < _storage.CargoType.X || editStorage.Y < _storage.CargoType.Y || editStorage.Z < _storage.CargoType.Z)
                {
                    throw new Exception(ErrorConstants.WRONG_STORAGE_SIZE);
                }

                _storage.Y = editStorage.Y;
                _storage.X = editStorage.X;
                _storage.Z = editStorage.Z;

                StorageInfoLoader.Save(_storage);

                ReloadInfo();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, ErrorConstants.ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void buttonAddCargoState_Click(object sender, EventArgs e)
        {
            try
            {
                AddStateInfo addState = new AddStateInfo();

                addState.ShowDialog();

                if (addState.ContainersCount < 0 || addState.ContainersCount > _storage.CalculateMaxCapacity())
                {
                    throw new Exception(ErrorConstants.WRONG_STORAGE_STATE);
                }

                StorageStateInfo info = new StorageStateInfo();

                info.TimeChange = addState.ArrivingTime;

                info.StorageFullness = addState.ContainersCount;

                info.StorageCapacity = _storage.CalculateMaxCapacity();

                _storage.AddChangeInfo(info);

                StorageInfoLoader.Save(_storage);

                ReloadInfo();
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, ErrorConstants.ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
 {
     try
     {
         if (_storage != null)
         {
             StorageInfoLoader.Save(_storage);
         }
     }
     catch (Exception exception)
     {
         MessageBox.Show(exception.Message, ErrorConstants.CRITICAL_ERROR, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }