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 { WholesaleDiscountInfo target = new WholesaleDiscountInfo(); target.Name = addpromoteSales.Item.Name; target.Description = addpromoteSales.Item.Description; target.Quantity = num; target.DiscountValue = num2; target.MemberGradeIds = chklMemberGrade.SelectedValue; Session["wholesaleDiscountInfo"] = target; if (chklMemberGrade.SelectedValue.Count <= 0) { str = Formatter.FormatErrorMessage("适合的客户必须选择一个"); } ValidationResults results = Hishop.Components.Validation.Validation.Validate<WholesaleDiscountInfo>(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 (SubsitePromoteHelper.AddPromotion(target)) { case PromotionActionStatus.Success: { int activeIdByPromotionName = SubsitePromoteHelper.GetActiveIdByPromotionName(target.Name); base.Response.Redirect(Globals.ApplicationPath + "/Shopadmin/promotion/MyPromotionProducts.aspx?ActiveId=" + activeIdByPromotionName, true); return; } case PromotionActionStatus.DuplicateName: ShowMsg("已存在此名称的促销活动", false); return; case PromotionActionStatus.SameCondition: ShowMsg("已经存在相同满足条件的优惠活动", false); return; } ShowMsg("添加促销活动--批发打折错误", false); } } } }
public static WholesaleDiscountInfo PopulateWholesaleDiscount(IDataRecord reader) { if (reader == null) { return null; } WholesaleDiscountInfo info = new WholesaleDiscountInfo(); info.ActivityId = (int) reader["ActivityId"]; info.Name = (string) reader["Name"]; if (DBNull.Value != reader["Description"]) { info.Description = (string) reader["Description"]; } info.Quantity = (int) reader["Quantity"]; info.DiscountValue = Convert.ToInt32(reader["DiscountValue"]); return info; }
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; }
public abstract PromotionActionStatus CreateWholesaleDiscount(WholesaleDiscountInfo promote);
public override WholesaleDiscountInfo GetWholesaleDiscountInfo(int activeId) { DbCommand sqlStringCommand = database.GetSqlStringCommand("SELECT * FROM distro_Promotions P INNER JOIN distro_WholesaleDiscounts 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(); WholesaleDiscountInfo info2 = new WholesaleDiscountInfo(); using (IDataReader reader = database.ExecuteReader(sqlStringCommand)) { if (reader.Read()) { info = DataMapper.PopulatePromote(reader); info2 = DataMapper.PopulateWholesaleDiscount(reader); } info2.Name = info.Name; info2.Description = info.Description; } return info2; }
public override PromotionActionStatus CreateWholesaleDiscount(WholesaleDiscountInfo 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_AddWholesaleDiscount"); database.AddInParameter(storedProcCommand, "DistributorUserId", DbType.Int32, HiContext.Current.User.UserId); database.AddInParameter(storedProcCommand, "ActivityId", DbType.Int32, activityId); database.AddInParameter(storedProcCommand, "Quantity", DbType.Int32, promote.Quantity); database.AddInParameter(storedProcCommand, "DiscountValue", DbType.Int32, promote.DiscountValue); 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; }