public AddItemWindow(GridItem item) { AlwaysLoad(); _importedConfig = item.Configitem; LoadFromConfig(item); }
private async void TrySave_Click(object sender, RoutedEventArgs e) { List <string> issues = new List <string>(); if (ItemTextbox.SelectedIndex == -1) { issues.Add("Select an item."); } if (_selectedItem != null && _selectedItem.ItemHasRanks) { if (string.IsNullOrEmpty(Text_RankMin.Text)) { issues.Add("Include a minimum rank you would like to search for."); } if (string.IsNullOrEmpty(Text_RankMax.Text)) { issues.Add("Include a maximum rank you would like to search for."); } } if (string.IsNullOrEmpty(Text_Price.Text)) { issues.Add("Include a price."); } switch ((CB_QuantityType.SelectedItem as ComboBoxItem).Content.ToString()) { case "Any": break; case "At least": if (string.IsNullOrEmpty(Quantity_Selector_Single.Text)) { issues.Add("Include a minimum quantity to search for."); } break; case "At most": if (string.IsNullOrEmpty(Quantity_Selector_Single.Text)) { issues.Add("Include a maximum quantity to search for."); } break; case "Between": if (string.IsNullOrEmpty(Quantity_Selector_Single.Text)) { issues.Add("Include a maximum quantity to search for."); } if (string.IsNullOrEmpty(Quantity_Selector_Single.Text)) { issues.Add("Include a minimum quantity to search for."); } break; } if (issues.Count != 0) { StackPanel stackPanel = new StackPanel { Margin = new Thickness(4, 4, 4, 4) }; Button b = new Button { Command = DialogHost.CloseDialogCommand, Content = "Close" }; TextBlock te = new TextBlock { Text = "Please fix the following issues:", Padding = new Thickness(20, 20, 20, 10), FontWeight = FontWeights.Bold, Foreground = Brushes.IndianRed }; stackPanel.Children.Add(te); foreach (var issue in issues) { TextBlock t = new TextBlock { Text = issue, Padding = new Thickness(20, 10, 20, 10) }; stackPanel.Children.Add(t); } stackPanel.Children.Add(b); await DialogHost.Show(stackPanel); } else { C.Item itemBody = new C.Item { UrlName = _selectedItem.UrlName, Name = ItemTextbox.Text, Price = int.Parse(Text_Price.Text), Enabled = true }; if (_selectedItem.ItemHasRanks) { itemBody.ModRankMin = int.Parse(Text_RankMin.Text); itemBody.ModRankMax = int.Parse(Text_RankMax.Text); } switch ((CB_QuantityType.SelectedItem as ComboBoxItem).Content.ToString()) { case "Any": itemBody.QuantityMin = 0; itemBody.QuantityMax = 999; break; case "At least": itemBody.QuantityMin = int.Parse(Quantity_Selector_Single.Text); itemBody.QuantityMax = 999; break; case "At most": itemBody.QuantityMin = 0; itemBody.QuantityMax = int.Parse(Quantity_Selector_Single.Text); break; case "Between": itemBody.QuantityMin = int.Parse(Text_QuantityMin.Text); itemBody.QuantityMax = int.Parse(Text_QuantityMax.Text); break; } switch ((CB_BuySellSelector.SelectedItem as ComboBoxItem).Content.ToString()) { case "Buying": itemBody.Type = OrderType.Buy; break; case "Selling": itemBody.Type = OrderType.Sell; break; } if (_importedConfig != null) { int index = Global.Configuration.Items.IndexOf(_importedConfig); if (index != -1) { Global.Configuration.Items[index] = itemBody; } } else { Global.Configuration.Items.Add(itemBody); } Functions.Config.Save(); Close(); } }
private GridItem LoadFromConfiguration(C.Item i) { var g = new GridItem { Name = i.Name, Price = i.Price, Type = i.Type, Enabled = i.Enabled, Image = Path.Combine(Functions.PathToTemp(), Path.GetFileName(FNA.GetFilePair(i.UrlName).FileName)) }; if (i.QuantityMin == 0 && i.QuantityMax != 999) { g.Quantity = $"≤ {i.QuantityMax}"; } else if (i.QuantityMin != 0 && i.QuantityMax == 999) { g.Quantity = $"≥ {i.QuantityMin}"; } else if (i.QuantityMin == 0 && i.QuantityMax == 999) { g.Quantity = "ANY"; } else { g.Quantity = $"{i.QuantityMin} - {i.QuantityMax}"; } if (i.ModRankMin != null && i.ModRankMax != null) { g.Rank = i.ModRankMax == i.ModRankMin ? $"{i.ModRankMin}" : $"{i.ModRankMin} - {i.ModRankMax}"; } else if (i.ModRankMin != null && i.ModRankMax == null) { g.Rank = $"{i.ModRankMin} +"; } else if (i.ModRankMin == null && i.ModRankMax != null) { g.Rank = $"- {i.ModRankMax}"; } else { g.Rank = "N/A"; } switch (i.Type) { case OrderType.Buy: g.OrderText = "WTB"; g.OrderForeground = Constants.WtbForeground; g.OrderBackground = Constants.WtbBackground; break; case OrderType.Sell: g.OrderText = "WTS"; g.OrderForeground = Constants.WtsForeground; g.OrderBackground = Constants.WtsBackground; break; } g.Configitem = i; return(g); }