void CombineItems(combination C) { if (C.firstDestroy) { for (int i = 0; i < panel.transform.childCount; i++) { if (C.first == panel.transform.GetChild(i).name) { Destroy(panel.transform.GetChild(i).gameObject); break; } } } if (C.secondDestroy) { for (int i = 0; i < panel.transform.childCount; i++) { if (C.second == panel.transform.GetChild(i).name) { Destroy(panel.transform.GetChild(i).gameObject); break; } } } AddItem(C.resultName); CommentControl.SendMessage("StartComment", C.Comment); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /// /// /// Create a new Combination /// /// /// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// public static combination createCombination(int id_product, int att1, int att2, string price, string idImage) { combination comb = new combination(); if (att1 != 0) { comb.associations.product_option_values.Add(createPOV(att1)); } if (att2 != 0) { comb.associations.product_option_values.Add(createPOV(att2)); } if (idImage != "-- Seleccione una imagen --") { comb.associations.images.Add(createImage(Int32.Parse(idImage))); } comb.available_date = "0000-00-00"; //comb.default_on = 1; comb.ean13 = ""; //comb.ecotax = ""; comb.id = getIDComb(); comb.id_product = id_product; comb.location = ""; comb.minimal_quantity = 1; if (price != "") { comb.price = Decimal.Round((Decimal.Parse(price) / (Decimal)1.21), 6); } comb.reference = ""; comb.supplier_reference = ""; comb.upc = ""; return(comb); }
private async Task <stock_available> GetStockValue(product product, Assort assort) { combination combination = null; if (!string.IsNullOrWhiteSpace(assort.Size) || !string.IsNullOrWhiteSpace(assort.Color) || !string.IsNullOrWhiteSpace(assort.Reference)) { combination = await _combinationProcessor.GetOrCreateCombination(product, assort); } var filter = new Dictionary <string, string> { { "id_product", product.id.Value.ToString(CultureInfo.InvariantCulture) } }; var stocks = await _apiFactory.StockFactory.GetByFilter(filter, null, null); if (stocks == null || !stocks.Any()) { return(await CreateStock(product, assort, combination)); } var stock = combination != null ? stocks.FirstOrDefault(s => s.id_product_attribute == combination.id) : stocks.FirstOrDefault(s => s.id_product == product.id); return(stock ?? await CreateStock(product, assort, combination)); }
////////////////////////////////////////////////////////////////////////////////////////////////// /// /// /// 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; } }
internal static product MapCombination(product product, combination combination) { if (combination == null) { return(product); } product.associations.combinations.Add( new combinations { id = combination.id.Value }); return(product); }
private async Task <combination> CheckCombination(combination combination, Assort assort, product product) { if (combination != null && combination.reference != assort.Reference) { combination.reference = assort.Reference; await _apiFactory.CombinationFactory.Update(combination); } if (!product.associations.combinations.Exists(s => s.id == combination.id)) { product = ProductsMapper.MapCombination(product, combination); await _apiFactory.ProductFactory.Update(product); } return(combination); }
private async Task <combination> CreateCombination(product product, Assort assort, product_option_value sizeOptionValue, product_option_value colorOptionValue, bool isDefault) { var combination = new combination { id_product = product.id, reference = assort.Reference, ean13 = assort.Ean13, associations = new AssociationsCombination(), minimal_quantity = 1, default_on = Convert.ToInt32(isDefault), }; combination.associations.product_option_values = new List <Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value>(); if (colorOptionValue != null) { combination.associations.product_option_values.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value { id = colorOptionValue.id.Value }); } if (sizeOptionValue != null) { combination.associations.product_option_values.Add(new Bukimedia.PrestaSharp.Entities.AuxEntities.product_option_value { id = sizeOptionValue.id.Value }); } combination = await _apiFactory.CombinationFactory.Add(combination); product = ProductsMapper.MapCombination(product, combination); Log.Information("Combitation created. Size: {0}, Color: {1}. Product reference: {2}, Combination Reference: {3}", sizeOptionValue?.name[0].Value, colorOptionValue?.name[0].Value, product.reference, combination.reference); await _apiFactory.ProductFactory.Update(product); return(combination); }
/// <summary> /// Evaluate Player card to identify type of combination /// reads the line of card values from array,spilt player1 and player2 cards and assign to card object /// </summary> public void EvaluatePlayerCards() { try { player1 = new Card[5]; player2 = new Card[5]; int cardIndex = 0; string[] tempCardCombination; string cardSuit; string cardValue; foreach (string lineInput in deckFromTextFile) { tempCardCombination = lineInput.Split(" "); foreach (string card in tempCardCombination) { cardSuit = card.Substring(1); cardValue = card.Substring(0, 1); if (cardIndex < 5) { player1[cardIndex] = new Card { Suit = (CARDSUIT)Enum.Parse(typeof(CARDSUIT), cardSuit, true), Value = (CARDVALUE)Enum.Parse(typeof(CARDVALUE), cardValue, true) }; } else { player2[cardIndex - 5] = new Card { Suit = (CARDSUIT)Enum.Parse(typeof(CARDSUIT), cardSuit, true), Value = (CARDVALUE)Enum.Parse(typeof(CARDVALUE), cardValue, true) }; } cardIndex++; } cardIndex = 0; // Sort the card of each player by value var sortPlayer1 = from hand in player1.ToList() orderby hand.Value select hand; var sortPlayer2 = from hand in player2.ToList() orderby hand.Value select hand; int sortCardIndex = 0; foreach (var sortedCard in sortPlayer1) { player1[sortCardIndex] = sortedCard; sortCardIndex++; } sortCardIndex = 0; foreach (var sortedCard in sortPlayer2) { player2[sortCardIndex] = sortedCard; sortCardIndex++; } //Evaluate EvaluationBase player1Evaluation = new EvaluationBase(player1); EvaluationBase player2Evaluation = new EvaluationBase(player2); combination player1Combination = player1Evaluation.EvaluatePlayerHand(); combination player2Combination = player2Evaluation.EvaluatePlayerHand(); string player1Value = ""; foreach (var element in player1) { player1Value += ((int)element.Value).ToString() + element.Suit + " "; } string player2Value = ""; foreach (var element in player2) { player2Value += ((int)element.Value).ToString() + element.Suit + " "; } if (player1Combination > player2Combination) { player1WinningHands++; } else if (player1Combination < player2Combination) { player2WinningHands++; } else { if (player1Evaluation.HandValues.Total > player2Evaluation.HandValues.Total) { player1WinningHands++; } else if (player1Evaluation.HandValues.Total < player2Evaluation.HandValues.Total) { player2WinningHands++; } else if (player1Evaluation.HandValues.HighCard > player2Evaluation.HandValues.HighCard) { player1WinningHands++; } else if (player1Evaluation.HandValues.HighCard < player2Evaluation.HandValues.HighCard) { player2WinningHands++; } else { EvaluateHighCard(4);// Evaluate From last to determine winner. } } if (log) { //Console.WriteLine(player1Value + " " + player2Value + " " + player1Combination + " " + player2Combination + " " + player1Evaluation.HandValues.Total + " " + player2Evaluation.HandValues.Total + " " + player1Evaluation.HandValues.HighCard + " " + player2Evaluation.HandValues.HighCard + " " + player1WinningHands + " " + player2WinningHands); WriteLog("-----------------------------------------------------------------------------------------------"); WriteLog("Player1 Value: " + player1Value + " Player2 Value: " + player2Value); WriteLog("Combination: " + player1Combination + " Combination: " + player2Combination); } } } catch (Exception ex) { Console.WriteLine("Error occured in EvaluatePlayerCards " + ex.Message); } }
private async Task <stock_available> CreateStock(product product, Assort assort, combination combination) { var stock = new stock_available { id_product = product.id, quantity = assort.Balance }; if (combination != null) { stock.id_product_attribute = combination.id; } return((await _apiFactory.StockFactory.AddList(new List <stock_available> { stock })).First()); }