public string ShowFromItem(string toItem) { int fromItems = 0; if (CurrentDiscountGroupID != "0") { DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(CurrentDiscountGroupID); for (int i = 0; i < discountGroup.DiscountRules.Count; i++) { if (discountGroup.DiscountRules[i].ToItems == ConvertUtilities.ToInt32(toItem)) { return(String.Format("{0}", ++fromItems)); } else { fromItems = discountGroup.DiscountRules[i].ToItems; } } } else { MainContext.RedirectMainControl("QuantityDiscountList.ascx", ""); } return(String.Format("{0}", ++fromItems)); }
protected void uxDiscountGroupGrid_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { GridViewRow rowGrid = uxDiscountGroupGrid.Rows[e.RowIndex]; string discountGroupID = uxDiscountGroupGrid.DataKeys[e.RowIndex]["DiscountGroupID"].ToString(); DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(discountGroupID); discountGroup = GetDiscountGroupFromGrid(discountGroup, rowGrid); if (String.IsNullOrEmpty(discountGroup.GroupName)) { throw new VevoException(Resources.DiscountGroupMessage.ItemUpdateErrorEmpty); } DataAccessContext.DiscountGroupRepository.Save(discountGroup); uxDiscountGroupGrid.EditIndex = -1; RefreshGrid(); uxMessage.DisplayMessage(Resources.DiscountGroupMessage.ItemUpdateSuccess); uxStatusHidden.Value = "Updated"; } finally { e.Cancel = true; } }
protected void uxDiscountGroupGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Add") { GridViewRow rowAdd = uxDiscountGroupGrid.FooterRow; DiscountGroup discountGroup = new DiscountGroup(); discountGroup = GetDiscountGroupFromGrid(discountGroup, rowAdd); if (String.IsNullOrEmpty(discountGroup.GroupName)) { uxMessage.DisplayMessage(Resources.DiscountGroupMessage.ItemAddErrorEmpty); return; } discountGroup = AddUnlimitedDiscountRule(discountGroup); DataAccessContext.DiscountGroupRepository.Save(discountGroup); ClearData(rowAdd); RefreshGrid(); uxMessage.DisplayMessage(Resources.DiscountGroupMessage.ItemAddSuccess); uxStatusHidden.Value = "Added"; } }
protected override void RefreshGrid() { DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(CurrentDiscountGroupID); uxDiscountGrid.DataSource = discountGroup.DiscountRules; uxDiscountGrid.DataBind(); }
protected void uxDiscountGrid_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { GridViewRow rowGrid = uxDiscountGrid.Rows[e.RowIndex]; string DiscountRuleID = uxDiscountGrid.DataKeys[e.RowIndex]["DiscountRuleID"].ToString(); DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(CurrentDiscountGroupID); discountGroup = SetUpDiscontRuleFromGrid(discountGroup, rowGrid, DiscountRuleID); DataAccessContext.DiscountGroupRepository.Save(discountGroup); uxDiscountGrid.EditIndex = -1; RefreshGrid(); uxMessage.DisplayMessage(Resources.DiscountMessage.ItemUpdateSuccess); uxStatusHidden.Value = "Updated"; } finally { e.Cancel = true; } }
private DiscountGroup SetUpDiscontRuleFromGrid(DiscountGroup discountGroup, GridViewRow row, string discountRuleID) { for (int i = 0; i < discountGroup.DiscountRules.Count; i++) { if (discountGroup.DiscountRules[i].DiscountRuleID == discountRuleID) { string minitemText = ((TextBox)row.FindControl("uxToItemsText")).Text; discountGroup.DiscountRules[i].ToItems = (String.IsNullOrEmpty(minitemText)) ? 0 : int.Parse(minitemText); string amountText = ((TextBox)row.FindControl("uxAmountText")).Text; string discountResult = (String.IsNullOrEmpty(amountText) ? "0" : amountText); switch (CurrentDiscountType) { case "Percentage": discountGroup.DiscountRules[i].Percentage = ConvertUtilities.ToDouble(discountResult); discountGroup.DiscountRules[i].Amount = 0; break; case "Price": discountGroup.DiscountRules[i].Amount = decimal.Parse(discountResult); discountGroup.DiscountRules[i].Percentage = 0; break; default: discountGroup.DiscountRules[i].Percentage = 0; discountGroup.DiscountRules[i].Amount = 0; break; } } } return(discountGroup); }
private void CreateDummyRow(IList <DiscountGroup> list) { DiscountGroup discountGroup = new DiscountGroup(); discountGroup.DiscountGroupID = "-1"; discountGroup.GroupName = ""; list.Add(discountGroup); }
protected void Page_Load(object sender, EventArgs e) { if (!MainContext.IsPostBack) { DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(CurrentDiscountGroupID); uxGroupNameLabel.Text = discountGroup.GroupName; CurrentDiscountType = discountGroup.DiscountType.ToString(); } }
private DiscountGroup AddUnlimitedDiscountRule(DiscountGroup discountGroup) { DiscountRule discountRule = new DiscountRule(); discountRule.ToItems = SystemConst.UnlimitedNumber; discountRule.Percentage = 0; discountRule.Amount = 0; discountGroup.DiscountRules.Add(discountRule); return(discountGroup); }
private DiscountGroup GetDiscountGroupFromGrid(DiscountGroup discountGroup, GridViewRow row) { string uxGroupNameText = ((TextBox)row.FindControl("uxGroupNameText")).Text; string uxDiscountType = ((DropDownList)row.FindControl("uxDiscountTypeDrop")).SelectedValue; string uxProductOptionDiscount = ((DropDownList)row.FindControl("uxProductOptionDiscount")).SelectedValue; discountGroup.GroupName = uxGroupNameText; discountGroup.DiscountType = GetDiscountType(uxDiscountType); discountGroup.ProductOptionDiscount = ConvertUtilities.ToBoolean(uxProductOptionDiscount); return(discountGroup); }
private DiscountGroup RemovedDiscountRule(DiscountGroup discountGroup, string discountRuleID) { for (int i = 0; i < discountGroup.DiscountRules.Count; i++) { if (discountGroup.DiscountRules[i].DiscountRuleID == discountRuleID) { discountGroup.DiscountRules.RemoveAt(i); return(discountGroup); } } return(discountGroup); }
public async Task <Object> NewRentacar(Rentacar rentacar) { string userId = User.Claims.First(c => c.Type == "UserID").Value; var user = await _dataBase.Users.FindAsync(userId); if (user == null) { return(Unauthorized("")); } if (user.Role != "sys") { return(Unauthorized("")); } try { var loc = new Location() { NameOfCity = rentacar.Location.NameOfCity, NameOfStreet = rentacar.Location.NameOfStreet, NumberInStreet = rentacar.Location.NumberInStreet, GeoHeight = rentacar.Location.GeoHeight, GeoWidth = rentacar.Location.GeoWidth }; _dataBase.Locations.Add(loc); var dg = new DiscountGroup() { GroupName = rentacar.DiscountGroups.ToList()[0].GroupName, MinPoints = rentacar.DiscountGroups.ToList()[0].MinPoints, DiscountPercentage = rentacar.DiscountGroups.ToList()[0].DiscountPercentage }; //_dataBase.DiscountGroups.Add(dg); _dataBase.SaveChanges(); var rent = new Rentacar() { NameOfService = rentacar.NameOfService, DescriptionOfService = "", Image = "", LocationID = loc.Id }; rentacar.LocationID = rentacar.Location.Id; _dataBase.Rentacars.Add(rent); rent.DiscountGroups.Add(dg); _dataBase.SaveChanges(); var test = _dataBase.Rentacars.Include(r => r.DiscountGroups).Include(r => r.Location); return(Ok(rentacar)); } catch (Exception e) { return(BadRequest(e)); } }
public async Task <Object> NewAirline(Airline airline) { string userId = User.Claims.First(c => c.Type == "UserID").Value; var user = await _dataBase.Users.FindAsync(userId); if (user == null) { return(Unauthorized("")); } if (user.Role != "sys") { return(Unauthorized("")); } try { var loc = new Location() { NameOfCity = airline.Location.NameOfCity, NameOfStreet = airline.Location.NameOfStreet, NumberInStreet = airline.Location.NumberInStreet, GeoHeight = airline.Location.GeoHeight, GeoWidth = airline.Location.GeoWidth }; _dataBase.Locations.Add(loc); var dg = new DiscountGroup() { GroupName = airline.DiscountGroups.ToList()[0].GroupName, MinPoints = airline.DiscountGroups.ToList()[0].MinPoints, DiscountPercentage = airline.DiscountGroups.ToList()[0].DiscountPercentage }; //_dataBase.DiscountGroups.Add(dg); _dataBase.SaveChanges(); var air = new Airline() { NameOfAirline = airline.NameOfAirline, DescriptionOfAirline = airline.DescriptionOfAirline, Image = "", LocationID = loc.Id }; _dataBase.Airlines.Add(air); air.DiscountGroups.Add(dg); _dataBase.SaveChanges(); return(Ok(air)); } catch (Exception e) { return(BadRequest(e)); } }
public void PopulateControls() { DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(DiscountGroupID); if (discountGroup.DiscountRules.Count > 0) { uxQuantityDiscountView.DataSource = discountGroup.DiscountRules; uxQuantityDiscountView.DataBind(); uxQuantityDiscountPanel.Visible = true; } else { uxQuantityDiscountPanel.Visible = false; } }
protected void Page_PreRender(object sender, EventArgs e) { if (DataAccessContext.Configurations.GetBoolValue("PriceRequireLogin") && !Page.User.Identity.IsAuthenticated) { uxShowLink.Visible = false; } DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(DiscountGroupID); if (discountGroup.DiscountRules.Count > 0) { uxQuantityDiscountView.DataSource = discountGroup.DiscountRules; uxQuantityDiscountView.DataBind(); } else { uxQuantityDiscountPanel.Visible = false; } }
public async Task <Object> AddNewDiscountGroup(DiscountGroupInfo group) { string userId = User.Claims.First(c => c.Type == "UserID").Value; var user = await _dataBase.Users.FindAsync(userId); if (user == null) { return(Unauthorized()); } if (user.Role != "sys") { return(Unauthorized()); } var rent = _dataBase.Rentacars.Include(r => r.DiscountGroups).First(r => r.Id == int.Parse(group.ServiceId)); if (rent == null) { return(BadRequest("No rentacar found")); } if (rent.DiscountGroups.ToList().Find(g => g.MinPoints == group.MinPoints && g.DiscountPercentage == group.DiscountPercentage) != null) { return(BadRequest("Can't have groups with same Minimum points and Percengate values!")); } if (rent.DiscountGroups.ToList().Find(g => g.GroupName == group.GroupName) != null) { return(BadRequest("Group with same name exist!")); } var disc = new DiscountGroup() { DiscountPercentage = group.DiscountPercentage, GroupName = group.GroupName, MinPoints = group.MinPoints }; rent.DiscountGroups.Add(disc); _dataBase.SaveChanges(); var ret = rent.DiscountGroups.ToList(); ret.Sort(new DiscountGroupListSort()); return(Ok(ret)); }
// This function upgrade DiscountGroup and DiscountRule table from version 2.52 to 3.0. // In version 2.52, the "MinItems" column in DiscountRule is the starting quantity to use discount rate. // In version 3.0, the "ToItems" column is the ending quantity to use discount rate. // // ----- Version 2.52 ----- // MinItems Amount // 5 10 // 10 20 // // Will be converted to // // ----- Version 3.0 ----- // ToItems Amount // 4 0 // 9 10 // Above 20 private void CopyDiscount() { DataTable discountGroupTable = GetAllDiscountGroup(); DataTable discountRuleTable = GetAllDiscountRule(); for (int i = 0; i < discountGroupTable.Rows.Count; i++) { string discountGroupID = discountGroupTable.Rows[i]["DiscountGroupID"].ToString(); DataRow[] discountrule = discountRuleTable.Select("DiscountGroupID = " + discountGroupID); DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(discountGroupID); discountGroup.DiscountType = (DiscountGroup.DiscountTypeEnum)Enum.Parse( typeof(DiscountGroup.DiscountTypeEnum), discountrule[0]["DiscountType"].ToString()); discountGroup.ProductOptionDiscount = false; discountGroup = CopyDiscountRule(discountGroup); DataAccessContext.DiscountGroupRepository.Save(discountGroup); } DataAccess.ExecuteNonQueryNoParameter("ALTER TABLE DiscountRule DROP COLUMN DiscountType;"); }
protected string ShowFromItem(object toItem) { int fromItems = 0; if (DiscountGroupID != "0") { DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(DiscountGroupID); for (int i = 0; i < discountGroup.DiscountRules.Count; i++) { if (discountGroup.DiscountRules[i].ToItems == ConvertUtilities.ToInt32(toItem)) { return(String.Format("{0}", ++fromItems)); } else { fromItems = discountGroup.DiscountRules[i].ToItems; } } } return(String.Format("{0}", ++fromItems)); }
protected void uxDiscountGrid_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Add") { GridViewRow rowAdd = uxDiscountGrid.FooterRow; DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(CurrentDiscountGroupID); DiscountRule discountRule = new DiscountRule(); discountRule = GetNewDiscontRuleFromGrid(discountRule, rowAdd); if (!IsExisted(discountRule.ToItems)) { if (discountRule.ToItems <= UnlimitedNumber) { discountGroup.DiscountRules.Add(discountRule); DataAccessContext.DiscountGroupRepository.Save(discountGroup); ClearData(rowAdd); RefreshGrid(); uxMessage.DisplayMessage(Resources.DiscountMessage.ItemAddSuccess); uxStatusHidden.Value = "Added"; } else { uxMessage.DisplayError(Resources.DiscountMessage.TomuchItemError); } } else { uxStatusHidden.Value = "Error"; uxMessage.DisplayError(Resources.DiscountMessage.MinItemError); } } }
protected void uxDeleteButton_Click(object sender, EventArgs e) { try { bool deleted = false; foreach (GridViewRow row in uxDiscountGrid.Rows) { CheckBox deleteCheck = (CheckBox)row.FindControl("uxCheck"); if (deleteCheck != null && deleteCheck.Checked) { string discountRuleID = uxDiscountGrid.DataKeys[row.RowIndex]["DiscountRuleID"].ToString(); DiscountGroup discountGroup = DataAccessContext.DiscountGroupRepository.GetOne(CurrentDiscountGroupID); discountGroup = RemovedDiscountRule(discountGroup, discountRuleID); DataAccessContext.DiscountGroupRepository.Save(discountGroup); deleted = true; } } uxDiscountGrid.EditIndex = -1; if (deleted) { uxMessage.DisplayMessage(Resources.DiscountMessage.ItemDeleteSuccess); } uxStatusHidden.Value = "Deleted"; } catch (Exception ex) { uxMessage.DisplayException(ex); } RefreshGrid(); }
//private void CopyDiscountRule( DataRow[] discountrule ) //{ // int firstToItems = ConvertUtilities.ToInt32( discountrule[0]["ToItems"] ) - 1; // int toItems; // DiscountRuleAccess.Create( discountrule[0]["DiscountGroupID"].ToString(), firstToItems.ToString(), 0, 0 ); // for (int j = 0; j < discountrule.Length - 1; j++) // { // toItems = ConvertUtilities.ToInt32( discountrule[j + 1]["ToItems"] ) - 1; // DiscountRuleAccess.Update( // discountrule[j]["DiscountRuleID"].ToString(), // discountrule[j]["DiscountGroupID"].ToString(), // toItems.ToString(), // float.Parse( discountrule[j]["Percentage"].ToString() ), // ConvertUtilities.ToDecimal( discountrule[j]["Amount"] ) // ); // } // int Last = discountrule.Length - 1; // DiscountRuleAccess.Update( // discountrule[Last]["DiscountRuleID"].ToString(), // discountrule[Last]["DiscountGroupID"].ToString(), // SystemConst.UnlimitedNumber.ToString(), // float.Parse( discountrule[Last]["Percentage"].ToString() ), // ConvertUtilities.ToDecimal( discountrule[Last]["Amount"] ) // ); //} private DiscountGroup CopyDiscountRule(DiscountGroup discountGroup) { int firstToItems = discountGroup.DiscountRules[0].ToItems - 1; int toItems; DiscountRule discountRule = new DiscountRule(); discountRule.DiscountGroupID = discountGroup.DiscountGroupID; discountRule.ToItems = firstToItems; discountRule.Amount = 0; discountRule.Percentage = 0; discountGroup.DiscountRules.Add(discountRule); for (int j = 0; j < discountGroup.DiscountRules.Count - 1; j++) { toItems = discountGroup.DiscountRules[j + 1].ToItems - 1; discountGroup.DiscountRules[j].ToItems = toItems; } int Last = discountGroup.DiscountRules.Count - 1; discountGroup.DiscountRules[Last].ToItems = SystemConst.UnlimitedNumber; return(discountGroup); }