Exemple #1
0
        public decimal GetGoodDiscountAmount(DataRow order, DataRow[] orderLine)
        {
            decimal result = 0M;

            decimal.TryParse(order["DiscountAmount"].ToString(), out result);
            decimal goodsAmount = GetGoodsAmount(orderLine);
            string  str         = order["DiscountName"].ToString();

            if (order["DiscountValueType"] == DBNull.Value)
            {
                return(goodsAmount);
            }
            DiscountValueType type = (DiscountValueType)order["DiscountValueType"];
            decimal           num3 = 0M;

            decimal.TryParse(order["DiscountValue"].ToString(), out num3);
            if ((string.IsNullOrEmpty(str) || (result <= 0M)) || ((num3 <= 0M) || !Enum.IsDefined(typeof(DiscountValueType), type)))
            {
                return(goodsAmount);
            }
            if (type == DiscountValueType.Amount)
            {
                return(goodsAmount - num3);
            }
            return(goodsAmount * (num3 / 10M));
        }
Exemple #2
0
 private static decimal Calculate(decimal undiscountedPrice, decimal value, DiscountValueType discountValueType)
 {
     if (discountValueType == DiscountValueType.Percent)
     {
         return(undiscountedPrice * (value / 100));
     }
     return(value);
 }
        private static decimal Calculate(decimal sourceCodeValue, decimal amountToApplyOn, DiscountValueType valueType)
        {
            if (valueType == DiscountValueType.Percent)
            {
                var discountAmount = (amountToApplyOn * (sourceCodeValue / 100));
                return(amountToApplyOn <= discountAmount ? amountToApplyOn : discountAmount);
            }

            return(amountToApplyOn <= sourceCodeValue ? amountToApplyOn : sourceCodeValue);
        }
Exemple #4
0
 public abstract void GetPromotionsWithAmount(decimal amount, out int discountActivityId, out string discountName, out decimal discountValue, out DiscountValueType discountValueType, out int feeFreeActivityId, out string feeFreeName, out bool eightFree, out bool orderOptionFree, out bool procedureFeeFree);
Exemple #5
0
 public override void GetPromotionsWithAmount(decimal amount, out int discountActivityId, out string discountName, out decimal discountValue, out DiscountValueType discountValueType, out int feeFreeActivityId, out string feeFreeName, out bool eightFree, out bool orderOptionFree, out bool procedureFeeFree)
 {
     discountActivityId = 0;
     discountName = null;
     discountValue = 0M;
     discountValueType = DiscountValueType.Amount;
     feeFreeActivityId = 0;
     feeFreeName = null;
     eightFree = false;
     orderOptionFree = false;
     procedureFeeFree = false;
     DbCommand sqlStringCommand = this.database.GetSqlStringCommand("SELECT TOP 1 p.ActivityId, p.Name, fd.DiscountValue, fd.ValueType FROM distro_Promotions p INNER JOIN distro_FullDiscounts fd ON p.ActivityId = fd.ActivityId  INNER JOIN distro_PromotionMemberGrades pm ON pm.ActivityId=fd.ActivityId WHERE @Amount >= fd.Amount  AND @GradeId IN (SELECT GradeId FROM distro_PromotionMemberGrades WHERE distro_PromotionMemberGrades.ActivityId=fd.ActivityId)  AND p.DistributorUserId = @DistributorUserId ORDER BY fd.Amount DESC");
     this.database.AddInParameter(sqlStringCommand, "Amount", DbType.Currency, amount);
     this.database.AddInParameter(sqlStringCommand, "DistributorUserId", DbType.Int32, HiContext.Current.SiteSettings.UserId.Value);
     this.database.AddInParameter(sqlStringCommand, "GradeId", DbType.Int32, (Users.GetUser(HiContext.Current.User.UserId) as Member).GradeId);
     using (IDataReader reader = this.database.ExecuteReader(sqlStringCommand))
     {
         if (reader.Read())
         {
             discountActivityId = reader.GetInt32(0);
             discountName = reader.GetString(1);
             discountValue = reader.GetDecimal(2);
             discountValueType = (DiscountValueType) reader.GetInt32(3);
         }
     }
     sqlStringCommand = this.database.GetSqlStringCommand("SELECT TOP 1 p.ActivityId, p.Name, ff.ShipChargeFree, ff.ServiceChargeFree, ff.OptionFeeFree FROM distro_Promotions p INNER JOIN distro_FullFree ff ON p.ActivityId = ff.ActivityId INNER JOIN distro_PromotionMemberGrades pm ON pm.ActivityId=ff.ActivityId WHERE DistributorUserId = @DistributorUserId AND @SubAmount >= ff.Amount  AND @GradeId IN (SELECT GradeId FROM distro_PromotionMemberGrades WHERE distro_PromotionMemberGrades.ActivityId=ff.ActivityId) ORDER BY ff.Amount DESC");
     decimal num = 0M;
     if ((discountValueType == DiscountValueType.Percent) && (discountValue > 0M))
     {
         num = (amount * discountValue) / 100M;
     }
     else if ((discountValueType == DiscountValueType.Amount) && (discountValue > 0M))
     {
         num = amount - discountValue;
     }
     if (num > 0M)
     {
         this.database.AddInParameter(sqlStringCommand, "SubAmount", DbType.Currency, num);
     }
     else
     {
         this.database.AddInParameter(sqlStringCommand, "SubAmount", DbType.Currency, amount);
     }
     this.database.AddInParameter(sqlStringCommand, "DistributorUserId", DbType.Int32, HiContext.Current.SiteSettings.UserId.Value);
     this.database.AddInParameter(sqlStringCommand, "GradeId", DbType.Int32, (Users.GetUser(HiContext.Current.User.UserId) as Member).GradeId);
     using (IDataReader reader2 = this.database.ExecuteReader(sqlStringCommand))
     {
         if (reader2.Read())
         {
             feeFreeActivityId = reader2.GetInt32(0);
             feeFreeName = reader2.GetString(1);
             eightFree = reader2.GetBoolean(2);
             procedureFeeFree = reader2.GetBoolean(3);
             orderOptionFree = reader2.GetBoolean(4);
         }
     }
 }
