Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Manejo de Matrices.
- Clase Producto______________________________________________
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace WindowsFormsApplication2
- {
- class Producto
- {
- private string nombre;
- private double precio;
- private int cantidad;
- private double importe;
- public string pnombre
- {
- get { return nombre; }
- set { nombre = value; }
- }
- public double pprecio
- {
- get { return precio; }
- set { precio = value; }
- }
- public int pcantidad
- {
- get { return cantidad; }
- set { cantidad = value; }
- }
- public double pimporte
- {
- get { return importe; }
- set { importe= value; }
- }
- public double calcularImporte()
- {
- importe = precio * cantidad;
- return pimporte;
- }
- }
- }
- Clase Form________________________________________
- 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 WindowsFormsApplication2
- {
- public partial class Form1 : Form
- {
- //const int tam = 3;
- //Producto[] aP = new Producto[tam];
- //int c = 0;
- const int suc = 2;
- const int dia = 3;
- Producto[,] mProd = new Producto[suc, dia];
- int cs = 0;
- int cd = 0;
- public Form1()
- {
- InitializeComponent();
- //for (int i = 0; i < tam; i++) //Inicializo el Array
- //{
- // aP[i] = null;
- //}
- for (int f = 0; f < suc; f++)
- for (int c = 0; c < dia; c++)
- mProd[f, c] = null;
- }
- private void btnCargar_Click(object sender, EventArgs e)
- {
- Producto p = new Producto();
- p.pnombre = txtNombre.Text;
- p.pprecio = Convert.ToDouble(txtPrecio.Text);
- p.pcantidad = Convert.ToInt16(txtCantidad.Text);
- mProd[cs, cd] = p;
- lstNombre.Items.Add(mProd[cs, cd].pnombre);
- lstPrecio.Items.Add(mProd[cs, cd].pprecio);
- lstCantidad.Items.Add(mProd[cs, cd].pcantidad);
- cs++;
- if (cs == suc) //Lógica de Recorrido por Columna
- {
- cd++;
- cs = 0;
- }
- if (cd == dia)
- {
- MessageBox.Show("Se completó la venta de la semana");
- btnCargar.Enabled = false;
- btnCalcular.Enabled = true;
- }
- //if (c < 3)
- //{
- // aP[c] = new Producto();
- // if (txtNombre.Text != "" && txtCantidad.Text != "" && txtPrecio.Text != "")
- // {
- // aP[c].pnombre = txtNombre.Text;
- // aP[c].pcantidad = Convert.ToInt16(txtCantidad.Text);
- // aP[c].pprecio = Convert.ToDouble(txtPrecio.Text);
- // aP[c].calcularImporte();
- //
- // lstNombre.Items.Add(aP[c].pnombre);
- // lstCantidad.Items.Add(aP[c].pcantidad);
- // lstPrecio.Items.Add(aP[c].pprecio);
- // c++;
- // txtPrecio.Clear();
- // txtNombre.Clear();
- // txtCantidad.Clear();
- // txtNombre.Select();
- // }
- // else
- // MessageBox.Show("Casillas vacias");
- //}
- //else
- // MessageBox.Show("Lleno");
- //
- }
- private void btnCalcular_Click(object sender, EventArgs e)
- {
- double total = 0;
- lstImporte.Items.Clear();
- for (int c = 0; c < dia; c++)
- {
- for (int f = 0; f < suc; f++)
- {
- lstImporte.Items.Add(mProd[f, c].calcularImporte());
- total += mProd[f, c].calcularImporte();
- }
- }
- txtTotal.Text = total.ToString();
- //double total = 0;
- //lstImporte.Items.Clear();
- //for (int i = 0; i < c; i++)
- //{
- // lstImporte.Items.Add(aP[i].calcularImporte());
- // total += aP[i].calcularImporte();
- // txtTotal.Text = Convert.ToString(total);
- //}
- }
- private void btnTotalSuc_Click(object sender, EventArgs e)
- {
- double totalSuc = 0;
- double totalGral = 0;
- for (int f = 0; f < suc; f++)
- {
- totalSuc = 0;
- for(int c = 0; c < dia; c++)
- totalSuc += mProd[f, c].calcularImporte();
- lstSuc.Items.Add("Suc: " + (f + 1) + "$ " + totalSuc);
- totalGral += totalSuc;
- }
- txtTotalSuc.Text = totalGral.ToString();
- }
- private void btnTotalDia_Click(object sender, EventArgs e)
- {
- double totalDia = 0;
- double totalGral = 0;
- for (int c = 0; c < dia; c++)
- {
- totalDia = 0;
- for (int f = 0; f < suc; f++)
- totalDia += mProd[f, c].calcularImporte();
- lstDia.Items.Add("Dia: " + (c + 1) + "$ " + totalDia);
- totalGral += totalDia;
- }
- txtTotalDia.Text = totalGral.ToString();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement