Exemple #1
0
        private void CargarProductos()
        {
            long idEmpresa = ((Empresa)cmbEmpresa.SelectedItem).idEmpresa.Value;

            dtpFechaHasta_CloseUp(null, null);
            _BindingListtbProducto.Clear();
            ((Modelo)cmbModelo.SelectedItem).tbProducto.Where(x => x.estadoRegistro).ToList().ForEach(x =>
            {
                x.seleccionado      = false;
                x.producto          = x.idProducto.ToString() + " - " + x.descripcion;
                x.idIndiceComercial = 0;
                x.indiceComercial   = 0;
                x.idCosto           = 0;
                x.costo             = 0;
                x.fechaHasta        = new DateTime(2020, 12, 31);
                x.idProcesarPrecio  = 0;
                tbIndiceComercial _tbIndiceComercial = edmCosolemFunctions.getIndiceComercial(idEmpresa, x.idProducto);
                if (_tbIndiceComercial != null)
                {
                    x.idIndiceComercial = _tbIndiceComercial.idIndiceComercial;
                    x.indiceComercial   = _tbIndiceComercial.indiceComercial;
                }
                tbIndiceFinanciero _tbIndiceFinanciero = edmCosolemFunctions.getIndiceFinanciero(idEmpresa, x.idProducto);
                if (_tbIndiceFinanciero != null)
                {
                    x.idIndiceFinanciero = _tbIndiceFinanciero.idIndiceFinanciero;
                    x.indiceFinanciero   = _tbIndiceFinanciero.indiceFinanciero;
                }
                tbIndiceInformativo _tbIndiceInformativo = edmCosolemFunctions.getIndiceInformativo(idEmpresa, x.idProducto);
                if (_tbIndiceInformativo != null)
                {
                    x.idIndiceInformativo = _tbIndiceInformativo.idIndiceInformativo;
                    x.indiceInformativo   = _tbIndiceInformativo.indiceInformativo;
                }
                tbCosto _tbCosto = edmCosolemFunctions.getCosto(idEmpresa, x.idProducto);
                if (_tbCosto != null)
                {
                    x.idCosto    = _tbCosto.idCosto;
                    x.costo      = _tbCosto.costo;
                    x.fechaHasta = _tbCosto.fechaHasta;
                }
                tbProcesarPrecio _tbProcesarPrecio = edmCosolemFunctions.getProcesarPrecio(idEmpresa, x.idProducto);
                if (_tbProcesarPrecio != null)
                {
                    x.idProcesarPrecio = _tbProcesarPrecio.idProcesarPrecio;
                }
                _BindingListtbProducto.Add(x);
            });
        }
