Exemple #1
0
        private void btnNext_Click(object sender, EventArgs e)
        {
            int num;
            int num2;
            string str = string.Empty;
            if (ValidateValues(out num, out num2))
            {
                if (!addpromoteSales.IsValid)
                {
                    ShowMsg(addpromoteSales.CurrentErrors, false);
                }
                else
                {
                    PurchaseGiftInfo target = new PurchaseGiftInfo();
                    target.Name = addpromoteSales.Item.Name;
                    target.Description = addpromoteSales.Item.Description;
                    target.MemberGradeIds = chklMemberGrade.SelectedValue;
                    target.BuyQuantity = num;
                    target.GiveQuantity = num2;
                    if (target.GiveQuantity > target.BuyQuantity)
                    {
                        str = Formatter.FormatErrorMessage("赠送数量不能大于购买数量");
                    }
                    if (chklMemberGrade.SelectedValue.Count <= 0)
                    {
                        str = str + Formatter.FormatErrorMessage("适合的客户必须选择一个");
                    }
                    ValidationResults results = Hishop.Components.Validation.Validation.Validate<PurchaseGiftInfo>(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
                    {
                        switch (PromoteHelper.AddPromotion(target))
                        {
                            case PromotionActionStatus.Success:
                                {
                                    int activeIdByPromotionName = PromoteHelper.GetActiveIdByPromotionName(target.Name);
                                    base.Response.Redirect(Globals.GetAdminAbsolutePath("/promotion/PromotionProducts.aspx?ActiveId=" + activeIdByPromotionName), true);
                                    return;
                                }
                            case PromotionActionStatus.DuplicateName:
                                ShowMsg("已存在此名称的促销活动", false);
                                return;

                            case PromotionActionStatus.SameCondition:
                                ShowMsg("已经存在相同满足条件的优惠活动", false);
                                return;
                        }
                        ShowMsg("添加促销活动--买几送几错误", false);
                    }
                }
            }
        }
Exemple #2
0
 public static PurchaseGiftInfo PopulatePurchaseGift(IDataRecord reader)
 {
     if (reader == null)
     {
         return null;
     }
     PurchaseGiftInfo info = new PurchaseGiftInfo();
     info.ActivityId = (int) reader["ActivityId"];
     info.Name = (string) reader["Name"];
     if (DBNull.Value != reader["Description"])
     {
         info.Description = (string) reader["Description"];
     }
     info.BuyQuantity = (int) reader["BuyQuantity"];
     info.GiveQuantity = (int) reader["GiveQuantity"];
     return info;
 }
Exemple #3
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;
        }
Exemple #4
0
 public abstract PromotionActionStatus CreatePurchaseGift(PurchaseGiftInfo promote);
Exemple #5
0
 public override PurchaseGiftInfo GetPurchaseGiftInfo(int activeId)
 {
     DbCommand sqlStringCommand = database.GetSqlStringCommand("SELECT * FROM distro_Promotions P INNER JOIN distro_PurchaseGifts 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();
     PurchaseGiftInfo info2 = new PurchaseGiftInfo();
     using (IDataReader reader = database.ExecuteReader(sqlStringCommand))
     {
         if (reader.Read())
         {
             info = DataMapper.PopulatePromote(reader);
             info2 = DataMapper.PopulatePurchaseGift(reader);
         }
         info2.Name = info.Name;
         info2.Description = info.Description;
     }
     return info2;
 }
Exemple #6
0
 public override PromotionActionStatus CreatePurchaseGift(PurchaseGiftInfo 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();
                 }
                 if (((promote.ProductList != null) && (promote.ProductList.Count > 0)) && (AddPromotionProducts(activityId, promote.ProductList, tran) <= 0))
                 {
                     tran.Rollback();
                 }
                 DbCommand storedProcCommand = database.GetStoredProcCommand("sub_Promotions_AddPurchaseGift");
                 database.AddInParameter(storedProcCommand, "DistributorUserId", DbType.Int32, HiContext.Current.User.UserId);
                 database.AddInParameter(storedProcCommand, "ActivityId", DbType.Int32, activityId);
                 database.AddInParameter(storedProcCommand, "BuyQuantity", DbType.Int32, promote.BuyQuantity);
                 database.AddInParameter(storedProcCommand, "GiveQuantity", DbType.Int32, promote.GiveQuantity);
                 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;
 }