Advertisement
Ecchijpbp

Programación 2 - Clase 4

Sep 4th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.81 KB | None | 0 0
  1. Manejo de Matrices.
  2.  
  3.  
  4. Clase Producto______________________________________________
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10.  
  11. namespace WindowsFormsApplication2
  12. {
  13. class Producto
  14. {
  15. private string nombre;
  16. private double precio;
  17. private int cantidad;
  18. private double importe;
  19.  
  20. public string pnombre
  21. {
  22. get { return nombre; }
  23. set { nombre = value; }
  24. }
  25.  
  26. public double pprecio
  27. {
  28. get { return precio; }
  29. set { precio = value; }
  30. }
  31.  
  32. public int pcantidad
  33. {
  34. get { return cantidad; }
  35. set { cantidad = value; }
  36. }
  37.  
  38. public double pimporte
  39. {
  40. get { return importe; }
  41. set { importe= value; }
  42. }
  43.  
  44. public double calcularImporte()
  45. {
  46. importe = precio * cantidad;
  47. return pimporte;
  48. }
  49. }
  50. }
  51. Clase Form________________________________________
  52. using System;
  53. using System.Collections.Generic;
  54. using System.ComponentModel;
  55. using System.Data;
  56. using System.Drawing;
  57. using System.Linq;
  58. using System.Text;
  59. using System.Threading.Tasks;
  60. using System.Windows.Forms;
  61.  
  62. namespace WindowsFormsApplication2
  63. {
  64. public partial class Form1 : Form
  65. {
  66.  
  67. //const int tam = 3;
  68. //Producto[] aP = new Producto[tam];
  69. //int c = 0;
  70.  
  71. const int suc = 2;
  72. const int dia = 3;
  73. Producto[,] mProd = new Producto[suc, dia];
  74. int cs = 0;
  75. int cd = 0;
  76.  
  77.  
  78.  
  79. public Form1()
  80. {
  81. InitializeComponent();
  82. //for (int i = 0; i < tam; i++) //Inicializo el Array
  83. //{
  84. // aP[i] = null;
  85. //}
  86. for (int f = 0; f < suc; f++)
  87. for (int c = 0; c < dia; c++)
  88. mProd[f, c] = null;
  89. }
  90.  
  91.  
  92. private void btnCargar_Click(object sender, EventArgs e)
  93. {
  94. Producto p = new Producto();
  95. p.pnombre = txtNombre.Text;
  96. p.pprecio = Convert.ToDouble(txtPrecio.Text);
  97. p.pcantidad = Convert.ToInt16(txtCantidad.Text);
  98.  
  99. mProd[cs, cd] = p;
  100.  
  101. lstNombre.Items.Add(mProd[cs, cd].pnombre);
  102. lstPrecio.Items.Add(mProd[cs, cd].pprecio);
  103. lstCantidad.Items.Add(mProd[cs, cd].pcantidad);
  104.  
  105. cs++;
  106. if (cs == suc) //Lógica de Recorrido por Columna
  107. {
  108. cd++;
  109. cs = 0;
  110. }
  111. if (cd == dia)
  112. {
  113. MessageBox.Show("Se completó la venta de la semana");
  114. btnCargar.Enabled = false;
  115. btnCalcular.Enabled = true;
  116. }
  117.  
  118. //if (c < 3)
  119. //{
  120. // aP[c] = new Producto();
  121. // if (txtNombre.Text != "" && txtCantidad.Text != "" && txtPrecio.Text != "")
  122. // {
  123. // aP[c].pnombre = txtNombre.Text;
  124. // aP[c].pcantidad = Convert.ToInt16(txtCantidad.Text);
  125. // aP[c].pprecio = Convert.ToDouble(txtPrecio.Text);
  126. // aP[c].calcularImporte();
  127. //
  128. // lstNombre.Items.Add(aP[c].pnombre);
  129. // lstCantidad.Items.Add(aP[c].pcantidad);
  130. // lstPrecio.Items.Add(aP[c].pprecio);
  131. // c++;
  132. // txtPrecio.Clear();
  133. // txtNombre.Clear();
  134. // txtCantidad.Clear();
  135. // txtNombre.Select();
  136. // }
  137. // else
  138. // MessageBox.Show("Casillas vacias");
  139. //}
  140. //else
  141. // MessageBox.Show("Lleno");
  142. //
  143. }
  144.  
  145. private void btnCalcular_Click(object sender, EventArgs e)
  146. {
  147. double total = 0;
  148. lstImporte.Items.Clear();
  149.  
  150. for (int c = 0; c < dia; c++)
  151. {
  152. for (int f = 0; f < suc; f++)
  153. {
  154. lstImporte.Items.Add(mProd[f, c].calcularImporte());
  155. total += mProd[f, c].calcularImporte();
  156. }
  157. }
  158.  
  159.  
  160.  
  161.  
  162. txtTotal.Text = total.ToString();
  163. //double total = 0;
  164. //lstImporte.Items.Clear();
  165. //for (int i = 0; i < c; i++)
  166. //{
  167. // lstImporte.Items.Add(aP[i].calcularImporte());
  168. // total += aP[i].calcularImporte();
  169. // txtTotal.Text = Convert.ToString(total);
  170. //}
  171. }
  172.  
  173. private void btnTotalSuc_Click(object sender, EventArgs e)
  174. {
  175. double totalSuc = 0;
  176. double totalGral = 0;
  177.  
  178. for (int f = 0; f < suc; f++)
  179. {
  180. totalSuc = 0;
  181. for(int c = 0; c < dia; c++)
  182. totalSuc += mProd[f, c].calcularImporte();
  183. lstSuc.Items.Add("Suc: " + (f + 1) + "$ " + totalSuc);
  184. totalGral += totalSuc;
  185. }
  186. txtTotalSuc.Text = totalGral.ToString();
  187. }
  188.  
  189. private void btnTotalDia_Click(object sender, EventArgs e)
  190. {
  191. double totalDia = 0;
  192. double totalGral = 0;
  193.  
  194. for (int c = 0; c < dia; c++)
  195. {
  196. totalDia = 0;
  197. for (int f = 0; f < suc; f++)
  198. totalDia += mProd[f, c].calcularImporte();
  199. lstDia.Items.Add("Dia: " + (c + 1) + "$ " + totalDia);
  200. totalGral += totalDia;
  201. }
  202. txtTotalDia.Text = totalGral.ToString();
  203. }
  204.  
  205. }
  206. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement