private async void DeletePrice_Click(object sender, RoutedEventArgs e) { if (PriceFormGrid.Opacity != 0) { ResetPriceForm(); PriceFormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid")); } //Get button control Button Control = (Button)sender; //Get category information var PriceData = NovaAPI.APIPrice.price.Find(x => x.id == Control.Tag.ToString()); if (MessageBox.Show($"A continuación se eliminara la categoria '{PriceData.name}'{Environment.NewLine}¿Desea continuar?", "Eliminar categoria", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { var Data = new NovaAPI.APIPrice.PriceClass(); Data.id = PriceData.id; //Delete category string requestData = JsonConvert.SerializeObject(Data); bool response = await NovaAPI.APIPrice.GetValues("3", DataConfig.LocalAPI, requestData); if (response) { NovaAPI.APIPrice.price.Remove(PriceData); PricesGrid.Items.Refresh(); } else { MessageBox.Show($"Error al eliminar la categoria, INFO: {Environment.NewLine}{NovaAPI.APIPrice.Message}"); } } }
private async void SetProductInfo(NovaAPI.APIProdructs.ProductClass Data) { //Get price parameters var PriceData = new NovaAPI.APIPrice.PriceClass(); PriceData.id = Data.id; //rol json data string requestData = JsonConvert.SerializeObject(PriceData); try { NovaAPI.APIProdructPrice.price.Clear(); } catch (Exception Ex) { } //Load prices data bool Response = await NovaAPI.APIProdructPrice.GetValues("5", DataConfig.LocalAPI, requestData); if (Response) { //Set product default price var GeneralPData = new NovaAPI.APIPrice.PriceClass() { name = "Precio general", value = Data.sellprice }; NovaAPI.APIProdructPrice.price.Insert(0, GeneralPData); EditPrice = EditProduct == true ? false : true; //Set price categories PriceCatCB.ItemsSource = NovaAPI.APIProdructPrice.price; PriceCatCB.Items.Refresh(); //PriceCatCB.SelectedIndex = PriceCatCB.SelectedItem == null ? 0 : PriceCatCB.SelectedIndex; int PCount = Convert.ToInt32(Data.branch_count); int MinPCount = Convert.ToInt32(Data.minstock); string PInfo = ""; if (PCount == 0) { PInfo = "(Sin existencias)"; ProductBranchCountLB.Foreground = new SolidColorBrush(Colors.DarkRed); InventoryInBT.IsEnabled = false; } else if (PCount < MinPCount && MinPCount != 0) { PInfo = "(Poca existencia)"; ProductBranchCountLB.Foreground = new SolidColorBrush(Colors.DarkOrange); InventoryInBT.IsEnabled = true; } else { ProductBranchCountLB.Foreground = new SolidColorBrush(Colors.DarkGreen); InventoryInBT.IsEnabled = true; } ProductBranchCountLB.Content = $"{PCount} {PInfo}"; if (PriceCatCB.SelectedItem == null) { PriceCatCB.SelectedIndex = SelectedCatIndex; } } }
//Set popup content private async void ProductPopUp_Opened(object sender, EventArgs e) { //Get/Set product parameters var Data = new NovaAPI.APIPrice.PriceClass(); Data.id = ProductSelectIndex; //rol json data string requestData = JsonConvert.SerializeObject(Data); try { NovaAPI.APIProdructPrice.price.Clear(); } catch (Exception) { } //Load prices data bool Response = await NovaAPI.APIProdructPrice.GetValues("5", DataConfig.LocalAPI, requestData); if (Response) { SolidColorBrush ContainerColor = (SolidColorBrush)Application.Current.TryFindResource("PanelLightBackground"); //Create prices controls for (int i = 0; i < NovaAPI.APIProdructPrice.price.Count; i++) { ContainerColor = ContainerColor == (SolidColorBrush)Application.Current.TryFindResource("PanelLightBackground") ? new SolidColorBrush(Colors.White) : (SolidColorBrush)Application.Current.TryFindResource("PanelLightBackground"); Grid Container = new Grid { Height = 30, Background = ContainerColor }; //Price Name Label Name = new Label { Content = NovaAPI.APIProdructPrice.price[i].type == "0" ? $"{NovaAPI.APIProdructPrice.price[i].name}:" : $"{NovaAPI.APIProdructPrice.price[i].name} ({NovaAPI.APIProdructPrice.price[i].value}%):", FontSize = 14, Opacity = .7, HorizontalAlignment = HorizontalAlignment.Right, Margin = new Thickness(0, 0, (PriceStack.ActualWidth / 2) + 50, 0) }; Label PercentValue = new Label(); CurrencyTextBox GeneralValue = new CurrencyTextBox(); //If price type 0 if (NovaAPI.APIProdructPrice.price[i].type == "0") { GeneralValue.Name = $"value{NovaAPI.APIProdructPrice.price[i].id}"; GeneralValue.Number = Convert.ToInt32(NovaAPI.APIProdructPrice.price[i].value); GeneralValue.StringFormat = "C0"; GeneralValue.FontSize = 14; GeneralValue.HorizontalContentAlignment = HorizontalAlignment.Left; GeneralValue.Width = 100; GeneralValue.HorizontalAlignment = HorizontalAlignment.Left; GeneralValue.Margin = new Thickness(PriceStack.ActualWidth / 2, 3, 0, 3); Container.Children.Add(GeneralValue); }//If price type 1 else { double ProductValue = Convert.ToInt32(NovaAPI.APIProdructs.products.Find(x => x.id == Data.id).pSell); double DiscountValue = Convert.ToInt32(NovaAPI.APIProdructPrice.price[i].value); double TotalDiscount = ProductValue != 0 && DiscountValue != 0 ? Math.Round((ProductValue * DiscountValue) / 100) : 0; string price = string.Format("{0:C0}", ProductValue - TotalDiscount); PercentValue.Content = $"{price} \t \t (Descuento: {string.Format("{0:C0}",TotalDiscount)})"; PercentValue.FontSize = 14; PercentValue.Opacity = .7; PercentValue.Margin = new Thickness(PriceStack.ActualWidth / 2, 0, 0, 0); Container.Children.Add(PercentValue); } Container.Children.Add(Name); PriceStack.Children.Add(Container); } PopUpSaveBT.IsEnabled = true; } else { ErrorMessage.Content = NovaAPI.APIProdructPrice.Message; ErrorMessage.Visibility = Visibility.Visible; } }
private async void SavePriceBT_Click(object sender, RoutedEventArgs e) { NewPriceBT.Focus(); if (PriceNameTX.Text.Length == 0 || PriceNameTX.Text.Length < 4) { MessageBox.Show("El nombre de la categoria no puede estar en blanco o ser inferior a 4 caracteres"); PriceNameTX.Focus(); return; } int value = Convert.ToInt32(PriceValueTX.Text); if (value > 100) { MessageBox.Show("El rango del valor debe estar entre 0 - 100 %"); PriceValueTX.Focus(); return; } //Get/Set Category parameters var Data = new NovaAPI.APIPrice.PriceClass(); Data.id = PriceSelectIndex; Data.name = PriceNameTX.Text; Data.type = PriceTypeCB.SelectedIndex.ToString(); Data.value = PriceValueTX.Text; //rol json data string requestData = JsonConvert.SerializeObject(Data); bool response; //Modify / Create request if (Data.id.Length > 0) { response = await NovaAPI.APIPrice.GetValues("2", DataConfig.LocalAPI, requestData); } else { response = await NovaAPI.APIPrice.GetValues("1", DataConfig.LocalAPI, requestData); } //Request response if (response) { if (Data.id.Length > 0) { ////On Category modified var PriceData = NovaAPI.APIPrice.price.Find(x => x.id == Data.id); PriceData.name = Data.name; PriceData.value = Data.value; PricesGrid.Items.Refresh(); PriceFormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid")); ResetPriceForm(); } else { //On new category created response var PriceData = new NovaAPI.APIPrice.PriceClass(); PriceData.name = Data.name; PriceData.type = Data.type; PriceData.value = Data.value; PriceData.id = NovaAPI.APISupplier.LastID; PriceFormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid")); ResetPriceForm(); NovaAPI.APIPrice.price.Add(PriceData); //Reload rol data LoadPrices(); } } else { MessageBox.Show($"Error al crear la categoria, INFO: {Environment.NewLine}{NovaAPI.APIPrice.Message}"); } }