Beispiel #1
0
        void CreateGiftCards(Customer customer, ShoppingCart cart)
        {
            var giftCardProductTypeIds = string.Format("{0},{1},{2}", AppLogic.AppConfig("GiftCard.CertificateProductTypeIDs").Trim(','),
                                                       AppLogic.AppConfig("GiftCard.EmailProductTypeIDs").Trim(','),
                                                       AppLogic.AppConfig("GiftCard.PhysicalProductTypeIDs").Trim(','))
                                         .Split(',')
                                         .Select(int.Parse)
                                         .ToList();

            foreach (var item in cart.CartItems.Where(ci => giftCardProductTypeIds.Contains(ci.ProductTypeId)))
            {
                //Check the number of certificate records in the GiftCard table for this item.
                int numCards = DB.GetSqlN("SELECT COUNT(*) AS N FROM GiftCard WHERE ShoppingCartRecID = @ShoppingCartRecId",
                                          new SqlParameter[] { new SqlParameter("@ShoppingCartRecId", item.ShoppingCartRecordID) });

                if (numCards < item.Quantity)
                {
                    //Add records if not enough
                    for (int i = 1; i <= item.Quantity - numCards; i++)
                    {
                        GiftCard.CreateGiftCard(PurchasedByCustomerID: customer.CustomerID,
                                                SerialNumber: null,
                                                OrderNumber: null,
                                                ShoppingCartRecID: item.ShoppingCartRecordID,
                                                ProductID: item.ProductID,
                                                VariantID: item.VariantID,
                                                InitialAmount: item.Price,
                                                ExpirationDate: null,
                                                Balance: item.Price,
                                                GiftCardTypeID: item.ProductTypeId,
                                                EMailName: null,
                                                EMailTo: null,
                                                EMailMessage: null,
                                                ValidForCustomers: null,
                                                ValidForProducts: null,
                                                ValidForManufacturers: null,
                                                ValidForCategories: null,
                                                ValidForSections: null,
                                                ExtensionData: null);
                    }
                }
                else if (numCards > item.Quantity)
                {
                    //Delete records if there are too many.
                    DB.ExecuteSQL(string.Format("DELETE FROM GiftCard WHERE GiftCardID IN (SELECT TOP {0} GiftCardID FROM GiftCard WHERE ShoppingCartRecID = {1} ORDER BY GiftCardID DESC)",
                                                numCards - item.Quantity,
                                                item.ShoppingCartRecordID));
                }
            }
        }
