Agregar archivos de proyecto.
This commit is contained in:
101
bdGrupoSanchoToro/extensiones/detallesfacturas.cs
Normal file
101
bdGrupoSanchoToro/extensiones/detallesfacturas.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using tsUtilidades.Extensiones;
|
||||
using System.Globalization;
|
||||
|
||||
|
||||
namespace bdGrupoSanchoToro.db
|
||||
{
|
||||
|
||||
public partial class detallesfacturas
|
||||
{
|
||||
|
||||
public double Importe
|
||||
{
|
||||
get
|
||||
{
|
||||
return Math.Round(this.Cantidad * this.Precio, 2, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
}
|
||||
public string Descripcion
|
||||
{
|
||||
get
|
||||
{
|
||||
return (this.idProductoNavigation.Descripcion + " " + this.Observaciones.NothingAVacio()).Trim();
|
||||
}
|
||||
}
|
||||
private byte[]? _DetalleRTF;
|
||||
|
||||
[NotMapped]
|
||||
public byte[] DetalleRTF
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_DetalleRTF == null)
|
||||
{
|
||||
if (this.idDetalleRTFNavigation != null && this.idDetalleRTFNavigation.Fichero != null)
|
||||
{
|
||||
_DetalleRTF = idDetalleRTFNavigation.Fichero;
|
||||
}
|
||||
else
|
||||
{
|
||||
_DetalleRTF = new byte[0];
|
||||
}
|
||||
}
|
||||
return _DetalleRTF;
|
||||
}
|
||||
set
|
||||
{
|
||||
_DetalleRTF = value;
|
||||
}
|
||||
}
|
||||
[NotMapped]
|
||||
public bool DetalleRTFModificado { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public string DetalleRTFString
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
if (this.idDetalleRTFNavigation != null && this.idDetalleRTFNavigation.Fichero != null && this.idDetalleRTFNavigation.Fichero.Length>0)
|
||||
{
|
||||
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
|
||||
return encoding.GetString( idDetalleRTFNavigation.Fichero);
|
||||
}
|
||||
else
|
||||
{
|
||||
return ConvertToRtf(this.Descripcion,9.75);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string ConvertToRtf(string inputText, double fontSize)
|
||||
{
|
||||
// Validar el tamaño de la fuente
|
||||
if (fontSize <= 0)
|
||||
{
|
||||
throw new ArgumentException("El tamaño de la fuente debe ser mayor que cero.");
|
||||
}
|
||||
|
||||
// Crear el encabezado RTF
|
||||
StringBuilder rtf = new StringBuilder();
|
||||
rtf.Append(@"{\rtf1\ansi\deff0");
|
||||
rtf.Append(@"{\fonttbl{\f0 Arial;}}");
|
||||
string fs = Math.Round(fontSize * 2,0).ToString(CultureInfo.InvariantCulture);
|
||||
rtf.Append(@"\fs").Append(fs); // RTF usa la mitad del tamaño de punto
|
||||
|
||||
// Agregar el texto
|
||||
rtf.Append(" ");
|
||||
rtf.Append(inputText.Replace("\n", @"\par "));
|
||||
|
||||
// Cerrar el documento RTF
|
||||
rtf.Append("}");
|
||||
|
||||
return rtf.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user