コード例 #1
0
        // GET: Medicamentos
        public void leerArchivo()
        {
            string Path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"~/App_Data/MOCK_DATA.csv";

            LibraryClassTrees.MedicamentoBT aux;
            using (StreamReader sr = System.IO.File.OpenText(Path))
            {
                string s;
                while ((s = sr.ReadLine()) != null)
                {
                    if (s != "")
                    {
                        aux             = new LibraryClassTrees.MedicamentoBT();
                        aux.Id          = Convert.ToInt32(s.Split('|')[0]);
                        aux.Nombre      = s.Split('|')[1];
                        aux.Descripcion = s.Split('|')[2];
                        aux.Productora  = s.Split('|')[3];
                        aux.Precio      = Convert.ToDouble(s.Split('|')[4]);
                        aux.Cantidad    = Convert.ToInt32(s.Split('|')[5]);
                        ArbolMedicamentos.AgregarElemento(aux);
                        medicamentos.Add(aux);
                    }
                }
            }
        }
コード例 #2
0
        public ActionResult Ingresa(string Nombre, int Id, double Precio)
        {
            if (ArbolMedicamentos.Raiz == null)
            {
                leerArchivo();
            }

            Random num      = new Random();
            int    Cantidad = num.Next(0, 15);

            v1 = new LibraryClassTrees.MedicamentoBT {
                Nombre = Nombre, Id = Id, Precio = Precio, Cantidad = Cantidad
            };
            ArbolMedicamentos.AgregarElemento(v1);
            a++;
            return(View(v1));
        }
コード例 #3
0
 void BuscaActualiza(Nodo nNodo, MedicamentoBT data)
 {
     if (nNodo != null && nNodo.Medicamento.Id != data.Id)
     {
         if (data.Id < nNodo.Medicamento.Id)
         {
             BuscaActualiza(nNodo.izquierdo, data);
         }
         if (data.Id > nNodo.Medicamento.Id)
         {
             BuscaActualiza(nNodo.Derecho, data);
         }
     }
     if (nNodo.Medicamento.Id == data.Id)
     {
         nNodo.Medicamento = data;
     }
 }
コード例 #4
0
        public ActionResult BuscarNombre()
        {
            if (ArbolMedicamentos.Raiz == null)
            {
                leerArchivo();
            }

            var visi = medicamentos;

            foreach (var item in visi)
            {
                if ((Request.Form["Nombre"]) == item.Nombre)
                {
                    BuscarC = new LibraryClassTrees.MedicamentoBT {
                        Id = item.Id, Nombre = item.Nombre, Cantidad = item.Cantidad, Precio = item.Precio
                    };
                    ViewBag.Mostrar = BuscarC;
                }
            }
            return(View());
        }
コード例 #5
0
        //Agregar nuevo elemento
        public void AgregarElemento(MedicamentoBT item)
        {
            Nodo nuevo = new Nodo(item);

            nuevo.izquierdo = null;
            nuevo.Derecho   = null;
            if (Raiz == null)
            {
                Raiz = nuevo;
            }
            else
            {
                Nodo anterior = null;
                Nodo recorre  = null;
                recorre = Raiz;
                while (recorre != null)
                {
                    anterior = recorre;
                    int comparison = String.Compare(item.Nombre, recorre.Medicamento.Nombre, comparisonType: StringComparison.OrdinalIgnoreCase);

                    if (comparison < 1)
                    {
                        recorre = recorre.izquierdo;
                    }
                    else
                    {
                        recorre = recorre.Derecho;
                    }
                }
                int comparison2 = String.Compare(item.Nombre, anterior.Medicamento.Nombre, comparisonType: StringComparison.OrdinalIgnoreCase);
                if (comparison2 < 1)
                {
                    anterior.izquierdo = nuevo;
                }
                else
                {
                    anterior.Derecho = nuevo;
                }
            }
        }
コード例 #6
0
 //Busca elemento para actualizar datos
 public void ActualizaDatos(MedicamentoBT data)
 {
     BuscaActualiza(Raiz, data);
 }
コード例 #7
0
 public Nodo AuxBusqueda;     // Variable para almacenar elemento encontrado
 public Nodo BuscaRegresa(MedicamentoBT data)
 {
     AuxBusqueda = null;
     Busca(Raiz, data.Id);
     return(AuxBusqueda);
 }
コード例 #8
0
 public Nodo(MedicamentoBT Medicamento)
 {
     this.Medicamento = Medicamento;
 }