Beispiel #2
0
        private void CreateGiftCards(ShoppingCart cart)
        {
            for (int i = 0; i < cart.CartItems.Count; i++)
            {
                CartItem c                 = (CartItem)cart.CartItems[i];
                string   ProdTypeIDs       = AppLogic.AppConfig("GiftCard.CertificateProductTypeIDs").TrimEnd(',').TrimStart(',') + "," + AppLogic.AppConfig("GiftCard.EmailProductTypeIDs").TrimEnd(',').TrimStart(',') + "," + AppLogic.AppConfig("GiftCard.PhysicalProductTypeIDs").TrimEnd(',').TrimStart(',');
                string[] ProdTypeIDArray   = ProdTypeIDs.Split(',');
                string[] FindProductTypeID = { c.ProductTypeId.ToString() };
                if (ArrayContainsValue(ProdTypeIDArray, FindProductTypeID))
                {
                    //Check the number of certificate records in the GiftCard table for this item.
                    int CardCnt = DB.GetSqlN("select count(*) as N from GiftCard where " +
                                             "ShoppingCartRecID=" + c.ShoppingCartRecordID.ToString() +
                                             " and PurchasedByCustomerID=" + cart.ThisCustomer.CustomerID.ToString());
                    //Add records if not enough
                    if (CardCnt < c.Quantity)
                    {
                        for (int j = 1; j <= c.Quantity - CardCnt; j++)
                        {
                            GiftCard.CreateGiftCard(ThisCustomer.CustomerID, null, null, c.ShoppingCartRecordID, null, null, c.Price, null, c.Price, c.ProductTypeId, null, null, null, null, null, null, null, null, null);
                        }
                    }
                    //Delete records if there are too many. Delete from the end of the list just because we have to delete something.
                    if (CardCnt > c.Quantity)
                    {
                        int    DeleteCnt = CardCnt - c.Quantity;
                        string sql       = "delete from GiftCard where GiftCardID in (select TOP " + DeleteCnt.ToString() + " GiftCardID from GiftCard where ShoppingCartRecID=" + c.ShoppingCartRecordID.ToString() + " and PurchasedByCustomerID=" + cart.ThisCustomer.CustomerID.ToString() + " order by GiftCardID DESC)";
                        DB.ExecuteSQL(sql);
                    }

                    //GiftCard.DeleteGiftCardsInCart(c.m_ShoppingCartRecordID);
                }

                if (ArrayContainsValue(AppLogic.AppConfig("GiftCard.EmailProductTypeIDs").Split(','), FindProductTypeID))
                {
                    ContainsEmailGiftCards = true;
                }
            }
        }
        private bool SaveForm()
        {
            if (Page.IsValid)
            {
                //giftCardId = 0 means we're creating a new giftcard
                var creatingGiftCard = giftCardId == 0;
                var giftCardType     = Localization.ParseNativeInt(ddType.SelectedValue);
                var customerId       = Localization.ParseNativeInt(hdnCustomerId.Value);

                //validate customer id if creating giftcard
                if (creatingGiftCard && customerId == 0)
                {
                    AlertMessage.PushAlertMessage("admin.editgiftcard.InvalidEmail".StringResource(), AlertMessage.AlertType.Error);
                    return(false);
                }

                //validate email fields if we're creating an EmailGiftCard
                if (giftCardType == (int)GiftCardTypes.EMailGiftCard && creatingGiftCard)
                {
                    if (txtEmailBody.Text.Length == 0 ||
                        txtEmailName.Text.Length == 0 ||
                        txtEmailTo.Text.Length == 0)
                    {
                        AlertMessage.PushAlertMessage("admin.editgiftcard.EnterEmailPreferences".StringResource(), AlertMessage.AlertType.Error);
                        return(false);
                    }

                    //make sure the customer has set up their email properly
                    if (AppLogic.AppConfig("MailMe_Server").Length == 0 ||
                        AppLogic.AppConfig("MailMe_FromAddress") == "*****@*****.**")
                    {
                        //Customer has not configured their MailMe AppConfigs yet
                        AlertMessage.PushAlertMessage("giftcard.email.error.2".StringResource(), AlertMessage.AlertType.Error);
                        return(false);
                    }
                }

                //make sure the date is filled in
                if (txtDate.SelectedDate == null)
                {
                    AlertMessage.PushAlertMessage("admin.common.FillinExpirationDate".StringResource(), AlertMessage.AlertType.Error);
                    return(false);
                }

                //check if valid SN
                var isDuplicateSerialNumberSql = string.Format("select count(GiftCardID) as N from GiftCard with (NOLOCK) where GiftCardID<>{0} and lower(SerialNumber)={1}",
                                                               giftCardId,
                                                               DB.SQuote(txtSerial.Text.ToLowerInvariant().Trim()));
                var isDuplicateSerialNumber = DB.GetSqlN(isDuplicateSerialNumberSql) > 0;

                if (isDuplicateSerialNumber)
                {
                    AlertMessage.PushAlertMessage("admin.editgiftcard.ExistingGiftCard".StringResource(), AlertMessage.AlertType.Error);
                    return(false);
                }

                if (creatingGiftCard)
                {
                    //insert a new card
                    var newGiftCard = GiftCard.CreateGiftCard(customerId,
                                                              txtSerial.Text,
                                                              Localization.ParseNativeInt(txtOrder.Text),
                                                              0,
                                                              0,
                                                              0,
                                                              Localization.ParseNativeDecimal(txtAmount.Text),
                                                              txtDate.SelectedDate.Value,
                                                              Localization.ParseNativeDecimal(txtAmount.Text),
                                                              ddType.SelectedValue,
                                                              CommonLogic.Left(txtEmailName.Text, 100),
                                                              CommonLogic.Left(txtEmailTo.Text, 100),
                                                              txtEmailBody.Text,
                                                              null,
                                                              null,
                                                              null,
                                                              null,
                                                              null,
                                                              null);

                    try
                    {
                        newGiftCard.SendGiftCardEmail();
                    }
                    catch
                    {
                        //reload page, but inform the admin the the email could not be sent
                        AlertMessage.PushAlertMessage("giftcard.email.error.1".StringResource(), AlertMessage.AlertType.Success);
                    }

                    //reload page
                    giftCardId         = newGiftCard.GiftCardID;
                    etsMapper.ObjectID = giftCardId;
                    AlertMessage.PushAlertMessage("admin.editgiftcard.GiftCardAdded".StringResource(), AlertMessage.AlertType.Success);
                }
                else
                {
                    //update existing card
                    DB.ExecuteSQL(
                        @"UPDATE GiftCard SET
							SerialNumber=@serialNumber,
							ExpirationDate=@expirationDate,
							DisabledByAdministrator=@disabledByAdministrator
						WHERE GiftCardID=@giftCardId"                        ,
                        new[]
                    {
                        new SqlParameter("@serialNumber", txtSerial.Text),
                        new SqlParameter("@expirationDate", Localization.ToDBShortDateString(Localization.ParseNativeDateTime(txtDate.SelectedDate.Value.ToString()))),
                        new SqlParameter("@disabledByAdministrator", Localization.ParseNativeInt(rblAction.SelectedValue)),
                        new SqlParameter("@giftCardId", giftCardId)
                    });

                    etsMapper.ObjectID = giftCardId;
                    AlertMessage.PushAlertMessage("admin.editgiftcard.GiftCardUpdated".StringResource(), AlertMessage.AlertType.Success);
                }
                etsMapper.Save();
            }

            return(true);
        }
