They passed me a program in C # in POO, I have my notions that they are classes and objects, but I wanted to know why in PRODUCTOMODEL first instance Producto pro=new Producto();
and then create Product p to later match.
Then I see that in frmPRODUCTO they do pr = model.find (); .
I can not understand why they do those things (maybe it is poorly implemented, but if compiled) , I do not know if it will be pattern design.
This is the code:
PRODUCT CLASS
public class Producto
{
// propiedades
public string IdProducto { get; set; }
public string Nombre { get; set; }
public DateTime Fecha { get; set; }
public decimal Precio { get; set; }
public int Cantidad { get; set; }
//constructor
public Producto()
{
IdProducto = "P001";
Nombre = "Producto Inicial";
Fecha = DateTime.Now;
Precio = 120.50M;
Cantidad = 100;
}
PRODUCTOMODEL CLASS
public class ProductoModel
{
Producto pro=new Producto();
//constructor
public ProductoModel()
{
}
// metodos para procesar
public void create(Producto p)
{
pro = p;
}
//public Producto find()
//{
// return pro;
//}
public Producto find(Producto o)
{
return pro;
}
frmPRODUCT
public frmProducto()
{
InitializeComponent();
}
// instanciar objeto de la clase productocontroller
ProductoController obj = new ProductoController();
Producto pr=new Producto();
ProductoModel model = new ProductoModel();
private void btnMostrar_Click(object sender, EventArgs e)
{
pr = model.find();
lblIdproducto.Text = pr.IdProducto;
lblNombre.Text = pr.Nombre;
lblFecha.Text = pr.Fecha.ToShortDateString();
lblPrecio.Text = pr.Precio.ToString();
lblCantidad.Text = pr.Cantidad.ToString();
//pr = model.find(pr);
}
private void btnRegistrar_Click(object sender, EventArgs e)
{
// asignar valores al objeto pr
pr.IdProducto =""+ txtIdproducto.Text;
pr.Nombre = txtNombre.Text;
pr.Fecha = dtpFecha.Value;
pr.Precio = decimal.Parse(txtPrecio.Text);
pr.Cantidad = (int)numCantidad.Value;
// registrar producto
model.create(pr);
txtIdproducto.Text = pr.IdProducto;
MessageBox.Show("Producto registrado con exito", "exito", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}