コード例 #1
0
        public void transfer([FromForm] int idProduct, [FromForm] int idO1, [FromForm] int idO2, [FromForm] int cant)
        {
            SDES.obtainKey();
            ArbolB <OfficeProduct> .IniciarArbol("OfficeProduct", new StringToObject(OfficeProduct.StringToObject), new ObjectToString(OfficeProduct.ObjectToString));

            var data1 = ArbolB <OfficeProduct> .Recorrido(new OfficeProduct { IdOffice = idO1, IdProduct = idProduct }, 1);

            var data2 = ArbolB <OfficeProduct> .Recorrido(new OfficeProduct { IdOffice = idO2, IdProduct = idProduct }, 1);

            if (data1.Count != 0 && data1[0].Inventory - cant >= 0)
            {
                if (data2.Count == 0)
                {
                    ArbolB <OfficeProduct> .InsertarArbol(new OfficeProduct { IdOffice = idO2, IdProduct = idProduct, Inventory = cant });
                }
                else
                {
                    data2[0].Inventory = data2[0].Inventory + cant;
                    ArbolB <OfficeProduct> .Modificar(data2[0], new string[2] {
                        data2[0].Inventory.ToString(), string.Empty
                    }, new Modify(OfficeProduct.Alter));
                }
                data1[0].Inventory = data1[0].Inventory - cant;
                ArbolB <OfficeProduct> .Modificar(data1[0], new string[2] {
                    data1[0].Inventory.ToString(), string.Empty
                }, new Modify(OfficeProduct.Alter));
            }
        }
コード例 #2
0
        public List <OfficeProduct> AllOfficeProduct()
        {
            ArbolB <OfficeProduct> .IniciarArbol("OfficeProduct", new StringToObject(OfficeProduct.StringToObject), new ObjectToString(OfficeProduct.ObjectToString));

            SDES.obtainKey();
            return(ArbolB <OfficeProduct> .Recorrido(null));
        }
コード例 #3
0
        public List <ProductData> ProductShow([FromForm] int id)
        {
            ArbolB <ProductData> .IniciarArbol("Product", new StringToObject(ProductData.StringToObject), new ObjectToString(ProductData.ObjectToString));

            SDES.obtainKey();
            return(ArbolB <ProductData> .Recorrido(new ProductData { ID = id }, 1));
        }
コード例 #4
0
        public void Add([FromForm] OfficeProduct info)
        {
            ArbolB <OfficeProduct> .IniciarArbol("OfficeProduct", new StringToObject(OfficeProduct.StringToObject), new ObjectToString(OfficeProduct.ObjectToString));

            SDES.obtainKey();
            ArbolB <OfficeProduct> .InsertarArbol(new OfficeProduct { IdOffice = info.IdOffice, IdProduct = info.IdProduct, Inventory = info.Inventory });
        }
コード例 #5
0
        public List <OfficeData> OfficeShow([FromForm] int id)
        {
            ArbolB <OfficeData> .IniciarArbol("Office", new StringToObject(OfficeData.StringToObject), new ObjectToString(OfficeData.ObjectToString));

            SDES.obtainKey();
            return(ArbolB <OfficeData> .Recorrido(new OfficeData { ID = id }, 1));
        }
コード例 #6
0
        public void Add([FromForm] IFormFile info)
        {
            ArbolB <ProductData> .IniciarArbol("Product", new StringToObject(ProductData.StringToObject), new ObjectToString(ProductData.ObjectToString));

            SDES.obtainKey();
            ProductData.InsertCSV(info.OpenReadStream());
        }
コード例 #7
0
        public List <OfficeProduct> OfficeProductShow([FromForm] int idOffice, [FromForm] int idProduct)
        {
            ArbolB <OfficeProduct> .IniciarArbol("OfficeProduct", new StringToObject(OfficeProduct.StringToObject), new ObjectToString(OfficeProduct.ObjectToString));

            SDES.obtainKey();
            return(ArbolB <OfficeProduct> .Recorrido(new OfficeProduct { IdOffice = idOffice, IdProduct = idProduct }, 1));
        }
コード例 #8
0
        public void Add([FromForm] OfficeData info)
        {
            ArbolB <OfficeData> .IniciarArbol("Office", new StringToObject(OfficeData.StringToObject), new ObjectToString(OfficeData.ObjectToString));

            SDES.obtainKey();
            ArbolB <OfficeData> .InsertarArbol(new OfficeData { ID = ArbolB <OfficeData> .newID(), Name = info.Name, Address = info.Address });
        }
