コード例 #1
0
        private void MostrarListas()
        {
            Console.Clear();
            int    val_opcion;
            string val_opcion_string;

            //ListasDeCompra = new List<List<Producto>>();
            Console.ForegroundColor = ConsoleColor.Cyan;

            if (ListasDeCompra.Count > 0)
            {
                Console.WriteLine("Listas disponibles");
                Console.WriteLine("********************************");
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("E - Salir");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("********************************");
                Console.WriteLine("|Id | Nombre ");
                foreach (KeyValuePair <int, string> item in NombresLista)
                {
                    Console.WriteLine("|{0} | {1}", item.Key, item.Value);
                    Console.WriteLine("----------------------------");
                }
                Console.Write("Detalle de lista, digite el Id: ");
                val_opcion_string = Console.ReadLine();


                if (val_opcion_string.ToLower() == "e")
                {
                    MenuP.ShowMenuPrincipal();
                }
                val_opcion = Convert.ToInt32(val_opcion_string);
                Console.Write("Tipo detalle \n1 - Producto por categoria 2 - Todos : ");
                int opcion = Convert.ToInt32(Console.ReadLine());

                switch (opcion)
                {
                case 1:
                    Console.WriteLine("1 - Frutas 2 - Vegetales 3 - Lacteos");
                    int opcion_cat = Convert.ToInt32(Console.ReadLine());
                    DetalleLista(val_opcion, opcion_cat);
                    break;

                case 2:
                    DetalleLista(val_opcion);
                    break;

                default:
                    break;
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("***No existe lista de compra***");
                Console.ReadKey();
                MenuP.ShowMenuPrincipal();
            }
        }
コード例 #2
0
 static void Main(string[] args)
 {
     MenuP.ShowMenuPrincipal();
 }
コード例 #3
0
        private void CrearLista(List <Producto> listaProducto = null, string _nombreLista = "")
        {
            Console.Clear();
            Producto producto = new Producto();

            string nombreLista = _nombreLista;

            if (listaProducto == null)
            {
                listaProducto = new List <Producto>();
            }
            int id_producto = 0;

            Console.ForegroundColor = ConsoleColor.Cyan;

            if (ContadorLista <= 10)
            {
                try
                {
                    if (listaProducto.Count <= 0)
                    {
                        Console.Write("Nombre de lista: ");
                        nombreLista = Console.ReadLine();
                    }

                    Console.Write("Nombre de producto: ");
                    producto.Nombre = Console.ReadLine();

                    Console.Write("Categoria 1 - Frutas 2 - Vegetales 3 - Lacteos: ");
                    int No_cat = Convert.ToInt32(Console.ReadLine());

                    switch (No_cat)
                    {
                    case 1:
                        producto.Categoria = Product_cat.Frutas;
                        break;

                    case 2:
                        producto.Categoria = Product_cat.Vegetales;
                        break;

                    case 3:
                        producto.Categoria = Product_cat.Lacteos;
                        break;

                    default:
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Error! Opcion no valida");
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine("los productos agregado anterior a este aun se mantienen.");
                        Console.ReadKey();
                        CrearLista(listaProducto, nombreLista);
                        break;
                    }

                    Console.Write("Precio: ");
                    producto.Precio = Convert.ToDouble(Console.ReadLine());
                    listaProducto.Add(producto);

                    Console.Write("Agregar otro producto Y-Si N-No: ");
                    string val_opcion = Console.ReadLine();

                    if (val_opcion.ToLower() == "y")
                    {
                        ContadorLista++;
                        CrearLista(listaProducto, nombreLista);
                    }
                    else if (val_opcion.ToLower() == "n")
                    {
                        ListasDeCompra.Add(listaProducto);
                        id_producto = ListasDeCompra.Count - 1;
                        NombresLista.Add(id_producto, nombreLista);
                        MenuP.ShowMenuPrincipal();
                    }
                }
                catch (Exception)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Error! Opcion no valida");
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("los productos agregado anterior a este aun se mantienen.");
                    Console.ReadKey();
                    CrearLista(listaProducto, nombreLista);
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.WriteLine("Solo se permite un maximo de 10 producto por lista de compra");
                Console.ReadKey();
                MenuP.ShowMenuPrincipal();
            }
        }