Exemple #6
0
        private void btnAddDiscount_Click(object sender, EventArgs e)
        {
            decimal amount   = 0m;
            decimal discount = 0m;
            int     rate     = 0;
            string  str      = string.Empty;

            if (ValidateValues(out amount, out discount, out rate))
            {
                DiscountValueType selectedValue = radioValueType.SelectedValue;
                if (!addpromoteSales.IsValid)
                {
                    ShowMsg(addpromoteSales.CurrentErrors, false);
                }
                else
                {
                    FullDiscountInfo target = new FullDiscountInfo();
                    target.Name        = addpromoteSales.Item.Name;
                    target.Description = addpromoteSales.Item.Description;
                    target.Amount      = amount;
                    target.ValueType   = selectedValue;

                    switch (selectedValue)
                    {
                    case DiscountValueType.Amount:
                    {
                        target.DiscountValue = discount;
                        break;
                    }

                    case DiscountValueType.Percent:
                    {
                        target.DiscountValue = rate;
                        break;
                    }
                    }
                    target.MemberGradeIds = chklMemberGrade.SelectedValue;
                    if (chklMemberGrade.SelectedValue.Count <= 0)
                    {
                        str = str + Formatter.FormatErrorMessage("适合的客户必须选择一个");
                    }
                    ValidationResults results = Hishop.Components.Validation.Validation.Validate <FullDiscountInfo>(target, new string[] { "ValPromotion" });
                    if (!results.IsValid)
                    {
                        foreach (ValidationResult result in (IEnumerable <ValidationResult>)results)
                        {
                            str = str + Formatter.FormatErrorMessage(result.Message);
                        }
                    }
                    if (!string.IsNullOrEmpty(str))
                    {
                        ShowMsg(str, false);
                    }
                    else
                    {
                        PromotionActionStatus status = SubsitePromoteHelper.AddPromotion(target);
                        switch (status)
                        {
                        case PromotionActionStatus.Success:
                            txtAmount.Text        = string.Empty;
                            txtDiscountValue.Text = string.Empty;
                            addpromoteSales.Reset();
                            ShowMsg("成功添加了促销活动--满额打折", true);
                            return;

                        case PromotionActionStatus.DuplicateName:
                            ShowMsg("已存在此名称的促销活动", false);
                            return;
                        }
                        if (status == PromotionActionStatus.SameCondition)
                        {
                            ShowMsg("已经存在相同满足条件的优惠活动", false);
                        }
                        else
                        {
                            txtAmount.Text        = string.Empty;
                            txtDiscountValue.Text = string.Empty;
                            addpromoteSales.Reset();
                            ShowMsg("添加促销活动--满额打折错误", false);
                        }
                    }
                }
            }
        }
