Beispiel #1
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();
            }
        }