Ejemplo n.º 1
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            //Load data category and products
            await LoadCategory();
            await LoadPrices();

            LoadProducts();

            ProductCatCB.ItemsSource = NovaAPI.APICategory.category;

            NewProductBT.Focus();
        }
Ejemplo n.º 2
0
        //Refresh products data
        private void RefreshProducts_Click(object sender, RoutedEventArgs e)
        {
            if (FormGrid.Opacity == 1)
            {
                FormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
            }

            if (FilterGrid.Opacity == 1)
            {
                FilterGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
            }

            TotalPages = 0;
            Pagination = 1;

            ResetForm();

            LoadProducts();
            NewProductBT.Focus();
        }
Ejemplo n.º 3
0
        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}");
            }
        }