Exemple #1
0
        private void btnAgregarMaterial_Click(object sender, EventArgs e)
        {
            btnAgregarMaterial.Visible = false;
            try
            {
                _Producto.Id                    = Convert.ToInt32(txtId.Text);
                _Producto.Categoria.Id          = Convert.ToInt32(txtCategoriaId.Text);
                _Producto.Categoria.Descripcion = txtCategoriaDescripcion.Text;

                MaterialBLL _MaterialBLL = new MaterialBLL();

                _Material = _MaterialBLL.ObtenerMaterial(int.Parse(this.txtMaterialId.Text));
                misMateriales.Add(_Material);


                if (_Material == null)
                {
                    MessageBox.Show("El Material No existe !", "Anteción", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }


                DetalleMaterial oDetalleMaterial = new DetalleMaterial()
                {
                    Producto      = _Producto,
                    Material      = _Material,
                    UnidadMedidad = txtUMedidaMaterial.Text,
                    Cantidad      = int.Parse(txtCantidadMaterial.Text),
                    Costo         = 0
                                    //  No_Linea = this.dgvDatos.Rows.Count,
                };
                _Producto.AgregarMaterial(oDetalleMaterial);


                oDetalleMaterial = _Producto.AgregarMaterial(oDetalleMaterial);

                txtPrecioVenta.Text = "";
                txtPrecioVenta.Text = _Producto.CalcularPrecioProducto().ToString();

                string[] item = { oDetalleMaterial.Material.Id.ToString(),     oDetalleMaterial.Material.Descripcion, oDetalleMaterial.Material.Uni_Medida,
                                  oDetalleMaterial.Material.Precio.ToString(), oDetalleMaterial.Cantidad.ToString(),  oDetalleMaterial.Costo.ToString() };

                dgvListaMateriales.Rows.Add(item);

                this.txtMaterialId.Clear();
                this.txtMaterialDescripcion.Clear();
                this.txtUMedidaMaterial.Clear();
                this.txtCantidadMaterial.Clear();

                _Material = null;
            }
            catch (Exception er)
            {
                StringBuilder msg = new StringBuilder();
                msg.AppendFormat("Message        {0}\n", er.Message);
                MessageBox.Show(msg.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }