private void InitializeWindow(ILotteryGameRepository lotteryGameRepository, IDrawRepository drawRepository, IDrawService drawService) { _window = new LotteryWindow(lotteryGameRepository, drawRepository, drawService); _window.Show(); _gameCombobox = _window.GetPrivateFieldValue <ComboBox>(); _fromDatePicker = _window.GetPrivateFieldValueByName <DatePicker>("FromDatePicker"); _untilDatePicker = _window.GetPrivateFieldValueByName <DatePicker>("UntilDatePicker"); _showDrawsButton = _window.GetPrivateFieldValueByName <Button>("ShowDrawsButton"); _newDrawButton = _window.GetPrivateFieldValueByName <Button>("NewDrawButton"); _drawsListView = _window.GetPrivateFieldValueByName <ListView>("DrawsListView"); }
/*! * \brief ButtonClick event handler for creating a new lottery session. * * If there is error in the input arguments, preventing the lottery from being * created, the function sets the error message and marks the area of * error by setting its label to a red color. * * \param sender Object that triggered the ButtonClick event. * \param e Event information. */ private void BtnCreate_Click(object sender, RoutedEventArgs e) { LabLotteryNumRange.Foreground = Brushes.Black; LabTicketPrice.Foreground = Brushes.Black; int lotteryNumMax; try { lotteryNumMax = int.Parse(TxtLotteryNumRangeMax.Text); } catch (FormatException) { LabLotteryNumRange.Foreground = Brushes.Red; TxtLabErrorMsg.Text = "Maximum lottery number is not a valid integer."; return; } if (lotteryNumMax < Lottery.LotteryNumberMin) { TxtLabErrorMsg.Text = "Maximum lottery cannot be less than " + Lottery.LotteryNumberMin + "."; return; } int ticketPrice; try { ticketPrice = int.Parse(TxtTicketPrice.Text); } catch (FormatException) { LabTicketPrice.Foreground = Brushes.Red; TxtLabErrorMsg.Text = "Ticket price is not a valid integer."; return; } if (ticketPrice < 0) { TxtLabErrorMsg.Text = "Ticket price cannot be negative."; return; } var resutt = LotteryWindow.InitNewLotteryModel(lotteryNumMax, ticketPrice); switch (resutt) { case WndMain.LotteryInitResult.Success: break; case WndMain.LotteryInitResult.InvalidNumberLimit: LabLotteryNumRange.Foreground = Brushes.Red; TxtLabErrorMsg.Text = Lottery.InvalidLotteryNumberErrorMsg; return; case WndMain.LotteryInitResult.InvalidTicketPrice: LabTicketPrice.Foreground = Brushes.Red; TxtLabErrorMsg.Text = Lottery.InvalidTicketPriceErrorMsg; return; case WndMain.LotteryInitResult.GeneralError: TxtLabErrorMsg.Text = "An unspecified error occured."; return; } IsCanceling = false; Owner.IsEnabled = true; Owner.Focus(); LotteryWindow.IgnoreSaveOnClosing = false; this.Close(); }