Ejemplo n.º 1
0
        protected override bool aceptar()
        {
            // Si seleccionó al menos un cliente
            if (ltvBusqueda.SelectedItems.Count > 0)
            {
                object tag = ltvBusqueda.SelectedItems[0].Tag;

                if (tag != null)
                {
                    try
                    {
                        tag = ((ArticuloPlantaHistorico)tag).ArticuloPlanta;
                    }catch (Exception ex) {}

                    articuloSeleccionado = (ArticuloPlanta)tag;

                    this.DialogResult = DialogResult.OK;

                    this.Close();

                    return(true);
                }
            }

            Mensaje mensaje = new Mensaje("Debe seleccionar un Artículo.", Mensaje.TipoMensaje.Alerta, Mensaje.Botones.OK);

            mensaje.ShowDialog();

            return(false);
        }
Ejemplo n.º 2
0
        private void cargarDatos(Comprobante_Remito remito)
        {
            txtNroRemito.Text        = remito.numero.ToString();
            dtpFecha.Value           = remito.fechaIngreso;
            txtPlanta.Text           = remito.Planta.nombre;
            txtRazonSocial.Text      = remito.Planta.Cliente.razonSocial;
            txtObs.Text              = remito.observacion;
            txtOrdenCompra.Text      = remito.ordenCompra;
            txtEnviarA.Text          = planta.direccion;
            cboTipoRem.SelectedIndex = cboTipoRem.FindStringExact(remito.tipo);
            txtDomicilio.Text        = remito.Planta.Cliente.direccion;
            txtLocalidad.Text        = remito.Planta.Cliente.Localidad.nombre;
            txtSitIva.Text           = remito.Planta.Cliente.SituacionFrenteIva.nombre;
            txtCUIT.Text             = remito.Planta.Cliente.cuit;
            txtCantBultos.Text       = remito.cantidadBultos.ToString();
            cboUnidad.SelectedIndex  = cboUnidad.FindStringExact(remito.Unidad.nombre);
            txtPeso.Text             = remito.pesoTotalKg.ToString("0.00");
            cboMoneda.SelectedIndex  = cboMoneda.FindStringExact(remito.Moneda.nombre);
            txtTotal.Text            = remito.importe.ToString("0.00");
            chkNF.Checked            = !remito.facturable;

            int i = 0;

            dgvItems.Rows.Clear();
            foreach (VentaArticuloPlanta itemRem in remito.VentaArticuloPlanta)
            {
                decimal precioCalc;
                precioCalc = Global.Servicio.ConviertePrecio(itemRem.precio, itemRem.Moneda, (Moneda)((ComboBoxItem)cboMoneda.SelectedItem).Value);
                dgvItems.Rows.Add();
                ArticuloPlanta artPla = remito.Planta.ArticuloPlanta.Where(a => a.idArticulo == itemRem.TipoArticulo.id).First();
                dgvItems.Rows[i].Tag = artPla;
                dgvItems.Rows[i].Cells["clmArt"].Value    = remito.Planta.codigo + artPla.contador.ToString();
                dgvItems.Rows[i].Cells["clmCant"].Value   = itemRem.cantidad.ToString("0.00");
                dgvItems.Rows[i].Cells["clmUnidad"].Value = itemRem.TipoArticulo.Unidad.abreviatura;
                dgvItems.Rows[i].Cells["clmDesc"].Value   = itemRem.TipoArticulo.nombre;
                dgvItems.Rows[i].Cells["clmLote"].Value   = itemRem.lote;
                dgvItems.Rows[i].Cells["clmLote"].Tag     = Global.Servicio.obtenerLote(itemRem.lote);
                Presentacion present;
                if (itemRem.idPresentacion != null)
                {
                    present = Global.Servicio.obtenerPresentacion((int)itemRem.idPresentacion);
                    dgvItems.Rows[i].Cells["clmPresent"].Value = "x " + present.litrosEnvase.ToString();
                    dgvItems.Rows[i].Cells["clmPresent"].Tag   = present;
                }
                else
                {
                    dgvItems.Rows[i].Cells["clmPresent"].Value = "";
                    dgvItems.Rows[i].Cells["clmPresent"].Tag   = null;
                }

                dgvItems.Rows[i].Cells["clmMon"].Value    = ((Moneda)((ComboBoxItem)cboMoneda.SelectedItem).Value).simbologia;
                dgvItems.Rows[i].Cells["clmPrecio"].Value = precioCalc;
                dgvItems.Rows[i].Cells["clmPrecio"].Tag   = itemRem.precio;
                dgvItems.Rows[i].Cells["clmImp"].Value    = (itemRem.cantidad * precioCalc);

                i++;
            }
        }
