////////////////////////////////////////////////////////////////////////////////////////////////// /// /// /// Event click to create a Prestashop Product from an Odacash Product /// /// /// ////////////////////////////////////////////////////////////////////////////////////////////////// public void btnInsert_Click(object sender, RoutedEventArgs e) { // If no product is selected inform the user a terminates the execution if (productsBox.SelectedItem.ToString() == "-- Selecione el producto de Odacash --") { System.Windows.MessageBox.Show("Elija un producto", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, System.Windows.MessageBoxOptions.DefaultDesktopOnly); return; } ProductFactory pf = new ProductFactory(ConfigurationManager.AppSettings["baseUrl"].ToString(), ConfigurationManager.AppSettings["accProduct"].ToString(), ""); ImageFactory imf = new ImageFactory(ConfigurationManager.AppSettings["baseUrl"].ToString(), ConfigurationManager.AppSettings["accImages"].ToString(), ""); TextRange textRangeLarge = new TextRange(largeDesc.Document.ContentStart, largeDesc.Document.ContentEnd); TextRange textRangeShort = new TextRange(shortDesc.Document.ContentStart, shortDesc.Document.ContentEnd); try { // Create a Product product newProd = createProduct(name.Text, yes.IsChecked, textRangeShort.Text, textRangeLarge.Text, price.Text, categoryBox.SelectedItem.ToString(), manufacturerBox.SelectedItem.ToString(), textStock.Text, textNoStock.Text); // Add the product to the web pf.Add(newProd); // If the product have images add it too. if (imgBox.HasItems) { for (int i = 0; imgBox.Items.Count > i; i++) { imf.AddProductImage((long)newProd.id, imgBox.Items[i].ToString()); } } // Create a link to sync the stock between Odacash and Prestashop insertInventory(name.Text, ConfigurationManager.AppSettings["idPrestashop"].ToString(), "0", idOdacash.Text); } catch (Exception ex) { // Display errors in a txt and alert the user with a messageBox 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); System.Windows.MessageBox.Show("Se ha pruducido un error.Puede ver el contenido del mismo en el log del programa", "Error", MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK, System.Windows.MessageBoxOptions.DefaultDesktopOnly); } } finally { // Restart the fields when the executions ends productsBox.SelectedIndex = 0; idOdacash.Text = ""; name.Text = ""; price.Text = ""; shortDesc.Document.Blocks.Clear(); largeDesc.Document.Blocks.Clear(); categoryBox.SelectedIndex = 0; manufacturerBox.SelectedIndex = 0; textStock.Text = ""; textNoStock.Text = ""; imgBox.Items.Clear(); } }
public static void AnadirImagen(int product_id, ImageSlider slider, List <long> ids, string file) { ImageFactory IF = new ImageFactory(_BaseUrl, _Account, _Password); IF.AddProductImage((long)product_id, file); var ll = IF.GetProductImages((long)product_id); var img = IF.GetProductImage((long)product_id, ll.LastOrDefault().id); ids.Add(ll.LastOrDefault().id); System.IO.MemoryStream stream = new MemoryStream(); stream.Write(img, 0, img.Length); Image bitmap = Bitmap.FromStream(stream); slider.Images.Add(bitmap); slider.CurrentImageIndex = slider.Images.Count - 1; }