Beispiel #1
0
        private void LblBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validations

                var exceptionMessage = string.Empty;

                if (TypesHelper.IsEmpty(TxtDescripcion.Text))
                {
                    exceptionMessage = "No se puede realizar la busqueda ya que no se informó ningún filtro";
                }

                if (!TypesHelper.IsEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }

                #endregion

                List <Rol> roles = null;

                if (ChkExacta.Checked)
                {
                    //Se va a realizar una busqueda exacta (=)
                    var rol = RolPersistance.GetByName(TxtDescripcion.Text);
                    if (rol != null)
                    {
                        roles = _roles = new List <Rol> {
                            rol
                        }
                    }
                    ;
                }
                else
                {
                    //Se va a realizar una busqueda inexacta (LIKE)
                    roles = _roles = RolPersistance.GetByNameLike(TxtDescripcion.Text);
                }

                if (roles == null || roles.Count == 0)
                {
                    throw new Exception("No se encontraron roles según los filtros informados.");
                }

                //Recargo los valores de la grilla a partir de los resultados obtenidos en la busqueda
                RefreshSources(roles);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atención");
            }
        }
        private void LblBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validations

                var filtersSetted    = false;
                var exceptionMessage = string.Empty;

                if (!TypesHelper.IsEmpty(TxtDescripcion.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(TxtStock.Text))
                {
                    filtersSetted = true;
                    if (!TypesHelper.IsNumeric(TxtStock.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El stock de la publicacion debe ser numérico.";
                    }
                }

                if (!TypesHelper.IsEmpty(TxtPrecio.Text))
                {
                    filtersSetted = true;
                    if (!TypesHelper.IsDecimal(TxtPrecio.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El precio de la publicacion debe ser decimal (o numérico).";
                    }
                }

                if (!TypesHelper.IsEmpty(CboEstadoPublicacion.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(CboVisibilidad.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(CboTipoPublicacion.Text))
                {
                    filtersSetted = true;
                }

                if (!filtersSetted)
                {
                    exceptionMessage = "No se puede realizar la busqueda ya que no se informó ningún filtro";
                }

                if (!TypesHelper.IsEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }

                #endregion

                //Armo el objeto que representa a los filtros
                var filters = new PublicacionFilters
                {
                    IdUsuario           = SessionManager.CurrentUser.ID,
                    Descripcion         = (!TypesHelper.IsEmpty(TxtDescripcion.Text)) ? TxtDescripcion.Text : null,
                    Stock               = (!TypesHelper.IsEmpty(TxtStock.Text) && ChkBusquedaExacta.Checked) ? Convert.ToInt32(TxtStock.Text) : (int?)null,
                    Precio              = (!TypesHelper.IsEmpty(TxtPrecio.Text) && ChkBusquedaExacta.Checked) ? Convert.ToDouble(TxtPrecio.Text) : (double?)null,
                    IdEstadoPublicacion = (ChkBusquedaExacta.Checked) ? ((EstadoPublicacion)CboEstadoPublicacion.SelectedItem).ID : (int?)null,
                    IdVisibilidad       = (ChkBusquedaExacta.Checked) ? ((Visibilidad)CboVisibilidad.SelectedItem).ID : (int?)null,
                    IdTipoPublicacion   = (ChkBusquedaExacta.Checked) ? ((TipoPublicacion)CboTipoPublicacion.SelectedItem).ID : (int?)null
                };

                //Obtengo las publicaciones que cumplen con la busqueda
                var publications = (ChkBusquedaExacta.Checked) ? PublicacionPersistance.GetAllByParameters(filters) : PublicacionPersistance.GetAllByParametersLike(filters);

                if (publications == null || publications.Count == 0)
                {
                    throw new Exception("No se encontraron publicaciones según los filtros informados.");
                }

                //Cargo el resultado en la grilla
                RefreshSources(publications);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atención");
            }
        }
Beispiel #3
0
        private void LblFiltrar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validaciones

                var filtersSetted    = false;
                var exceptionMessage = string.Empty;

                if (!TypesHelper.IsEmpty(CboAño.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(CboTrimestre.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(CboListado.Text))
                {
                    filtersSetted = true;
                }

                if ((int)CboListado.SelectedValue == 1 && !TypesHelper.IsEmpty(CboVisibilidad.Text))
                {
                    filtersSetted = true;
                }

                if (!filtersSetted)
                {
                    exceptionMessage = "No se puede obtener el listado estadístico. Verifique que haya ingresado los filtros correctamente.";
                }

                if (!TypesHelper.IsEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }

                #endregion

                var monthDesde = "";
                var dayHasta   = "";
                var monthHasta = "";

                //Si es la primera estadística, puede que esté filtrada por mes, si está en 00, filtro por trimestre
                if ((string)cboMes.SelectedValue == "00" || (int)CboListado.SelectedValue != 1)
                {
                    switch ((int)CboTrimestre.SelectedValue)
                    {
                    case 1: monthDesde = "01"; monthHasta = "03"; break;

                    case 2: monthDesde = "04"; monthHasta = "06"; break;

                    case 3: monthDesde = "07"; monthHasta = "09"; break;

                    case 4: monthDesde = "10"; monthHasta = "12"; break;
                    }
                }
                else
                {
                    monthDesde = monthHasta = (string)cboMes.SelectedValue;
                }

                switch (monthHasta)
                {
                case "01":
                case "03":
                case "05":
                case "07":
                case "08":
                case "10":
                case "12": dayHasta = "31"; break;

                case "04":
                case "06":
                case "09":
                case "11": dayHasta = "30"; break;

                case "02": dayHasta = "28"; break;
                }

                var fechaDesde = DateTime.Parse("01/" + monthDesde + "/" + CboAño.SelectedValue.ToString());
                var fechaHasta = DateTime.Parse(dayHasta + "/" + monthHasta + "/" + CboAño.SelectedValue.ToString());

                //Creo los filtros con los que se ejecuta la consulta.
                var filters = new EstadisticaFilters
                {
                    FechaDesde  = fechaDesde,
                    FechaHasta  = fechaHasta,
                    Visibilidad = (!TypesHelper.IsEmpty(CboVisibilidad.Text) && (int)CboVisibilidad.SelectedValue != 0) ? (int)CboVisibilidad.SelectedValue : (int?)null
                };

                var listado = new List <Estadistica>();
                switch ((int)CboListado.SelectedValue)
                {
                case 1:
                    listado = EstadisticaPersistance.GetSellersWithMoreProductsNotSold(filters);
                    break;

                case 2:
                    listado = EstadisticaPersistance.GetSellersWithMoreBilling(filters);
                    break;

                case 3:
                    listado = EstadisticaPersistance.GetSellersWithBetterQualifications(filters);
                    break;

                case 4:
                    listado = EstadisticaPersistance.GetClientsWithMoreNotQualifiedPublications(filters);
                    break;
                }

                if (listado == null || listado.Count == 0)
                {
                    throw new Exception("No se encontraron estadísticas según los filtros informados.");
                }

                LoadGrid(listado);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atención");
                ClearDataGridView();
            }
        }
Beispiel #4
0
        private void LblBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validations

                var filtersSetted    = false;
                var exceptionMessage = string.Empty;

                if (!TypesHelper.IsEmpty(txtCodigo.Text))
                {
                    filtersSetted = true;
                    if (!TypesHelper.IsNumeric(txtCodigo.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El código debe ser numérico.";
                    }
                }
                if (!TypesHelper.IsEmpty(txtDesc.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(txtPrecio.Text))
                {
                    filtersSetted = true;
                    if (!TypesHelper.IsDecimal(txtPrecio.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El precio de la publicacion ser decimal (o numérico).";
                    }
                }

                if (!TypesHelper.IsEmpty(txtFecha.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(txtCantidad.Text))
                {
                    filtersSetted = true;
                    if (!TypesHelper.IsNumeric(txtCantidad.Text))
                    {
                        exceptionMessage += Environment.NewLine + "La cantidad debe ser numérica.";
                    }
                }


                if (!filtersSetted)
                {
                    exceptionMessage = "No se puede realizar la busqueda ya que no se informó ningún filtro";
                }

                if (!TypesHelper.IsEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }

                #endregion

                var filters = new HistoryCompraFilters
                {
                    Codigo      = (!TypesHelper.IsEmpty(txtCodigo.Text)) ? Convert.ToInt32(txtCodigo.Text) : (int?)null,
                    Descripcion = (!TypesHelper.IsEmpty(txtDesc.Text)) ? txtDesc.Text : null,
                    Precio      = (!TypesHelper.IsEmpty(txtPrecio.Text)) ? Convert.ToDouble(txtPrecio.Text) : (double?)null,
                    Fecha       = (!TypesHelper.IsEmpty(txtFecha.Text)) ? txtFecha.Text : null,
                    Cantidad    = (!TypesHelper.IsEmpty(txtCantidad.Text)) ? Convert.ToInt32(txtCantidad.Text) : (int?)null
                };

                var historyCompras = (cBExact.Checked) ? CompraPersistance.GetAllComprasByParameters(SessionManager.CurrentUser, filters) : CompraPersistance.GetAllComprasByParametersLike(SessionManager.CurrentUser, filters);

                if (historyCompras == null || historyCompras.Count == 0)
                {
                    throw new Exception("No se encontraron compras según los filtros informados.");
                }

                RefreshSources(historyCompras);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atención");
                ClearFiltersAndTable();
            }
        }
Beispiel #5
0
        private void LblListo_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validations

                var exceptionMessage = string.Empty;

                if (Auction)
                {
                    if (TypesHelper.IsEmpty(TxtValorInicioSubasta.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El valor de inicio de la subasta no puede ser vacío.";
                    }

                    if (!TypesHelper.IsDecimal(TxtValorInicioSubasta.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El valor de inicio de la subasta debe ser decimal (o numérico).";
                    }
                }
                else
                {
                    if (TypesHelper.IsEmpty(TxtPrecio.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El precio del articulo no puede ser vacío.";
                    }

                    if (!TypesHelper.IsDecimal(TxtPrecio.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El precio del articulo debe ser decimal (o numérico).";
                    }
                }

                if (TypesHelper.IsEmpty(TxtDescripcion.Text))
                {
                    exceptionMessage += Environment.NewLine + "La descripcion del articulo no puede ser vacío.";
                }

                if (TypesHelper.IsEmpty(TxtStock.Text))
                {
                    exceptionMessage += Environment.NewLine + "El stock del articulo no puede ser vacío.";
                }

                if (!TypesHelper.IsNumeric(TxtStock.Text))
                {
                    exceptionMessage += Environment.NewLine + "El stock del articulo debe ser numérico.";
                }

                if (LstRubro.CheckedItems.Count == 0)
                {
                    exceptionMessage += Environment.NewLine + "Debe informar por lo menos un rubro.";
                }

                if (!TypesHelper.IsEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }

                #endregion

                if (insertMode)
                {
                    #region Insert the new publication

                    if (CboVisibilidad.Text == "Gratis" && CboEstadoPublicacion.Text == "Publicada")
                    {
                        var freePublicationsActive = PublicacionPersistance.GetAllActiveAndFreeByUser(SessionManager.CurrentUser.ID);
                        if (freePublicationsActive > 2)
                        {
                            throw new Exception("No se puede generar la publicación, ya que cuenta con tres publicaciones activas con visibilidad 'Gratis'.");
                        }
                    }

                    var publication = new Publicacion();

                    LoadObjectFromUIControls(publication);

                    var dialogAnswer = MessageBox.Show("Esta seguro que quiere insertar la nueva publicacion?", "Atencion", MessageBoxButtons.YesNo);
                    if (dialogAnswer == DialogResult.Yes)
                    {
                        if (PublicacionPersistance.Insert(publication) == 1)
                        {
                            MessageBox.Show("Se inserto satisfactoriamente la nueva publicacion", "Atencion");
                            CompleteAction = true;
                            Close();
                        }
                    }

                    #endregion
                }
                else
                {
                    #region Update an existing publication

                    #region Validations

                    var messageExceptions = string.Empty;

                    //Realizo la validación solo cuando cambió o el estado o el tipo de publicación
                    if (CurrentPublication.EstadoPublicacion.Descripcion != CboEstadoPublicacion.Text || CurrentPublication.Visibilidad.Descripcion != CboVisibilidad.Text)
                    {
                        if (CboVisibilidad.Text == "Gratis" && CboEstadoPublicacion.Text == "Publicada")
                        {
                            var freePublicationsActive = PublicacionPersistance.GetAllActiveAndFreeByUser(SessionManager.CurrentUser.ID);
                            if (freePublicationsActive > 2)
                            {
                                throw new Exception("No se puede generar la publicación, ya que cuenta con tres publicaciones activas con visibilidad 'Gratis'.");
                            }
                        }
                    }

                    if (CurrentPublication.EstadoPublicacion.Descripcion == "Publicada" && CboEstadoPublicacion.Text == "Borrador")
                    {
                        messageExceptions += "No se puede cambiar el estado de una publicacion 'Publicada' a 'Borrador'.";
                    }

                    if (CurrentPublication.EstadoPublicacion.Descripcion == "Publicada" && CurrentPublication.Stock > Convert.ToInt32(TxtStock.Text))
                    {
                        messageExceptions += Environment.NewLine + "No se puede decrementar el stock de una publicacion en estado 'Publicada'.";
                    }

                    if (!TypesHelper.IsEmpty(messageExceptions))
                    {
                        throw new Exception(messageExceptions);
                    }

                    #endregion

                    var oldDescription = CurrentPublication.Descripcion;
                    LoadObjectFromUIControls(CurrentPublication);

                    var dialogAnswer = MessageBox.Show(string.Format("Esta seguro que quiere modificar la publicacion {0}?", oldDescription), "Atencion", MessageBoxButtons.YesNo);
                    if (dialogAnswer == DialogResult.Yes)
                    {
                        if (CboTipoPublicacion.Text == "Subasta" && CboEstadoPublicacion.Text == "Finalizada")
                        {
                            using (var transaction = DataBaseManager.Instance().Connection.BeginTransaction(IsolationLevel.Serializable))
                            {
                                if (PublicacionPersistance.Update(CurrentPublication, transaction) == 1)
                                {
                                    var lastOffer = OfertaPersistance.GetLastOfertaByPublication(CurrentPublication.ID, transaction);

                                    //No tiene ofertas, no genero ningun registro en la tabla de compras
                                    if (lastOffer == null)
                                    {
                                        CommitTransaction(transaction);
                                        return;
                                    }

                                    var purchase = CompraPersistance.Insert(lastOffer.ConvertToPurchase(), transaction);

                                    //Commiteo la transaccion solo si pudo insertar la compra en la base de datos
                                    if (purchase.ID != 0)
                                    {
                                        CommitTransaction(transaction);
                                        return;
                                    }
                                    else
                                    {
                                        transaction.Rollback();
                                    }
                                }
                                else
                                {
                                    transaction.Rollback();
                                }
                            }
                        }
                        else if (PublicacionPersistance.Update(CurrentPublication) == 1)
                        {
                            MessageBox.Show("Se modifico satisfactoriamente la publicacion", "Atencion");
                            CompleteAction = true;
                            Close();
                        }
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atencion");
            }
        }
        private void LblBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validations

                var filtersSetted    = false;
                var exceptionMessage = string.Empty;

                if (!TypesHelper.IsEmpty(TxtNombre.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(TxtApellido.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(CboTipoDocumento.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(TxtDocumento.Text))
                {
                    filtersSetted = true;
                }

                int document;
                if (int.TryParse(TxtDocumento.Text, out document))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(TxtEmail.Text))
                {
                    filtersSetted = true;
                }

                if (!filtersSetted)
                {
                    exceptionMessage = "No se puede realizar la búsqueda. Verifique que haya ingresado algún filtro y que los mismos sean válidos.";
                }

                if (!TypesHelper.IsEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }

                #endregion

                //Cargar los filtros ingresados en el objeto de tipo ClienteFilters
                var filters = new ClienteFilters
                {
                    Nombre        = (!TypesHelper.IsEmpty(TxtNombre.Text)) ? TxtNombre.Text : null,
                    Apellido      = (!TypesHelper.IsEmpty(TxtApellido.Text)) ? TxtApellido.Text : null,
                    TipoDocumento = (!TypesHelper.IsEmpty(CboTipoDocumento.Text)) ? (int)CboTipoDocumento.SelectedValue : (int?)null,
                    NroDocumento  = (!TypesHelper.IsEmpty(TxtDocumento.Text)) ? Convert.ToInt32(TxtDocumento.Text) : (int?)null,
                    Email         = (!TypesHelper.IsEmpty(TxtEmail.Text)) ? TxtEmail.Text : null
                };

                var clientes = (ChkBusquedaExacta.Checked) ? ClientePersistance.GetAllClientsByParameters(filters) : ClientePersistance.GetAllClientsByParametersLike(filters);

                if (clientes == null || clientes.Count == 0)
                {
                    throw new Exception("No se encontraron clientes según los filtros informados.");
                }

                //Refrescar la grilla, cargando los Clientes que se obtuvieron como resultado de los filtros
                RefreshSources(clientes);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atención");
            }
        }
        private void LblFacturar_Click(object sender, EventArgs e)
        {
            #region Validaciones

            var exceptionMessage = string.Empty;

            if (TypesHelper.IsEmpty(TxtCantidad.Text) || !TypesHelper.IsNumeric(TxtCantidad.Text))
            {
                exceptionMessage = "Ingrese una cantidad correcta de publicaciones a facturar";
            }

            if (PagaConTarjeta)
            {
                #region Validaciones datos tarjeta

                if (TypesHelper.IsEmpty(TxtCodSeguridad.Text))
                {
                    exceptionMessage += Environment.NewLine + "El codigo de seguridad de la tarjeta es obligatorio";
                }

                if (!TypesHelper.IsNumeric(TxtCodSeguridad.Text))
                {
                    exceptionMessage += Environment.NewLine + "El codigo de seguridad de la tarjeta debe ser numerico";
                }

                if (TypesHelper.IsEmpty(TxtDni.Text))
                {
                    exceptionMessage += Environment.NewLine + "El numero de documento del titular de la tarjeta es obligatorio";
                }

                if (!TypesHelper.IsNumeric(TxtDni.Text))
                {
                    exceptionMessage += Environment.NewLine + "El numero de documento del titular de la tarjeta debe ser numerico";
                }

                if (TypesHelper.IsEmpty(TxtNroTarjeta.Text))
                {
                    exceptionMessage += Environment.NewLine + "El numero de la tarjeta es obligatorio";
                }

                if (!TypesHelper.IsNumeric(TxtNroTarjeta.Text))
                {
                    exceptionMessage += Environment.NewLine + "El numero de la tarjeta debe ser numerico";
                }

                if (TypesHelper.IsEmpty(TxtTarjeta.Text))
                {
                    exceptionMessage += Environment.NewLine + "La descripcion de la tarjeta es obligatorio";
                }

                if (TypesHelper.IsEmpty(TxtTitular.Text))
                {
                    exceptionMessage += Environment.NewLine + "El nombre del titular de la tarjeta es obligatorio";
                }

                if (TypesHelper.IsEmpty(TxtVencimiento.Text))
                {
                    exceptionMessage += Environment.NewLine + "La fecha de vencimiento de la tarjeta es obligatorio";
                }

                if (!TypesHelper.IsNumeric(TxtVencimiento.Text))
                {
                    exceptionMessage += Environment.NewLine + "La fecha de vencimiento de la tarjeta debe ser numerico";
                }

                #endregion
            }

            if (!TypesHelper.IsEmpty(exceptionMessage))
            {
                MessageBox.Show(exceptionMessage, "Atencion");
                return;
            }

            #endregion

            #region Obtengo las publicaciones que voy a rendir

            var cant = Convert.ToInt32(TxtCantidad.Text.Trim());
            if (cant > LstPublicaciones.Items.Count)
            {
                cant = LstPublicaciones.Items.Count;
            }

            var listaPublicacionesAFacturar = PublicationsList.GetRange(0, cant);
            var itemsFactura = new List <ItemFactura>();

            #endregion

            #region Obtengo todos los items de la factura

            foreach (var publicacionFacturar in listaPublicacionesAFacturar)
            {
                var comprasPorPublicacion = CompraPersistance.GetByPublicationId(publicacionFacturar.ID);
                if (comprasPorPublicacion != null)
                {
                    //Pueden ser tanto compras inmediatas o subastas, esta hecho de forma polimorfica
                    foreach (var compra in comprasPorPublicacion)
                    {
                        itemsFactura.Add(compra.ConvertToItemFactura());
                    }
                }

                //Agrego el item factura de la publicacion en si misma (aunque no tenga compras)
                itemsFactura.Add(publicacionFacturar.ConvertToItemFactura());
            }

            #endregion

            using (var transaction = DataBaseManager.Instance().Connection.BeginTransaction(IsolationLevel.Serializable))
            {
                try
                {
                    var dialogAnswer = MessageBox.Show("¿Está seguro que quiere facturar " + cant + " publicacion/es?", "Atención", MessageBoxButtons.YesNo);
                    if (dialogAnswer == DialogResult.Yes)
                    {
                        #region Armo y guardo la factura en si misma

                        var factura = new Factura
                        {
                            Fecha     = ConfigurationVariables.FechaSistema,
                            Numero    = FacturaPersistance.GetUltimoNumeroFactura(transaction) + 1,
                            FormaPago = FormaPagoPersistance.GetById((int)CboFormaPago.SelectedValue, transaction),
                            Usuario   = (Usuario)SessionManager.CurrentUser,
                            Total     = itemsFactura.Sum(item => item.Monto)
                        };

                        //Guardo la factura en la base de datos (y me retorna la factura insertada con el ID correspondiente)
                        factura = FacturaPersistance.InsertFactura(factura, transaction);

                        #endregion

                        if (factura.ID != 0)
                        {
                            Dictionary <int, int> visibilidadesPorUsuario = VisibilidadPersistance.GetAllByUser(SessionManager.CurrentUser, transaction);

                            #region Guardo los items en la base

                            //Creación de los Items de la Factura
                            foreach (var item in itemsFactura)
                            {
                                item.Factura = factura;

                                #region Logica de bonificacion de items

                                /* Realizo la modificacion del contador solo si el item generado surgio a partir
                                 * de una compra y no es el item de la publicacion en si misma. */
                                if (item.ContadorBonificacion)
                                {
                                    var idVisibilidad = item.Publicacion.Visibilidad.ID;

                                    if (visibilidadesPorUsuario.ContainsKey(idVisibilidad))
                                    {
                                        visibilidadesPorUsuario[idVisibilidad]++;
                                    }
                                    else
                                    {
                                        visibilidadesPorUsuario.Add(idVisibilidad, 1);
                                    }

                                    if (visibilidadesPorUsuario[idVisibilidad] == 10)
                                    {
                                        item.Monto = visibilidadesPorUsuario[idVisibilidad] = 0;
                                    }
                                }

                                #endregion
                            }

                            var insertoCorrectamente = ItemFacturaPersistance.InsertItemsFactura(itemsFactura, transaction);

                            if (!insertoCorrectamente)
                            {
                                throw new Exception("Se produjo un error durante la insercion de los items de la factura");
                            }

                            #endregion

                            #region Guardo la informacion de las visibilidades

                            insertoCorrectamente = VisibilidadPersistance.InsertVisibilidadesRendidasPorUsuario(visibilidadesPorUsuario, SessionManager.CurrentUser.ID, transaction);
                            if (!insertoCorrectamente)
                            {
                                throw new Exception("Se produjo un error durante la insercion de la informacion de las visibilidades rendidas por usuario");
                            }

                            #endregion

                            #region Guardo la informacion de la tarjeta de credito

                            if (PagaConTarjeta)
                            {
                                var tarjeta = new TarjetaCredito
                                {
                                    Tarjeta         = TxtTarjeta.Text,
                                    NumeroTarjeta   = Convert.ToInt32(TxtNroTarjeta.Text),
                                    Vencimiento     = Convert.ToInt32(TxtVencimiento.Text),
                                    CodigoSeguridad = Convert.ToInt32(TxtCodSeguridad.Text),
                                    Titular         = TxtTitular.Text,
                                    DniTitular      = Convert.ToInt32(TxtDni.Text),
                                    Factura         = factura
                                };

                                tarjeta = TarjetaCreditoPersistance.Insert(tarjeta, transaction);

                                if (tarjeta.ID == 0)
                                {
                                    throw new Exception("Se produjo un error durante la insercion de la informacion de la tarjeta");
                                }
                            }

                            #endregion

                            transaction.Commit();

                            MessageBox.Show("Se facturaron satisfactoriamente las publicaciones", "Atencion");
                            CompleteAction = true;

                            Close();
                        }
                        else
                        {
                            transaction.Rollback();
                        }
                    }
                }
                catch (Exception ex)
                {
                    transaction.Rollback();

                    TxtCantidad.Clear();
                    MessageBox.Show(ex.Message, "Atencion");
                }
            }
        }
Beispiel #8
0
        private void LblGrabar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validations

                var exceptionMessage = string.Empty;

                if (TypesHelper.IsEmpty(TxtDescripcion.Text))
                {
                    exceptionMessage += Environment.NewLine + "La descripción de la visibilidad no puede ser vacía.";
                }

                if (TypesHelper.IsEmpty(TxtDuracion.Text))
                {
                    exceptionMessage += Environment.NewLine + "La duración de la visibilidad no puede ser vacía.";
                }

                if (!TypesHelper.IsNumeric(TxtDuracion.Text))
                {
                    exceptionMessage += Environment.NewLine + "La duración de la visibilidad debe ser numérica.";
                }

                if (TypesHelper.IsEmpty(TxtPorcentajeVenta.Text))
                {
                    exceptionMessage += Environment.NewLine + "El porcentaje de la venta de la visibilidad no puede ser vacío.";
                }

                if (!TypesHelper.IsDecimal(TxtPorcentajeVenta.Text))
                {
                    exceptionMessage += Environment.NewLine + "El porcentaje de la venta de la visibilidad debe ser decimal (o numérico).";
                }

                if (TypesHelper.IsEmpty(TxtPrecioPublicar.Text))
                {
                    exceptionMessage += Environment.NewLine + "El precio por publicar de la visibilidad no puede ser vacío.";
                }

                if (!TypesHelper.IsDecimal(TxtPrecioPublicar.Text))
                {
                    exceptionMessage += Environment.NewLine + "El precio por publicar de la visibilidad debe ser decimal (o numérico).";
                }

                if (!TypesHelper.IsEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }

                #endregion

                if (insertMode)
                {
                    var filters = new VisibilidadFilters {
                        Descripcion = TxtDescripcion.Text
                    };

                    //Valido que no exista un rol con la descripcion informada
                    if (VisibilidadPersistance.GetAllByParameters(filters).Count > 0)
                    {
                        throw new Exception("Ya existe una visibilidad con la descripcion informada.");
                    }

                    #region Inserto la nueva visibilidad

                    var visibility = new Visibilidad();
                    visibility.Descripcion     = TxtDescripcion.Text;
                    visibility.Duracion        = Convert.ToInt32(TxtDuracion.Text);
                    visibility.PrecioPublicar  = Convert.ToDouble(TxtPrecioPublicar.Text);
                    visibility.PorcentajeVenta = Convert.ToDouble(TxtPorcentajeVenta.Text);
                    visibility.Activo          = ChkActivo.Checked;

                    var dialogAnswer = MessageBox.Show("Esta seguro que quiere insertar la nueva visibilidad?", "Atencion", MessageBoxButtons.YesNo);
                    if (dialogAnswer == DialogResult.Yes)
                    {
                        if (VisibilidadPersistance.Insert(visibility) == 1)
                        {
                            MessageBox.Show("Se inserto satisfactoriamente la nueva visibilidad", "Atencion");
                            CompleteAction = true;
                            Close();
                        }
                    }

                    #endregion
                }
                else
                {
                    #region Modifico una visibilidad existente

                    if (OldVisibilityActive && !ChkActivo.Checked)
                    {
                        //Si cambió el valor de 'Activo' y existen publicaciones con dicha visibilidad, arrojo una excepcion
                        if (PublicacionPersistance.GetAllByVisibility(CurrentVisibility.ID).Count() > 0)
                        {
                            throw new Exception("No se puede modificar la visibilidad ya que existen publicaciones con dicho valor.");
                        }
                    }

                    CurrentVisibility.Descripcion     = TxtDescripcion.Text;
                    CurrentVisibility.Duracion        = Convert.ToInt32(TxtDuracion.Text);
                    CurrentVisibility.PrecioPublicar  = Convert.ToDouble(TxtPrecioPublicar.Text);
                    CurrentVisibility.PorcentajeVenta = Convert.ToDouble(TxtPorcentajeVenta.Text);
                    CurrentVisibility.Activo          = ChkActivo.Checked;

                    var dialogAnswer = MessageBox.Show(string.Format("Esta seguro que quiere modificar la visibilidad {0}?", CurrentVisibility.Descripcion), "Atencion", MessageBoxButtons.YesNo);
                    if (dialogAnswer == DialogResult.Yes)
                    {
                        //Modifico exitosamente si la cantidad de registros afectados es 1
                        if (VisibilidadPersistance.Update(CurrentVisibility) == 1)
                        {
                            MessageBox.Show("Se modifico satisfactoriamente la visibilidad", "Atencion");
                            CompleteAction = true;
                            Close();
                        }
                    }

                    #endregion
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atención");
                Close();
            }
        }
        private void LblBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validations

                var filtersSetted    = false;
                var exceptionMessage = string.Empty;

                if (!TypesHelper.IsEmpty(TxtDescripcion.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(TxtDuracion.Text))
                {
                    filtersSetted = true;
                    if (!TypesHelper.IsNumeric(TxtDuracion.Text))
                    {
                        exceptionMessage += Environment.NewLine + "La duración de la visibilidad debe ser numérica.";
                    }
                }

                if (!TypesHelper.IsEmpty(TxtPrecioPublicar.Text))
                {
                    filtersSetted = true;
                    if (!TypesHelper.IsDecimal(TxtPrecioPublicar.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El precio por publicar de la visibilidad debe ser decimal (o numérico).";
                    }
                }

                if (!TypesHelper.IsEmpty(TxtPorcentajeVenta.Text))
                {
                    filtersSetted = true;
                    if (!TypesHelper.IsDecimal(TxtPorcentajeVenta.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El porcentaje de la venta de la visibilidad debe ser decimal (o numérico).";
                    }
                }

                if (!filtersSetted)
                {
                    exceptionMessage = "No se puede realizar la busqueda ya que no se informó ningún filtro";
                }

                if (!TypesHelper.IsEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }

                #endregion

                //Armo el objeto que representa a los filtros a partir de los valores de los controles
                var filters = new VisibilidadFilters
                {
                    Descripcion     = (!TypesHelper.IsEmpty(TxtDescripcion.Text)) ? TxtDescripcion.Text : null,
                    PrecioPublicar  = (!TypesHelper.IsEmpty(TxtPrecioPublicar.Text) && ChkBusquedaExacta.Checked) ? Convert.ToDouble(TxtPrecioPublicar.Text) : (double?)null,
                    PorcentajeVenta = (!TypesHelper.IsEmpty(TxtPorcentajeVenta.Text) && ChkBusquedaExacta.Checked) ? Convert.ToDouble(TxtPorcentajeVenta.Text) : (double?)null,
                    Duracion        = (!TypesHelper.IsEmpty(TxtDuracion.Text) && ChkBusquedaExacta.Checked) ? Convert.ToInt32(TxtDuracion.Text) : (int?)null
                };

                var visibilities = (ChkBusquedaExacta.Checked) ? VisibilidadPersistance.GetAllByParameters(filters) : VisibilidadPersistance.GetAllByParametersLike(filters);

                if (visibilities == null || visibilities.Count == 0)
                {
                    throw new Exception("No se encontraron visibilidades según los filtros informados.");
                }

                //Cargo la grilla a partir de los registros obtenidos en la busqueda
                RefreshSources(visibilities);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atención");
            }
        }
Beispiel #10
0
        private void LblBuscar_Click(object sender, EventArgs e)
        {
            try
            {
                #region Validations

                var filtersSetted    = false;
                var exceptionMessage = string.Empty;

                if (!TypesHelper.IsEmpty(TxtRazonSocial.Text))
                {
                    filtersSetted = true;
                }

                if (!TypesHelper.IsEmpty(TxtCuit.Text))
                {
                    filtersSetted = true;
                    if (!TypesHelper.IsCUITValid(TxtCuit.Text))
                    {
                        exceptionMessage += Environment.NewLine + "El cuit no es un cuit válido.";
                    }
                }

                if (!TypesHelper.IsEmpty(TxtEmail.Text))
                {
                    filtersSetted = true;
                }

                if (!filtersSetted)
                {
                    exceptionMessage = "No se puede realizar la busqueda ya que no se informó ningún filtro";
                }

                if (!TypesHelper.IsEmpty(exceptionMessage))
                {
                    throw new Exception(exceptionMessage);
                }

                #endregion

                var filters = new EmpresaFilters
                {
                    RazonSocial = (!TypesHelper.IsEmpty(TxtRazonSocial.Text)) ? TxtRazonSocial.Text : null,
                    Cuit        = (!TypesHelper.IsEmpty(TxtCuit.Text)) ? TxtCuit.Text : null,
                    Email       = (!TypesHelper.IsEmpty(TxtEmail.Text)) ? TxtEmail.Text : null
                };

                var empresas = (ChkBusquedaExacta.Checked) ? EmpresaPersistance.GetAllBusinessByParameters(filters) : EmpresaPersistance.GetAllBusinessByParametersLike(filters);

                if (empresas == null || empresas.Count == 0)
                {
                    throw new Exception("No se encontraron empresas según los filtros informados.");
                }

                RefreshSources(empresas);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Atención");
            }
        }