void wizz_Finished(object sender, RoutedEventArgs e)
        {
            if (rb_yes.IsChecked.Value == true)
                p = new Collective_product();
            else
            p = new Product();

            p.Billing_name = tb_billingName.Text;
            p.Default_sale_price = int.Parse(tb_defaultPrice.Text);
            p.Item_number = Globals.GetId("IRP");
            p.Minimum_stock =int.Parse(tb_minimumStock.Text);
            p.Name = tb_name.Text;
            p.Stock_price = 0;
            p.Stock_price_date = DateTime.Now;
            p.Total_sales = 0;
            p.VAT_rate = tb_vatRate.Text;
            p.Packing_name = tb_packingName.Text;
            p.Missing_quantity = 0;
            p.Packing_size = (Packing_size)cb_size.SelectedItem;
            p.Description = tb_description.Text;
            if(p is Collective_product)
            {
                p.Minimum_stock = 0;
                p.Product_properties = properties;
                p.Description = "Konfigurálható termék";
                Product_property startProp = p.Product_properties.ToList()[0];
                foreach (Product_property_value spv in startProp.Product_property_values)
                {
                    int temp = p.Product_properties.Count;
                    if (temp == 1)
                    {
                        temp = 2;
                        hasOne = true;
                    }
                    for (int i = 1; i < temp; i++)
                    {
                        Product_property pActual=null;
                        int temp2;
                        if (!hasOne)
                        {
                            pActual = p.Product_properties.ToList()[i];
                            temp2 = pActual.Product_property_values.Count;
                        }
                        else temp2 = 1;
                        for (int j = 0; j < temp2; j++)
                        {
                            Product pSub = new Product();
                            pSub.Billing_name = tb_billingName.Text;
                            pSub.Default_sale_price = int.Parse(tb_defaultPrice.Text);
                            pSub.Item_number = Globals.GetId("IRP");
                            pSub.Minimum_stock = 0;
                            pSub.Name = tb_name.Text;
                            pSub.Stock_price = 0;
                            pSub.Stock_price_date = DateTime.Now;
                            pSub.Total_sales = 0;
                            pSub.VAT_rate = tb_vatRate.Text;
                            pSub.Packing_name = tb_packingName.Text;
                            pSub.Missing_quantity = 0;
                            pSub.Packing_size = (Packing_size)cb_size.SelectedItem;
                            pSub.Description = "";

                            for (int k = 0; k < p.Product_properties.Count; k++)
                            {
                                Product_property pActual2 = p.Product_properties.ToList()[k];
                                if (pActual == pActual2)
                                {
                                        //pSub.Details += pActual2.Name + ": " + pActual2.Product_property_values.ToList()[j].Value + ", ";
                                        Product_property pProp = new Product_property { Name = pActual2.Name };
                                        pProp.Product_property_values.Add(pActual2.Product_property_values.ToList()[j]);
                                        pSub.Product_properties.Add(pProp);
                                }
                                else
                                    if (pActual2 == startProp)
                                    {
                                        //pSub.Details += pActual2.Name + ": " + spv + ", ";
                                        Product_property pProp = new Product_property { Name = pActual2.Name };
                                        pProp.Product_property_values.Add(spv);
                                        pSub.Product_properties.Add(pProp);
                                    }
                                    else
                                    {
                                        //pSub.Details += pActual2.Name + ": " + pActual2.Product_property_values.ToList()[0].Value + ", ";
                                        Product_property pProp = new Product_property { Name = pActual2.Name };
                                        pProp.Product_property_values.Add(pActual2.Product_property_values.ToList()[0]);
                                        pSub.Product_properties.Add(pProp);
                                    }

                            }

                            //pSub.Details= pSub.Details.Remove(pSub.Details.Length - 2);
                            ((Collective_product)p).Products.Add(pSub);
                        }
                    }
                }
            }

            if (Globals.AddProduct(p, Databases.localModel))
                grid_Finish.Visibility = System.Windows.Visibility.Visible;
        }
Beispiel #2
0
 public static bool AddProduct(Product p, DataModelContainer destModel)
 {
     try
     {
         destModel.ProductSet.Add(p);
         destModel.SaveChanges();
         return true;
     }
     catch(Exception ex)
     {
         return false;
     }
 }