Пример #1
0
 public static FullDiscountInfo PopulateFullDiscount(IDataRecord reader)
 {
     if (reader == null)
     {
         return null;
     }
     FullDiscountInfo info = new FullDiscountInfo();
     info.ActivityId = (int) reader["ActivityId"];
     info.Name = (string) reader["Name"];
     if (DBNull.Value != reader["Description"])
     {
         info.Description = (string) reader["Description"];
     }
     info.Amount = (decimal) reader["Amount"];
     info.DiscountValue = (decimal) reader["DiscountValue"];
     info.ValueType = (DiscountValueType) ((int) reader["ValueType"]);
     return info;
 }
Пример #2
0
        public static PromotionInfo PopulatePromote(IDataRecord reader)
        {
            if (reader == null)
            {
                return null;
            }
            PromotionInfo info = null;
            switch (((PromoteType) reader["PromoteType"]))
            {
                case PromoteType.FullDiscount:
                    info = new FullDiscountInfo();
                    break;

                case PromoteType.FullFree:
                    info = new FullFreeInfo();
                    break;

                case PromoteType.PurchaseGift:
                    info = new PurchaseGiftInfo();
                    break;

                case PromoteType.WholesaleDiscount:
                    info = new WholesaleDiscountInfo();
                    break;
            }
            info.ActivityId = (int) reader["ActivityId"];
            info.Name = (string) reader["Name"];
            if (DBNull.Value != reader["Description"])
            {
                info.Description = (string) reader["Description"];
            }
            return info;
        }
Пример #3
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);
                        }
                    }
                }
            }
        }
Пример #4
0
 public abstract PromotionActionStatus CreateFullDiscount(FullDiscountInfo promote);
Пример #5
0
 public override FullDiscountInfo GetFullDiscountInfo(int activeId)
 {
     DbCommand sqlStringCommand = database.GetSqlStringCommand("SELECT * FROM distro_Promotions P INNER JOIN distro_FullDiscounts F ON P.ActivityId=F.ActivityId WHERE P.ActivityId=@ActivityId AND P.DistributorUserId=@DistributorUserId");
     database.AddInParameter(sqlStringCommand, "ActivityId", DbType.Int32, activeId);
     database.AddInParameter(sqlStringCommand, "DistributorUserId", DbType.Int32, HiContext.Current.User.UserId);
     PromotionInfo info = new PromotionInfo();
     FullDiscountInfo info2 = new FullDiscountInfo();
     using (IDataReader reader = database.ExecuteReader(sqlStringCommand))
     {
         if (reader.Read())
         {
             info = DataMapper.PopulatePromote(reader);
             info2 = DataMapper.PopulateFullDiscount(reader);
         }
         info2.Name = info.Name;
         info2.Description = info.Description;
     }
     return info2;
 }
Пример #6
0
 public override PromotionActionStatus CreateFullDiscount(FullDiscountInfo promote)
 {
     PromotionActionStatus unknowError = PromotionActionStatus.UnknowError;
     using (DbConnection connection = database.CreateConnection())
     {
         connection.Open();
         DbTransaction tran = connection.BeginTransaction();
         try
         {
             int activityId = CreatePromotion(promote, tran);
             if (activityId > 0)
             {
                 if (((promote.MemberGradeIds != null) && (promote.MemberGradeIds.Count > 0)) && (ReSetPromotionMemberGraders(activityId, promote.MemberGradeIds, tran) <= 0))
                 {
                     tran.Rollback();
                 }
                 DbCommand storedProcCommand = database.GetStoredProcCommand("sub_Promotions_AddFullDiscount");
                 database.AddInParameter(storedProcCommand, "DistributorUserId", DbType.Int32, HiContext.Current.User.UserId);
                 database.AddInParameter(storedProcCommand, "ActivityId", DbType.Int32, activityId);
                 database.AddInParameter(storedProcCommand, "Amount", DbType.Currency, promote.Amount);
                 database.AddInParameter(storedProcCommand, "DiscountValue", DbType.Currency, promote.DiscountValue);
                 database.AddInParameter(storedProcCommand, "ValueType", DbType.Int32, (int)promote.ValueType);
                 database.AddParameter(storedProcCommand, "ReturnValue", DbType.Int32, ParameterDirection.ReturnValue, string.Empty, DataRowVersion.Default, null);
                 database.ExecuteNonQuery(storedProcCommand, tran);
                 unknowError = (PromotionActionStatus)Convert.ToInt32(database.GetParameterValue(storedProcCommand, "ReturnValue"));
                 if (unknowError == PromotionActionStatus.Success)
                 {
                     tran.Commit();
                 }
                 else
                 {
                     tran.Rollback();
                 }
             }
             else if (activityId == 0)
             {
                 unknowError = PromotionActionStatus.DuplicateName;
                 tran.Rollback();
             }
         }
         catch
         {
             if (tran.Connection != null)
             {
                 tran.Rollback();
             }
             unknowError = PromotionActionStatus.UnknowError;
         }
         connection.Close();
     }
     return unknowError;
 }