Ejemplo n.º 1
0
        /// <summary>
        ///     Provides the instance related to a character index in the textbox
        /// </summary>
        /// <param name="index"></param>
        /// <returns></returns>
        protected INamable GetInstance(int index)
        {
            INamable retVal = null;

            if (Model != null)
            {
                InterpreterTreeNode node = Parse(EditionTextBox.Text);
                if (node != null)
                {
                    ContextGrabber grabber = new ContextGrabber();
                    retVal = grabber.GetContext(index, node);
                }

                if (retVal == null)
                {
                    // Perform a fuzzy search by trying to find the corresponding expression text
                    string text = GetExpressionText(EditionTextBox.Text, index);
                    node  = Parse(text);
                    index = text.Length - 1;

                    if (node != null)
                    {
                        ContextGrabber grabber = new ContextGrabber();
                        retVal = grabber.GetContext(index, node);
                    }
                }
            }

            return(retVal);
        }
Ejemplo n.º 2
0
 public List <Customer> GetAllCustomers()
 {
     using (var context = new ContextGrabber())
     {
         var Customers = context.Customers.ToList();
         return(Customers);
     }
 }
Ejemplo n.º 3
0
 public List <Customer> GetListCustomersByEstado(Estado estado)
 {
     using (var context = new ContextGrabber())
     {
         var customers = context.Customers.Where(c => c.Estado == estado);
         return(customers.ToList());
     }
 }
Ejemplo n.º 4
0
 public void CreateOrder(Order order)
 {
     using (var context = new ContextGrabber())
     {
         context.Orders.Add(order);
         context.SaveChanges();
     }
 }
Ejemplo n.º 5
0
 public void CreateProduct(Product product)
 {
     using (var context = new ContextGrabber())
     {
         context.Products.Add(product);
         context.SaveChanges();
     }
 }
Ejemplo n.º 6
0
 public List <Product> GetAllProducts()
 {
     using (var context = new ContextGrabber())
     {
         var Products = context.Products.ToList();
         return(Products);
     }
 }
Ejemplo n.º 7
0
 public Product GetProductById(int id)
 {
     using (var context = new ContextGrabber())
     {
         var product = context.Products.Find(id);
         return(product);
     }
 }
