Exemple #1
0
    protected void Page_PreRender(object sender, EventArgs e)
    {
        if (grid.UpdatedRow != null)
        {
            decimal sum;
            if (decimal.TryParse(grid.UpdatedRow["Sum"], out sum))
            {
                var certificate =
                    GiftCertificateService.GetCertificateByID(Convert.ToInt32(grid.UpdatedRow["ID"]));

                if (!certificate.Paid && Convert.ToBoolean(grid.UpdatedRow["Paid"]) && !CustomerSession.CurrentCustomer.IsVirtual)
                {
                    GiftCertificateService.SendCertificateMails(certificate);
                }
                certificate.Sum    = sum;
                certificate.Enable = Convert.ToBoolean(grid.UpdatedRow["Enable"]);
                certificate.Type   = (CertificatePostType)int.Parse(grid.UpdatedRow["Type"]);
                certificate.Used   = Convert.ToBoolean(grid.UpdatedRow["Used"]);
                certificate.Paid   = Convert.ToBoolean(grid.UpdatedRow["Paid"]);
                GiftCertificateService.UpdateCertificateById(certificate);
            }
        }

        DataTable data = _paging.PageItems;

        while (data.Rows.Count < 1 && _paging.CurrentPageIndex > 1)
        {
            _paging.CurrentPageIndex--;
            data = _paging.PageItems;
        }

        var clmn = new DataColumn("IsSelected", typeof(bool))
        {
            DefaultValue = _inverseSelection
        };

        data.Columns.Add(clmn);
        if ((_selectionFilter != null) && (_selectionFilter.Values != null))
        {
            for (int i = 0; i <= data.Rows.Count - 1; i++)
            {
                int intIndex = i;
                if (Array.Exists(_selectionFilter.Values, c => c == (data.Rows[intIndex]["ID"]).ToString()))
                {
                    data.Rows[i]["IsSelected"] = !_inverseSelection;
                }
            }
        }

        if (data.Rows.Count < 1)
        {
            goToPage.Visible = false;
        }

        grid.DataSource = data;
        grid.DataBind();

        pageNumberer.PageCount = _paging.PageCount;
        lblFound.Text          = _paging.TotalRowsCount.ToString();
    }
 protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     if (e.CommandName == "DeleteCertificate")
     {
         GiftCertificateService.DeleteCertificateById(SQLDataHelper.GetInt(e.CommandArgument));
     }
     if (e.CommandName == "SendCertificate")
     {
         GiftCertificateService.SendCertificateMails(
             GiftCertificateService.GetCertificateByID(SQLDataHelper.GetInt(e.CommandArgument)));
     }
 }
    protected void CreateCertificate()
    {
        if (!DataValidation())
        {
            return;
        }

        MsgErr(true);

        try
        {
            var curCurrency = CurrencyService.CurrentCurrency;
            Certificate = new GiftCertificate
            {
                CertificateCode    = lblCertificateCode.Text,
                FromName           = txtFromName.Text,
                ToName             = txtToName.Text,
                Paid               = chkPaid.Checked,
                Used               = chkUsed.Checked,
                Enable             = chkEnable.Checked,
                Type               = rbtnEmail.Checked ? CertificatePostType.Email : CertificatePostType.Mail,
                Sum                = Convert.ToDecimal(txtSum.Text),
                CertificateMessage = txtMessage.Text,
                CurrencyCode       = curCurrency.Symbol,
                CurrencyValue      = curCurrency.Value,
                FromEmail          = txtFromEmail.Text
            };
            if (rbtnEmail.Checked)
            {
                Certificate.Email = txtEmail.Text;
            }
            else
            {
                Certificate.Country = cboCountry.SelectedItem.Text;
                Certificate.Zone    = MultiViewRegion.ActiveViewIndex == 0 ? cboRegion.SelectedItem.Text : txtState.Text;
                Certificate.City    = txtCity.Text;
                Certificate.Zip     = txtZip.Text;
                Certificate.Address = txtAddress.Text;
            }
            if (Certificate.Paid && !CustomerSession.CurrentCustomer.IsVirtual)
            {
                GiftCertificateService.SendCertificateMails(Certificate);
            }

            GiftCertificateService.AddCertificate(Certificate);
        }
        catch (Exception ex)
        {
            MsgErr(ex.Message + " Create Certificate error");
            Debug.LogError(ex);
        }
    }
    protected void SaveCertificate()
    {
        if (!DataValidation())
        {
            return;
        }

        try
        {
            // var certificate = GiftCertificateService.GetCertificateByID(CertificateId);

            bool isPaid = !Certificate.Paid && chkPaid.Checked;

            Certificate.CertificateId   = CertificateId;
            Certificate.CertificateCode = lblCertificateCode.Text;
            Certificate.FromName        = txtFromName.Text;
            Certificate.ToName          = txtToName.Text;
            Certificate.Paid            = chkPaid.Checked;
            Certificate.Used            = chkUsed.Checked;
            Certificate.Enable          = chkEnable.Checked;
            Certificate.Type            = (rbtnEmail.Checked ? CertificatePostType.Email : CertificatePostType.Mail);
            Certificate.Sum             = Convert.ToDecimal(txtSum.Text);
            Certificate.FromEmail       = txtFromEmail.Text;

            if (rbtnEmail.Checked)
            {
                Certificate.Email = txtEmail.Text;
            }
            else
            {
                Certificate.Country = cboCountry.SelectedItem.Text;
                Certificate.Zone    = MultiViewRegion.ActiveViewIndex == 0 ? cboRegion.SelectedItem.Text : txtState.Text;
                Certificate.City    = txtCity.Text;
                Certificate.Zip     = txtZip.Text;
                Certificate.Address = txtAddress.Text;
            }

            if (isPaid)
            {
                GiftCertificateService.SendCertificateMails(Certificate);
            }

            GiftCertificateService.UpdateCertificateById(Certificate);
        }
        catch (Exception ex)
        {
            MsgErr(ex.Message + " SaveSertificate error");
            Debug.LogError(ex);
        }
    }