Evitar redonde de precios ala hora de mostrar un informe
Publicado por Ronal (1 intervención) el 03/10/2017 21:40:22
Hola muy buenas tardes tengo un problema ala hora de imprimir un reporte ya que cuando ingresos productos con precios que así por ejemplo 1,50 me los redondea a 2 dolares y eso no es correcto les muestro la aparte del código
Esta parte es donde listo mis productos antes de imprimir el reporte
y esta parte del código es donde guardo la informacion para luego proceder ala vista del reporte
pues ya probe con Math.Truncate con "N2" y siempre me redondea los precios
les muestro un ejemplo del reporte que imprimí con ese problema
Esta parte es donde listo mis productos antes de imprimir el reporte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
private void btn_listar_Click(object sender, EventArgs e)
{
try
{
error.Dispose();
object[] Controles = { txt_empresa, txt_contacto, txt_lote, txt_area, txt_hacienda, txt_producto, txt_presentacion, txt_cantidad, txt_costo, txt_costo_total, txt_codigo_proveedor, txt_codigo_lote, txt_codigo_producto };
if (Bll_Validacion.Validacion(Controles, error))
{
dgv_cotizacion.Rows.Add();
int Index = dgv_cotizacion.Rows.Count - 1;
dgv_cotizacion.Rows[Index].Cells[0].Value = txt_producto.Text;
dgv_cotizacion.Rows[Index].Cells[1].Value = txt_presentacion.Text;
dgv_cotizacion.Rows[Index].Cells[2].Value = txt_cantidad.Text;
dgv_cotizacion.Rows[Index].Cells[3].Value = txt_costo.Text;
dgv_cotizacion.Rows[Index].Cells[4].Value = txt_costo_total.Text;
dgv_cotizacion.Rows[Index].Cells[5].Value = txt_codigo_proveedor.Text;
dgv_cotizacion.Rows[Index].Cells[6].Value = txt_codigo_lote.Text;
dgv_cotizacion.Rows[Index].Cells[7].Value = txt_codigo_producto.Text;
btn_guardar.Visible = true;
Limpiar();
}
else
{
MessageBox.Show("Hay un o mas campos en blanco", "CAMPOS EN BLANCO", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
y esta parte del código es donde guardo la informacion para luego proceder ala vista del reporte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
private void btn_guardar_Click(object sender, EventArgs e)
{
try
{
var Resultado = MessageBox.Show("¿Su salida esta lista? ", "Opciones", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (Resultado == DialogResult.Yes)
{
Modelo_Solicitud MDS = new Modelo_Solicitud();
MDS.IdProveedor = Convert.ToInt32(dgv_cotizacion.CurrentRow.Cells[5].Value);
_Id_Solicitud = BLS.InsertSolicitud(MDS);
//decimal Costo = Math.Truncate(Convert.ToDecimal(txt_costo.Text)*100)/ 100;
for (int i = 0; i < dgv_cotizacion.Rows.Count; i++)
{
Modelo_Cotizacion MDC = new Modelo_Cotizacion();
MDC.Cantidad = Convert.ToInt32(dgv_cotizacion.Rows[i].Cells[2].Value.ToString());
//MDC.Costo = Costo;
MDC.Costo = Math.Truncate(Convert.ToDouble(dgv_cotizacion.Rows[i].Cells[3].Value.ToString()) * 100) / 100;
//MDC.Costo = Convert.ToDecimal(dgv_cotizacion.Rows[i].Cells[3].Value.ToString());
MDC.IdProveedor = Convert.ToInt32(dgv_cotizacion.Rows[i].Cells[5].Value.ToString());
MDC.IdLote = Convert.ToInt32(dgv_cotizacion.Rows[i].Cells[6].Value.ToString());
MDC.IdProducto = Convert.ToInt32(dgv_cotizacion.Rows[i].Cells[7].Value.ToString());
MDC.IdSolicitud = _Id_Solicitud;
BLC.InsertCotizacion(MDC);
//MDC.Costo.ToString("#.00");
MDC.Costo.ToString("N2");
txt_empresa.Text = "";
txt_contacto.Text = "";
txt_email.Text = "";
txt_telefono.Text = "";
txt_lote.Text = "";
txt_area.Text = "";
txt_hacienda.Text = "";
txt_codigo_lote.Text = "";
txt_codigo_proveedor.Text = "";
txt_cantidad.Enabled = false;
txt_costo.Enabled = false;
btn_quitar.Visible = false;
btn_modificar.Visible = false;
btn_guardar.Visible = false;
btn_listar.Visible = false;
btn_listar_lote.Visible = false;
btn_listar_producto.Visible = false;
btn_listar_proveedor.Visible = false;
}
dgv_cotizacion.Rows.Clear();
Frm_Reporte_Cotizacion Vl = new Frm_Reporte_Cotizacion();
Vl.Id_Solicitud = _Id_Solicitud;
Vl.ShowDialog();
}
else if (Resultado == DialogResult.No)
{
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally { }
}
les muestro un ejemplo del reporte que imprimí con ese problema
Valora esta pregunta
0