Ejemplo n.º 1
0
        //////////////////////////////////////////////////////////////////////////////////////////////////
        ///                                                                                            ///
        ///                                Create the combination                                      ///
        ///                                                                                            ///
        //////////////////////////////////////////////////////////////////////////////////////////////////

        public void btnInsert_Click(object sender, RoutedEventArgs e)
        {
            // If no product is selected display a messageBox
            if (productsBox.SelectedItem.ToString() == "-- Seleccione el producto de Prestashop --")
            {
                System.Windows.MessageBox.Show("Elija un producto", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, System.Windows.MessageBoxOptions.DefaultDesktopOnly);
                return;
            }
            // If no attribute is selected  display a messageBox
            if ((attributeBox.SelectedItem.ToString() == "-- Seleccione un atributo para la combinacion --") && (attributeBox2.SelectedItem.ToString() == "-- Seleccione un atributo para la combinacion --"))
            {
                System.Windows.MessageBox.Show("Elija minimo un atributo para la combinacion", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, System.Windows.MessageBoxOptions.DefaultDesktopOnly);
                return;
            }
            try
            {
                CombinationFactory cf = new CombinationFactory(ConfigurationManager.AppSettings["baseUrl"].ToString(), ConfigurationManager.AppSettings["accCombination"].ToString(), "");
                // Create a new combination
                combination newComb = createCombination(Int32.Parse(idPrestashop.Text), getAttributeID(attributeBox.SelectedItem.ToString()), getAttributeID(attributeBox2.SelectedItem.ToString()), price.Text, imageBox.SelectedItem.ToString());

                // Add the combination to the product
                cf.Add(newComb);

                // If an Odacash product is selected create a link to sync the  stock between Odacash and Prestashop
                if (idOdacash.Text != "")
                {
                    Library.insertInventory(productsBox.SelectedItem.ToString(), idPrestashop.Text, newComb.id.ToString(), idOdacash.Text);
                }
            }
            catch (Exception ex)
            {
                // Save the error message in a txt file
                using (StreamWriter writer = new StreamWriter(@"C:\ExportProduct\ExportProducts.txt", true))
                {
                    writer.WriteLine("Message :" + ex.Message + "<br/>" + Environment.NewLine + "StackTrace :" + ex.StackTrace +
                                     "" + Environment.NewLine + "Date :" + DateTime.Now.ToString());
                    writer.WriteLine(Environment.NewLine + "-----------------------------------------------------------------------------" + Environment.NewLine);
                }
            }
            finally
            {
                // Restart all the files when the execution is over
                productsBox.SelectedIndex   = 0;
                idPrestashop.Text           = "";
                attributeBox.SelectedIndex  = 0;
                attributeBox2.SelectedIndex = 0;
                odacashBox.SelectedIndex    = 0;
                price.Text = "";
                img.Source = null;
            }
        }
Ejemplo n.º 2
0
        public void TestStraight([Values(true, false)] bool draw)
        {
            var assert = draw
                                ? (Action <object>)(Assert.IsNull)
                                : o => Assert.IsNotNull(o);

            assert(CombinationFactory.TryGetStraight(
                       new[]
            {
                new Card(new MajorCardNomination(MajorCardType.Ace), Clubs),
                new Card(new MajorCardNomination(MajorCardType.King), Clubs),
                new Card(new MajorCardNomination(MajorCardType.Queen), Clubs),
                new Card(new MajorCardNomination(MajorCardType.Jack), Clubs),
                new Card(new MinorCardNomination(draw? 9 : 10), Suit.Diamonds),
            }));
        }
        public async Task InitFactories(string url, string account)
        {
            string       baseUrl  = url;
            const string password = "";

            ProductFactory         = new ProductFactory(baseUrl, account, password);
            CategoryFactory        = new CategoryFactory(baseUrl, account, password);
            StockFactory           = new StockAvailableFactory(baseUrl, account, password);
            FeatureValuesFactory   = new ProductFeatureValueFactory(baseUrl, account, password);
            ImageFactory           = new ImageFactory(baseUrl, account, password);
            ProductSupplierFactory = new ProductSupplierFactory(baseUrl, account, password);

            ManufacturerFactory = new ManufacturerFactory(baseUrl, account, password);

            SpecialPriceFactory = new SpecificPriceFactory(baseUrl, account, password);

            var featuresFactory = new ProductFeatureFactory(baseUrl, account, password);
            var features        = await featuresFactory.GetAll();

            //SizeFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Размер", StringComparison.OrdinalIgnoreCase));
            //ColorFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Цвет", StringComparison.OrdinalIgnoreCase));

            BatteryFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Батарейки", StringComparison.OrdinalIgnoreCase));
            if (BatteryFeature == null)
            {
                BatteryFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Батарейки")
                    }
                };
                BatteryFeature = await featuresFactory.Add(BatteryFeature);
            }

            MaterialFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Материал", StringComparison.OrdinalIgnoreCase));
            if (MaterialFeature == null)
            {
                MaterialFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Материал")
                    }
                };
                MaterialFeature = await featuresFactory.Add(MaterialFeature);
            }

            CountryFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Страна", StringComparison.OrdinalIgnoreCase));
            if (CountryFeature == null)
            {
                CountryFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Страна")
                    }
                };
                CountryFeature = await featuresFactory.Add(CountryFeature);
            }

            PackingFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Упаковка", StringComparison.OrdinalIgnoreCase));
            if (PackingFeature == null)
            {
                PackingFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Упаковка")
                    }
                };
                PackingFeature = await featuresFactory.Add(PackingFeature);
            }

            LengthFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Длина", StringComparison.OrdinalIgnoreCase));
            if (LengthFeature == null)
            {
                LengthFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Длина")
                    }
                };
                LengthFeature = await featuresFactory.Add(LengthFeature);
            }

            DiameterFeature = features.FirstOrDefault(f => f.name.First().Value.Equals("Диаметр", StringComparison.OrdinalIgnoreCase));
            if (DiameterFeature == null)
            {
                DiameterFeature = new product_feature()
                {
                    name = new List <language> {
                        new language(1, "Диаметр")
                    }
                };
                DiameterFeature = await featuresFactory.Add(DiameterFeature);
            }

            var optionsFactory = new ProductOptionFactory(baseUrl, account, password);
            var options        = await optionsFactory.GetAll();

            SizeOption = options.FirstOrDefault(f => f.name.First().Value.Equals("size", StringComparison.OrdinalIgnoreCase));
            if (SizeOption == null)
            {
                Log.Error("Size option not found, add size option!");
                throw new Exception("Size option not found");
            }

            ColorOption = options.FirstOrDefault(f => f.name.First().Value.Equals("color", StringComparison.OrdinalIgnoreCase));
            if (ColorOption == null)
            {
                Log.Error("Color option not found, add size option!");
                throw new Exception("Color option not found");
            }

            OptionsValueFactory = new ProductOptionValueFactory(baseUrl, account, password);

            CombinationFactory = new CombinationFactory(baseUrl, account, password);

            SupplierFactory = new SupplierFactory(baseUrl, account, password);
            Suppliers       = await SupplierFactory.GetAll();

            if (!Suppliers.Any())
            {
                throw new Exception("Suppliers not found, add them manualy");
            }
        }