Ejemplo n.º 1
0
        private void removeChildren(DiscountComposite d)
        {
            foreach (DiscountComponent child in d.getChildren())
            {
                if (child is DiscountComposite)
                {
                    removeChildren((DiscountComposite)child);
                }
                else
                {
                    if (child is ReliantDiscount)
                    {
                        ReliantDiscount r = (ReliantDiscount)child;

                        if (r.getProduct() != null)
                        {
                            r.getProduct().removeReliantDiscount();
                        }
                    }
                    if (child is VisibleDiscount)
                    {
                        VisibleDiscount v = (VisibleDiscount)child;

                        if (v.getProduct() != null)
                        {
                            v.getProduct().removeDiscount();
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void removeDiscount(DiscountComponent d)
 {
     try
     {
         //SqlConnection connection = Connector.getInstance().getSQLConnection();
         lock (connection)
         {
             connection.Open();
             connection.Execute("DELETE FROM DiscountComponent WHERE id=@id ", new { id = d.getId() });
             if (d is Discount)
             {
                 connection.Execute("DELETE FROM Discount WHERE id=@id ", new { id = d.getId() });
                 connection.Close();
             }
             else
             {
                 connection.Execute("DELETE FROM DiscountComposite WHERE id=@id ", new { id = d.getId() });
                 DiscountComposite composite = (DiscountComposite)d;
                 connection.Close();
                 foreach (DiscountComponent component in composite.getChildren())
                 {
                     removeDiscount(component);
                 }
             }
             discounts.Remove(d);
         }
     }
     catch (Exception e)
     {
         if (connection.State == ConnectionState.Open)
         {
             connection.Close();
         }
         throw e;
     }
 }
Ejemplo n.º 3
0
        public void addDiscount(DiscountComponent d)
        {
            try
            {
                //SqlConnection connection = Connector.getInstance().getSQLConnection();
                lock (connection)
                {
                    connection.Open();
                    string sql = "INSERT INTO [dbo].[DiscountComponent] (id, percentage, duration, type, storeId, isPartOfComplex)" +
                                 " VALUES (@id,@percentage, @duration, @type, @storeId, @isPartOfComplex)";
                    int isPartOfComplex;
                    if (d.getIsPartOfComplex())
                    {
                        isPartOfComplex = 1;
                    }
                    else
                    {
                        isPartOfComplex = 0;
                    }
                    if (d is Discount)
                    {
                        connection.Execute(sql, new
                        {
                            id         = d.getId(),
                            percentage = d.getPercentage(),
                            duration   = d.getDuration(),
                            type       = "Discount",
                            storeId    = d.getStoreId(),
                            isPartOfComplex
                        });
                        if (d is VisibleDiscount)
                        {
                            VisibleDiscount v = (VisibleDiscount)d;
                            addVisibleDiscount(v);
                        }
                        if (d is ReliantDiscount)
                        {
                            ReliantDiscount r = (ReliantDiscount)d;
                            addReliantDiscount(r);
                        }
                    }
                    if (d is DiscountComposite)
                    {
                        DiscountComposite composite = (DiscountComposite)d;
                        connection.Execute(sql, new
                        {
                            id         = d.getId(),
                            percentage = d.getPercentage(),
                            duration   = d.getDuration(),
                            type       = "Composite",
                            storeId    = d.getStoreId(),
                            isPartOfComplex
                        });
                        foreach (DiscountComponent child in composite.getChildren())
                        {
                            string sql2 = "INSERT INTO [dbo].[DiscountComposite] (id, childid, type)" +
                                          " VALUES (@id, @childid, @type)";

                            connection.Execute(sql2, new
                            {
                                id      = d.getId(),
                                childid = child.getId(),
                                type    = composite.getType()
                            });
                        }
                    }
                    connection.Close();
                    discounts.AddFirst(d);
                }
            }

            catch (Exception e)
            {
                connection.Close();
                throw e;
            }
        }