Exemple #2
0
        private void tsbGrabar_Click(object sender, EventArgs e)
        {
            try
            {
                dgvProductos_CellEndEdit(null, null);

                long idEmpresa = ((Empresa)cmbEmpresa.SelectedItem).idEmpresa.Value;

                string mensaje = String.Empty;
                if (idEmpresa == 0)
                {
                    mensaje += "Seleccione empresa\n";
                }
                if (((Marca)cmbMarca.SelectedItem).idMarca == 0)
                {
                    mensaje += "Seleccione marca\n";
                }
                if (((Linea)cmbLinea.SelectedItem).idLinea == 0)
                {
                    mensaje += "Seleccione línea\n";
                }
                if (((Grupo)cmbGrupo.SelectedItem).idGrupo == 0)
                {
                    mensaje += "Seleccione grupo\n";
                }
                if (((SubGrupo)cmbSubGrupo.SelectedItem).idSubGrupo == 0)
                {
                    mensaje += "Seleccione subgrupo\n";
                }
                if (((Modelo)cmbModelo.SelectedItem).idModelo == 0)
                {
                    mensaje += "Seleccione modelo\n";
                }
                if (_BindingListtbProducto.Count == 0)
                {
                    mensaje += "Ingrese al menos 1 producto\n";
                }
                if (_BindingListtbProducto.Where(x => x.fechaHasta.Date < Program.fechaHora.Date).Any())
                {
                    mensaje += "Costo con fecha de vigencia menor a la fecha actual\n";
                }

                if (String.IsNullOrEmpty(mensaje.Trim()))
                {
                    _BindingListtbProducto.ToList().ForEach(x =>
                    {
                        tbCosto _tbCosto = (from C in _dbCosolemEntities.tbCosto where C.idCosto == x.idCosto select C).FirstOrDefault();
                        if (_tbCosto == null)
                        {
                            _tbCosto                  = new tbCosto();
                            _tbCosto.idEmpresa        = idEmpresa;
                            _tbCosto.idProducto       = x.idProducto;
                            _tbCosto.costo            = x.costo;
                            _tbCosto.fechaDesde       = Program.fechaHora.Date;
                            _tbCosto.fechaHasta       = x.fechaHasta.Date;
                            _tbCosto.estadoRegistro   = true;
                            _tbCosto.fechaHoraIngreso = Program.fechaHora;
                            _tbCosto.idUsuarioIngreso = idUsuario;
                            _tbCosto.terminalIngreso  = Program.terminal;
                            _dbCosolemEntities.tbCosto.AddObject(_tbCosto);
                        }
                        else
                        {
                            _tbCosto.costo = x.costo;
                            _tbCosto.fechaHoraUltimaModificacion = Program.fechaHora;
                            _tbCosto.idUsuarioUltimaModificacion = idUsuario;
                            _tbCosto.terminalUltimaModificacion  = Program.terminal;
                        }
                        if (x.indiceComercial > 0 && x.indiceFinanciero > 0 && x.indiceInformativo > 0 && x.costo > 0)
                        {
                            tbProcesarPrecio _tbProcesarPrecio = (from PP in _dbCosolemEntities.tbProcesarPrecio where PP.idProcesarPrecio == x.idProcesarPrecio select PP).FirstOrDefault();
                            if (_tbProcesarPrecio == null)
                            {
                                _tbProcesarPrecio                  = new tbProcesarPrecio();
                                _tbProcesarPrecio.idEmpresa        = idEmpresa;
                                _tbProcesarPrecio.idProducto       = x.idProducto;
                                _tbProcesarPrecio.procesarPrecio   = true;
                                _tbProcesarPrecio.estadoRegistro   = true;
                                _tbProcesarPrecio.fechaHoraIngreso = Program.fechaHora;
                                _tbProcesarPrecio.idUsuarioIngreso = idUsuario;
                                _tbProcesarPrecio.terminalIngreso  = Program.terminal;
                                _dbCosolemEntities.tbProcesarPrecio.AddObject(_tbProcesarPrecio);
                            }
                            else
                            {
                                _tbProcesarPrecio.fechaHoraUltimaModificacion = Program.fechaHora;
                                _tbProcesarPrecio.idUsuarioUltimaModificacion = idUsuario;
                                _tbProcesarPrecio.terminalUltimaModificacion  = Program.terminal;
                            }
                        }
                    });
                    _dbCosolemEntities.SaveChanges();

                    MessageBox.Show("Registro grabado satisfactoriamente", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    frmCostos_Load(null, null);
                }
                else
                {
                    MessageBox.Show(mensaje, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                Util.MostrarException(this.Text, ex);
            }
        }
Exemple #3
0
        private void tsbProcesar_Click(object sender, EventArgs e)
        {
            try
            {
                dgvProcesarPrecios_CellEndEdit(null, null);
                List <tbProcesarPrecio> _ListtbProcesarPrecio = ((List <tbProcesarPrecio>)dgvProcesarPrecios.DataSource).Where(x => x.seleccionado).ToList();

                string mensaje = String.Empty;

                if (_ListtbProcesarPrecio.Count == 0)
                {
                    mensaje += "Seleccione al menos 1 precio para proceder a procesarlo\n";
                }
                if (_ListtbProcesarPrecio.Where(x => x.costo <= 0 || x.indiceComercial <= 0 || x.indiceFinanciero <= 0 || x.indiceInformativo <= 0).Any())
                {
                    mensaje += "Hay productos seleccionados con costo, índice comercial, índice financiero o índice informativo menor o igual que 0, favor verificar\n";
                }


                if (String.IsNullOrEmpty(mensaje.Trim()))
                {
                    _ListtbProcesarPrecio.ForEach(x =>
                    {
                        tbProcesarPrecio _tbProcesarPrecio = (from PP in _dbCosolemEntities.tbProcesarPrecio where PP.idProcesarPrecio == x.idProcesarPrecio select PP).FirstOrDefault();
                        if (_tbProcesarPrecio != null)
                        {
                            _tbProcesarPrecio.procesarPrecio = false;
                            _tbProcesarPrecio.estadoRegistro = false;
                            _tbProcesarPrecio.fechaHoraUltimaModificacion = Program.fechaHora;
                            _tbProcesarPrecio.idUsuarioUltimaModificacion = idUsuario;
                            _tbProcesarPrecio.terminalUltimaModificacion  = Program.terminal;
                        }
                        _dbCosolemEntities.tbPrecio.Where(y => y.idEmpresa == idEmpresa && y.idProducto == x.idProducto && y.estadoRegistro).ToList().ForEach(z =>
                        {
                            z.estadoRegistro = false;
                            z.fechaHoraUltimaModificacion = Program.fechaHora;
                            z.idUsuarioUltimaModificacion = idUsuario;
                            z.terminalUltimaModificacion  = Program.terminal;
                            z.fechaHoraEliminacion        = Program.fechaHora;
                            z.idUsuarioEliminacion        = idUsuario;
                            z.terminalEliminacion         = Program.terminal;
                        });
                        tbPrecio _tbPrecio           = new tbPrecio();
                        _tbPrecio.idEmpresa          = idEmpresa;
                        _tbPrecio.idProducto         = x.idProducto;
                        _tbPrecio.costo              = x.costo;
                        _tbPrecio.precioOferta       = _tbPrecio.costo * x.indiceComercial;
                        _tbPrecio.precioVentaPublico = _tbPrecio.precioOferta * x.indiceFinanciero;
                        _tbPrecio.precioInformativo  = _tbPrecio.precioVentaPublico * x.indiceInformativo;
                        _tbPrecio.estadoRegistro     = true;
                        _tbPrecio.fechaHoraIngreso   = Program.fechaHora;
                        _tbPrecio.idUsuarioIngreso   = idUsuario;
                        _tbPrecio.terminalIngreso    = Program.terminal;
                        _dbCosolemEntities.tbPrecio.AddObject(_tbPrecio);
                    });
                    _dbCosolemEntities.SaveChanges();

                    MessageBox.Show("Registro grabado satisfactoriamente", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    frmPrecios_Load(null, null);
                }
                else
                {
                    MessageBox.Show(mensaje, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            catch (Exception ex)
            {
                Util.MostrarException(this.Text, ex);
            }
        }