Example #1
0
 //Clear category form data
 private void ResetCategoryForm()
 {
     if (CategoryFormGrid.Opacity == 1)
     {
         CategoryFormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
     }
     CategoryNameTX.Clear();
     CategoryCodeTX.Clear();
     SaveCategoryBT.IsEnabled = false;
 }
Example #2
0
 //Category form visibility logic
 private void NewCategoryBT_Click(object sender, RoutedEventArgs e)
 {
     //From grid animation
     if (CategoryFormGrid.Opacity == 0)
     {
         CategoryFormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("PopUpGrid"));
         CategoryNameTX.Focus();
         SaveCategoryBT.IsEnabled = true;
     }
     else if (CategoryNameTX.Text.Length == 0)
     {
         CategoryFormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
         ResetCategoryForm();
     }
     //Clear category form values
     if (CategoryNameTX.Text.Length > 0)
     {
         ResetCategoryForm();
     }
 }
Example #3
0
        private async void DeleteCategory_Click(object sender, RoutedEventArgs e)
        {
            if (CategoryFormGrid.Opacity != 0)
            {
                ResetCategoryForm();
                CategoryFormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
            }

            //Get button control
            Button Control = (Button)sender;

            //Get category information
            var CategoryData = NovaAPI.APICategory.category.Find(x => x.id == Control.Tag.ToString());

            if (CategoryData.products != "0")
            {
                MessageBox.Show("No se puede eliminar, la categoria cuenta con productos asignados");
                return;
            }

            if (MessageBox.Show($"A continuación se eliminara la categoria '{CategoryData.name}'{Environment.NewLine}¿Desea continuar?", "Eliminar categoria", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
            {
                var Data = new NovaAPI.APICategory.CategoryClass();
                Data.id = CategoryData.id;

                //Delete category
                string requestData = JsonConvert.SerializeObject(Data);
                bool   response    = await NovaAPI.APICategory.GetValues("3", DataConfig.LocalAPI, requestData);

                if (response)
                {
                    NovaAPI.APICategory.category.Remove(CategoryData);
                    CategoryGrid.Items.Refresh();
                }
                else
                {
                    MessageBox.Show($"Error al eliminar la categoria, INFO: {Environment.NewLine}{NovaAPI.APICategory.Message}");
                }
            }
        }
Example #4
0
        private void EditCategory_Click(object sender, RoutedEventArgs e)
        {
            //Get button control
            Button Control = (Button)sender;

            var CategoryData = NovaAPI.APICategory.category.Find(x => x.id == Control.Tag.ToString());

            if (CategoryFormGrid.Opacity == 0)
            {
                CategoryFormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("PopUpGrid"));
            }

            //Set category information to controls
            CategoryNameTX.Text = CategoryData.name;
            CategoryCodeTX.Text = CategoryData.code;


            //Set selected category id index for edition save
            CategorySelectIndex = Control.Tag.ToString();

            //Focus editable category
            CategoryNameTX.Focus();
            SaveCategoryBT.IsEnabled = true;
        }
Example #5
0
        private async void SaveCategoryBT_Click(object sender, RoutedEventArgs e)
        {
            NewCategoryBT.Focus();

            if (CategoryNameTX.Text.Length == 0 || CategoryNameTX.Text.Length < 4)
            {
                MessageBox.Show("El nombre de la categoria no puede estar en blanco o ser inferior a 4 caracteres");
                CategoryNameTX.Focus();
                return;
            }

            var Category = NovaAPI.APICategory.category.Find(x => x.code == CategoryCodeTX.Text || x.name == CategoryNameTX.Text);

            if (Category != null && CategorySelectIndex != Category.id)
            {
                MessageBox.Show("El nombre o codigo de la categoria ya esta en uso");
                CategoryNameTX.Focus();
                return;
            }

            if (CategoryCodeTX.Text.Length == 0)
            {
                MessageBox.Show("El codigo de la categoria no puede estar en blanco");
                CategoryNameTX.Focus();
                return;
            }

            //Get/Set Category parameters
            var Data = new NovaAPI.APICategory.CategoryClass();

            Data.id   = CategorySelectIndex;
            Data.name = CategoryNameTX.Text;
            Data.code = CategoryCodeTX.Text;


            //rol json data
            string requestData = JsonConvert.SerializeObject(Data);

            bool response;

            //Modify / Create request
            if (Data.id.Length > 0)
            {
                response = await NovaAPI.APICategory.GetValues("2", DataConfig.LocalAPI, requestData);
            }
            else
            {
                response = await NovaAPI.APICategory.GetValues("1", DataConfig.LocalAPI, requestData);
            }

            //Request response
            if (response)
            {
                if (Data.id.Length > 0)
                {
                    //On Category modified
                    var CategoryData = NovaAPI.APICategory.category.Find(x => x.id == Data.id);
                    CategoryData.name     = Data.name;
                    CategoryData.code     = Data.code;
                    CategoryData.products = Data.products;
                    CategoryGrid.Items.Refresh();
                    CategoryFormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
                    ResetCategoryForm();
                }
                else
                {
                    //On new category created response
                    var CategoryData = new NovaAPI.APICategory.CategoryClass();
                    CategoryData.name     = Data.name;
                    CategoryData.code     = Data.code;
                    CategoryData.products = "0";
                    CategoryData.id       = NovaAPI.APISupplier.LastID;

                    CategoryFormGrid.BeginStoryboard((Storyboard)Application.Current.TryFindResource("FadeInGrid"));
                    ResetCategoryForm();

                    NovaAPI.APICategory.category.Add(CategoryData);

                    //Reload rol data
                    LoadCategory();
                }
            }
            else
            {
                MessageBox.Show($"Error al crear la categoria, INFO: {Environment.NewLine}{NovaAPI.APICategory.Message}");
            }
        }