private void OkCommandExecute()
        {
            if (OkCommandCanExecute())
            {
                float price;
                if (this.SelectedTicket.Discount > 0 &&
                    DateTime.Now.Date >= this.SelectedTicket.DiscountFrom.Date &&
                    DateTime.Now.Date <= this.SelectedTicket.DiscountUntil.Date)
                {
                    price = this.SelectedTicket.Price - this.SelectedTicket.Price * this.SelectedTicket.Discount / 100;
                }
                else
                {
                    price = this.SelectedTicket.Price;
                }

                string interrogation = $"Total price: {price}. Continue?";

                if (MessageBox.Show(interrogation, "Confirm!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    ClientMembership clientMembership = new ClientMembership();
                    clientMembership.Active       = true;
                    clientMembership.Client       = this.Client;
                    clientMembership.ClientId     = this.Client.Id;
                    clientMembership.Comment      = "";
                    clientMembership.EntranceLeft = this.SelectedTicket.MaxEntrance;
                    clientMembership.Price        = price;
                    clientMembership.SoldOn       = DateTime.Now;
                    clientMembership.Ticket       = this.SelectedTicket;
                    clientMembership.TicketId     = this.SelectedTicket.Id;
                    clientMembership.User         = new User();
                    clientMembership.UserId       = 1;
                    clientMembership.ValidAfter   = this.SelectedDate;

                    if (Data.Catalog.AddClientMembership(clientMembership) == 1)
                    {
                        MessageBox.Show("Ticket sold!", "Succes!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        ViewService.CloseDialog(this);
                    }
                    else
                    {
                        MessageBox.Show("Error while selling ticket!", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else
            {
                this.ErrorMessage = "There are invalid or empty fields!";
            }
        }
Example #2
0
        public int AddClientMembership(ClientMembership clientMembership)
        {
            this.catalogDatabase.ClientMemberships.Add(clientMembership);

            try
            {
                this.catalogDatabase.SaveChanges();
            }
            catch (Exception e)
            {
                return(0);
            }

            return(1);
        }
Example #3
0
        public int DecreaseEntranceNumberByMembershipId(int membershipId)
        {
            ClientMembership tmp = this.catalogDatabase.ClientMemberships.Single(cm => cm.Id == membershipId);

            tmp.EntranceLeft = (short)(tmp.EntranceLeft - 1);
            try
            {
                this.catalogDatabase.SaveChanges();
            }
            catch (Exception e)
            {
                return(0);
            }

            return(1);
        }
Example #4
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            CURRENCY cur = EnumConverter.StringToCurrency(cbCurrency.Text);

            ClientMembership member = ClientMembership.Normal;

            switch (cbMember.Text)
            {
            case "Gold":
                member = ClientMembership.Gold;
                break;

            case "Platinum":
                member = ClientMembership.Platinum;
                break;
            }



            int age;

            int.TryParse(tbAge.Text, out age);
            decimal.TryParse(tbSetBalance.Text, out decimal blnc);
            try
            {
                _bank.AddNewClient(tbName.Text, tbSurname.Text, age, tbPhone.Text, tbMail.Text, cur, chkbEnabled.Checked, member, blnc);
                _bank.SaveClients();
                MessageBox.Show("Client Added!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                pnlRegistration.Visible = false;
                pnlAccountProp.Visible  = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #5
0
        private void CheckUserRegData(string name, string surname, int age, string phone, string mail, ClientMembership membership, CURRENCY currency)
        {
            Regex[] regex = new Regex[6];
            regex[0] = new Regex(@"^[A-z]{1,30}$");
            regex[1] = new Regex(@"^[+]994[55|50|51|70|77]{2}[0-9]{7}$");
            regex[2] = new Regex("^[_a-z0-9-]+(.[a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$", RegexOptions.IgnoreCase);
            regex[3] = new Regex(@"^[AZN|USD|EUR]{3}$");
            regex[4] = new Regex(@"^[Gold|Normal|Platinum]{4,8}$");

            if (!regex[0].IsMatch(name))
            {
                throw new ArgumentException("Wrong name!");
            }
            if (!regex[0].IsMatch(surname))
            {
                throw new ArgumentException("Wrong surname!");
            }
            if (!(Convert.ToInt32(age) > 18 && Convert.ToInt32(age) < 100))
            {
                throw new ArgumentException("Wrong age!");
            }
            if (!regex[2].IsMatch(mail))
            {
                throw new ArgumentException("Wrong mail!");
            }
            if (!regex[1].IsMatch(phone))
            {
                throw new ArgumentException("Wrong phone!");
            }
            if (!regex[3].IsMatch(currency.ToString()))
            {
                throw new ArgumentException("Wrong currency!");
            }
            if (!regex[4].IsMatch(membership.ToString()))
            {
                throw new ArgumentException("Wrong membership!");
            }
        }
Example #6
0
        public void AddNewClient(string name, string surname, int age, string phone, string mail, CURRENCY currency, bool enabled, ClientMembership membership, decimal balance = 0)
        {
            mail = mail.ToLower();
            try
            {
                CheckUserRegData(name, surname, age, phone, mail, membership, currency);
            }
            catch (Exception e)
            {
                throw e;
            }
            if (membership == ClientMembership.Platinum)
            {
                _clients.Add(new PlatinumClient(name, surname, age, phone, mail, currency, enabled, balance));
            }
            else if (membership == ClientMembership.Gold)
            {
                _clients.Add(new GoldenClient(name, surname, age, phone, mail, currency, enabled, balance));
            }
            else
            {
                _clients.Add(new Client(name, surname, age, phone, mail, currency, enabled, balance));
            }

            SetID(_clients[_clients.Count - 1]);
            SetAccount(_clients[_clients.Count - 1]);
        }