Ejemplo n.º 8
0
 public void CreateCustomer(Customer customer)
 {
     using (var context = new ContextGrabber())
     {
         context.Customers.Add(customer);
         context.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 public Customer GetCustomerById(int id)
 {
     using (var context = new ContextGrabber())
     {
         var customer = context.Customers.Find(id);
         return(customer);
     }
 }
Ejemplo n.º 10
0
 /*** Este metodo devolvera una lista de productos con estado ACTIVO ***/
 public List <Product> GetAllProductsDisponibles()
 {
     using (var context = new ContextGrabber())
     {
         var products = context.Products.Where(p => p.Estado == Estado.ACTIVO);
         return(products.ToList());
     }
 }
Ejemplo n.º 11
0
 public void DeleteProduct(Product product)
 {
     using (var context = new ContextGrabber())
     {
         context.Products.Attach(product);
         context.Products.Remove(product);
         context.SaveChanges();
     }
 }
Ejemplo n.º 12
0
 public void EditOrder(Order order)
 {
     using (var context = new ContextGrabber())
     {
         context.Orders.Add(order);
         context.Entry(order).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 13
0
 public void EditProduct(Product product)
 {
     using (var context = new ContextGrabber())
     {
         context.Products.Add(product);
         context.Entry(product).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 14
0
 public void EditCustomer(Customer customer)
 {
     using (var context = new ContextGrabber())
     {
         context.Customers.Add(customer);
         context.Entry(customer).State = System.Data.Entity.EntityState.Modified;
         context.SaveChanges();
     }
 }
Ejemplo n.º 15
0
 public void DeleteCustomer(Customer customer)
 {
     using (var context = new ContextGrabber())
     {
         context.Customers.Attach(customer);
         context.Customers.Remove(customer);
         context.SaveChanges();
     }
 }
Ejemplo n.º 16
0
 public List <Order> GetAllOrders()
 {
     using (var context = new ContextGrabber())
     {
         var products = context.Products.ToList();
         var customer = context.Customers.ToList();
         var orders   = context.Orders.ToList();
         return(orders);
     }
 }
Ejemplo n.º 17
0
        public void TestFunctionCall()
        {
            Dictionary       test = CreateDictionary("Test");
            NameSpace        n1   = CreateNameSpace(test, "N1");
            Structure        s1   = CreateStructure(n1, "S1");
            StructureElement el1  = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2   = CreateStructure(n1, "S2");
            StructureElement el2  = CreateStructureElement(s2, "E2", "S1");
            Variable         v    = CreateVariable(n1, "V", "S1");

            v.setDefaultValue("N1.S1 { E1 => True }");
            Function function = CreateFunction(n1, "f", "S1");

            Compiler.Compile_Synchronous(true, true);

            RuleCondition rc     = CreateRuleAndCondition(n1, "Rule1");
            Parser        parser = new Parser();

            {
                //                   0         1
                //                   012345678901
                const string            text      = "V <- f().S";
                VariableUpdateStatement statement = parser.Statement(rc, text, true, true) as VariableUpdateStatement;
                ContextGrabber          grabber   = new ContextGrabber();
                Assert.AreEqual(v, grabber.GetContext(0, statement));
                Assert.AreEqual(v, grabber.GetContext(1, statement));
                Assert.IsNull(grabber.GetContext(2, statement));
                Assert.IsNull(grabber.GetContext(3, statement));
                Assert.IsNull(grabber.GetContext(4, statement));
                Assert.AreEqual(function, grabber.GetContext(5, statement));
                Assert.AreEqual(function, grabber.GetContext(6, statement));
                Assert.AreEqual(function, grabber.GetContext(7, statement));
                Assert.AreEqual(s1, grabber.GetContext(8, statement));
                Assert.IsNull(grabber.GetContext(9, statement));
                Assert.IsNull(grabber.GetContext(10, statement));
            }

            {
                //                   0
                //                   0123456789
                const string            text      = "V <- f().";
                VariableUpdateStatement statement = parser.Statement(rc, text, true, true) as VariableUpdateStatement;
                ContextGrabber          grabber   = new ContextGrabber();
                Assert.AreEqual(v, grabber.GetContext(0, statement));
                Assert.AreEqual(v, grabber.GetContext(1, statement));
                Assert.IsNull(grabber.GetContext(2, statement));
                Assert.IsNull(grabber.GetContext(3, statement));
                Assert.IsNull(grabber.GetContext(4, statement));
                Assert.AreEqual(function, grabber.GetContext(5, statement));
                Assert.AreEqual(function, grabber.GetContext(6, statement));
                Assert.AreEqual(function, grabber.GetContext(7, statement));
                Assert.AreEqual(s1, grabber.GetContext(8, statement));
                Assert.IsNull(grabber.GetContext(9, statement));
            }
        }
Ejemplo n.º 18
0
        public void TestMapExpression()
        {
            Dictionary       test     = CreateDictionary("Test");
            NameSpace        n1       = CreateNameSpace(test, "N1");
            Structure        s1       = CreateStructure(n1, "S1");
            StructureElement el1      = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2       = CreateStructure(n1, "S2");
            StructureElement el2      = CreateStructureElement(s2, "E2", "S1");
            Function         function = CreateFunction(n1, "f", "S1");

            Collection collection = CreateCollection(n1, "Col", "S1", 10);
            Variable   v          = CreateVariable(n1, "V", "Col");

            Compiler.Compile_Synchronous(true, true);

            RuleCondition rc     = CreateRuleAndCondition(n1, "Rule1");
            Parser        parser = new Parser();

            {
                //                   0         1         2
                //                   012345678901234567890123456
                const string  text       = "MAP V | X. USING X IN X.E1";
                MapExpression expression = parser.Expression(rc, text, null, true, null, true, true) as MapExpression;
                Assert.IsNotNull(expression);
                ContextGrabber grabber = new ContextGrabber();
                Assert.IsNull(grabber.GetContext(0, expression));
                Assert.IsNull(grabber.GetContext(1, expression));
                Assert.IsNull(grabber.GetContext(2, expression));
                Assert.IsNull(grabber.GetContext(3, expression));
                Assert.AreEqual(v, grabber.GetContext(4, expression));
                Assert.AreEqual(v, grabber.GetContext(5, expression));
                Assert.IsNull(grabber.GetContext(6, expression));
                Assert.IsNull(grabber.GetContext(7, expression));
                Assert.AreEqual(expression.IteratorVariable, grabber.GetContext(8, expression));
                Assert.AreEqual(expression.IteratorVariable, grabber.GetContext(9, expression));
                Assert.IsNull(grabber.GetContext(10, expression));
                Assert.IsNull(grabber.GetContext(11, expression));
                Assert.IsNull(grabber.GetContext(12, expression));
                Assert.IsNull(grabber.GetContext(13, expression));
                Assert.IsNull(grabber.GetContext(14, expression));
                Assert.IsNull(grabber.GetContext(15, expression));
                Assert.IsNull(grabber.GetContext(16, expression));
                Assert.IsNull(grabber.GetContext(17, expression));
                Assert.IsNull(grabber.GetContext(18, expression));
                Assert.IsNull(grabber.GetContext(19, expression));
                Assert.IsNull(grabber.GetContext(20, expression));
                Assert.IsNull(grabber.GetContext(21, expression));
                Assert.AreEqual(expression.IteratorVariable, grabber.GetContext(22, expression));
                Assert.AreEqual(expression.IteratorVariable, grabber.GetContext(23, expression));
                Assert.AreEqual(el1, grabber.GetContext(24, expression));
                Assert.AreEqual(el1, grabber.GetContext(25, expression));
                Assert.AreEqual(el1, grabber.GetContext(26, expression));
                Assert.IsNull(grabber.GetContext(27, expression));
            }
        }
Ejemplo n.º 19
0
 public Order GetOrderById(int id)
 {
     using (var context = new ContextGrabber())
     {
         var products    = context.Products.ToList();
         var orderDetail = context.OrderDetails.ToList();
         var customer    = context.Customers.ToList();
         var order       = context.Orders.Find(id);
         return(order);
     }
 }
Ejemplo n.º 20
0
        public void TestApplyStatement()
        {
            Dictionary       test     = CreateDictionary("Test");
            NameSpace        n1       = CreateNameSpace(test, "N1");
            Structure        s1       = CreateStructure(n1, "S1");
            StructureElement el1      = CreateStructureElement(s1, "E1", "Boolean");
            Structure        s2       = CreateStructure(n1, "S2");
            StructureElement el2      = CreateStructureElement(s2, "E2", "S1");
            Function         function = CreateFunction(n1, "f", "S1");

            Collection collection = CreateCollection(n1, "Col", "S1", 10);
            Variable   v          = CreateVariable(n1, "V", "Col");

            Compiler.Compile_Synchronous(true, true);

            RuleCondition rc     = CreateRuleAndCondition(n1, "Rule1");
            Parser        parser = new Parser();

            {
                //                   0         1         2
                //                   012345678901234567890123
                const string   text      = "APPLY X <- X ON V | X.";
                ApplyStatement statement = parser.Statement(rc, text, true, true) as ApplyStatement;
                Assert.IsNotNull(statement);
                ContextGrabber grabber = new ContextGrabber();
                Assert.IsNull(grabber.GetContext(0, statement));
                Assert.IsNull(grabber.GetContext(1, statement));
                Assert.IsNull(grabber.GetContext(2, statement));
                Assert.IsNull(grabber.GetContext(3, statement));
                Assert.IsNull(grabber.GetContext(4, statement));
                Assert.IsNull(grabber.GetContext(5, statement));
                Assert.AreEqual(statement.IteratorVariable, grabber.GetContext(6, statement));
                Assert.AreEqual(statement.IteratorVariable, grabber.GetContext(7, statement));
                Assert.IsNull(grabber.GetContext(8, statement));
                Assert.IsNull(grabber.GetContext(9, statement));
                Assert.IsNull(grabber.GetContext(10, statement));
                Assert.AreEqual(statement.IteratorVariable, grabber.GetContext(11, statement));
                Assert.AreEqual(statement.IteratorVariable, grabber.GetContext(12, statement));
                Assert.IsNull(grabber.GetContext(13, statement));
                Assert.IsNull(grabber.GetContext(14, statement));
                Assert.IsNull(grabber.GetContext(15, statement));
                Assert.AreEqual(v, grabber.GetContext(16, statement));
                Assert.AreEqual(v, grabber.GetContext(17, statement));
                Assert.IsNull(grabber.GetContext(18, statement));
                Assert.IsNull(grabber.GetContext(19, statement));
                Assert.AreEqual(statement.IteratorVariable, grabber.GetContext(20, statement));
                Assert.AreEqual(statement.IteratorVariable, grabber.GetContext(21, statement));
                Assert.IsNull(grabber.GetContext(22, statement));
            }
        }
Ejemplo n.º 21
0
        public void DeleteOrder(Order order)
        {
            using (var context = new ContextGrabber())
            {
                var orderContext = context.Orders.Find(order.OrderID);

                foreach (var detail in order.Details.ToList())
                {
                    var detailContext = context.OrderDetails.Find(detail.OrderDetailID);
                    context.OrderDetails.Attach(detailContext);
                    context.OrderDetails.Remove(detailContext);
                    context.SaveChanges();
                }

                context.Orders.Attach(orderContext);
                context.Orders.Remove(orderContext);
                context.SaveChanges();
            }
        }