//Toggle product form private async void NewProductBT_Click(object sender, RoutedEventArgs e) { if (FilterGrid.Opacity != 0) { FilterGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid")); await Task.Delay(100); } //From grid animation if (FormGrid.Opacity == 0) { FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("PopUpGrid")); ProductCodeTX.Focus(); SaveProductBT.IsEnabled = true; } else if (ProductCodeTX.Text.Length == 0) { FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid")); ResetForm(); } //Clear products values if (ProductCodeTX.Text.Length > 0) { ResetForm(); SaveProductBT.IsEnabled = true; } }
//Edit product button toggle private void Edit_Click(object sender, RoutedEventArgs e) { //Get button control Button Control = (Button)sender; if (FilterGrid.Opacity != 0) { FilterGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid")); } var ProductData = NovaAPI.APIProdructs.products.Find(x => x.id == Control.Tag.ToString()); if (FormGrid.Opacity == 0) { FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("PopUpGrid")); } //Set popup name PopUpProductName.Content = ProductData.name; PopUpProductValue.Content = string.Format("Precio venta general: {0:C0}", Convert.ToInt32(ProductData.sellprice)); //Set product information to controls ProductCodeTX.Text = ProductData.code; ProductNameTX.Text = ProductData.name; ProductCatCB.SelectedItem = NovaAPI.APICategory.category.Find(x => x.id == ProductData.category); ProductCostTX.Number = Convert.ToInt32(ProductData.costprice); ProductPriceTX.Number = Convert.ToInt32(ProductData.sellprice); ProductTypeCB.SelectedIndex = Convert.ToInt32(ProductData.unity_type); MinStockTX.Text = ProductData.minstock; MaxStockTX.Text = ProductData.maxstock; //Set taxes if (ProductData.iva == "0" && ProductData.iac == "0" && ProductData.iva5 == "0") { TaxNoneRB.IsChecked = true; } else { TaxIvaRB.IsChecked = ProductData.iva == "1" ? true : false; TaxIva5RB.IsChecked = ProductData.iva5 == "1" ? true : false; TaxIacRB.IsChecked = ProductData.iac == "1" ? true : false; } //Set selected product id index for edition save ProductSelectIndex = Control.Tag.ToString(); //Focus editable product ProductCodeTX.Focus(); SaveProductBT.IsEnabled = true; PricesBT.IsEnabled = true; }
private void ResetForm() { ProductCodeTX.Clear(); ProductNameTX.Clear(); ProductCatCB.SelectedIndex = 0; ProductSelectIndex = ""; ProductCostTX.Number = 0; ProductPriceTX.Number = 0; MinStockTX.Text = "0"; MaxStockTX.Text = "0"; PricesBT.IsEnabled = false; ProductCatCB.SelectedIndex = 0; SaveProductBT.IsEnabled = false; }
private async void SaveProductBT_Click(object sender, RoutedEventArgs e) { NewProductBT.Focus(); if (ProductCodeTX.Text.Length == 0) { MessageBox.Show("El codigo del producto no puede estar en blanco"); ProductCodeTX.Focus(); return; } else if (ProductNameTX.Text.Length == 0 || ProductNameTX.Text.Length < 5) { MessageBox.Show("El nombre del producto no puede estar en blanco o ser inferior a 5 caracteres"); ProductNameTX.Focus(); return; } //Get/Set product parameters var Data = new NovaAPI.APIProdructs.ProductClass(); Data.id = ProductSelectIndex; Data.code = ProductCodeTX.Text; Data.name = ProductNameTX.Text; Data.category = ((NovaAPI.APICategory.CategoryClass)ProductCatCB.SelectedItem).id; Data.costprice = ProductCostTX.Number.ToString(); Data.sellprice = ProductPriceTX.Number.ToString(); Data.minstock = MinStockTX.Text; Data.maxstock = MaxStockTX.Text; Data.unity_type = ProductTypeCB.SelectedIndex.ToString(); Data.hproduct = H; Data.iva = TaxIvaRB.IsChecked == true ? "1" : "0"; Data.iac = TaxIacRB.IsChecked == true ? "1" : "0"; Data.iva5 = TaxIva5RB.IsChecked == true ? "1" : "0"; //rol json data string requestData = JsonConvert.SerializeObject(Data); bool response; //Modify / Create request if (Data.id.Length > 0) { response = await NovaAPI.APIProdructs.GetValues("2", DataConfig.LocalAPI, requestData); } else { response = await NovaAPI.APIProdructs.GetValues("1", DataConfig.LocalAPI, requestData); } //Request response if (response) { if (Data.id.Length > 0) { //On Product modified var ProductData = NovaAPI.APIProdructs.products.Find(x => x.id == Data.id); ProductData.code = Data.code; ProductData.name = Data.name; ProductData.category = Data.category; ProductData.costprice = Data.costprice; ProductData.sellprice = Data.sellprice; ProductData.minstock = Data.minstock; ProductData.maxstock = Data.maxstock; ProductData.unity_type = Data.unity_type; ProductData.iac = Data.iac; ProductData.iva5 = Data.iva5; ProductData.iva = Data.iva; ProductsGrid.Items.Refresh(); FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid")); ResetForm(); } else { //On new produict created response var ProductData = new NovaAPI.APIProdructs.ProductClass(); ProductData.code = Data.code; ProductData.name = Data.name; ProductData.category = Data.category; ProductData.costprice = Data.costprice; ProductData.sellprice = Data.sellprice; ProductData.minstock = Data.minstock; ProductData.maxstock = Data.maxstock; ProductData.iac = Data.iac; ProductData.iva5 = Data.iva5; ProductData.iva = Data.iva; ProductData.unity_type = Data.unity_type; ProductData.id = NovaAPI.APIProdructs.LastID; FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid")); ResetForm(); NovaAPI.APIProdructs.products.Add(ProductData); //reset pagination TotalPages = 0; Pagination = 1; //Reload product data LoadProducts(null, ProductData.code); } } else { MessageBox.Show($"Error al crear el producto, INFO: {Environment.NewLine}{NovaAPI.APIProdructs.Message}"); } }