Ejemplo n.º 3
0
        protected override bool cargarBusqueda()
        {
            frmBusquedaPrecios frmBusquedaArticulo = new frmBusquedaPrecios();
            DialogResult       res = frmBusquedaArticulo.ShowDialog();

            lblUltimaModificacion.Text = "Última modificación: ";

            if (res == DialogResult.OK)
            {
                ArticuloPlanta          = frmBusquedaArticulo.articuloSeleccionado;
                txtPrecioInicial.Text   = ArticuloPlanta.precio.ToString();
                cboMoneda.SelectedIndex = cboMoneda.FindStringExact(ArticuloPlanta.Moneda.nombre);
                if (ArticuloPlanta.Planta.Cliente != null)
                {
                    cboCliente.SelectedIndex = cboCliente.FindStringExact(ArticuloPlanta.Planta.Cliente.razonSocial);
                }
                else
                {
                    Cargador.cargarPlantas(cboPlanta, "Sin especificar");
                    Cargador.cargarClientes(cboCliente, "Sin especificar");
                    cboCliente.SelectedIndex = 0;
                }

                cboPlanta.SelectedIndex    = cboPlanta.FindStringExact(ArticuloPlanta.Planta.nombre);
                cboArticulo.SelectedIndex  = cboArticulo.FindStringExact(ArticuloPlanta.TipoArticulo.nombre);
                txtNumero.Text             = ArticuloPlanta.Planta.codigo + ArticuloPlanta.contador.ToString();
                lblUltimaModificacion.Text = "Última modificación: " + ArticuloPlanta.fechaCambio.ToShortDateString() + " " + ArticuloPlanta.fechaCambio.ToShortTimeString();
                VistaEliminado(ArticuloPlanta.eliminado.HasValue);

                cboMoneda_SelectedIndexChanged(null, null);
                txtPrecioInicial_KeyUp(null, null);

                int i = 0;
                dgvPrecios.Rows.Clear();
                foreach (PreciosAdicionales pa in ArticuloPlanta.PreciosAdicionales)
                {
                    dgvPrecios.Rows.Add();
                    dgvPrecios.Rows[i].Cells["clmPresent"].Value = "x " + pa.Presentacion.litrosEnvase.ToString();
                    dgvPrecios.Rows[i].Cells["clmPresent"].Tag   = pa.Presentacion;
                    dgvPrecios.Rows[i].Cells["clmPrecio"].Value  = pa.precio.ToString("0.00");

                    i++;
                }

                CargarPreciosHist();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 4
0
        protected override void agregar()
        {
            ArticuloPlanta = new ArticuloPlanta();
            limpiarControles(gpbPrecios);
            dgvPrecios.Rows.Clear();
            dgvPreciosHist.Rows.Clear();
            gpbPrecios.Enabled       = true;
            dgvPrecios.Enabled       = true;
            cboMoneda.SelectedIndex  = 0;
            cboCliente.SelectedIndex = 0;
            Cargador.cargarPlantas(cboPlanta, "Sin especificar");
            cboPlanta.SelectedIndex = 0;
            cboCliente.Focus();

            VistaEliminado(false);
        }
Ejemplo n.º 5
0
        private void dgvItems_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
        {
            TextBox        celda  = e.Control as TextBox;
            ArticuloPlanta artPla = (ArticuloPlanta)dgvItems.Rows[dgvItems.CurrentCell.RowIndex].Tag;

            switch (dgvItems.CurrentCell.OwningColumn.Name)
            {
            case "clmArt":
                Cargador.cargarArticuloPlanta(celda, planta);
                break;

            case "clmDesc":
                Cargador.cargarArticulosDePlanta(celda, planta);
                break;

            case "clmLote":
                if (artPla != null)
                {
                    Cargador.cargarLotes(celda, artPla.TipoArticulo, 0);
                }
                break;

            case "clmPresent":
                Cargador.cargarPresentaciones(celda);
                break;

            case "clmPrecio":
                if (artPla != null)
                {
                    Cargador.cargarPrecios(celda, artPla);
                }
                break;

            default:
                var lista = new List <string>();
                AutoCompleteStringCollection listaAuto = new AutoCompleteStringCollection();
                listaAuto.AddRange(lista.ToArray());
                celda.AutoCompleteCustomSource = listaAuto;
                celda.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
                celda.AutoCompleteSource       = AutoCompleteSource.CustomSource;
                break;
            }
        }
Ejemplo n.º 6
0
        public static void cargarPrecios(TextBox celda, ArticuloPlanta artPla, string textoPrimerItem = "")
        {
            List <PreciosAdicionales>    precios     = new List <PreciosAdicionales>();
            AutoCompleteStringCollection descPrecios = new AutoCompleteStringCollection();

            precios.Add(new PreciosAdicionales {
                precio = artPla.precio
            });
            precios.AddRange(artPla.PreciosAdicionales);
            descPrecios.AddRange(precios.Select(p => p.precio.ToString("0.00")).ToArray());
            //precios.ForEach(p => descPrecios.Add)
            //foreach (PreciosAdicionales precio in precios)
            //{
            //    descPrecios.Add(precio.precio.ToString("0.00"));
            //}
            celda.AutoCompleteCustomSource = descPrecios;
            celda.AutoCompleteMode         = AutoCompleteMode.SuggestAppend;
            celda.AutoCompleteSource       = AutoCompleteSource.CustomSource;
        }
Ejemplo n.º 7
0
        protected override bool guardar()
        {
            try
            {
                if (cliente != null && planta != null)
                {
                    if (txtEnviarA.Text.Trim() == "")
                    {
                        Mensaje unMensaje = new Mensaje("Debe ingresar una dirección de envío", Mensaje.TipoMensaje.Error, Mensaje.Botones.OK);
                        unMensaje.ShowDialog();
                        return(false);
                    }

                    if (Estado == Estados.Agregar)
                    {
                        remito = new Comprobante_Remito();
                    }

                    if (txtNroRemito.Text != "")
                    {
                        remito.numero = long.Parse(txtNroRemito.Text);
                    }
                    else
                    {
                        remito.numero = 0;
                    }

                    remito.Moneda       = (Moneda)((ComboBoxItem)cboMoneda.SelectedItem).Value;
                    remito.Planta       = planta;
                    remito.observacion  = txtObs.Text;
                    remito.anulado      = false;
                    remito.tipo         = cboTipoRem.Text;
                    remito.fechaIngreso = dtpFecha.Value;
                    remito.ordenCompra  = txtOrdenCompra.Text;
                    remito.idUnidad     = ((Unidad)((ComboBoxItem)cboUnidad.SelectedItem).Value).id;
                    remito.importe      = 0;
                    remito.facturable   = !chkNF.Checked;

                    remito.VentaArticuloPlanta.Clear();

                    foreach (DataGridViewRow fila in dgvItems.Rows)
                    {
                        if (!fila.IsNewRow)
                        {
                            ArticuloPlanta      artPla = (ArticuloPlanta)fila.Tag;
                            VentaArticuloPlanta venta  = new VentaArticuloPlanta();
                            if (artPla != null)
                            {
                                remito.importe    += decimal.Parse(fila.Cells["clmImp"].Value.ToString());
                                venta.TipoArticulo = artPla.TipoArticulo;
                                venta.Moneda       = artPla.Moneda;
                                decimal precio;
                                if (fila.Cells["clmPrecio"].Tag != null)
                                {
                                    precio = (decimal)fila.Cells["clmPrecio"].Tag;
                                }
                                else
                                {
                                    precio = artPla.precio;
                                }

                                venta.precio     = precio;
                                venta.cotizacion = artPla.Moneda.cotizacion;
                                venta.cantidad   = decimal.Parse(fila.Cells["clmCant"].FormattedValue.ToString());
                                venta.lote       = fila.Cells["clmLote"].FormattedValue.ToString();
                                Presentacion present = (Presentacion)fila.Cells["clmPresent"].Tag;
                                if (present != null)
                                {
                                    venta.idPresentacion = present.id;
                                }
                                remito.VentaArticuloPlanta.Add(venta);

                                //genera salidas de los productos remitados
                                Salida salida = new Salida();
                                salida.idCliente = planta.idCliente;
                                salida.fecha     = remito.fechaIngreso;
                                salida.cantidad  = venta.cantidad;
                                //si ingresó lote
                                if (fila.Cells["clmLote"].Tag != null)
                                {
                                    salida.Lote = (Lote)fila.Cells["clmLote"].Tag;
                                }
                                else
                                {
                                    salida.Lote = Global.Servicio.obtenerLoteProductoFinal(artPla.TipoArticulo, Global.DatosSesion);
                                }
                                //si ingresó presentación
                                if (fila.Cells["clmPresent"].Tag != null)
                                {
                                    salida.idPresentacion = ((Presentacion)fila.Cells["clmPresent"].Tag).id;
                                }

                                venta.Salida.Add(salida);           //para que se grabe en el add del remito
                                salida.VentaArticuloPlanta = venta; //para que lo hereden las salidas hijas en el cálculo
                                Global.Servicio.ObtenerSalidasMateriasPrimas(salida, Global.DatosSesion);
                            }
                        }
                    }

                    if (txtPeso.Text.Trim() == "")
                    {
                        DialogResult pregunta = MessageBox.Show("¿Está seguro que desea dejar la cantidad medida en 0?", "Atención", MessageBoxButtons.YesNo);
                        if (pregunta == DialogResult.Yes)
                        {
                            remito.pesoTotalKg = 0;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        remito.pesoTotalKg = decimal.Parse(txtPeso.Text);
                    }

                    if (txtCantBultos.Text.Trim() == "")
                    {
                        DialogResult pregunta = MessageBox.Show("¿Está seguro que desea dejar la cantidad de bultos en 0?", "Atención", MessageBoxButtons.YesNo);
                        if (pregunta == DialogResult.Yes)
                        {
                            remito.cantidadBultos = 0;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        remito.cantidadBultos = int.Parse(txtCantBultos.Text);
                    }

                    if (Estado == Estados.Agregar)
                    {
                        Global.Servicio.agregarRemito(remito, Global.DatosSesion);
                    }
                    else
                    {
                        Global.Servicio.actualizarRemito(remito, Global.DatosSesion);
                    }

                    Mensaje msj = new Mensaje("Remito guardado con éxito", Mensaje.TipoMensaje.Exito, Mensaje.Botones.OK);
                    msj.ShowDialog();

                    if (Estado == Estados.Agregar)
                    {
                        Global.Servicio.imprimirRemito(remito, txtEnviarA.Text, chkImprimirPrecios.Checked);
                        Global.Servicio.imprimirRemito(remito, txtEnviarA.Text, chkImprimirPrecios.Checked);
                        Global.Servicio.imprimirRemito(remito, txtEnviarA.Text, chkImprimirPrecios.Checked);

                        Global.Servicio.imprimirRemitoDigital(remito, txtEnviarA.Text, chkImprimirPrecios.Checked);
                    }

                    return(true);
                }
                else
                {
                    Mensaje unMensaje = new Mensaje("Debe seleccionar un cliente y una planta.", Mensaje.TipoMensaje.Error, Mensaje.Botones.OK);
                    unMensaje.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                Mensaje unMensaje = new Mensaje(ex.Message, Mensaje.TipoMensaje.Error, Mensaje.Botones.OK);
                unMensaje.ShowDialog();
                return(false);
            }
            return(false);
        }
Ejemplo n.º 8
0
        private void dgvItems_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            if (dgvItems.EditingControl == null)
            {
                return;
            }

            if (dgvItems[e.ColumnIndex, e.RowIndex].OwningColumn.Name == "clmArt")
            {
                ArticuloPlanta artPla = Global.Servicio.BuscarUnArticuloPlanta(dgvItems.EditingControl.Text);
                if (artPla != null)
                {
                    dgvItems.Rows[e.RowIndex].Tag = artPla;
                    dgvItems.EditingControl.Text  = artPla.Planta.codigo.Trim() + artPla.contador.ToString().Trim();
                    dgvItems[dgvItems.Columns["clmDesc"].Index, e.RowIndex].Value   = artPla.TipoArticulo.nombre;
                    dgvItems[dgvItems.Columns["clmUnidad"].Index, e.RowIndex].Value = artPla.TipoArticulo.Unidad.abreviatura;
                    dgvItems[dgvItems.Columns["clmMon"].Index, e.RowIndex].Value    = ((Moneda)((ComboBoxItem)cboMoneda.SelectedItem).Value).simbologia;
                    dgvItems[dgvItems.Columns["clmPrecio"].Index, e.RowIndex].Value = Global.Servicio.ConviertePrecio(artPla.precio, artPla.Moneda, (Moneda)((ComboBoxItem)cboMoneda.SelectedItem).Value);
                    dgvItems.Rows[e.RowIndex].Cells["clmPrecio"].Tag = null;

                    if (dgvItems[dgvItems.Columns["clmDesc"].Index, e.RowIndex].FormattedValue != "")
                    {
                        calcularImportes(decimal.Parse(dgvItems[dgvItems.Columns["clmCant"].Index, e.RowIndex].FormattedValue.ToString()), decimal.Parse(dgvItems[dgvItems.Columns["clmPrecio"].Index, e.RowIndex].Value.ToString()), e.RowIndex);
                    }
                    calcularPeso();
                }
                else
                {
                    dgvItems.Rows[e.RowIndex].Tag = null;
                    dgvItems[dgvItems.Columns["clmDesc"].Index, e.RowIndex].Value   = "";
                    dgvItems[dgvItems.Columns["clmCant"].Index, e.RowIndex].Value   = "0";
                    dgvItems[dgvItems.Columns["clmUnidad"].Index, e.RowIndex].Value = "";
                    dgvItems[dgvItems.Columns["clmMon"].Index, e.RowIndex].Value    = "";
                    dgvItems[dgvItems.Columns["clmPrecio"].Index, e.RowIndex].Value = "";
                    dgvItems[dgvItems.Columns["clmImp"].Index, e.RowIndex].Value    = "0";
                    calcularImportes(0, 0, e.RowIndex);
                    calcularPeso();
                }
            }

            if (dgvItems[e.ColumnIndex, e.RowIndex].OwningColumn.Name == "clmDesc")
            {
                ArticuloPlanta artPla = Global.Servicio.BuscarUnArticuloPlantaXDesc(planta, dgvItems.EditingControl.Text);
                if (artPla != null)
                {
                    dgvItems.Rows[e.RowIndex].Tag = artPla;
                    dgvItems[dgvItems.Columns["clmArt"].Index, e.RowIndex].Value = artPla.Planta.codigo.Trim() + artPla.contador.ToString().Trim();
                    dgvItems.EditingControl.Text = artPla.TipoArticulo.nombre;
                    dgvItems[dgvItems.Columns["clmUnidad"].Index, e.RowIndex].Value = artPla.TipoArticulo.Unidad.abreviatura;
                    dgvItems[dgvItems.Columns["clmMon"].Index, e.RowIndex].Value    = ((Moneda)((ComboBoxItem)cboMoneda.SelectedItem).Value).simbologia;
                    dgvItems[dgvItems.Columns["clmPrecio"].Index, e.RowIndex].Value = Global.Servicio.ConviertePrecio(artPla.precio, artPla.Moneda, (Moneda)((ComboBoxItem)cboMoneda.SelectedItem).Value);
                    dgvItems.Rows[e.RowIndex].Cells["clmPrecio"].Tag = null;

                    calcularPeso();
                    if (dgvItems[dgvItems.Columns["clmArt"].Index, e.RowIndex].FormattedValue != "")
                    {
                        calcularImportes(decimal.Parse(dgvItems[dgvItems.Columns["clmCant"].Index, e.RowIndex].FormattedValue.ToString()), decimal.Parse(dgvItems[dgvItems.Columns["clmPrecio"].Index, e.RowIndex].Value.ToString()), e.RowIndex);
                    }
                }
                else
                {
                    dgvItems.Rows[e.RowIndex].Tag = null;
                    dgvItems[dgvItems.Columns["clmArt"].Index, e.RowIndex].Value    = "";
                    dgvItems[dgvItems.Columns["clmCant"].Index, e.RowIndex].Value   = "0";
                    dgvItems[dgvItems.Columns["clmUnidad"].Index, e.RowIndex].Value = "";
                    dgvItems[dgvItems.Columns["clmMon"].Index, e.RowIndex].Value    = "";
                    dgvItems[dgvItems.Columns["clmPrecio"].Index, e.RowIndex].Value = "";
                    dgvItems[dgvItems.Columns["clmImp"].Index, e.RowIndex].Value    = "0";
                    calcularImportes(0, 0, e.RowIndex);
                    calcularPeso();
                }
            }

            if (dgvItems[e.ColumnIndex, e.RowIndex].OwningColumn.Name == "clmCant")
            {
                decimal val;
                if (decimal.TryParse(dgvItems.EditingControl.Text, out val))
                {
                    if (dgvItems[dgvItems.Columns["clmPrecio"].Index, e.RowIndex].FormattedValue != "")
                    {
                        calcularImportes(val, decimal.Parse(dgvItems[dgvItems.Columns["clmPrecio"].Index, e.RowIndex].Value.ToString()), e.RowIndex);
                        calcularPeso();
                    }
                }
                else
                {
                    dgvItems.EditingControl.Text = "0";
                    calcularImportes(0, 0, e.RowIndex);
                }
            }

            if (dgvItems[e.ColumnIndex, e.RowIndex].OwningColumn.Name == "clmLote")
            {
                Lote lote = Global.Servicio.obtenerLote(dgvItems.EditingControl.Text);
                dgvItems[e.ColumnIndex, e.RowIndex].Tag = lote;
                if (lote == null)
                {
                    dgvItems.EditingControl.Text = "";
                }
            }

            if (dgvItems[e.ColumnIndex, e.RowIndex].OwningColumn.Name == "clmPresent")
            {
                string[] textoCelda = dgvItems.EditingControl.Text.Split(new string[] { "x " }, StringSplitOptions.None);
                int      litros     = 0;
                if (textoCelda.Count() == 2)
                {
                    int.TryParse(textoCelda[1], out litros);
                }

                if (litros != 0)
                {
                    Presentacion present = Global.Servicio.obtenerPresentacionPorLitros(litros);
                    if (present != null)
                    {
                        dgvItems[e.ColumnIndex, e.RowIndex].Tag = present;
                        ArticuloPlanta artPla = (ArticuloPlanta)dgvItems.Rows[e.RowIndex].Tag;
                        if (artPla != null)
                        {
                            PreciosAdicionales precio = artPla.PreciosAdicionales.Where(p => p.idPresentacion == present.id).SingleOrDefault();
                            if (precio != null)
                            {
                                dgvItems.Rows[e.RowIndex].Cells["clmPrecio"].Tag   = precio.precio;
                                dgvItems.Rows[e.RowIndex].Cells["clmPrecio"].Value = precio.precio.ToString("0.00");
                                calcularImportes(decimal.Parse(dgvItems[dgvItems.Columns["clmCant"].Index, e.RowIndex].FormattedValue.ToString()), decimal.Parse(dgvItems[dgvItems.Columns["clmPrecio"].Index, e.RowIndex].Value.ToString()), e.RowIndex);
                            }
                        }
                    }
                    else
                    {
                        dgvItems[e.ColumnIndex, e.RowIndex].Tag = null;
                        dgvItems.EditingControl.Text            = "";
                    }
                }
                else
                {
                    dgvItems[e.ColumnIndex, e.RowIndex].Tag = null;
                    dgvItems.EditingControl.Text            = "";
                }
            }

            if (dgvItems[e.ColumnIndex, e.RowIndex].OwningColumn.Name == "clmPrecio")
            {
                ArticuloPlanta artPla = (ArticuloPlanta)dgvItems.Rows[e.RowIndex].Tag;
                if (artPla != null)
                {
                    decimal val;
                    if (decimal.TryParse(dgvItems.EditingControl.Text, out val))
                    {
                        var precios = artPla.PreciosAdicionales.Select(p => p.precio).ToList();
                        precios.Add(artPla.precio);
                        if (precios.Contains(val))
                        {
                            dgvItems.Rows[e.RowIndex].Cells["clmPrecio"].Tag = val;
                            calcularImportes(decimal.Parse(dgvItems[dgvItems.Columns["clmCant"].Index, e.RowIndex].FormattedValue.ToString()), decimal.Parse(dgvItems.EditingControl.Text), e.RowIndex);

                            var present = artPla.PreciosAdicionales.Where(p => p.precio.ToString("0.00") == val.ToString("0.00")).SingleOrDefault();
                            if (present != null)
                            {
                                dgvItems.Rows[e.RowIndex].Cells["clmPresent"].Tag   = present.Presentacion;
                                dgvItems.Rows[e.RowIndex].Cells["clmPresent"].Value = "x " + present.Presentacion.litrosEnvase.ToString();
                            }
                        }
                        else
                        {
                            dgvItems.Rows[e.RowIndex].Cells["clmPrecio"].Tag = 0;
                            dgvItems.EditingControl.Text = "0.00";
                            calcularImportes(0, 0, e.RowIndex);
                        }
                    }
                    else
                    {
                        dgvItems.Rows[e.RowIndex].Cells["clmPrecio"].Tag = 0;
                        dgvItems.EditingControl.Text = "0.00";
                        calcularImportes(0, 0, e.RowIndex);
                    }
                }
                else
                {
                    dgvItems.Rows[e.RowIndex].Cells["clmPrecio"].Tag = null;
                    dgvItems.EditingControl.Text = "";
                }
            }
        }
Ejemplo n.º 9
0
        protected override bool guardar()
        {
            if (cboPlanta.Text.ToLower() == "sin especificar" || cboPlanta.SelectedItem == null)
            {
                Mensaje mensaje = new Mensaje("Seleccione una planta", Mensaje.TipoMensaje.Error, Mensaje.Botones.OK);
                mensaje.ShowDialog();
                return(false);
            }
            if (cboArticulo.Text.ToLower() == "sin especificar" || cboArticulo.SelectedItem == null)
            {
                Mensaje mensaje = new Mensaje("Seleccione un artículo", Mensaje.TipoMensaje.Error, Mensaje.Botones.OK);
                mensaje.ShowDialog();
                return(false);
            }

            ArticuloPlantaHistorico aph = new ArticuloPlantaHistorico();

            if (Estado == Estados.Modificar)
            {
                aph.ArticuloPlanta = ArticuloPlanta;
                aph.idMoneda       = ArticuloPlanta.idMoneda;
                aph.precio         = ArticuloPlanta.precio;
                aph.fechaCambio    = ArticuloPlanta.fechaCambio;
            }

            ArticuloPlanta.idArticulo  = cboArticulo.SelectedItem != null ? ((TipoArticulo)((ComboBoxItem)cboArticulo.SelectedItem).Value).id : -1;
            ArticuloPlanta.idPlanta    = cboPlanta.SelectedItem != null ? ((Planta)((ComboBoxItem)cboPlanta.SelectedItem).Value).id : -1;
            ArticuloPlanta.idMoneda    = cboMoneda.SelectedItem != null ? ((Moneda)((ComboBoxItem)cboMoneda.SelectedItem).Value).id : -1;
            ArticuloPlanta.precio      = decimal.Parse(txtPrecioInicial.Text);
            ArticuloPlanta.fechaCambio = DateTime.Now;

            try
            {
                string cadenaMensaje = "";

                //Guarda los precios adicionales
                ArticuloPlanta.PreciosAdicionales.Clear();
                foreach (DataGridViewRow fila in dgvPrecios.Rows)
                {
                    if (!fila.IsNewRow)
                    {
                        Presentacion       present         = (Presentacion)fila.Cells["clmPresent"].Tag;
                        PreciosAdicionales precioAdicional = new PreciosAdicionales();
                        if (present != null)
                        {
                            precioAdicional.Presentacion = present;
                            precioAdicional.precio       = decimal.Parse(fila.Cells["clmPrecio"].FormattedValue.ToString());
                            ArticuloPlanta.PreciosAdicionales.Add(precioAdicional);
                        }
                    }
                }

                // Guardamos los datos del ArticuloPlanta
                if (Estado == Estados.Agregar)
                {
                    ArticuloPlanta = Global.Servicio.AgregarArticuloPlanta(ArticuloPlanta, Global.DatosSesion);
                    cadenaMensaje  = "Precio dado de Alta exitosamente.";
                }
                else
                {
                    Global.Servicio.ActualizarArticuloPlanta(ArticuloPlanta, aph, Global.DatosSesion);
                    cadenaMensaje = "Precio Modificado con éxito.";
                }

                lblUltimaModificacion.Text = "Última modificación: " + DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString();
                CargarPreciosHist();

                // Mostramos mensaje de éxito
                Mensaje mensaje = new Mensaje(cadenaMensaje, Mensaje.TipoMensaje.Exito, Mensaje.Botones.OK);
                mensaje.ShowDialog();
                // Indica que el ArticuloPlanta se guardó correctamente
                return(true);
            }
            catch (Exception ex)
            {
                Mensaje unMensaje;

                if (ex.Message.Contains("key")) //Ver si la excepcion es del tipo System.InvalidOperationException
                {
                    unMensaje = new Mensaje("No es posible cambiar la Planta o el Artículo a una relación ya cargada.", Mensaje.TipoMensaje.Error, Mensaje.Botones.OK);
                    unMensaje.ShowDialog();
                }
                else
                {
                    unMensaje = new Mensaje(ex.Message, Mensaje.TipoMensaje.Error, Mensaje.Botones.OK);
                    unMensaje.ShowDialog();
                }
            }

            return(false);
        }