Beispiel #4
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                resetError("", false);

                StringBuilder sql = new StringBuilder(1024);

                //validate for the email type on insert for emailing
                int type = Localization.ParseNativeInt(ddType.SelectedValue);
                if ((type == 101) && (GiftCardID == 0))
                {
                    if ((txtEmailBody.Text.Length == 0) || (txtEmailName.Text.Length == 0) || (txtEmailTo.Text.Length == 0))
                    {
                        resetError(AppLogic.GetString("admin.editgiftcard.EnterEmailPreferences", SkinID, LocaleSetting), true);
                        return;
                    }
                }
                //validate customer id if creating giftcard  (ID = 0 is new giftcard)
                int customerId = Localization.ParseNativeInt(hdnCustomerId.Value);
                if (GiftCardID == 0 && customerId == 0)
                {
                    resetError(AppLogic.GetString("admin.editgiftcard.InvalidEmail", cust.SkinID, cust.LocaleSetting), true);
                    return;
                }

                //make sure the customer has set up their email properly
                if (type == 101 && GiftCardID == 0 && (AppLogic.AppConfig("MailMe_Server").Length == 0 || AppLogic.AppConfig("MailMe_FromAddress") == "*****@*****.**"))
                {
                    //Customer has not configured their MailMe AppConfigs yet
                    resetError(AppLogic.GetString("giftcard.email.error.2", cust.SkinID, cust.LocaleSetting), true);
                    return;
                }

                if (GiftCardID == 0)
                {
                    //insert a new card

                    //check if valid SN
                    int N = DB.GetSqlN("select count(GiftCardID) as N from GiftCard   with (NOLOCK)  where lower(SerialNumber)=" + DB.SQuote(txtSerial.Text.ToLowerInvariant().Trim()));
                    if (N != 0)
                    {
                        resetError(AppLogic.GetString("admin.editgiftcard.ExistingGiftCard", SkinID, LocaleSetting), true);
                        return;
                    }

                    //ok to add them
                    GiftCard card = GiftCard.CreateGiftCard(customerId,
                                                            txtSerial.Text,
                                                            Localization.ParseNativeInt(txtOrder.Text),
                                                            0,
                                                            0,
                                                            0,
                                                            Localization.ParseNativeDecimal(txtAmount.Text),
                                                            txtDate.Text,
                                                            Localization.ParseNativeDecimal(txtAmount.Text),
                                                            ddType.SelectedValue,
                                                            CommonLogic.Left(txtEmailName.Text, 100),
                                                            CommonLogic.Left(txtEmailTo.Text, 100),
                                                            txtEmailBody.Text,
                                                            null,
                                                            null,
                                                            null,
                                                            null,
                                                            null,
                                                            null);
                    GiftCardID = card.GiftCardID;

                    try
                    {
                        card.SendGiftCardEmail();
                    }
                    catch
                    {
                        //reload page, but inform the admin the the email could not be sent
                        Response.Redirect(AppLogic.AdminLinkUrl("editgiftcard.aspx") + "?iden=" + GiftCardID + "&added=3");
                    }

                    //reload page
                    etsMapper.ObjectID = GiftCardID;
                    etsMapper.Save();
                    Response.Redirect(AppLogic.AdminLinkUrl("editgiftcard.aspx") + "?iden=" + GiftCardID + "&added=1");
                }
                else
                {
                    //update existing card

                    //check if valid SN
                    int N = DB.GetSqlN("select count(GiftCardID) as N from GiftCard   with (NOLOCK)  where GiftCardID<>" + GiftCardID.ToString() + " and lower(SerialNumber)=" + DB.SQuote(txtSerial.Text.ToLowerInvariant().Trim()));
                    if (N != 0)
                    {
                        resetError(AppLogic.GetString("admin.editgiftcard.ExistingGiftCard", SkinID, LocaleSetting), true);
                        return;
                    }

                    //ok to update
                    sql.Append("UPDATE GiftCard SET ");
                    sql.Append("SerialNumber=" + DB.SQuote(txtSerial.Text) + ",");
                    sql.Append("ExpirationDate=" + DB.SQuote(Localization.ToDBShortDateString(Localization.ParseNativeDateTime(txtDate.Text))) + ",");
                    sql.Append("DisabledByAdministrator=" + Localization.ParseNativeInt(rblAction.SelectedValue));
                    sql.Append(" WHERE GiftCardID=" + GiftCardID);
                    DB.ExecuteSQL(sql.ToString());

                    etsMapper.ObjectID = GiftCardID;
                    etsMapper.Save();
                    //reload page
                    Response.Redirect(AppLogic.AdminLinkUrl("editgiftcard.aspx") + "?iden=" + GiftCardID + "&added=2");
                }
                etsMapper.Save();
            }
        }