Exemple #7
0
 public abstract void GetPromotionsWithAmount(decimal amount, out int discountActivityId, out string discountName, out decimal discountValue, out DiscountValueType discountValueType, out int feeFreeActivityId, out string feeFreeName, out bool eightFree, out bool orderOptionFree, out bool procedureFeeFree);
Exemple #8
0
        public override void GetPromotionsWithAmount(decimal amount, out int discountActivityId, out string discountName, out decimal discountValue, out DiscountValueType discountValueType, out int feeFreeActivityId, out string feeFreeName, out bool eightFree, out bool orderOptionFree, out bool procedureFeeFree)
        {
            discountActivityId = 0;
            discountName       = null;
            discountValue      = 0M;
            discountValueType  = DiscountValueType.Amount;
            feeFreeActivityId  = 0;
            feeFreeName        = null;
            eightFree          = false;
            orderOptionFree    = false;
            procedureFeeFree   = false;
            DbCommand sqlStringCommand = this.database.GetSqlStringCommand("SELECT TOP 1 p.ActivityId, p.Name, fd.DiscountValue, fd.ValueType FROM Hishop_Promotions p INNER JOIN Hishop_FullDiscounts fd ON p.ActivityId = fd.ActivityId INNER JOIN Hishop_PromotionMemberGrades pm ON pm.ActivityId=fd.ActivityId WHERE @Amount >= fd.Amount  AND @GradeId IN (SELECT GradeId FROM Hishop_PromotionMemberGrades WHERE Hishop_PromotionMemberGrades.ActivityId=fd.ActivityId)ORDER BY fd.Amount DESC");

            this.database.AddInParameter(sqlStringCommand, "Amount", DbType.Currency, amount);
            this.database.AddInParameter(sqlStringCommand, "GradeId", DbType.Int32, (Users.GetUser(HiContext.Current.User.UserId) as Member).GradeId);
            using (IDataReader reader = this.database.ExecuteReader(sqlStringCommand))
            {
                if (reader.Read())
                {
                    discountActivityId = reader.GetInt32(0);
                    discountName       = reader.GetString(1);
                    discountValue      = reader.GetDecimal(2);
                    discountValueType  = (DiscountValueType)reader.GetInt32(3);
                }
            }
            sqlStringCommand = this.database.GetSqlStringCommand("SELECT TOP 1 p.ActivityId, p.Name, ff.ShipChargeFree, ff.ServiceChargeFree, ff.OptionFeeFree FROM Hishop_Promotions p INNER JOIN Hishop_FullFree ff ON p.ActivityId = ff.ActivityId INNER JOIN Hishop_PromotionMemberGrades pm ON pm.ActivityId=ff.ActivityId WHERE @SubAmount >= ff.Amount  AND @GradeId IN (SELECT GradeId FROM Hishop_PromotionMemberGrades WHERE Hishop_PromotionMemberGrades.ActivityId=ff.ActivityId)  ORDER BY ff.Amount DESC");
            decimal num = 0M;

            if ((discountValueType == DiscountValueType.Percent) && (discountValue > 0M))
            {
                num = (amount * discountValue) / 100M;
            }
            else if ((discountValueType == DiscountValueType.Amount) && (discountValue > 0M))
            {
                num = amount - discountValue;
            }
            if (num > 0M)
            {
                this.database.AddInParameter(sqlStringCommand, "SubAmount", DbType.Currency, num);
            }
            else
            {
                this.database.AddInParameter(sqlStringCommand, "SubAmount", DbType.Currency, amount);
            }
            this.database.AddInParameter(sqlStringCommand, "GradeId", DbType.Int32, (Users.GetUser(HiContext.Current.User.UserId) as Member).GradeId);
            using (IDataReader reader2 = this.database.ExecuteReader(sqlStringCommand))
            {
                if (reader2.Read())
                {
                    feeFreeActivityId = reader2.GetInt32(0);
                    feeFreeName       = reader2.GetString(1);
                    eightFree         = reader2.GetBoolean(2);
                    procedureFeeFree  = reader2.GetBoolean(3);
                    orderOptionFree   = reader2.GetBoolean(4);
                }
            }
        }