//////////////////////////////////////////////////////////////////////////////////////////////////
        ///                                                                                            ///
        ///            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();
            }
        }
Пример #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (this.Action == "add")
            {
                ProductModel info = new ProductModel();

                info.salecount      = Int32.Parse(this.txtsalecount.Text.Trim());
                info.productcount   = Int32.Parse(this.txtproductcount.Text.Trim());
                info.productname    = this.txtproductname.Text;
                info.price          = Decimal.Parse(this.txtprice.Text.Trim());
                info.itemprice      = this.txtitemprice.Text;
                info.includepicpath = this.txtincludepicpath.Text.Trim();
                info.createtime     = DateTime.Now;
                info.categoryid     = Int32.Parse(this.ddlProductCategory.SelectedItem.Value);
                info.iscommend      = this.chkiscommend.Checked ? 1 : 0;
                info.productcode    = Int32.Parse(this.rblproductcode.SelectedValue);
                info.specification  = this.editorcontent.Value;

                //产品相册
                string[] albumArr = Request.Form.GetValues("hid_photo_name");
                if (albumArr.Length > 0)
                {
                    string pics   = string.Empty;
                    string dotstr = "";
                    foreach (string sp in albumArr)
                    {
                        pics  += dotstr + sp;
                        dotstr = "|";
                    }

                    info.productpics = pics;
                }

                ProductFactory.Add(info);
            }
            else if (this.Action == "edit")
            {
                int          productid = HYRequest.GetQueryInt("productid", 0);
                ProductModel info      = ProductFactory.Get(productid);

                info.salecount      = Int32.Parse(this.txtsalecount.Text.Trim());
                info.productcount   = Int32.Parse(this.txtproductcount.Text.Trim());
                info.productname    = this.txtproductname.Text;
                info.price          = Decimal.Parse(this.txtprice.Text.Trim());
                info.itemprice      = this.txtitemprice.Text;
                info.includepicpath = this.txtincludepicpath.Text.Trim();
                info.createtime     = DateTime.Now;
                info.categoryid     = Int32.Parse(this.ddlProductCategory.SelectedItem.Value);
                info.iscommend      = this.chkiscommend.Checked ? 1 : 0;
                info.productcode    = Int32.Parse(this.rblproductcode.SelectedValue);
                info.specification  = this.editorcontent.Value;

                //产品相册
                string[] albumArr = Request.Form.GetValues("hid_photo_name");
                if (albumArr.Length > 0)
                {
                    string pics   = string.Empty;
                    string dotstr = "";
                    foreach (string sp in albumArr)
                    {
                        pics  += dotstr + sp;
                        dotstr = "|";
                    }

                    info.productpics = pics;
                }

                ProductFactory.Update(info);
            }

            ClientScript.RegisterStartupScript(this.GetType(), "AddEditTips", "<script language=\"javascript\">window.location='productlist.aspx';</script>");
        }
Пример #3
0
 public IActionResult Product([FromBody] Bukimedia.PrestaSharp.Entities.product product)
 {
     productFactory.Add(product);
     return(Ok(product));
 }