コード例 #9
0
        public List <ProductData> AllProduct()
        {
            ArbolB <ProductData> .IniciarArbol("Product", new StringToObject(ProductData.StringToObject), new ObjectToString(ProductData.ObjectToString));

            SDES.obtainKey();
            return(ArbolB <ProductData> .Recorrido(null));
        }
コード例 #10
0
        public void Add([FromForm] ProductData info)
        {
            ArbolB <ProductData> .IniciarArbol("Product", new StringToObject(ProductData.StringToObject), new ObjectToString(ProductData.ObjectToString));

            SDES.obtainKey();
            ArbolB <ProductData> .InsertarArbol(new ProductData { ID = ArbolB <ProductData> .newID(), Name = info.Name, Price = info.Price });
        }
コード例 #11
0
        public void Alter([FromForm] OfficeProduct info)
        {
            SDES.obtainKey();
            ArbolB <OfficeProduct> .IniciarArbol("OfficeProduct", new StringToObject(OfficeProduct.StringToObject), new ObjectToString(OfficeProduct.ObjectToString));

            ArbolB <OfficeProduct> .Modificar(info, new string[2] {
                info.Inventory.ToString(), null
            }, new Modify(OfficeProduct.Alter));
        }
コード例 #12
0
        public void Alter([FromForm] ProductData info)
        {
            SDES.obtainKey();
            ArbolB <ProductData> .IniciarArbol("Product", new StringToObject(ProductData.StringToObject), new ObjectToString(ProductData.ObjectToString));

            ArbolB <ProductData> .Modificar(info, new string[2] {
                info.Name, info.Price.ToString()
            }, new Modify(ProductData.Alter));
        }
コード例 #13
0
        public void Alter([FromForm] string Name, [FromForm] int id)
        {
            SDES.obtainKey();
            ArbolB <ProductData> .IniciarArbol("Product", new StringToObject(ProductData.StringToObject), new ObjectToString(ProductData.ObjectToString));

            ArbolB <ProductData> .Modificar(new ProductData { ID = id }, new string[2] {
                Name, null
            }, new Modify(ProductData.Alter));
        }
コード例 #14
0
        public void Alter([FromForm] OfficeData info)
        {
            SDES.obtainKey();
            ArbolB <OfficeData> .IniciarArbol("Office", new StringToObject(OfficeData.StringToObject), new ObjectToString(OfficeData.ObjectToString));

            ArbolB <OfficeData> .Modificar(info,
                                           new string[2] {
                info.Name, info.Address
            },
                                           new Modify(OfficeData.Alter));
        }
コード例 #15
0
        public void Alter(int key)
        {
            if (key < 1024 && key >= 0)
            {
                ArbolB <OfficeData> .IniciarArbol("Office", new StringToObject(OfficeData.StringToObject), new ObjectToString(OfficeData.ObjectToString));

                ArbolB <OfficeData> .ModificarArbol(key);

                ArbolB <OfficeProduct> .IniciarArbol("OfficeProduct", new StringToObject(OfficeProduct.StringToObject), new ObjectToString(OfficeProduct.ObjectToString));

                ArbolB <OfficeProduct> .ModificarArbol(key);

                ArbolB <ProductData> .IniciarArbol("Product", new StringToObject(ProductData.StringToObject), new ObjectToString(ProductData.ObjectToString));

                ArbolB <ProductData> .ModificarArbol(key);

                SDES.manageKey(key);
            }
        }
コード例 #16
0
        public static void Comprimir(string nombre)
        {
            Directory.CreateDirectory("temp");
            ArbolB <ProductData> .IniciarArbol(nombre, null, null);

            using (var streamReader = new FileStream($"Datos\\{nombre}.txt", FileMode.Open))
            {
                using (var reader = new BinaryReader(streamReader))
                {
                    using (var streamWriter = new FileStream($"temp\\{nombre}.txt", FileMode.OpenOrCreate))
                    {
                        using (var writer = new BinaryWriter(streamWriter))
                        {
                            var DiccionarioLetras = new Dictionary <string, string>();
                            var bufferLength      = 10000;
                            var bytebuffer        = new byte[bufferLength];
                            var stringLetra       = string.Empty;

                            while (reader.BaseStream.Position != reader.BaseStream.Length)
                            {
                                bytebuffer = reader.ReadBytes(bufferLength);

                                for (int i = 0; i < bytebuffer.Count(); i++)
                                {
                                    stringLetra = Convert.ToString(Convert.ToChar(bytebuffer[i]));

                                    if (!DiccionarioLetras.ContainsKey(stringLetra))
                                    {
                                        var stringnum = Convert.ToString(DiccionarioLetras.Count() + 1, 2);
                                        DiccionarioLetras.Add(stringLetra, stringnum);
                                        stringLetra = string.Empty;
                                    }
                                }
                            }

                            writer.Write(Encoding.UTF8.GetBytes(Convert.ToString(DiccionarioLetras.Count).PadLeft(8, '0').ToCharArray()));

                            foreach (var fila in DiccionarioLetras)
                            {
                                writer.Write(Convert.ToByte(Convert.ToChar(fila.Key[0])));
                            }

                            reader.BaseStream.Position = 0;
                            stringLetra = string.Empty;
                            var anterior = string.Empty;

                            var ListaCaracteres = new List <string>();

                            while (reader.BaseStream.Position != reader.BaseStream.Length)
                            {
                                bytebuffer = reader.ReadBytes(bufferLength);

                                for (int i = 0; i < bytebuffer.Count(); i++)
                                {
                                    stringLetra += Convert.ToString(Convert.ToChar(bytebuffer[i]));

                                    if (!DiccionarioLetras.ContainsKey(stringLetra))
                                    {
                                        var stringnum = Convert.ToString(DiccionarioLetras.Count() + 1, 2);
                                        DiccionarioLetras.Add(stringLetra, stringnum);
                                        ListaCaracteres.Add(DiccionarioLetras[anterior]);
                                        anterior    = string.Empty;
                                        anterior   += stringLetra.Last();
                                        stringLetra = anterior;
                                    }
                                    else
                                    {
                                        anterior = stringLetra;
                                    }
                                }
                            }

                            ListaCaracteres.Add(DiccionarioLetras[stringLetra]);

                            var cantMaxBits = Math.Log2((float)DiccionarioLetras.Count);
                            cantMaxBits = cantMaxBits % 1 >= 0.5 ? Convert.ToInt32(cantMaxBits) : Convert.ToInt32(cantMaxBits) + 1;

                            writer.Write(Convert.ToByte(cantMaxBits));

                            for (int i = 0; i < ListaCaracteres.Count; i++)
                            {
                                ListaCaracteres[i] = ListaCaracteres[i].PadLeft(Convert.ToInt32(cantMaxBits), '0');
                            }

                            var bufferEscritura = new List <byte>();

                            var aux = string.Empty;

                            foreach (var item in ListaCaracteres)
                            {
                                aux += item;
                                if (aux.Length >= 8)
                                {
                                    var max = aux.Length / 8;
                                    for (int i = 0; i < max; i++)
                                    {
                                        bufferEscritura.Add(Convert.ToByte(Convert.ToInt32(aux.Substring(0, 8), 2)));
                                        aux = aux.Substring(8);
                                    }
                                }
                            }

                            if (aux.Length != 0)
                            {
                                bufferEscritura.Add(Convert.ToByte(Convert.ToInt32(aux.PadRight(8, '0'), 2)));
                            }

                            writer.Write(bufferEscritura.ToArray());
                        }
                    }
                }
            }
        }
コード例 #17
0
        public List <Producto> RecorridoInOrder()
        {
            ArbolB <Producto> .IniciarArbol("Productos", new StringToObject(Producto.StringToProducto), new ObjectToString(Producto.ProductoToString));

            return(ArbolB <Producto> .Recorrido(null, null));
        }
コード例 #18
0
        public List <Producto> Busqueda([FromForm] Producto dato)
        {
            ArbolB <Producto> .IniciarArbol("Productos", new StringToObject(Producto.StringToProducto), new ObjectToString(Producto.ProductoToString));

            return(ArbolB <Producto> .Recorrido(dato, null, 1));
        }
コード例 #19
0
        public void Agregar([FromForm] Producto dato)
        {
            ArbolB <Producto> .IniciarArbol("Productos", new StringToObject(Producto.StringToProducto), new ObjectToString(Producto.ProductoToString));

            ArbolB <Producto> .InsertarArbol(dato);
        }