Exemple #1
0
        public Dto_SellerNode UpdateSellers(Dto_SellerNode sellersNode)
        {
            Dto_SellerNode   Head             = sellersNode;
            LogicStoreSystem logicStoreSystem = new LogicStoreSystem();
            int selectedMode = logicStoreSystem.selectedMode("vendedor");

            if (selectedMode == 1)
            {
                Dto_Seller seller = new Dto_Seller();
                Console.WriteLine("\nNombre: ");
                seller.Name = Console.ReadLine();
                Console.WriteLine("Documento: ");
                seller.Document = Int32.Parse(Console.ReadLine());
                Console.WriteLine("Genero: ");
                seller.Gender = Console.ReadLine();
                Console.WriteLine("Edad: ");
                seller.Age = int.Parse(Console.ReadLine());
                Console.WriteLine("Telefono: ");
                seller.Phone = Console.ReadLine();
                Console.WriteLine("Estrato: ");
                seller.Stratum = int.Parse(Console.ReadLine());

                Dto_SellerNode newSellerNode = new Dto_SellerNode();
                newSellerNode.Seller = seller;

                Dto_SellerNode last = Head;
                while (last.Next != null)
                {
                    last = last.Next;
                }
                seller.Code = last.Seller.Code + 1;
                last.Next   = newSellerNode;
            }
            else if (selectedMode == 2)
            {
                Dto_SellerNode sellers;
                Dto_SellerNode baseSellerNode = sellersNode;
                Dto_SellerNode iterator       = sellersNode;
                Dto_SellerNode last           = sellersNode;
                string         type           = "false";

                Console.WriteLine("\n¿Que codigo deseas eliminar?: ");
                int deleteCode = int.Parse(Console.ReadLine());

                int countSellers = 1;

                if (last != null)
                {
                    while (last.Next != null)
                    {
                        countSellers++;
                        last = last.Next;
                    }

                    while (type == "false")
                    {
                        for (int i = 0; i < countSellers; i++)
                        {
                            if (iterator.Seller.Code == deleteCode)
                            {
                                sellers = iterator.Next;
                                if (deleteCode == baseSellerNode.Seller.Code)
                                {
                                    sellersNode = baseSellerNode.Next;
                                    type        = "true";
                                    break;
                                }
                                else
                                {
                                    while (baseSellerNode.Seller.Code != deleteCode)
                                    {
                                        if (baseSellerNode.Next != null & baseSellerNode.Next.Seller.Code != deleteCode)
                                        {
                                            baseSellerNode = baseSellerNode.Next;
                                            type           = "true";
                                        }
                                        else
                                        {
                                            type = "true";
                                            break;
                                        }
                                    }
                                    baseSellerNode.Next = sellers;
                                }
                            }
                            iterator = iterator.Next;
                        }

                        if (type == "false")
                        {
                            Console.WriteLine("\nEl codigo que deseas eliminar no existe, por favor elige otro");
                            deleteCode = int.Parse(Console.ReadLine());
                            iterator   = sellersNode;
                            Console.WriteLine(" ");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("\nNo cuentas con ningun Vendedor, por favor selecciona la opcion de agregar o continua");
                }
            }
            return(sellersNode);
        }
Exemple #2
0
        public Dto_ProductNode UpdateProducts(Dto_ProductNode productsNode)
        {
            Dto_ProductNode  Head             = productsNode;
            LogicStoreSystem logicStoreSystem = new LogicStoreSystem();
            int selectedMode = logicStoreSystem.selectedMode("producto");

            if (selectedMode == 1)
            {
                Dto_Product product = new Dto_Product();
                Console.WriteLine("\nNombre: ");
                product.Name = Console.ReadLine();
                Console.WriteLine("Precio: ");
                product.Price = Double.Parse(Console.ReadLine());
                Console.WriteLine("Categoria: ");
                product.Category = Console.ReadLine();
                Console.WriteLine("Stock: ");
                product.Stock = int.Parse(Console.ReadLine());

                Dto_ProductNode newProductNode = new Dto_ProductNode();
                newProductNode.Product = product;

                Dto_ProductNode last = Head;
                while (last.Next != null)
                {
                    last = last.Next;
                }
                product.Code = last.Product.Code + 1;
                last.Next    = newProductNode;
            }
            else if (selectedMode == 2)
            {
                Dto_ProductNode products;
                Dto_ProductNode baseProductNode = productsNode;
                Dto_ProductNode iterator        = productsNode;
                Dto_ProductNode last            = productsNode;
                string          type            = "false";

                Console.WriteLine("\n¿Que codigo deseas eliminar?: ");
                int deleteCode = int.Parse(Console.ReadLine());

                int countProducts = 1;

                if (last != null)
                {
                    while (last.Next != null)
                    {
                        countProducts++;
                        last = last.Next;
                    }

                    while (type == "false")
                    {
                        for (int i = 0; i < countProducts; i++)
                        {
                            if (iterator.Product.Code == deleteCode)
                            {
                                products = iterator.Next;
                                if (deleteCode == baseProductNode.Product.Code)
                                {
                                    productsNode = baseProductNode.Next;
                                    type         = "true";
                                    break;
                                }
                                else
                                {
                                    while (baseProductNode.Product.Code != deleteCode)
                                    {
                                        if (baseProductNode.Next != null & baseProductNode.Next.Product.Code != deleteCode)
                                        {
                                            baseProductNode = baseProductNode.Next;
                                            type            = "true";
                                        }
                                        else
                                        {
                                            type = "true";
                                            break;
                                        }
                                    }
                                    baseProductNode.Next = products;
                                }
                            }
                            iterator = iterator.Next;
                        }

                        if (type == "false")
                        {
                            Console.WriteLine("\nEl codigo que deseas eliminar no existe, por favor elige otro");
                            deleteCode = int.Parse(Console.ReadLine());
                            iterator   = productsNode;
                            Console.WriteLine(" ");
                        }
                    }
                }
                else
                {
                    Console.WriteLine("\nNo cuentas con ningun Producto, por favor selecciona la opcion de agregar o continua");
                }
            }
            return(productsNode);
        }