protected override void Process() { using (var unit = GetUnitOfWork()) { foreach (var rule in AllRules) { var orderRepo = unit.Scope.Repository <OrderRule>(); var existingRule = orderRepo.GetSingle(r => r.Name == rule.Name); if (existingRule == null) { existingRule = new OrderRule { Name = rule.Name }; orderRepo.Add(existingRule); } } try { unit.Save(); } catch (Exception e) { log.AuditFatal("Import failed", e, "Order Rule import"); } } }
public static OrderViewModel OrderPizza(Guid userId, Guid pizzaId, Guid bottomId, Guid sauceId, List <Guid> ingredientId) { UnitOfWorkRepository unitOfWork = new UnitOfWorkRepository(); OrderRule orderrule = new OrderRule(); var order = unitOfWork.OrderRepository.GetAllOrders().Where(x => x.UserId == userId).FirstOrDefault(); var piz = unitOfWork.PizzaRepository.GetPizzaId(pizzaId); var bot = unitOfWork.BottomRepository.GetBottom(bottomId); var sc = unitOfWork.SauceRepository.GetSauceId(sauceId); if (order == null) { order = new Order(); order.Id = Guid.NewGuid(); order.OrderRule = new List <OrderRule>(); } List <Ingredients> _Ing = new List <Ingredients>(); foreach (var ing in ingredientId) { var ingr = unitOfWork.IngredientRepository.GetAllIngredients().Where(x => x.Id == ing).FirstOrDefault(); _Ing.Add(ingr); } foreach (var ing in _Ing) { Pizza_Ingredient pizza_Ingredient = new Pizza_Ingredient(); pizza_Ingredient.Id = Guid.NewGuid(); pizza_Ingredient.IngriedientId = ing.Id; pizza_Ingredient.PizzaIngredient_Id = pizzaId; unitOfWork.PizzaIngredientRepository.AddPizza_Ingredients(pizza_Ingredient); piz.PizzaIngredient.Add(pizza_Ingredient); } bot.SauceId = sc.Id; piz.BottomId = bot.Id; piz.OrderRuleId = orderrule.Id; orderrule.Id = Guid.NewGuid(); orderrule.OrderId = order.Id; orderrule.PizzaId = piz.Id; order.OrderRule.Add(orderrule); unitOfWork.PizzaRepository.UpdatePizza(piz); unitOfWork.OrderRepository.AddOrUpdate(order); unitOfWork.OrderRuleRepository.AddOrUpdate(orderrule); var pizza = PizzaModelFactory.ConvertPizza(piz); var orderViewModel = new OrderViewModel() { pizza = pizza, bottom = BottomModelFacotry.ConvertBottom(bot), sauce = SauceModelFactory.ConvertSauce(sc), ingredients = IngredientModelFactory.ConvertIngredients(_Ing) }; return(orderViewModel); }
private void SearchQueryMSetOrderByShouldWork() { const OrderRule expected = OrderRule.Desc; var obj = new SearchQueryM { OrderBy = expected.ToString() }; Assert.Equal(expected, obj.OrderByValue); }
static IOrderedQueryable <T> OrderByRulesRecursivly <T>(IOrderedQueryable <T> dataCollection, List <OrderRule> rules) { if (!rules.Any()) { return(dataCollection); } // apply first rule OrderRule rule = rules.First(); MethodInfo orderOperator = rule.Descending ? ThenByDescendingMethodInfo : ThenByMethodInfo; IOrderedQueryable <T> orderedDataCollection = OrderByFieldOrPropertyName(dataCollection, orderOperator, rule.FieldOrPropertyName); // apply next rules recursivly return(OrderByRulesRecursivly(orderedDataCollection, rules.Skip(1).ToList())); }
/// <summary> /// Order <paramref name="dataCollection"/> according to <paramref name="rules"/> sequence /// </summary> /// <typeparam name="T">Collection item type</typeparam> /// <param name="dataCollection">Queryable collection</param> /// <param name="rules">Order rules to apply</param> /// <returns>Ordered queryable collection</returns> public static IOrderedQueryable <T> OrderByRules <T>(this IQueryable <T> dataCollection, IEnumerable <OrderRule> rules) { if (!rules.Any()) { throw new ArgumentException("Rules list is empty", "rules"); } // apply first rule (special case: use OrderBy operator and not ThenBy) OrderRule rule = rules.First(); MethodInfo orderOperator = rule.Descending ? OrderByDescendingMethodInfo : OrderByMethodInfo; IOrderedQueryable <T> orderedDataCollection = OrderByFieldOrPropertyName(dataCollection, orderOperator, rule.FieldOrPropertyName); // apply next rules recursivly return(OrderByRulesRecursivly(orderedDataCollection, rules.Skip(1).ToList())); }
public void AddOrUpdate(OrderRule orderRuleNew) { var orderrule = Database.OrderRule.Where(x => x.Id == orderRuleNew.Id).FirstOrDefault(); if (orderrule != null) { orderrule = orderRuleNew; Database.OrderRule.AddOrUpdate(orderrule); Database.SaveChanges(); } else { AddOrderRule(orderRuleNew); } }
public static OrderRuleModel ConvertOrderRule(OrderRule orderrule) { if (orderrule == null) { return(null); } var pizzaModel = PizzaModelFactory.GetPizzaModel(orderrule.PizzaId); OrderRuleModel model = new OrderRuleModel { Id = orderrule.Id, OrderId = orderrule.OrderId, Pizza = pizzaModel }; return(model); }
public static OrderRule ConvertOrderRuleModel(OrderRuleModel model) { if (model == null) { return(null); } OrderRule orderRule = new OrderRule() { Id = model.Id, OrderId = model.OrderId, PizzaId = model.Pizza.Id }; return(orderRule); }
/// <summary> /// Список "проблемных" счётчиков /// </summary> /// <param name="orderRule"></param> /// <returns></returns> public static List <MeterProblemInformationViewItem> GetMeterProblemInformations(OrderRule orderRule) { MeterProblemInformation model = null; model = GetDataFromArmtes <MeterProblemInformation>(String.Format(@"api/DeviceInformationApi/GetMeterProblemInformationModel?orderRule={0}", orderRule)); if (model != null) { return(model.MeterProblemInformationViewItems); } else { return(null); } }
/// <summary> /// OrderBy extension /// </summary> /// <typeparam name="T">Entity type</typeparam> /// <param name="source">Source collection</param> /// <param name="sortField">Sorting field by</param> /// <param name="orderRule">Order rule</param> /// <returns>Sorted iqueryable</returns> public static IQueryable <T> OrderBy <T>(this IQueryable <T> source, SortFields sortField, OrderRule orderRule) { var type = typeof(T); var property = type.GetProperty(sortField.ToString()); var parameter = Expression.Parameter(type, "p"); var propertyAccess = Expression.MakeMemberAccess(parameter, property); var orderByExp = Expression.Lambda(propertyAccess, parameter); var resultExp = Expression.Call( typeof(Queryable), orderRule == OrderRule.Asc ? "OrderBy" : "OrderByDescending", new[] { type, property.PropertyType }, source.Expression, Expression.Quote(orderByExp)); return(source.Provider.CreateQuery <T>(resultExp)); }
/// <summary> /// 分页获取元素集合 /// </summary> /// <param name="pageIndex">页索引</param> /// <param name="pageSize">页大小</param> /// <param name="totalRecords">总记录数</param> /// <param name="totalPages">总页数</param> /// <param name="predicate">条件</param> /// <param name="sortField">排序字段(如果不指定排序字段 那么默认按照id 排序)</param> /// <param name="rule">排序规则</param> /// <returns></returns> /// <returns></returns> public List <StudentsModel> GetstudentsElementsByPagerAndCondition(int pageIndex, int pageSize, out int totalRecords, out int totalPages, Expression <Func <StudentsModel, bool> > predicate, string sortField = null, OrderRule rule = OrderRule.ASC) { List <StudentsModel> result = null; try { result = dal_students.GetElementsByPagerAndCondition(pageIndex, pageSize, out totalRecords, out totalPages, predicate, sortField, rule); } catch (Exception ex) { throw ex; } return(result); }
public ColumnContext(int row_height, CellRenderState state, OrderRule order_rules) { this.row_height = row_height; this.renderState = state; this.order_rules = order_rules; }
public ColumnContext(int row_height, CellRenderState state, OrderRule order_rules) { this.row_height = row_height; this.renderState = state; this.order_rules = order_rules; }
public void Order(OrderRule[] rules) { throw new NotImplementedException(); }
public ActionResult Order(OrderRequest request) { if (!ModelState.IsValid) { var error = ModelState.Values.Where(v => v.Errors.Count() > 0).First(); return(this.RenderError(r => r.Message = error.Errors.First().ErrorMessage)); } var productEntity = _productRepo.Find(p => p.Id == request.OrderModel.ProductId); var totalAmount = productEntity.Price * request.OrderModel.Quantity; if (totalAmount <= 0) { return(this.RenderError(r => r.Message = "商品价格信息错误!")); } var orderNo = OrderRule.CreateCode(); using (var ts = new TransactionScope()) { var orderEntity = _orderRepo.Insert(new OrderEntity() { BrandId = productEntity.Brand_Id, CreateDate = DateTime.Now, CreateUser = request.AuthUser.Id, CustomerId = request.AuthUser.Id, InvoiceDetail = request.OrderModel.InvoiceDetail, InvoiceSubject = request.OrderModel.InvoiceTitle, NeedInvoice = request.OrderModel.NeedInvoice, Memo = request.OrderModel.Memo, PaymentMethodCode = request.OrderModel.Payment.PaymentCode, PaymentMethodName = request.OrderModel.Payment.PaymentName, ShippingAddress = request.OrderModel.ShippingAddress.ShippingAddress, ShippingContactPerson = request.OrderModel.ShippingAddress.ShippingContactPerson, ShippingContactPhone = request.OrderModel.ShippingAddress.ShippingContactPhone, ShippingFee = OrderRule.ComputeFee(request), ShippingZipCode = request.OrderModel.ShippingAddress.ShippingZipCode, Status = (int)OrderStatus.Create, StoreId = productEntity.Store_Id, UpdateDate = DateTime.Now, UpdateUser = request.AuthUser.Id, TotalAmount = totalAmount, OrderNo = orderNo }); _orderItemRepo.Insert(new OrderItemEntity() { BrandId = productEntity.Brand_Id, CreateDate = DateTime.Now, CreateUser = request.AuthUser.Id, ItemPrice = productEntity.Price, OrderNo = orderNo, ProductId = productEntity.Id, Quantity = request.OrderModel.Quantity, Status = (int)DataStatus.Normal, StoreId = productEntity.Store_Id, UnitPrice = productEntity.UnitPrice, UpdateDate = DateTime.Now, UpdateUser = request.AuthUser.Id, ExtendPrice = productEntity.Price * request.OrderModel.Quantity, ProductDesc = request.OrderModel.ProductDesc }); _orderLogRepo.Insert(new OrderLogEntity() { CreateDate = DateTime.Now, CreateUser = request.AuthUser.Id, CustomerId = request.AuthUser.Id, Operation = string.Format("创建订单"), OrderNo = orderNo, Type = (int)OrderOpera.FromCustomer }); ts.Complete(); return(new RestfulResult() { Data = new OrderResponse().FromEntity <OrderEntity>(orderEntity) }); } }
public OrderClause(string propertyName, OrderRule rule) { this.PropertyName = propertyName; this.Criterion = rule; }
protected void Rules_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "New") { String id = e.CommandArgument.ToString(); Int32 index = Settings.CostingRules.IndexOf(id); OrderRule rule = new OrderRule(); rule.Matches.Add(new OrderMatch()); Settings.CostingRules.Insert(index, rule); Settings.CostingRules.Save(); Rules.DataBind(); Rules.EditIndex = index; } else if (e.CommandName == "MoveUp") { String id = e.CommandArgument.ToString(); Int32 index = Settings.CostingRules.IndexOf(id); if (index > 0) { OrderRule rule = Settings.CostingRules[index]; Settings.CostingRules.RemoveAt(index); Settings.CostingRules.Insert(index - 1, rule); Settings.CostingRules.Save(); Rules.DataBind(); } } else if (e.CommandName == "MoveDown") { String id = e.CommandArgument.ToString(); Int32 index = Settings.CostingRules.IndexOf(id); if (index < (Settings.CostingRules.Count - 2)) { OrderRule rule = Settings.CostingRules[index]; Settings.CostingRules.RemoveAt(index); Settings.CostingRules.Insert(index + 1, rule); Settings.CostingRules.Save(); Rules.DataBind(); } } else if (e.CommandName == "Update") { if (Page.IsValid) { GridViewRow row = Rules.Rows[Rules.EditIndex]; if (row != null) { OrderMatchList matches = ((BVModules_Shipping_Order_Rules_OrderMatchEditor) row.FindControl("OrderMatchEditor")).GetMatches(); DropDownList orderPropertyList = (DropDownList)row.FindControl("ValueOrderPropertyField"); DropDownList packagePropertyList = (DropDownList)row.FindControl("ValuePackagePropertyField"); OrderProperties orderProperty = (OrderProperties)Enum.Parse(typeof(OrderProperties), orderPropertyList.SelectedValue); PackageProperties packageProperty = (PackageProperties)Enum.Parse(typeof(PackageProperties), packagePropertyList.SelectedValue); if (orderProperty == OrderProperties.PackageProperty && packageProperty == PackageProperties.Distance) { if (PostalCode.IsPostalDataInstalled()) { Anthem.Manager.AddScriptForClientSideEval("alert('No postal code data has been installed. The Distance property will always return -1.');"); } } else { foreach (OrderMatch match in matches) { if (match.OrderProperty == OrderProperties.PackageProperty && match.PackageProperty == PackageProperties.Distance) { if (PostalCode.IsPostalDataInstalled()) { Anthem.Manager.AddScriptForClientSideEval("alert('No postal code data has been installed. The Distance property will always return -1.');"); break; } } } } Page.Items["matches"] = matches; } } } else if (e.CommandName == "View") { if (Page.IsValid) { GridViewRow row = Rules.Rows[Rules.EditIndex]; if (row != null) { GridView grid = row.FindControl("SampleShippingCosts") as GridView; if (grid != null) { Int32 count; grid.Visible = true; Session["SampleData"] = GetSampleOrders(row, out count); grid.DataSource = Session["SampleData"]; grid.DataBind(); if (count > grid.PageSize*5) { grid.Caption = string.Format("{0}+ matching orders", grid.PageSize*5); } else { grid.Caption = string.Format("{0} matching order", count); if (count == 0 || count > 1) grid.Caption += "s"; } } } } } }
private List <SampleOrderResult> GetSampleOrders(GridViewRow row, out int count) { GridView grid = (GridView)row.FindControl("SampleShippingCosts"); OrderRule rule = new OrderRule(Rules.DataKeys[row.RowIndex].Value.ToString()); rule.Matches.AddRange( ((BVModules_Shipping_Order_Rules_OrderMatchEditor)row.FindControl("OrderMatchEditor")).GetMatches()); rule.Value = Decimal.Parse(((TextBox)row.FindControl("ValueField")).Text); rule.ValueCustomProperty = ((DropDownList)row.FindControl("ValueCustomPropertyField")).SelectedValue; rule.ValueItemPropertyAsString = ((DropDownList)row.FindControl("ValueItemPropertyField")).SelectedValue; rule.ValuePackagePropertyAsString = ((DropDownList)row.FindControl("ValuePackagePropertyField")).SelectedValue; rule.ValuePropertyAsString = ((DropDownList)row.FindControl("ValueOrderPropertyField")).SelectedValue; count = 0; // Scan all placed orders List <SampleOrderResult> results = new List <SampleOrderResult>(); foreach (Order order in Order.FindByCriteria(new OrderSearchCriteria())) { Order heavyOrder = Order.FindByBvin(order.Bvin); // "Unship" all of the items so that the samples look like they // were just placed. Skip any orders with deleted items. bool skipOrder = false; foreach (LineItem lineitem in heavyOrder.Items) { if (lineitem.AssociatedProduct == null || lineitem.AssociatedProduct.ShippingMode == ShippingMode.None) { skipOrder = true; } else { lineitem.QuantityShipped = 0; } } if (skipOrder) { break; } if (rule.IsMatch(heavyOrder)) { count += 1; if (count > grid.PageSize * 5) { break; } SampleOrderResult result = new SampleOrderResult(); result.OrderNumber = order.OrderNumber; result.OrderDisplay = string.Format("<a href=\"{0}\" target=\"order\">{1}</a>", Page.ResolveUrl( string.Format("~/BVAdmin/Orders/ViewOrder.aspx?id={0}", order.Bvin)), order.OrderNumber); List <string> matchValues = new List <string>(); List <string> limitValues = new List <string>(); if (rule.IsDefaultRule) { matchValues.Add("n/a"); limitValues.Add("n/a"); } else { for (int index = 0; index < rule.Matches.Count; index++) { OrderMatch match = rule.Matches[index]; string matchValue = OrderPropertiesHelper.GetOrderPropertyValue(heavyOrder, match.OrderProperty, match.PackageProperty, match.ItemProperty, match.CustomProperty, "1").ToString(); if (string.IsNullOrEmpty(matchValue)) { matchValue = "(empty)"; } matchValues.Add(matchValue); string limitValue = OrderPropertiesHelper.GetOrderPropertyValue(heavyOrder, match.LimitOrderProperty, match.LimitPackageProperty, match.LimitItemProperty, match.LimitCustomProperty, match.Limit).ToString(); if (string.IsNullOrEmpty(limitValue)) { limitValue = "(empty)"; } limitValues.Add(limitValue); } } result.MatchValues = string.Join(", ", matchValues.ToArray()); result.LimitValues = string.Join(", ", limitValues.ToArray()); object value = OrderPropertiesHelper.GetOrderPropertyValue(heavyOrder, rule.ValueOrderProperty, rule.ValuePackageProperty, rule.ValueItemProperty, rule.ValueCustomProperty, "1"); result.Value = value == null ? "n/a" : value.ToString(); if (String.IsNullOrEmpty(result.Value)) { result.Value = "(empty)"; } ShippingRate rate = new ShippingRate(((OrderRulesEditor)NamingContainer).NameFieldText, string.Empty, string.Empty, 0, string.Empty); decimal?cost = rule.GetCost(heavyOrder); if (cost.HasValue) { rate.Rate = cost.Value; result.RateDisplay = rate.RateAndNameForDisplay; } else { result.RateDisplay = "Hidden"; } results.Add(result); } } results.Sort(); return(results); }
protected String GetRuleAsString(String id) { OrderRule rule = Settings.CostingRules[id]; return(rule.ToString()); }
protected void Rules_RowCreated(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { String id = Rules.DataKeys[e.Row.RowIndex].Value.ToString(); OrderRule rule = Settings.CostingRules[id]; Int32 rowIndex = (Rules.PageIndex * Rules.PageSize) + e.Row.RowIndex; if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate) { if (rowIndex == Settings.CostingRules.Count - 1) { e.Row.FindControl("DeleteRow").Visible = false; e.Row.FindControl("MoveRuleUp").Visible = false; e.Row.FindControl("MoveRuleDown").Visible = false; } if (rowIndex == Settings.CostingRules.Count - 2) { e.Row.FindControl("MoveRuleDown").Visible = false; } if (rowIndex == 0) { e.Row.FindControl("MoveRuleUp").Visible = false; } } else if ((e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit) { DropDownList orderPropertyList = (DropDownList)e.Row.FindControl("ValueOrderPropertyField"); DropDownList packagePropertyList = (DropDownList)e.Row.FindControl("ValuePackagePropertyField"); DropDownList itemPropertyList = (DropDownList)e.Row.FindControl("ValueItemPropertyField"); DropDownList customPropertyList = (DropDownList)e.Row.FindControl("ValueCustomPropertyField"); HelpLabel customPropertyLabel = (HelpLabel)e.Row.FindControl("ValueCustomPropertyLabel"); Label multiplierLabel = (Label)e.Row.FindControl("ValueMultiplierLabel"); HelpLabel valueLabel = (HelpLabel)e.Row.FindControl("ValueLabel"); TextBox valueField = (TextBox)e.Row.FindControl("ValueField"); BaseValidator valueRequired = (BaseValidator)e.Row.FindControl("ValueRequired"); BaseValidator valueNumeric = (BaseValidator)e.Row.FindControl("ValueNumeric"); orderPropertyList.Items.Clear(); orderPropertyList.Items.AddRange(GetOrderProperties()); packagePropertyList.Items.Clear(); packagePropertyList.Items.AddRange(GetPackageProperties()); packagePropertyList.Visible = false; itemPropertyList.Items.Clear(); itemPropertyList.Items.AddRange(GetItemProperties()); itemPropertyList.Visible = false; if (rule.ValueOrderProperty == OrderProperties.ItemProperty) { itemPropertyList.Visible = true; PrepareCustomPropertyField(customPropertyLabel, customPropertyList, rule.ValueItemProperty); PrepareValueField(multiplierLabel, valueLabel, valueField, valueRequired, valueNumeric, rule.ValueItemProperty); } else if (rule.ValueOrderProperty == OrderProperties.PackageProperty) { packagePropertyList.Visible = true; PrepareCustomPropertyField(customPropertyLabel, customPropertyList, rule.ValuePackageProperty); PrepareValueField(multiplierLabel, valueLabel, valueField, valueRequired, valueNumeric, rule.ValuePackageProperty); } else { PrepareCustomPropertyField(customPropertyLabel, customPropertyList, rule.ValueOrderProperty); PrepareValueField(multiplierLabel, valueLabel, valueField, valueRequired, valueNumeric, rule.ValueOrderProperty); } if (customPropertyList.Items.Count == 0) { customPropertyList.Items.Add(new ListItem("", rule.ValueCustomProperty)); } if (customPropertyList.Items.FindByValue(rule.ValueCustomProperty) == null) { rule.ValueCustomProperty = customPropertyList.Items[0].Value; } } } }
protected void Rules_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "New") { String id = e.CommandArgument.ToString(); Int32 index = Settings.CostingRules.IndexOf(id); OrderRule rule = new OrderRule(); rule.Matches.Add(new OrderMatch()); Settings.CostingRules.Insert(index, rule); Settings.CostingRules.Save(); Rules.DataBind(); Rules.EditIndex = index; } else if (e.CommandName == "MoveUp") { String id = e.CommandArgument.ToString(); Int32 index = Settings.CostingRules.IndexOf(id); if (index > 0) { OrderRule rule = Settings.CostingRules[index]; Settings.CostingRules.RemoveAt(index); Settings.CostingRules.Insert(index - 1, rule); Settings.CostingRules.Save(); Rules.DataBind(); } } else if (e.CommandName == "MoveDown") { String id = e.CommandArgument.ToString(); Int32 index = Settings.CostingRules.IndexOf(id); if (index < (Settings.CostingRules.Count - 2)) { OrderRule rule = Settings.CostingRules[index]; Settings.CostingRules.RemoveAt(index); Settings.CostingRules.Insert(index + 1, rule); Settings.CostingRules.Save(); Rules.DataBind(); } } else if (e.CommandName == "Update") { if (Page.IsValid) { GridViewRow row = Rules.Rows[Rules.EditIndex]; if (row != null) { OrderMatchList matches = ((BVModules_Shipping_Order_Rules_OrderMatchEditor)row.FindControl("OrderMatchEditor")).GetMatches(); DropDownList orderPropertyList = (DropDownList)row.FindControl("ValueOrderPropertyField"); DropDownList packagePropertyList = (DropDownList)row.FindControl("ValuePackagePropertyField"); OrderProperties orderProperty = (OrderProperties)Enum.Parse(typeof(OrderProperties), orderPropertyList.SelectedValue); PackageProperties packageProperty = (PackageProperties)Enum.Parse(typeof(PackageProperties), packagePropertyList.SelectedValue); if (orderProperty == OrderProperties.PackageProperty && packageProperty == PackageProperties.Distance) { if (PostalCode.IsPostalDataInstalled()) { Anthem.Manager.AddScriptForClientSideEval("alert('No postal code data has been installed. The Distance property will always return -1.');"); } } else { foreach (OrderMatch match in matches) { if (match.OrderProperty == OrderProperties.PackageProperty && match.PackageProperty == PackageProperties.Distance) { if (PostalCode.IsPostalDataInstalled()) { Anthem.Manager.AddScriptForClientSideEval("alert('No postal code data has been installed. The Distance property will always return -1.');"); break; } } } } Page.Items["matches"] = matches; } } } else if (e.CommandName == "View") { if (Page.IsValid) { GridViewRow row = Rules.Rows[Rules.EditIndex]; if (row != null) { GridView grid = row.FindControl("SampleShippingCosts") as GridView; if (grid != null) { Int32 count; grid.Visible = true; Session["SampleData"] = GetSampleOrders(row, out count); grid.DataSource = Session["SampleData"]; grid.DataBind(); if (count > grid.PageSize * 5) { grid.Caption = string.Format("{0}+ matching orders", grid.PageSize * 5); } else { grid.Caption = string.Format("{0} matching order", count); if (count == 0 || count > 1) { grid.Caption += "s"; } } } } } } }
public OrderRule AddOrderRule(OrderRule rule) { Database.OrderRule.Add(rule); Database.SaveChanges(); return(rule); }
private List<SampleOrderResult> GetSampleOrders(GridViewRow row, out int count) { GridView grid = (GridView) row.FindControl("SampleShippingCosts"); OrderRule rule = new OrderRule(Rules.DataKeys[row.RowIndex].Value.ToString()); rule.Matches.AddRange( ((BVModules_Shipping_Order_Rules_OrderMatchEditor) row.FindControl("OrderMatchEditor")).GetMatches()); rule.Value = Decimal.Parse(((TextBox) row.FindControl("ValueField")).Text); rule.ValueCustomProperty = ((DropDownList) row.FindControl("ValueCustomPropertyField")).SelectedValue; rule.ValueItemPropertyAsString = ((DropDownList) row.FindControl("ValueItemPropertyField")).SelectedValue; rule.ValuePackagePropertyAsString = ((DropDownList) row.FindControl("ValuePackagePropertyField")).SelectedValue; rule.ValuePropertyAsString = ((DropDownList) row.FindControl("ValueOrderPropertyField")).SelectedValue; count = 0; // Scan all placed orders List<SampleOrderResult> results = new List<SampleOrderResult>(); foreach (Order order in Order.FindByCriteria(new OrderSearchCriteria())) { Order heavyOrder = Order.FindByBvin(order.Bvin); // "Unship" all of the items so that the samples look like they // were just placed. Skip any orders with deleted items. bool skipOrder = false; foreach (LineItem lineitem in heavyOrder.Items) { if (lineitem.AssociatedProduct == null || lineitem.AssociatedProduct.ShippingMode == ShippingMode.None) skipOrder = true; else lineitem.QuantityShipped = 0; } if (skipOrder) break; if (rule.IsMatch(heavyOrder)) { count += 1; if (count > grid.PageSize*5) break; SampleOrderResult result = new SampleOrderResult(); result.OrderNumber = order.OrderNumber; result.OrderDisplay = string.Format("<a href=\"{0}\" target=\"order\">{1}</a>", Page.ResolveUrl( string.Format("~/BVAdmin/Orders/ViewOrder.aspx?id={0}", order.Bvin)), order.OrderNumber); List<string> matchValues = new List<string>(); List<string> limitValues = new List<string>(); if (rule.IsDefaultRule) { matchValues.Add("n/a"); limitValues.Add("n/a"); } else { for (int index = 0; index < rule.Matches.Count; index++) { OrderMatch match = rule.Matches[index]; string matchValue = OrderPropertiesHelper.GetOrderPropertyValue(heavyOrder, match.OrderProperty, match.PackageProperty, match.ItemProperty, match.CustomProperty, "1").ToString(); if (string.IsNullOrEmpty(matchValue)) matchValue = "(empty)"; matchValues.Add(matchValue); string limitValue = OrderPropertiesHelper.GetOrderPropertyValue(heavyOrder, match.LimitOrderProperty, match.LimitPackageProperty, match.LimitItemProperty, match.LimitCustomProperty, match.Limit).ToString(); if (string.IsNullOrEmpty(limitValue)) limitValue = "(empty)"; limitValues.Add(limitValue); } } result.MatchValues = string.Join(", ", matchValues.ToArray()); result.LimitValues = string.Join(", ", limitValues.ToArray()); object value = OrderPropertiesHelper.GetOrderPropertyValue(heavyOrder, rule.ValueOrderProperty, rule.ValuePackageProperty, rule.ValueItemProperty, rule.ValueCustomProperty, "1"); result.Value = value == null ? "n/a" : value.ToString(); if (String.IsNullOrEmpty(result.Value)) result.Value = "(empty)"; ShippingRate rate = new ShippingRate(((OrderRulesEditor) NamingContainer).NameFieldText, string.Empty, string.Empty, 0, string.Empty); decimal? cost = rule.GetCost(heavyOrder); if (cost.HasValue) { rate.Rate = cost.Value; result.RateDisplay = rate.RateAndNameForDisplay; } else { result.RateDisplay = "Hidden"; } results.Add(result); } } results.Sort(); return results; }
/// <summary> /// 分页获取元素集合-ORM /// 注意:mysql 的存储过程 ,调用,不能输出参数。BUG.即使关闭了datareader 也不能关闭 依然isclosed =false /// </summary> /// <param name="pageIndex">页索引</param> /// <param name="pageSize">页大小</param> /// <param name="totalRecords">总记录数</param> /// <param name="totalPages">总页数</param> /// <param name="predicate">条件</param> /// <param name="sortField">排序字段</param> /// <param name="rule">排序规则</param> /// <returns></returns> public List <TElement> GetElementsByPagerAndCondition(int pageIndex, int pageSize, out int totalRecords, out int totalPages, Expression <Func <TElement, bool> > predicate, string sortField, OrderRule rule = OrderRule.ASC) { List <TElement> dataLst = new List <TElement>(); TElement entity = new TElement(); string tableInDbName; System.Reflection.PropertyInfo[] propertys; string[] filelds; string[] paras; ResolveEntity(entity, false, out tableInDbName, out propertys, out filelds, out paras); if (filelds.Length <= 1) { totalRecords = -1; totalPages = -1; //除主键后 没有其他字段 return(null); throw new Exception("未指定除主键后其他字段!"); } //获取字段 string splitor = string.Format("{0},{0}", this.FieldWrapperChar); var fieldSplitString = string.Concat(this.FieldWrapperChar, string.Join(splitor, filelds), this.FieldWrapperChar);//返回逗号分隔的字符串 例如:`ProvinceCode`,`ProvinceName` //解析查询条件 var whereStr = "1=1"; if (null != predicate) { whereStr = ResolveLambdaTreeToCondition.ConvertLambdaToCondition <TElement>(predicate, wrapperChar: this.FieldWrapperChar); } //调用分页存储过程 StringBuilder sb_Sql = new StringBuilder(); sb_Sql.Append(Contanst.PageSql_Call_Name); var sqlCmd = sb_Sql.ToString(); var sqlParas = new DynamicParameters(); sqlParas.Add("@PageIndex", pageIndex); //页索引 sqlParas.Add("@PageSize", pageSize); //页大小 sqlParas.Add("@TableName", tableInDbName); //表名称 sqlParas.Add("@SelectFields", fieldSplitString); //查询的字段 sqlParas.Add("@PrimaryKey", EntityIdentityFiledName); //查询的表的主键 sqlParas.Add("@ConditionWhere", whereStr); //查询条件 sqlParas.Add("@SortField", sortField); //排序字段 sqlParas.Add("@IsDesc", (int)rule); //倒排序 正排序 sqlParas.Add("@TotalRecords", DbType.Int32, direction: ParameterDirection.Output); //总记录数(可选参数) sqlParas.Add("@TotalPageCount", DbType.Int32, direction: ParameterDirection.Output); //总页数(输出参数 try { this.SqlOutPutToLogAsync(sqlCmd, sqlParas); using (var conn = DatabaseFactory.GetDbConnection(this.DbConfig)) { dataLst = conn.Query <TElement>(sqlCmd, sqlParas, commandType: CommandType.StoredProcedure).AsList(); } //查询完毕后 根据输出参数 返回总记录数 总页数 totalRecords = sqlParas.Get <int>("@TotalRecords"); totalPages = sqlParas.Get <int>("@TotalPageCount"); } catch (Exception ex) { //抛出Native 异常信息 throw ex; } finally { //清理字符串构建 sb_Sql.Clear(); sb_Sql = null; propertys = null; filelds = null; paras = null; } return(dataLst); }
public void Order(OrderRule rule) { throw new NotImplementedException(); }
/// <summary> /// 分页获取元素集合 /// </summary> /// <param name="pageIndex">页索引</param> /// <param name="pageSize">页大小</param> /// <param name="totalRecords">总记录数</param> /// <param name="totalPages">总页数</param> /// <param name="predicate">条件</param> /// <param name="sortField">排序字段(如果不指定排序字段 那么默认按照id 排序)</param> /// <param name="rule">排序规则</param> /// <returns></returns> public List <TElement> GetElementsByPagerAndCondition(int pageIndex, int pageSize, out int totalRecords, out int totalPages, Expression <Func <TElement, bool> > predicate, string sortField = null, OrderRule rule = OrderRule.ASC) { return(this.dbContext.GetElementsByPagerAndCondition(pageIndex, pageSize, out totalRecords, out totalPages, predicate, sortField, rule)); }