elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


  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


Código
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10.  
  11. namespace WindowsFormsApp1
  12. {
  13.    public partial class Form1 : Form
  14.    {
  15.  
  16.        Double valor = 0;
  17.        String operacion = "";
  18.        bool operacion_press = false;
  19.        Double valor1 = 100;
  20.  
  21.        public Form1()
  22.        {
  23.            InitializeComponent();
  24.        }
  25.  
  26.        private void button_click(object sender, EventArgs e)
  27.        {
  28.           if ((resultado.Text == "0")||(operacion_press))
  29.                resultado.Clear();
  30.            operacion_press = false;
  31.            Button b = (Button) sender;
  32.            resultado.Text = resultado.Text + b.Text;
  33.        }
  34.        private void btn_ce_Click(object sender, EventArgs e)
  35.        {
  36.            resultado.Text = "0";
  37.            res_2.Text = "0";
  38.        }
  39.  
  40.        private void operador_click(object sender, EventArgs e)
  41.        {
  42.            Button b = (Button)sender;
  43.            operacion = b.Text;
  44.            valor = Double.Parse(resultado.Text);
  45.            operacion_press = true;
  46.            res_2.Text = valor + " " + operacion;
  47.  
  48.        }
  49.  
  50.        private void btn_igual(object sender, EventArgs e)
  51.        {
  52.            res_2.Text = "";
  53.            switch (operacion)
  54.            {
  55.                case "+":
  56.                    resultado.Text = (valor + Double.Parse(resultado.Text)).ToString();
  57.                    res_2.Text = "El Resultado es " + Double.Parse(resultado.Text).ToString();
  58.                    break;
  59.                case "-":
  60.                    resultado.Text = (valor - Double.Parse(resultado.Text)).ToString();
  61.                    res_2.Text = "El Resultado es " + Double.Parse(resultado.Text).ToString();
  62.                    break;
  63.                case "*":
  64.                    resultado.Text = (valor * Double.Parse(resultado.Text)).ToString();
  65.                    res_2.Text = "El Resultado es " + Double.Parse(resultado.Text).ToString();
  66.                    break;
  67.                case "/":
  68.                    resultado.Text = (valor / Double.Parse(resultado.Text)).ToString();
  69.                    res_2.Text = "El Resultado es " + Double.Parse(resultado.Text).ToString();
  70.                    break;
  71.                case "√":
  72.                    resultado.Text = Math.Sqrt(valor).ToString();
  73.                    res_2.Text = "El Resultado es " + Double.Parse(resultado.Text).ToString();
  74.                    break;
  75.  
  76.  
  77.  
  78.  
  79.            } // fin switch
  80.  
  81.  
  82.  
  83.  
  84.        }
  85.         private void btn4_Click(object sender, EventArgs e)
  86.        {
  87.            resultado.Clear();
  88.            valor = 0;
  89.            res_2.Text = "0";
  90.  
  91.        }
  92.  
  93.        private void button5_Click(object sender, EventArgs e)
  94.        {
  95.            if (resultado.Text.Length > 0)
  96.  
  97.         resultado.Text = resultado.Text.Remove(resultado.Text.Length - 1, 1);
  98.        }
  99.  
  100.        private void btnpor_click(object sender, EventArgs e)
  101.        {
  102.  
  103.  
  104.          [b] [color=red] Double a;
  105.  
  106.  
  107.            a = Convert.ToDouble(resultado.Text) / Convert.ToDouble(100);
  108.            resultado.Text = System.Convert.ToString(a);
  109.            res_2.Text = " Porcentaje " + System.Convert.ToString(a);[/color]
  110. [/b]
  111.        }
  112.    }
  113. }
  114.  
  115. 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
  116.  
  117.  
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
Código
  1. $sesion=[" carro"];
, esta va con una
Código
  1. $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
