Esempio n. 1
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();
     }
 }
Esempio n. 2
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;
        }
Esempio n. 3
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}");
            }
        }