Esempio n. 1
0
        private void btnAccept_Click(object sender, EventArgs e)
        {
            cardNum = txtCardNumber.Text;
            string pin = txtPin.Text;

            if (_cardRepository.CheckLogin(cardNum, pin))
            {
                accId = _cardRepository.getAccId(cardNum);
                if (_accountRepository.CheckIfIdExists(accId))
                {
                    pnlLogin.Visible        = false;
                    pnlATMFunctions.Visible = true;
                    lblInfoText.Visible     = false;
                }
                else
                {
                    lblInfoText.Text    = $"Neexistujúci účet";
                    lblInfoText.Visible = true;
                }
            }
            else
            {
                _counter--;
                if (!cardNum.Equals(_prevCard))
                {
                    _counter = 2;
                }
                lblInfoText.Text    = $"Nesprávne údaje\nZostávajúce pokusy: {_counter}";
                lblInfoText.Visible = true;
                _prevCard           = cardNum;
            }
            if (_counter <= 0)
            {
                lblInfoText.Text    = $"Príliš veľa pokusov\nKarta je zablokovaná";
                lblInfoText.Visible = true;
                _cardRepository.BlockCard(cardNum);
            }
        }
        private void btnAccept_Click(object sender, EventArgs e)
        {
            //checks if sender id is inserted
            int idSender = 0;

            if (txtSender.Text.Length > 0)
            {
                idSender = int.Parse(txtSender.Text);
            }
            //checks if recipient id is inserted
            int idRecipient = 0;

            if (txtRecipient.Text.Length > 0)
            {
                idRecipient = int.Parse(txtRecipient.Text);
            }
            //checks if sum is inserted
            decimal sum = 0;

            if (txtSum.Text.Length > 0)
            {
                sum = decimal.Parse(txtSum.Text);
            }
            bool senderExists = false;

            //checks if sender is bank or exists in database
            if (idSender == -99)
            {
                senderExists = true;
            }
            else
            {
                senderExists = _bankAccountRepository.CheckIfIdExists(idSender);
            }
            bool recipientExists = false;

            //checks if recipient is bank or exists in database
            if (idRecipient == -99)
            {
                recipientExists = true;
            }
            else
            {
                recipientExists = _bankAccountRepository.CheckIfIdExists(idRecipient);
            }
            bool senderHasMoney = false;

            if (!recipientExists)
            {
                lblInfoText.Text    = "Prijímateľ neexistuje";
                lblInfoText.Visible = true;
            }
            if (!senderExists)
            {
                lblInfoText.Text    = "Odosielateľ neexistuje";
                lblInfoText.Visible = true;
            }
            //checks if sender has enough money or is bank
            else
            {
                if (idSender == -99)
                {
                    senderHasMoney = true;
                }
                else
                {
                    senderHasMoney = _bankAccountRepository.CheckIfEnoughMoney(idSender, sum);
                }
                if (!senderHasMoney)
                {
                    lblInfoText.Text    = "Odosielateľ nemá \ndostatok peňazí";
                    lblInfoText.Visible = true;
                }
            }
            //performs insert of transaction into database
            if (senderExists && recipientExists && senderHasMoney)
            {
                _transactionRepository.Transaction.Amount       = sum;
                _transactionRepository.Transaction.SenderID     = idSender;
                _transactionRepository.Transaction.RecipientID  = idRecipient;
                _transactionRepository.Transaction.Time         = DateTime.Now;
                _transactionRepository.Transaction.VS           = txtVS.Text;
                _transactionRepository.Transaction.KS           = txtKS.Text;
                _transactionRepository.Transaction.SS           = txtSS.Text;
                _transactionRepository.Transaction.TransMessage = txtMessage.Text;
                if (_transactionRepository.InsertTransaction(_transactionRepository.Transaction) > 0)
                {
                    if (idSender != -99)
                    {
                        //substracts money from sender account
                        _bankAccountRepository.SubstractMoney(idSender, _transactionRepository.Transaction.Amount);
                    }
                    if (idRecipient != -99)
                    {
                        //adds money to recipient account
                        _bankAccountRepository.AddMoney(idRecipient, _transactionRepository.Transaction.Amount);
                    }
                }
                DialogResult = DialogResult.OK;
            }
        }