Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string CartItemId   = string.Empty;
            string ImportItemId = string.Empty;

            if (Request.QueryString.AllKeys.Contains("CartId"))
            {
                CartItemId = Request.QueryString["CartId"].ToString();
            }
            if (!string.IsNullOrEmpty(CartItemId))
            {
                CurrentCartItemId.Value = CartItemId;
                pnlSearch.Visible       = false;
                divEdit.Visible         = true;
                pnlGrids.Visible        = false;
                GiftCertificateEdit1.CurrentCartItemID = Convert.ToInt32(CartItemId);
                GiftCertificateEdit1.Bind();
            }
            else if (Request.QueryString.AllKeys.Contains("ImportCartId"))
            {
                ImportItemId = Request.QueryString["ImportCartId"].ToString();
                if (!string.IsNullOrEmpty(ImportItemId))
                {
                    int certId            = Convert.ToInt32(ImportItemId);
                    ImportedGiftCert cert = ImportedGiftCert.GetById(certId);

                    if (cert != null)
                    {
                        CurrentCartItemId.Value = Convert.ToString(certId);
                        lblCode.Text            = cert.code.ToString();
                        txtAmount.Text          = cert.amount.Value.ToString();
                        txtDateUsed.Text        = cert.date_used;
                        chkRedeemed.Checked     = cert.is_used == "Y" ? true : false;
                        //txtUsedBy.Text = cert.used_by.ToString();

                        pnlImpCertEdit.Visible = true;
                    }
                    else
                    {
                        lblFBImpCert.Text = "Gift certificate not found.";
                    }
                }
            }

            else if (!IsPostBack)
            {
                //BindgvwIssuedCerts();
                //BindgvwRedeemedCerts();
                //BindgvwImportedGiftCerts();
            }
        }
Esempio n. 2
0
        void gvwImportedGiftCerts_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridView gvw = (GridView)sender;

            int certId            = int.Parse(gvw.SelectedDataKey.Value.ToString());
            ImportedGiftCert cert = ImportedGiftCert.GetById(certId);

            if (cert != null)
            {
                lblCode.Text        = cert.code.ToString();
                txtAmount.Text      = cert.amount.Value.ToString();
                txtDateUsed.Text    = cert.date_used;
                chkRedeemed.Checked = cert.is_used == "Y" ? true : false;
                //txtUsedBy.Text = cert.used_by.ToString();

                pnlImpCertEdit.Visible = true;
            }
            else
            {
                lblFBImpCert.Text = "Gift certificate not found.";
            }
        }
Esempio n. 3
0
        void btnSave_Click(object sender, EventArgs e)
        {
            ImportedGiftCert cert = ImportedGiftCert.GetBy(lblCode.Text);

            if (cert != null)
            {
                cert.is_used   = chkRedeemed.Checked ? "Y" : "N";
                cert.code      = long.Parse(lblCode.Text.Trim());
                cert.amount    = decimal.Parse(txtAmount.Text.Trim());
                cert.date_used = txtDateUsed.Text;
                //cert.used_by = txtUsedBy.Text;
                cert.Save();

                lblFBImpCert.Text = "Gift certificate has been saved.";
            }
            else
            {
                lblFBImpCert.Text = "Gift certificate not found.";
            }

            pnlImpCertEdit.Visible = false;
        }
        protected override void SaveForm()
        {
            try
            {
                hccLedger ledger = new hccLedger
                {
                    AspNetUserID      = CurrentAspNetUserId,
                    CreatedBy         = (Guid)Helpers.LoggedUser.ProviderUserKey,
                    CreatedDate       = DateTime.Now,
                    Description       = txtXactDesc.Text.Trim(),
                    TransactionTypeID = int.Parse(ddlXactTypes.SelectedValue)
                };

                if (ledger.TransactionType == Enums.LedgerTransactionType.RedeemGiftCertificate)
                {
                    hccCartItem gcCartItem   = hccCartItem.GetGiftBy(txtXactGCRedeem.Text);
                    bool        updateLedger = false;

                    if (gcCartItem != null)
                    {
                        gcCartItem.Gift_RedeemedBy   = CurrentAspNetUserId;
                        gcCartItem.Gift_RedeemedDate = DateTime.Now;
                        gcCartItem.Save();
                        updateLedger = true;
                    }
                    else
                    {
                        ImportedGiftCert cert = ImportedGiftCert.GetBy(txtXactGCRedeem.Text);
                        if (cert != null)
                        {
                            cert.used_by   = gcCartItem.UserProfileID;
                            cert.date_used = DateTime.Now.ToString();
                            cert.is_used   = "Y";
                            cert.Save();
                            updateLedger = true;
                        }
                    }

                    if (updateLedger)
                    {
                        ledger.TotalAmount    = gcCartItem.ItemPrice;
                        ledger.GiftRedeemCode = gcCartItem.Gift_RedeemCode;
                        ledger.Description    = "Gift Certificate Redemption: " + ledger.GiftRedeemCode;
                    }
                    else
                    {
                        ledger = null;
                    }
                }
                else
                {
                    ledger.TotalAmount = decimal.Parse(txtXactAmount.Text.Trim());
                }

                hccUserProfile profile = hccUserProfile.GetParentProfileBy(CurrentAspNetUserId);

                if (profile != null)
                {
                    // check against last entry for duplicate
                    hccLedger lastEntry        = hccLedger.GetByMembershipID(profile.MembershipID, null).OrderByDescending(a => a.CreatedDate).FirstOrDefault();
                    bool      isDuplicateEntry = false;

                    if (ledger != null)
                    {
                        if (lastEntry != null &&
                            ledger.CreatedBy == lastEntry.CreatedBy &&
                            ledger.CreditFromBalance == lastEntry.CreditFromBalance &&
                            ledger.Description == lastEntry.Description &&
                            ledger.PaymentDue == lastEntry.PaymentDue &&
                            ledger.TransactionTypeID == lastEntry.TransactionTypeID &&
                            ledger.TotalAmount == lastEntry.TotalAmount)
                        {
                            isDuplicateEntry = true;
                        }

                        if (!isDuplicateEntry)
                        {
                            switch (ledger.TransactionType)
                            {
                            case Enums.LedgerTransactionType.HCCAccountCredit:
                            case Enums.LedgerTransactionType.RedeemGiftCertificate:
                                profile.AccountBalance = profile.AccountBalance + ledger.TotalAmount;
                                break;

                            case Enums.LedgerTransactionType.HCCAccountDebit:
                                profile.AccountBalance = profile.AccountBalance - ledger.TotalAmount;
                                break;

                            case Enums.LedgerTransactionType.Purchase:
                            case Enums.LedgerTransactionType.Return:
                                ledger.PaymentDue = ledger.TotalAmount;
                                break;

                            default: break;
                            }

                            ledger.PostBalance = profile.AccountBalance;
                            ledger.Save();
                            profile.Save();

                            this.Bind();
                            OnSaved(new ControlSavedEventArgs(CurrentAspNetUserId));

                            txtXactAmount.Text   = string.Empty;
                            txtXactDesc.Text     = string.Empty;
                            txtXactGCRedeem.Text = string.Empty;
                            ddlXactTypes.ClearSelection();
                        }
                        else
                        {
                            lblXactFeedback.Text = "This appears to be a duplicate transaction. If it is not a duplicate, please provide a comment to differentiate this transaction from the last.";
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }