Exemplo n.º 1
0
    protected override void OnPreRender(EventArgs e)
    {
        int idCurrency = 1;

        int.TryParse(rblMena.SelectedValue, out idCurrency);
        var currency = _dropDownData.Currencies.First(x => x.Id == idCurrency);

        lblMena.Text = currency.Name;

        var now = DateTime.UtcNow;

        foreach (var item in _dropDownData.Poplatky)
        {
            item.CostString = currency.FormatMoney(item.Amount);
            item.CssClass   = (item.From ?? now) <= now && now <= (item.To ?? now) ? "currentFee" : "";
        }
        gridPoplatky.DataSource = _dropDownData.Poplatky.Where(x => x.Online);
        gridPoplatky.DataBind();

        gridPoplatkyNaMieste.DataSource = _dropDownData.Poplatky.Where(x => !x.Online);
        gridPoplatkyNaMieste.DataBind();

        float sum   = 0;
        bool  valid = true;

        for (int i = 0; i < _data.Count; i++)
        {
            _data[i]    = _controls[i].Data;
            _data[i].Id = _indices[i];
            _tabPanels[i].HeaderText = _data[i].Title;
            _controls[i].Currency    = currency;
            _data[i].Currency        = currency;
            _data[i].Single          = _data.Count == 1;
            _controls[i].Single      = _data.Count == 1;
            var cost = _data[i].GetCost(_dropDownData.Sluziaci, _dropDownData.Poplatky);
            sum += cost;
            _data[i].CostString = currency.FormatMoney(cost);
            valid = valid && _data[i].Valid;
        }

        trPayerEmail.Visible = _data.Count > 1;

        txtEmail.CssClass = "";
        if (_data.Count > 1 && !Common.ValidateEmail(txtEmail.Text.Trim()))
        {
            valid             = false;
            txtEmail.CssClass = "errorBorder";
        }

        var payerEmail = _data.Count > 1 ? txtEmail.Text.Trim().ToLower() : _data[0].Email.Trim().ToLower();

        txtCaptcha.CssClass = "";
        if (txtCaptcha.Text != "")
        {
            valid = false;
            txtCaptcha.CssClass = "errorBorder";
        }

        float sponzorskyDar = 0;

        txtDar.CssClass = "";
        if (!string.IsNullOrWhiteSpace(txtDar.Text))
        {
            if (!float.TryParse(txtDar.Text, out sponzorskyDar))
            {
                txtDar.CssClass = "errorBorder";
                valid           = false;
            }
            if (sponzorskyDar < 0)
            {
                sponzorskyDar = 0;
            }
        }

        var amountToPay = sum + sponzorskyDar / currency.Rate;

        lblSuma.Text = currency.FormatMoney(amountToPay);

        if (!chbGdprConsent.Checked)
        {
            valid = false;
        }
        lblGdprMissing.Visible = !chbGdprConsent.Checked;

        // check for duplicate emails
        var emailHash = new Dictionary <string, int>();

        foreach (var item in _data)
        {
            var email = item.Email.Trim().ToLower();
            if (string.IsNullOrWhiteSpace(email))
            {
                continue;
            }
            emailHash[email] = emailHash.ContainsKey(email) ? emailHash[email] + 1 : 1;
        }
        foreach (var item in emailHash)
        {
            if (item.Value > 1)
            {
                valid = false;
                for (int i = 0; i < _data.Count; i++)
                {
                    if (_data[i].Email.Trim().ToLower() == item.Key)
                    {
                        _data[i].Errors.Add(Common.ChybaEmailSaOpakuje);
                    }
                }
            }
        }

        lblResult.Text = "";
        if (valid && _registerClicked)
        {
            try
            {
                var emails = new List <Email>();

                if (_data.Count == 1)
                {
                    emails.Add(new Email(payerEmail, Emails.RegistrationSubject, Emails.GetSingle(_data[0], amountToPay, currency)));
                }
                else
                {
                    var payerIsRegistered = false;
                    for (var i = 0; i < _data.Count; i++)
                    {
                        _data[i].Email = _data[i].Email.Trim().ToLower();
                        if (payerEmail == _data[i].Email)
                        {
                            payerIsRegistered = true;
                            emails.Add(new Email(payerEmail, Emails.RegistrationSubject, Emails.GetMultiplePayerRegistered(_data, i, amountToPay, currency)));
                        }
                        else
                        {
                            emails.Add(new Email(_data[i].Email, Emails.RegistrationSubject, Emails.GetMultiple(_data[i], payerEmail)));
                        }
                    }
                    if (!payerIsRegistered)
                    {
                        emails.Add(new Email(payerEmail, Emails.RegistrationSubject, Emails.GetMultiplePayerNotRegistered(_data, amountToPay, currency, payerEmail)));
                    }
                }

                // write to database
                var data = Database.WriteData(_data, emails, payerEmail, sponzorskyDar, currency);
                if (data.Success)
                {
                    _success = true;
                }
                else
                {
                    // there are bad emails
                    valid = false;
                    foreach (var item in data.AlreadyRegisteredEmails)
                    {
                        for (int i = 0; i < _data.Count; i++)
                        {
                            if (_data[i].Email.Trim().ToLower() == item.Trim().ToLower())
                            {
                                _data[i].Errors.Add(Common.ChybaEmailUzZaregistrovany);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblResult.Text = ex.Message + " " + ex.InnerException;
            }
        }

        gridSummary.DataSource = _data;
        gridSummary.DataBind();

        pnlRegistration.Visible = !_success && !pnlRegistrationDone.Visible;
        pnlSuccess.Visible      = _success && !pnlRegistrationDone.Visible;

        base.OnPreRender(e);
    }
Exemplo n.º 2
0
    protected override void OnPreRender(EventArgs e)
    {
        for (int i = 0; i < _controls.Count; i++)
        {
            if (_controls[i].DeleteClicked && i >= 0 && i < _data.Count)
            {
                _data.RemoveAt(i);
                _countChanged = true;
            }
        }

        if (_countChanged)
        {
            GenerateControls();
        }

        int idCurrency = 1;

        int.TryParse(ddlMena.SelectedValue, out idCurrency);

        var currencyName = idCurrency == 1 ? "EUR" : "CZK";
        var currencyRate = idCurrency == 1 ? 1 : Common.ExchangeRateCZK;

        float sum   = 0;
        bool  valid = true;

        for (int i = 0; i < _data.Count; i++)
        {
            if (_countChanged)
            {
                _controls[i].Data = _data[i];
            }
            _data[i]                = _controls[i].Data;
            _data[i].Id             = i;
            _controls[i].Title      = _data[i].Title;
            _controls[i].IdCurrency = idCurrency;
            _data[i].IdCurrency     = idCurrency;
            _data[i].Single         = _data.Count == 1;
            _controls[i].Single     = _data.Count == 1;
            sum  += _data[i].Cost;
            valid = valid && _data[i].Valid;
        }

        trPayerEmail.Visible = _data.Count > 1;
        btnRegister.Text     = _data.Count > 1 ? string.Format("Registrovať {0} účastníkov", _data.Count) : "Registrovať 1 účastníka";

        lblEmailError.Text = "";
        if (_data.Count > 1 && !Common.ValidateEmail(txtEmail.Text.Trim()))
        {
            valid = false;
            lblEmailError.Text = Common.ChybaEmail;
        }

        var payerEmail = _data.Count > 1 ? txtEmail.Text.Trim().ToLower() : _data[0].Email.Trim().ToLower();

        lblCaptchaError.Text = "";
        var reCorrect = new Regex(@"((andrej\s+)?kiska)|((milo(s|š)\s+)?zeman)", RegexOptions.IgnoreCase);

        if (!reCorrect.IsMatch(txtCaptcha.Text.Trim()))
        {
            valid = false;
            lblCaptchaError.Text = Common.ChybaCaptcha;
        }

        float sponzorskyDar = 0;

        lblSponzorskyDar.Text = "";
        if (!string.IsNullOrWhiteSpace(txtDar.Text))
        {
            if (!float.TryParse(txtDar.Text, out sponzorskyDar))
            {
                lblSponzorskyDar.Text = Common.ChybaSponzorskyDar;
                valid = false;
            }
        }

        var amountToPay = sum * currencyRate + sponzorskyDar;
        var toPay       = string.Format("{0:0.00} {1}", amountToPay, currencyName);

        lblSuma.Text = toPay;

        // check for duplicate emails
        var emailHash = new Dictionary <string, int>();

        foreach (var item in _data)
        {
            var email = item.Email.Trim().ToLower();
            emailHash[email] = emailHash.ContainsKey(email) ? emailHash[email] + 1 : 1;
        }
        foreach (var item in emailHash)
        {
            if (item.Value > 1)
            {
                valid = false;
                for (int i = 0; i < _data.Count; i++)
                {
                    if (_data[i].Email.Trim().ToLower() == item.Key)
                    {
                        _data[i].Errors.Add(Common.ChybaEmailSaOpakuje);
                    }
                }
            }
        }

        var needHelp = chbPomoc.Checked;

        lblResult.Text = "";
        if (valid && _registerClicked)
        {
            try
            {
                var emails = new List <Email>();

                if (_data.Count == 1)
                {
                    emails.Add(new Email(payerEmail, Emails.RegistrationSubject, Emails.GetSingle(_data[0], toPay)));
                }
                else
                {
                    var payerIsRegistered = false;
                    for (var i = 0; i < _data.Count; i++)
                    {
                        _data[i].Email = _data[i].Email.Trim().ToLower();
                        if (payerEmail == _data[i].Email)
                        {
                            payerIsRegistered = true;
                            emails.Add(new Email(payerEmail, Emails.RegistrationSubject, Emails.GetMultiplePayerRegistered(_data, i, toPay)));
                        }
                        else
                        {
                            emails.Add(new Email(_data[i].Email, Emails.RegistrationSubject, Emails.GetMultiple(_data[i], payerEmail)));
                        }

                        /*
                         * if(_data[i].Sluziaci)
                         * {
                         *  // mail o dobrovolnikovi
                         *  emails.Add(new Email(Emails.VolunteerCoordinator, Emails.VolunteerSubject, Emails.GetVolunteer(_data[i])));
                         * }
                         */
                    }
                    if (!payerIsRegistered)
                    {
                        emails.Add(new Email(payerEmail, Emails.RegistrationSubject, Emails.GetMultiplePayerNotRegistered(_data, toPay, payerEmail)));
                    }
                }

                // write to database
                var data = Database.WriteData(_data, emails, payerEmail, amountToPay, sponzorskyDar, idCurrency, needHelp);
                if (data.Success)
                {
                    Response.Redirect("~/Success.aspx");
                    return;
                }

                // there are bad emails
                valid = false;
                foreach (var item in data.AlreadyRegisteredEmails)
                {
                    for (int i = 0; i < _data.Count; i++)
                    {
                        if (_data[i].Email.Trim().ToLower() == item.Trim().ToLower())
                        {
                            _data[i].Errors.Add(Common.ChybaEmailUzZaregistrovany);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblResult.Text = ex.Message + " " + ex.InnerException;
            }
        }

        lblErrorOnPage.Text     = valid ? "Všetko OK" : "Ešte niečo chýba (viď červené texty vyššie)";
        lblErrorOnPage.CssClass = valid ? "valid" : "error";

        gridSummary.DataSource = _data;
        gridSummary.DataBind();

        base.OnPreRender(e);
    }
Exemplo n.º 3
0
    protected override void OnPreRender(EventArgs e)
    {
        for (int i = 0; i < _controls.Count; i++)
        {
            if (_controls[i].DeleteClicked && i >= 0 && i < _data.Count)
            {
                _data.RemoveAt(i);
                _countChanged = true;
            }
        }

        if (_countChanged)
        {
            GenerateControls();
        }

        float sum   = 0;
        bool  valid = true;

        for (int i = 0; i < _data.Count; i++)
        {
            if (_countChanged)
            {
                _controls[i].Data = _data[i];
            }
            _data[i]            = _controls[i].Data;
            _data[i].Id         = i;
            _controls[i].Title  = _data[i].Title;
            _data[i].Single     = _data.Count == 1;
            _controls[i].Single = _data.Count == 1;
            sum  += _data[i].RegistrationFee;
            valid = valid && _data[i].Valid;
        }

        trPayerEmail.Visible = _data.Count > 1;
        btnRegister.Text     = _data.Count > 1 ? string.Format("Registrovať {0} účastníkov", _data.Count) : "Registrovať 1 účastníka";

        lblEmailError.Text = "";
        if (_data.Count > 1 && !Common.ValidateEmail(txtEmail.Text.Trim()))
        {
            valid = false;
            lblEmailError.Text = Common.ChybaEmail;
        }

        var payerEmail = _data.Count > 1 ? txtEmail.Text.Trim().ToLower() : _data[0].Email.Trim().ToLower();

        if (!IsCaptchaValid())
        {
            valid = false;
        }

        var amountToPay = sum;
        var toPay       = Common.FormatMoney(amountToPay);

        lblSuma.Text = toPay;

        // check for duplicate emails
        var emailHash = new Dictionary <string, int>();

        foreach (var item in _data)
        {
            var email = item.Email.Trim().ToLower();
            emailHash[email] = emailHash.ContainsKey(email) ? emailHash[email] + 1 : 1;
        }
        foreach (var item in emailHash)
        {
            if (item.Value > 1)
            {
                valid = false;
                for (int i = 0; i < _data.Count; i++)
                {
                    if (_data[i].Email.Trim().ToLower() == item.Key)
                    {
                        _data[i].Errors.Add(Common.ChybaEmailSaOpakuje);
                    }
                }
            }
        }

        lblResult.Text = "";
        if (valid && _registerClicked)
        {
            try
            {
                var emails = new List <Email>();

                if (_data.Count == 1)
                {
                    emails.Add(new Email(payerEmail, Emails.RegistrationSubject, Emails.GetSingle(_data[0], toPay, _totalPeople)));
                }
                else
                {
                    var payerIsRegistered = false;
                    for (var i = 0; i < _data.Count; i++)
                    {
                        _data[i].Email = _data[i].Email.Trim().ToLower();
                        if (payerEmail == _data[i].Email)
                        {
                            payerIsRegistered = true;
                            emails.Add(new Email(payerEmail, Emails.RegistrationSubject, Emails.GetMultiplePayerRegistered(_data, i, toPay, _totalPeople)));
                        }
                        else
                        {
                            emails.Add(new Email(_data[i].Email, Emails.RegistrationSubject, Emails.GetMultiple(_data[i], payerEmail, _totalPeople)));
                        }
                    }
                    if (!payerIsRegistered)
                    {
                        emails.Add(new Email(payerEmail, Emails.RegistrationSubject, Emails.GetMultiplePayerNotRegistered(_data, toPay, payerEmail)));
                    }
                }

                // write to database
                var data = Database.WriteData(_data, emails, payerEmail, amountToPay);
                if (data.Success)
                {
                    Response.Redirect("~/Success.aspx");
                    return;
                }

                // there are bad emails
                valid = false;
                foreach (var item in data.AlreadyRegisteredEmails)
                {
                    for (int i = 0; i < _data.Count; i++)
                    {
                        if (_data[i].Email.Trim().ToLower() == item.Trim().ToLower())
                        {
                            _data[i].Errors.Add(Common.ChybaEmailUzZaregistrovany);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                lblResult.Text = ex.Message + " " + ex.InnerException;
            }
        }

        lblErrorOnPage.Text     = valid ? "Všetko OK" : "Ešte niečo chýba (viď červené texty vyššie)";
        lblErrorOnPage.CssClass = valid ? "valid" : "error";

        gridSummary.DataSource = _data;
        gridSummary.DataBind();

        base.OnPreRender(e);
    }