|
Mostrar Mensajes
|
Páginas: [1]
|
1
|
Programación / .NET (C#, VB.NET, ASP) / porcentaje c#
|
en: 28 Abril 2020, 12:28 pm
|
hola chicos, llevo no mucho tiempo liado con c#, aprendiendo de tutoriales e internet, es lo que tiene estar confinado, el tema es que estoy haciendo una calculadora, pero tengo un problema en el tema porcentaje %, al hacerlo me sale el calculo de ( x numero *x numero / 100) , por poner un ejemplo, el 12 % de 75 me sale 9, bien yo querria (si tener que hacer nuevo codigo XD) que cuando haga esa operacion me saliese el resultado final, es decir (75 - 12 % = 66), pero no tengo manera, he tratado con ensayo y error, pero nada, al final mi mujer me echa de casa, porgo el codigo aqui si no os importa using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace WindowsFormsApp1 { public partial class Form1 : Form { Double valor = 0; String operacion = ""; bool operacion_press = false; Double valor1 = 100; public Form1() { InitializeComponent(); } private void button_click(object sender, EventArgs e) { if ((resultado.Text == "0")||(operacion_press)) resultado.Clear(); operacion_press = false; Button b = (Button) sender; resultado.Text = resultado.Text + b.Text; } private void btn_ce_Click(object sender, EventArgs e) { resultado.Text = "0"; res_2.Text = "0"; } private void operador_click(object sender, EventArgs e) { Button b = (Button)sender; operacion = b.Text; valor = Double.Parse(resultado.Text); operacion_press = true; res_2.Text = valor + " " + operacion; } private void btn_igual(object sender, EventArgs e) { res_2.Text = ""; switch (operacion) { case "+": resultado.Text = (valor + Double.Parse(resultado.Text)).ToString(); res_2.Text = "El Resultado es " + Double.Parse(resultado.Text).ToString(); break; case "-": resultado.Text = (valor - Double.Parse(resultado.Text)).ToString(); res_2.Text = "El Resultado es " + Double.Parse(resultado.Text).ToString(); break; case "*": resultado.Text = (valor * Double.Parse(resultado.Text)).ToString(); res_2.Text = "El Resultado es " + Double.Parse(resultado.Text).ToString(); break; case "/": resultado.Text = (valor / Double.Parse(resultado.Text)).ToString(); res_2.Text = "El Resultado es " + Double.Parse(resultado.Text).ToString(); break; case "√": resultado.Text = Math.Sqrt(valor).ToString(); res_2.Text = "El Resultado es " + Double.Parse(resultado.Text).ToString(); break; } // fin switch } private void btn4_Click(object sender, EventArgs e) { resultado.Clear(); valor = 0; res_2.Text = "0"; } private void button5_Click(object sender, EventArgs e) { if (resultado.Text.Length > 0) resultado.Text = resultado.Text.Remove(resultado.Text.Length - 1, 1); } private void btnpor_click(object sender, EventArgs e) { [b] [color=red] Double a; a = Convert.ToDouble(resultado.Text) / Convert.ToDouble(100); resultado.Text = System.Convert.ToString(a); res_2.Text = " Porcentaje " + System.Convert.ToString(a);[/color] [/b] } } } res_2.Text = " Porcentaje " + System.Convert.ToString(a); ***** deciros que el res_2.Text , es porque los datos salen a dos pantallas, tipo calculadora de windos
|
|
|
2
|
Programación / PHP / añadir o eliminar productos carro de compras
|
en: 17 Enero 2015, 17:53 pm
|
hola chicos, pues eso ando mirando tutoriales y dandole vueltas a ver como podria aumentar la cantidad del mismo articulo cuando le vuelvan a dar, he mirado muchos carrito pero es que el mio es totalmente distinto, de hecho el mio no tienes la tipica $sesion=[" carro"];
, esta va con una $sesion=["MM_IdUsuario"];
va recogiendod atos desde una pagina q la manda a una de manera oculta y la manda al carrito, por medio de un selec y un insert respectivamente, la manera de sumar seria creo qie igual, desde el carrito mandar datos a otra pagina y que esta lo devuelva ya calculado en caso de que pida dos del mismo, os dejo el codigo del carrito, donde aparece los productos ya elegidos <?php require_once('Connections/conexionzapatos.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { } switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } $insertGoTo = "prueb1234.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } } $varUsuario_DatosCarrito = "0"; if (isset($_SESSION["MM_IdUsuario"])) { $varUsuario_DatosCarrito = $_SESSION["MM_IdUsuario"]; } $query_DatosCarrito = sprintf("SELECT * FROM tblcarrito WHERE tblcarrito.idUsuario = %s AND tblcarrito.intTransaccionEfectuada = 0", GetSQLValueString ($varUsuario_DatosCarrito, "int")); $Transferencia="Transferencia"; $multiplicador = ObtenerIVA()/100; $valordelIVA = $preciototal * $multiplicador; ?> <?php if ($totalRows_DatosCarrito > 0) { // Show if recordset not empty ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr class="ver"> <td width="23%">Producto</td> <td width="33%">Unidades</td> <td width="33%">Precio</td> <td width="9%">Acciones</td> </tr> <?php $preciototal = 0;?> <?php do { ?> <tr class="letra"> <td align=""><?php echo ObtenerNombreProducto($row_DatosCarrito['idProducto']); ?></td> <td><?php echo $row_DatosCarrito['intCantidad']; ?><a href="sumar_producto.php?idlinea=<?php echo $row_DatosCarrito['intContador']; ?>">+</a> <?php if ($row_DatosCarrito['intCantidad']!=1){?> <a href="restar_producto.php?idlinea=<?php echo $row_DatosCarrito['intContador']; ?>">-</a> <?php }?></td> <td ><?php echo ObtenerPrecioProducto($row_DatosCarrito['idProducto']); ?> <span class="letra">Euros</span></td> <td><a href="eliminar_producto.php?recordID=<?php echo $row_DatosCarrito['idProducto']; ?>">Eliminar</a></td> </tr> <?php $preciototal = $preciototal + ObtenerPrecioProducto($row_DatosCarrito['idProducto']);?> <tr> <td> </td> <td align="right">Subtotal:</td> <td align="left"> <?php $multiplicador = (100 + ObtenerIVA())/100; $valorconIVA = $preciototal * $multiplicador; echo $valorconIVA;?> </td><td> <td width="2%"> </td> </tr> </tr> </table> <table width="433" height="32" align="left"> <td width="425" align="center"> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <input type="submit" value="Insertar registro" /> </tr> <input type="hidden" name="idCompra" value="" /> <input type="hidden" name="idUsuario" value="<?php echo $row_DatosCarrito['idUsuario']; ?>" /> <input type="hidden" name="fchFecha" value="<?php echo $hoy ?>" /> <input type="hidden" name="intTipoPago" value="<?php echo $Transferencia ?>" /> <input type="hidden" name="dblTotal" value="<?php $multiplicador = (100 + ObtenerIVA())/100; $valorconIVA = $preciototal * $multiplicador; echo $valorconIVA;?>" /> <input type="hidden" name="intEstado" value="1" /> <input type="hidden" name="strNombre" value=" <?php echo ObtenerNombreUsuario($_SESSION['MM_IdUsuario']) ?>" /> <input type="hidden" name="MM_insert" value="form1" /> </form> </table> <?php } // Show if recordset not empty ?> <?php if ($totalRows_DatosCarrito == 0) { // Show if recordset empty ?> <p> <table width="363" align="center"> <tr> <td width="355" align="center">Su Carro Esta Vacio</td> </tr> </table> <?php } // Show if recordset empty ?>
lo intente con un foreach , pero cuando lo hago me sale error, y pie de pagina, otra cosa seria es como cerrar la sesion del carro cuando se termine la compra, si que ello haga que el usuario tenga que volver a acceder a la pagina, gracias
|
|
|
5
|
Programación / PHP / [Resuelto] envio de datos carrito de compras y phpmailer
|
en: 6 Enero 2015, 22:31 pm
|
hola chicos, me llamo carlos, y bueno ando un poco perdido, llevo varias buscando como mandar los datos de mis productos y el precio , he conseguido mandar mensaje y asunto, pero.... dejo el codigo a ver si lo puedo solucionar, gracias esta es la que enviaria los datos a otra que los recoge y manda el email <?php require_once('Connections/conexionzapatos.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { } switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) { $insertSQL = sprintf("INSERT INTO tblcompra (idCompra, idUsuario, fchFecha, intTipoPago, dblTotal, intEstado, strNombre) VALUES (%s, %s, %s, %s, %s, %s, %s)", GetSQLValueString($_POST['idCompra'], "int"), GetSQLValueString($_POST['idUsuario'], "int"), GetSQLValueString($_POST['fchFecha'], "date"), GetSQLValueString($_POST['intTipoPago'], "text"), GetSQLValueString($_POST['dblTotal'], "double"), GetSQLValueString($_POST['intEstado'], "int"), GetSQLValueString($_POST['strNombre'], "text")); $insertGoTo = "recibido.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } } $maxRows_compra = 10; $pageNum_compra = 0; if (isset($_GET['pageNum_compra'])) { $pageNum_compra = $_GET['pageNum_compra']; } $startRow_compra = $pageNum_compra * $maxRows_compra; $varCompra_compra = "0"; if (isset($_SESSION["MM_IdUsuario"])) { $varCompra_compra = $_SESSION["MM_IdUsuario"]; } $query_compra = sprintf("SELECT * FROM tblcarrito WHERE tblcarrito.idUsuario = %s", GetSQLValueString ($varCompra_compra, "int")); $query_limit_compra = sprintf("%s LIMIT %d, %d", $query_compra, $startRow_compra, $maxRows_compra); if (isset($_GET['totalRows_compra'])) { $totalRows_compra = $_GET['totalRows_compra']; } else { } $totalPages_compra = ceil($totalRows_compra/$maxRows_compra)-1; $preciototal="ObtenerIVA()/100"; $multiplicador = "ObtenerIVA()/100"; $valordelIVA = "preciototal * $multiplicador"; $valorconIVA = "preciototal * $multiplicador"; $Transferencia="Transferencia"; $asunto="Cachemira.com"; $body="body"; $precio="$valorconIVA"; ?> <table width="324" align="center"> <tr> <td width="316" align="center" bgcolor="#EEEEEE"><strong>Resumen de su compra</strong></td> </tr> </table> <form action="recibido.php" method="post" name="form" id="form1"> <table width="618" height="94" align="center"> <tr bgcolor="#00FFFF"> <td align="center">Productos</td> <td align="center">Unidades</td> <td colspan="2" align="center">Total </td> </tr> <?php $preciototal = 0;?> <?php do { ?> <tr bgcolor="#FFECEC" align="center"> <td width="186" height="24" align="right"> <input name="idProducto" type="text" value="<?php echo ObtenerNombreProducto($row_compra['idProducto']); ?>" size="10" /> </td> <td width="102" align="right"><input type="text" name="idProducto" value="<?php echo $row_compra['intCantidad']; ?>" size="4" align="left" /></td> <td colspan="2" align="center"><input name="idProducto" type="text" value="<?php echo ObtenerPrecioProducto($row_compra['idProducto']); ?>" size="5" /></td> <?php $preciototal = $preciototal + ObtenerPrecioProducto($row_compra['idProducto']);?> <td height="27" align="center"> <td align="center"> <td align="center"> </tr> </table> </form> <tr> <table width="618" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="223" height="20"></td> <td width="137"></td> <td class="comproducto"><input name="preciototal" type="text" value="<?php $multiplicador = (100 + ObtenerIVA())/100; $valorconIVA = $preciototal * $multiplicador; echo $valorconIVA;?> " /> Euros IVA incluido</td> </tr> </table> <?php $body.='<tr> <td>Gracias por comprar en la cachemira.com, <br /> a continuacion le remitimos el total de su compra, esperamos verle pronto. </tr>'; $body.='<tr></tr>';?> <form id="formulario" method="post" action="recibido.php" enctype="multipart/form-data"> <input type="email" name="email" required> <input type="hidden" name="mensaje" value="<?php echo $body?>"> <input type="hidden" name="fchFecha" value="<?php echo $hoy ?>" /> <input type="hidden" name="body" value="<?php echo $body ?>" /> <input type="hidden" name="asunto" value="<?php echo $asunto ?>"> <input type="hidden" name="precio" value="125678" /> <input id="submit" type="submit" name="enviar" value="Enviar mail"> </form>
aqui la que recoge y manda <?php //Librerías para el envío de mail include_once('phpmailer/class.phpmailer.php'); include_once('phpmailer/class.smtp.php'); $para = $_POST['email']; $asunto= $_POST['asunto']; $mensaje = $_POST['mensaje']->$precio=$_POST['precio']; $fchFecha= $_POST['fchFecha'] ; $mensaje = $_POST['mensaje']; $precio=$_POST['precio']; //Este bloque es importante $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->SMTPSecure = "ssl"; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; //Nuestra cuenta $mail->Username ='@gmail.com'; $mail->Password = ' password //Agregar destinatario $mail->AddAddress($para); $mail->Subject = ($asunto); $mail->Body = $body ; $mail->precio = ($precio); //Para adjuntar archivo //$mail->AddAttachment($archivo['tmp_name'], $archivo['name']); $mail->MsgHTML($mensaje,$asunto,$precio); //Avisar si fue enviado o no y dirigir al index if($mail->Send()) { echo'<script type="text/javascript"> alert("Enviado Correctamente"); window.location="envio_realizado.php" </script>'; } else{ echo'<script type="text/javascript"> alert("NO ENVIADO, intentar de nuevo"); window.location="envio_realizado.php" </script>'; } ?>
esto es todo, a ver si hay suerte, gracias
|
|
|
|
|
|
|