예제 #1
0
        private static Coupon CreateCoupon(IDataReader reader)
        {
            //Get the coupon type id.
            int        couponTypeId = reader.GetInt32(reader.GetOrdinal("CouponTypeId"));
            CouponType couponType   = CouponType.GetCouponType(couponTypeId);

            //Get an XmlReader for the XmlData
            string xmlString = reader.GetString(reader.GetOrdinal("XmlData"));

            System.IO.StringReader rdr = new System.IO.StringReader(xmlString);
            XmlReader xmlData          = XmlReader.Create(rdr);

            //Deserialize the Xml to the object.
            XmlSerializer serializer = new XmlSerializer(couponType.CouponClassType);
            Coupon        newCoupon  = (Coupon)serializer.Deserialize(xmlData);

            //Load the common properties.
            newCoupon._couponCode  = reader.GetString(reader.GetOrdinal("CouponCode"));
            newCoupon._couponType  = couponType;
            newCoupon._isSingleUse = reader.GetBoolean(reader.GetOrdinal("IsSingleUse"));
            newCoupon._numUses     = reader.GetInt32(reader.GetOrdinal("NumberUses"));
            //the following is a stupid hack.
            //it seems to me that a nullable type should just convert from DbNull ...
            if (reader["ExpirationDate"] != DBNull.Value)
            {
                newCoupon._expirationDate = (DateTime?)reader["ExpirationDate"];
            }
            if (reader["UserId"] != DBNull.Value)
            {
                newCoupon._userId = (Guid?)reader["UserId"];
            }
            return(newCoupon);
        }
예제 #2
0
 private void EditCouponType(int couponTypeId)
 {
     Commerce.Promotions.CouponType selectedCouponType =
         Commerce.Promotions.CouponType.GetCouponType(couponTypeId);
     lblID.Text                  = selectedCouponType.CouponTypeID.ToString();
     txtDescription.Text         = selectedCouponType.Description;
     txtClassName.Text           = selectedCouponType.CouponClassType.FullName;
     couponTypeEditPanel.Visible = true;
 }
예제 #3
0
        private static CouponType CreateCouponTypeFromReader(IDataReader rdr)
        {
            CouponType newType = new CouponType(
                rdr.GetInt32(rdr.GetOrdinal("CouponTypeId")),
                rdr.GetString(rdr.GetOrdinal("Description")),
                rdr.GetString(rdr.GetOrdinal("ProcessingClassName")));

            //Add to the cache.

            _couponTypes.Add(newType.CouponTypeID, newType);
            return(newType);
        }
예제 #4
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (!Page.IsValid)
        {
            //no save ... exit.
            return;
        }
        string classTypeName = BuildFullClassName();

        try {
            if (!String.IsNullOrEmpty(lblID.Text))
            {
                //Edit on the coupon type.
                int couponTypeId;
                if (int.TryParse(lblID.Text, out couponTypeId))
                {
                    Commerce.Promotions.CouponType selectedCouponType =
                        Commerce.Promotions.CouponType.GetCouponType(couponTypeId);
                    selectedCouponType.Description     = txtDescription.Text;
                    selectedCouponType.CouponClassType = System.Web.Compilation.BuildManager.GetType(classTypeName, true);
                    selectedCouponType.Save();
                }
            }
            else
            {
                //this is a new coupon type.
                Commerce.Promotions.CouponType couponType =
                    new Commerce.Promotions.CouponType(
                        -1, txtDescription.Text.Trim(), classTypeName);
                couponType.Save();
            }
            lblMessage.ForeColor        = System.Drawing.Color.LightSteelBlue;
            lblMessage.Text             = "Coupon Type Saved";
            couponTypeEditPanel.Visible = false;
            BindCouponTypes();
        }
        catch (Exception ex) {
            lblMessage.ForeColor = System.Drawing.Color.Red;
            lblMessage.Text      = "Save failed<br/>" + ex.Message;
        }
    }
예제 #5
0
 protected Coupon(string couponCode, CouponType couponType)
 {
     _couponCode = couponCode;
     _couponType = couponType;
 }
 public void NewCoupon(Commerce.Promotions.CouponType cpnType)
 {
     btnGenerate.Visible       = true;
     ViewState["CouponTypeId"] = cpnType.CouponTypeID;
     ViewState["IsNew"]        = true;
 }
예제 #7
0
 public PercentOffCoupon(string couponCode, CouponType couponType)
     : base(couponCode, couponType)
 {
 }