Código
  1. <?php require_once('Connections/conexionzapatos.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.  if (PHP_VERSION < 6) {
  7.    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.  }
  9.  
  10.  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.  switch ($theType) {
  13.    case "text":
  14.      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.      break;    
  16.    case "long":
  17.    case "int":
  18.      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.      break;
  20.    case "double":
  21.      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.      break;
  23.    case "date":
  24.      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.      break;
  26.    case "defined":
  27.      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.      break;
  29.  }
  30.  return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36.  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  $insertGoTo = "prueb1234.php";
  39.  if (isset($_SERVER['QUERY_STRING'])) {
  40.    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  41.    $insertGoTo .= $_SERVER['QUERY_STRING'];
  42.  }
  43.  header(sprintf("Location: %s", $insertGoTo));
  44. }
  45.  
  46. $varUsuario_DatosCarrito = "0";
  47. if (isset($_SESSION["MM_IdUsuario"])) {
  48.  $varUsuario_DatosCarrito = $_SESSION["MM_IdUsuario"];
  49. }
  50. mysql_select_db($database_conexionzapatos, $conexionzapatos);
  51. $query_DatosCarrito = sprintf("SELECT * FROM tblcarrito WHERE tblcarrito.idUsuario = %s AND tblcarrito.intTransaccionEfectuada = 0", GetSQLValueString($varUsuario_DatosCarrito, "int"));
  52. $DatosCarrito = mysql_query($query_DatosCarrito, $conexionzapatos) or die(mysql_error());
  53. $row_DatosCarrito = mysql_fetch_assoc($DatosCarrito);
  54. $totalRows_DatosCarrito = mysql_num_rows($DatosCarrito);
  55.  
  56. $hoy = date("Y-m-d");
  57. $Transferencia="Transferencia";
  58.  
  59. $multiplicador =  ObtenerIVA()/100;
  60. $valordelIVA = $preciototal * $multiplicador;
  61.  
  62.  
  63. ?>
  64. <?php if ($totalRows_DatosCarrito > 0) { // Show if recordset not empty ?>
  65.       <table width="100%" border="0" cellspacing="0" cellpadding="0">
  66.                  <tr class="ver">
  67.                    <td width="23%">Producto</td>
  68.                    <td width="33%">Unidades</td>
  69.                    <td width="33%">Precio</td>
  70.                    <td width="9%">Acciones</td>
  71.                  </tr>
  72.                  <?php $preciototal = 0;?>
  73.                  <?php do { ?>
  74.  <tr class="letra">
  75.    <td align=""><?php echo ObtenerNombreProducto($row_DatosCarrito['idProducto']); ?></td>
  76.    <td><?php echo $row_DatosCarrito['intCantidad']; ?><a href="sumar_producto.php?idlinea=<?php echo $row_DatosCarrito['intContador']; ?>">+</a>    <?php if ($row_DatosCarrito['intCantidad']!=1){?>
  77.    <a href="restar_producto.php?idlinea=<?php echo $row_DatosCarrito['intContador']; ?>">-</a>    <?php }?></td>
  78.    <td ><?php echo ObtenerPrecioProducto($row_DatosCarrito['idProducto']); ?> <span class="letra">Euros</span></td>
  79.    <td><a href="eliminar_producto.php?recordID=<?php echo $row_DatosCarrito['idProducto']; ?>">Eliminar</a></td>
  80.  </tr>
  81. <?php   $preciototal = $preciototal + ObtenerPrecioProducto($row_DatosCarrito['idProducto']);?>
  82.  <?php } while ($row_DatosCarrito = mysql_fetch_assoc($DatosCarrito)); ?>
  83.        <tr>
  84.    <td>&nbsp;</td>
  85.    <td align="right">Subtotal:</td>
  86.    <td align="left"> <?php
  87.          $multiplicador =  (100 + ObtenerIVA())/100;
  88.          $valorconIVA = $preciototal * $multiplicador;
  89.          echo $valorconIVA;?>
  90.    </td><td>
  91.          <td width="2%">&nbsp;</td>
  92.        </tr>
  93. </tr>
  94.  </table>  
  95. <table width="433" height="32" align="left">
  96.    <td width="425" align="center">
  97.       <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  98.                      <input type="submit" value="Insertar registro" />
  99.                    </tr>
  100.  
  101.                  <input type="hidden" name="idCompra" value="" />
  102.                  <input type="hidden" name="idUsuario" value="<?php echo $row_DatosCarrito['idUsuario']; ?>" />
  103.                  <input type="hidden" name="fchFecha" value="<?php echo $hoy ?>" />
  104.                  <input type="hidden" name="intTipoPago" value="<?php echo $Transferencia ?>" />
  105.                  <input type="hidden" name="dblTotal" value="<?php
  106.          $multiplicador =  (100 + ObtenerIVA())/100;
  107.          $valorconIVA = $preciototal * $multiplicador;
  108.          echo $valorconIVA;?>" />
  109.                  <input type="hidden" name="intEstado" value="1" />
  110.                  <input type="hidden" name="strNombre" value=" <?php echo ObtenerNombreUsuario($_SESSION['MM_IdUsuario']) ?>" />
  111.  
  112.                  <input type="hidden" name="MM_insert" value="form1" />
  113.              </form>
  114.            </table>              
  115.   <?php } // Show if recordset not empty ?>
  116.   <?php if ($totalRows_DatosCarrito == 0) { // Show if recordset empty ?>
  117.  <p>&nbsp;<table width="363" align="center">
  118.    <tr>
  119.      <td width="355" align="center">Su Carro Esta Vacio</td>
  120.      </tr>
  121.  </table>
  122.  <?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
3  Programación / PHP / Re: envio de datos carrito de compras y phpmailer en: 16 Enero 2015, 17:54 pm
gracias pro responder, ya lo resolvi, no se si de forma muy ortodoxa, pero esta, gracias
4  Programación / PHP / Re: envio de datos carrito de compras y phpmailer en: 7 Enero 2015, 11:27 am
no, es que oculte el pasword logicamente, en el original sale mi email y mi paswword
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
Código
  1. <?php require_once('Connections/conexionzapatos.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6. if (PHP_VERSION < 6) {
  7. $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8. }
  9.  
  10. $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12. switch ($theType) {
  13. case "text":
  14. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15. break;
  16. case "long":
  17. case "int":
  18. $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19. break;
  20. case "double":
  21. $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22. break;
  23. case "date":
  24. $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25. break;
  26. case "defined":
  27. $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28. break;
  29. }
  30. return $theValue;
  31. }
  32. }
  33.  
  34. $editFormAction = $_SERVER['PHP_SELF'];
  35. if (isset($_SERVER['QUERY_STRING'])) {
  36. $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
  37. }
  38.  
  39. if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  40. $insertSQL = sprintf("INSERT INTO tblcompra (idCompra, idUsuario, fchFecha, intTipoPago, dblTotal, intEstado, strNombre) VALUES (%s, %s, %s, %s, %s, %s, %s)",
  41. GetSQLValueString($_POST['idCompra'], "int"),
  42. GetSQLValueString($_POST['idUsuario'], "int"),
  43. GetSQLValueString($_POST['fchFecha'], "date"),
  44. GetSQLValueString($_POST['intTipoPago'], "text"),
  45. GetSQLValueString($_POST['dblTotal'], "double"),
  46. GetSQLValueString($_POST['intEstado'], "int"),
  47. GetSQLValueString($_POST['strNombre'], "text"));
  48.  
  49. mysql_select_db($database_conexionzapatos, $conexionzapatos);
  50. $Result1 = mysql_query($insertSQL, $conexionzapatos) or die(mysql_error());
  51.  
  52. $insertGoTo = "recibido.php";
  53. if (isset($_SERVER['QUERY_STRING'])) {
  54. $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
  55. $insertGoTo .= $_SERVER['QUERY_STRING'];
  56. }
  57. header(sprintf("Location: %s", $insertGoTo));
  58. }
  59.  
  60. $maxRows_compra = 10;
  61. $pageNum_compra = 0;
  62. if (isset($_GET['pageNum_compra'])) {
  63. $pageNum_compra = $_GET['pageNum_compra'];
  64. }
  65. $startRow_compra = $pageNum_compra * $maxRows_compra;
  66.  
  67. $varCompra_compra = "0";
  68. if (isset($_SESSION["MM_IdUsuario"])) {
  69. $varCompra_compra = $_SESSION["MM_IdUsuario"];
  70. }
  71. mysql_select_db($database_conexionzapatos, $conexionzapatos);
  72. $query_compra = sprintf("SELECT * FROM tblcarrito WHERE tblcarrito.idUsuario = %s", GetSQLValueString($varCompra_compra, "int"));
  73. $query_limit_compra = sprintf("%s LIMIT %d, %d", $query_compra, $startRow_compra, $maxRows_compra);
  74. $compra = mysql_query($query_limit_compra, $conexionzapatos) or die(mysql_error());
  75. $row_compra = mysql_fetch_assoc($compra);
  76.  
  77. if (isset($_GET['totalRows_compra'])) {
  78. $totalRows_compra = $_GET['totalRows_compra'];
  79. } else {
  80. $all_compra = mysql_query($query_compra);
  81. $totalRows_compra = mysql_num_rows($all_compra);
  82. }
  83. $totalPages_compra = ceil($totalRows_compra/$maxRows_compra)-1;
  84.  
  85. $preciototal="ObtenerIVA()/100";
  86. $multiplicador = "ObtenerIVA()/100";
  87. $valordelIVA = "preciototal * $multiplicador";
  88. $valorconIVA = "preciototal * $multiplicador";
  89. $hoy = date("Y-m-d");
  90. $Transferencia="Transferencia";
  91. $asunto="Cachemira.com";
  92. $body="body";
  93. $precio="$valorconIVA";
  94. ?>
  95. <table width="324" align="center">
  96. <tr>
  97. <td width="316" align="center" bgcolor="#EEEEEE"><strong>Resumen de su compra</strong></td>
  98. </tr>
  99. </table>
  100.  
  101.  
  102. <form action="recibido.php" method="post" name="form" id="form1">
  103. <table width="618" height="94" align="center">
  104.  
  105. <tr bgcolor="#00FFFF">
  106. <td align="center">Productos</td>
  107. <td align="center">Unidades</td>
  108. <td colspan="2" align="center">Total </td>
  109.  
  110. </tr>
  111. <?php $preciototal = 0;?>
  112. <?php do { ?>
  113.  
  114. <tr bgcolor="#FFECEC" align="center">
  115. <td width="186" height="24" align="right">
  116. <input name="idProducto" type="text" value="<?php echo ObtenerNombreProducto($row_compra['idProducto']); ?>" size="10" /> </td>
  117. <td width="102" align="right"><input type="text" name="idProducto" value="<?php echo $row_compra['intCantidad']; ?>" size="4" align="left" /></td>
  118. <td colspan="2" align="center"><input name="idProducto" type="text" value="<?php echo ObtenerPrecioProducto($row_compra['idProducto']); ?>" size="5" /></td>
  119. <?php $preciototal = $preciototal + ObtenerPrecioProducto($row_compra['idProducto']);?>
  120.  
  121. <?php } while ($row_compra = mysql_fetch_assoc($compra)); ?><tr>
  122. <td height="27" align="center">
  123. <td align="center">
  124. <td align="center">
  125. </tr>
  126. </table>
  127. </form>
  128. <tr> <table width="618" align="center" cellpadding="0" cellspacing="0">
  129. <tr>
  130. <td width="223" height="20"></td>
  131. <td width="137"></td>
  132. <td class="comproducto"><input name="preciototal" type="text" value="<?php
  133. $multiplicador = (100 + ObtenerIVA())/100;
  134. $valorconIVA = $preciototal * $multiplicador;
  135. echo $valorconIVA;?>
  136. " /> Euros IVA incluido</td>
  137. </tr>
  138. </table>
  139. <?php $body.='<tr>
  140.  
  141. <td>Gracias por comprar en la cachemira.com, <br />
  142. a continuacion le remitimos el total de su compra, esperamos verle pronto.
  143. </tr>';
  144. $body.='<tr></tr>';?>
  145.  
  146.  
  147.  
  148. <form id="formulario" method="post" action="recibido.php" enctype="multipart/form-data">
  149.  
  150. <input type="email" name="email" required>
  151. <input type="hidden" name="mensaje" value="<?php echo $body?>"> <input type="hidden" name="fchFecha" value="<?php echo $hoy ?>" />
  152. <input type="hidden" name="body" value="<?php echo $body ?>" />
  153. <input type="hidden" name="asunto" value="<?php echo $asunto ?>">
  154. <input type="hidden" name="precio" value="125678" />
  155. <input id="submit" type="submit" name="enviar" value="Enviar mail">
  156. </form>
  157.  
