Exemple #1
0
        //------------------------------ EVENTHANDLERS --------------------------------------------------------

        /**
         * This eventhandler validates the user
         * as a buyer and returns a new window
         * if the validations checks out.
         * Validation fails if the buyer is the
         * seller of the salesSupply or if the
         * auction for the sales supply has
         * reach deadline. As a bonus if the
         * auction for the sales supply has
         * reached deadline and the buyer
         * has won the action, a dialog will
         * appear to inform the user, if the
         * user cliks on the auction.
         */
        private void AddBuyingOffer_DoubleClick(object sender, RoutedEventArgs e)
        {
            SalesSupply listItem      = ListBox.SelectedItem as SalesSupply;
            SalesSupply salesSupply   = _context.GetSalesSupply(listItem.Id);
            ContactInfo contactSeller = salesSupply.ContactInfo;

            if (contactSeller != null)
            {
                if (contactSeller != _buyerInfo && salesSupply.Deadline > DateTime.Now)
                {
                    BuyingOfferWindow offerWindow = new BuyingOfferWindow(this, salesSupply, _buyerInfo);
                    offerWindow.Show();
                    this.Hide();
                }
                else if (contactSeller == _buyerInfo)
                {
                    MessageBox.Show("Du kan ikke byde på dit eget salgsudbud.", "Fejlmeddelelse", MessageBoxButton.OK, MessageBoxImage.Stop);
                }
                else if (salesSupply.HighestBuyingOffer != null && salesSupply.HighestBuyingOffer.ContactInfo == _buyerInfo)
                {
                    MessageBox.Show("Tillykke! Du har vundet denne auktion.", "Lykønskning", MessageBoxButton.OK, MessageBoxImage.Information);
                }
                else
                {
                    MessageBox.Show("Tidsfristen er udløbet. Auktionen er lukket.", "Information", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
        public BuyingOfferWindow(MainWindow main, SalesSupply salesSupply, ContactInfo buyerInfo)
        {
            InitializeComponent();
            _main        = main;
            _context     = new AuctionDB();
            _salesSupply = _context.GetSalesSupply(salesSupply.Id);
            _buyerInfo   = _context.GetContactById(buyerInfo.Id);
            DataContext  = _salesSupply;

            // Set image.
            MetalImage.DataContext = _salesSupply.ImgPath;

            // Add text to binded labels.
            BindedMetalAmount.Content  = _salesSupply.MetalAmount + " gram";
            BindedPrice.Content        = _salesSupply.HighestPrice + " kr";
            BindedDeadline.DataContext = _salesSupply.DeadlineToString;
        }