public static int correct(Booking booking) { if (booking.IsCorrection) { return(-1); } if (booking.Date > BookingsHelper.getDateOfLastCashClosure()) { return(-2); } int newSourceAccountID = booking.TargetAccount.AccountID; int newTargetAccountID = booking.SourceAccount.AccountID; double amount = booking.Amount; string description = "#" + booking.BookingID + " " + IniParser.GetSetting("ACCOUNTING", "negativeBooking") + booking.SourceAccount.Number + " -> " + booking.TargetAccount.Number + ": " + amount + IniParser.GetSetting("APPSETTINGS", "currency"); int bookingID = Booking.Add(newSourceAccountID, newTargetAccountID, amount, null, UserSession.userAccountID, description, true); if (bookingID < 0) { return(-3); } return(0); }
/// <summary> /// Definiert das DateRangePanel /// </summary> /// <param name="dateFromProcessingFunction">Funktion, die vom Start-DatePicker bei Änderung aufgerufen wird</param> /// <param name="dateToProcessingFunction">Funktion, die vom Ende-DatePicker bei Änderung aufgerufen wird</param> /// <param name="datePickerFrom">Referenz zum darzustellenden DatePicker für Start</param> /// <param name="datePickerTo">Referenz zum darzustellenden DatePicker für Ende</param> public DateRangePanel(Action <DateTime> dateFromProcessingFunction, Action <DateTime> dateToProcessingFunction, ref DatePicker datePickerFrom, ref DatePicker datePickerTo) { this.dateFromProcessingFunction = dateFromProcessingFunction; this.dateToProcessingFunction = dateToProcessingFunction; this.datePickerFrom = datePickerFrom; this.datePickerTo = datePickerTo; Label lbFrom = new Label(); Label lbTo = new Label(); lbFrom.Content = IniParser.GetSetting("APPSETTINGS", "dateRangeFrom"); lbTo.Content = IniParser.GetSetting("APPSETTINGS", "dateRangeTo"); lbTo.Margin = new Thickness(10, 0, 0, 0); this.datePickerFrom.Width = 95; this.datePickerTo.Width = 95; this.datePickerFrom.SelectedDate = BookingsHelper.getDateOfLastCashClosure(); this.datePickerTo.SelectedDate = DateTime.Today; this.datePickerFrom.SelectedDateChanged += processDateFrom; this.datePickerTo.SelectedDateChanged += processDateTo; panel = new WrapPanel(); panel.HorizontalAlignment = HorizontalAlignment.Right; panel.VerticalAlignment = VerticalAlignment.Top; panel.Margin = new Thickness(30, 10, 20, 0); // links nur 30px wegen Platzmangel in Toolbar von Modul pSums panel.Children.Add(lbFrom); panel.Children.Add(this.datePickerFrom); panel.Children.Add(lbTo); panel.Children.Add(this.datePickerTo); }
/// <summary> /// Datum zurücksetzen /// </summary> public void resetDateRange() { // Zeige standardmäßig alle Buchungen des jeweiligen Kontos vom letzten Kassenschluss bis jetzt an this.dateFrom = BookingsHelper.getDateOfLastCashClosure(); this.dateTo = BookingsHelper.makeDateGreat(DateTime.Today); this.datePickerFrom.SelectedDate = this.dateFrom; this.datePickerTo.SelectedDate = this.dateTo; }
/// <summary> /// Liste mit ungefilterten Daten generieren /// </summary> private void generateDataGridDataUnfiltered() { this.bookingModelsUnchanged.Clear(); IEnumerable <Booking> bookings = Booking.GetBookings(); DateTime lastCashClosure = BookingsHelper.getDateOfLastCashClosure(); foreach (var booking in bookings) { bookingModelsUnchanged.Add(new BookingDataGridModel(booking, lastCashClosure)); } }
/// <summary> /// Löscht eine Buchung /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Delete_Click(object sender, RoutedEventArgs e) { try { int bookingID = (int)((Button)sender).CommandParameter; List <Booking> booking = Booking.GetBookings(bookingID).ToList(); Booking currentBooking = booking[0]; if (currentBooking == null) { throw new Exception(); } string date = SafeStringParser.safeParseToStr(currentBooking.Date, true); string warning = IniParser.GetSetting("ACCOUNTING", "warningBookingDelete").Replace("{0}", date); if (MessageBoxEnhanced.Warning(warning) == MessageBoxResult.No) { return; } if (currentBooking.Date <= BookingsHelper.getDateOfLastCashClosure()) { throw new Exception(IniParser.GetSetting("ERRORMSG", "bookingBeforeLastClosure")); } Booking.Delete(currentBooking.BookingID); // Refresh page generateDataGridDataUnfiltered(); refreshDataGrid(this.bookingModelsUnchanged); } catch { MessageBoxEnhanced.Error(IniParser.GetSetting("ERRORMSG", "deleteBooking")); } }
/// <summary> /// Öffnet das Formular zum Bearbeiten einer Buchung /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Edit_Click(object sender, RoutedEventArgs e) { try { int bookingID = (int)((Button)sender).CommandParameter; List <Booking> booking = Booking.GetBookings(bookingID).ToList(); Booking currentBooking = booking[0]; if (currentBooking == null) { throw new Exception(IniParser.GetSetting("ERRORMSG", "loadBooking")); } if (currentBooking.IsCorrection) { throw new Exception(IniParser.GetSetting("ERRORMSG", "correctionEdit")); } if (Booking.GetBookings().Where(b => b.IsCorrection).Where(b => b.Description.Contains("#" + currentBooking.BookingID.ToString())).ToList().Count > 0) { throw new Exception(IniParser.GetSetting("ERRORMSG", "correctionExists")); } if (currentBooking.Date <= BookingsHelper.getDateOfLastCashClosure()) { throw new Exception(IniParser.GetSetting("ERRORMSG", "bookingBeforeLastClosure")); } MainWindow mainWindow = Application.Current.MainWindow as MainWindow; Type pageType = typeof(pEditBooking); mainWindow.switchPage(IniParser.GetSetting("ACCOUNTING", "editBooking"), pageType, currentBooking); } catch (Exception ex) { MessageBoxEnhanced.Error(ex.Message); } }