aqui la que recoge y manda

Código
  1. <?php
  2. //Librerías para el envío de mail
  3. include_once('phpmailer/class.phpmailer.php');
  4. include_once('phpmailer/class.smtp.php');
  5.  
  6.  
  7. $para = $_POST['email'];
  8. $asunto= $_POST['asunto'];
  9. $mensaje = $_POST['mensaje']->$precio=$_POST['precio'];
  10. $fchFecha= $_POST['fchFecha'] ;
  11. $mensaje = $_POST['mensaje'];
  12. $precio=$_POST['precio'];
  13. //Este bloque es importante
  14. $mail = new PHPMailer();
  15. $mail->IsSMTP();
  16. $mail->SMTPAuth = true;
  17. $mail->SMTPSecure = "ssl";
  18. $mail->Host = "smtp.gmail.com";
  19. $mail->Port = 465;
  20.  
  21. //Nuestra cuenta
  22. $mail->Username ='@gmail.com';
  23. $mail->Password = ' password
  24.  
  25. //Agregar destinatario
  26.  
  27. $mail->AddAddress($para);
  28. $mail->Subject = ($asunto);
  29. $mail->Body = $body ;
  30. $mail->precio = ($precio);
  31.  
  32. //Para adjuntar archivo
  33. //$mail->AddAttachment($archivo['tmp_name'], $archivo['name']);
  34. $mail->MsgHTML($mensaje,$asunto,$precio);
  35.  
  36. //Avisar si fue enviado o no y dirigir al index
  37. if($mail->Send())
  38. {
  39. echo'<script type="text/javascript">
  40. alert("Enviado Correctamente");
  41. window.location="envio_realizado.php"
  42. </script>';
  43. }
  44. else{
  45. echo'<script type="text/javascript">
  46. alert("NO ENVIADO, intentar de nuevo");
  47. window.location="envio_realizado.php"
  48. </script>';
  49. }
  50. ?>
  51.  

esto es todo, a ver si hay suerte, gracias

Páginas: [1]
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines