Exemplo n.º 1
0
        public static string NombreCompletoRecibo(Lfx.Data.Connection dataBase, int iId)
        {
            // Toma el Id del recibo y devuelve el tipo y número (por ejemplo: "Recibo #003" o "Comprobante de Pago #256")
            Lfx.Data.Row TmpRecibo = dataBase.Row("recibos", "id_recibo", iId);

            if (TmpRecibo == null)
            {
                return("");
            }
            else if (System.Convert.ToInt32(TmpRecibo["numero"]) > 0)
            {
                return("Recibo Nº " + System.Convert.ToInt32(TmpRecibo["numero"]).ToString("00000000"));
            }
            else
            {
                return("Recibo S/N");
            }
        }
Exemplo n.º 2
0
        public static System.Drawing.Image ProductImage(Lfx.Data.Connection dataBase, int productId, DownloadImage downloadImage)
        {
            string CachePath     = Lfx.Environment.Folders.CacheFolder;
            string ImageFileName = "product_" + productId.ToString() + ".jpg";
            bool   ImageInCache  = System.IO.File.Exists(CachePath + ImageFileName);

            if (downloadImage == DownloadImage.Always ||
                (downloadImage == DownloadImage.OnlyIfNotInCache && ImageInCache == false) ||
                ((downloadImage == DownloadImage.PreferCacheOnSlowLinks && ImageInCache == false) || Lfx.Workspace.Master.SlowLink == false))
            {
                //Download image and save to cache
                Lfx.Data.Row ImagenDB = dataBase.Row("articulos_imagenes", "imagen", "id_articulo", productId);

                if (ImagenDB != null && ImagenDB.Fields["imagen"].Value != null && ((byte[])(ImagenDB.Fields["imagen"].Value)).Length > 5)
                {
                    //Guardar imagen en cache
                    System.IO.BinaryWriter wr = new System.IO.BinaryWriter(System.IO.File.OpenWrite(CachePath + ImageFileName), System.Text.Encoding.Default);
                    wr.Write(((byte[])(ImagenDB.Fields["imagen"].Value)));
                    wr.Close();

                    byte[] ByteArr = ((byte[])(ImagenDB.Fields["imagen"].Value));
                    System.Drawing.Image Img;

                    using (System.IO.MemoryStream loStream = new System.IO.MemoryStream(ByteArr)) {
                        Img = System.Drawing.Image.FromStream(loStream);
                    }
                    return(Img);
                }
                else
                {
                    //Devuelve la imagen de la categoría, en lugar de la del artículo
                    int CategoriaArticulo = dataBase.FieldInt("SELECT id_categoria FROM articulos WHERE id_articulo=" + productId.ToString());
                    return(CategoryImage(dataBase, CategoriaArticulo, downloadImage));
                }
            }

            //Serve only from cache
            if (ImageInCache)
            {
                return(System.Drawing.Image.FromFile(CachePath + ImageFileName));
            }

            return(null);
        }
Exemplo n.º 3
0
        public static System.Drawing.Image CategoryImage(Lfx.Data.Connection dataBase, int categoryId, DownloadImage downloadImage)
        {
            string CachePath     = Lfx.Environment.Folders.CacheFolder;
            string ImageFileName = "product_category_" + categoryId.ToString() + ".jpg";
            bool   ImageInCache  = System.IO.File.Exists(CachePath + ImageFileName);

            if (downloadImage == DownloadImage.Always ||
                (downloadImage == DownloadImage.OnlyIfNotInCache && ImageInCache == false) ||
                ((downloadImage == DownloadImage.PreferCacheOnSlowLinks && ImageInCache == false) || Lfx.Workspace.Master.SlowLink == false))
            {
                //Download image and save to cache
                Lfx.Data.Row ImagenDB = dataBase.Row("articulos_categorias", "imagen", "id_categoria", categoryId);

                if (ImagenDB != null && ImagenDB["imagen"] != null && ((byte[])(ImagenDB["imagen"])).Length > 5)
                {
                    //Guardar imagen en cache
                    System.IO.BinaryWriter wr = new System.IO.BinaryWriter(System.IO.File.OpenWrite(CachePath + ImageFileName), System.Text.Encoding.Default);
                    wr.Write(((byte[])(ImagenDB["imagen"])));
                    wr.Close();

                    byte[] ByteArr = ((byte[])(ImagenDB["imagen"]));
                    System.IO.MemoryStream loStream = new System.IO.MemoryStream(ByteArr);
                    return(System.Drawing.Image.FromStream(loStream));
                }
                else
                {
                    return(null);
                }
            }

            //Serve only from cache
            if (ImageInCache)
            {
                return(System.Drawing.Image.FromFile(CachePath + ImageFileName));
            }

            return(null);
        }