Exemple #1
0
        // Método para imprimir un ticket de venta de una lista
        public void printList(LTL_LotteryList pNumberList, int pTicketType = 0)
        {
            // Configurar impresión para Ticket de Venta
            SaleTicket saleTicket = new SaleTicket(pTicketType);

            saleTicket.companyName = UtilityService.getCompanyName();
            // Obtener datos del punto de venta
            LPS_LotteryPointSale pointSale = UtilityService.getPointSale();

            saleTicket.pointSaleName = pointSale.LPS_DisplayName;
            // Obtener usuario vendedor
            saleTicket.userName = SystemSession.username;
            // Obtener datos del sorteo
            LotteryDrawRepository drawRepo   = new LotteryDrawRepository();
            LTD_LotteryDraw       drawObject = drawRepo.getById(pNumberList.LTD_LotteryDraw);

            saleTicket.drawDate = drawObject.LTD_CreateDate;
            // Obtener datos de tipo de sorteo
            this.drawTypeRepo = new LotteryDrawTypeRepository();
            LDT_LotteryDrawType drawType = drawTypeRepo.getById(drawObject.LDT_LotteryDrawType);

            saleTicket.drawTypeCode = drawType.LDT_Code;
            // Obtener datos de los premios
            PrizeFactorService     prizeFactorService = new PrizeFactorService();
            LPF_LotteryPrizeFactor prizeFactor        = prizeFactorService.getByGroup(drawType.LDT_Id);

            if (prizeFactor != null)
            {
                saleTicket.prizeFactorArray[0] = prizeFactor.LPF_FirtsPrizeFactor;
                saleTicket.prizeFactorArray[1] = prizeFactor.LPF_SecondPrizeFactor;
                saleTicket.prizeFactorArray[2] = prizeFactor.LPF_ThirdPrizeFactor;
            }
            // Llenar datos del número de lista
            saleTicket.createDate   = DateTime.Now;
            saleTicket.ticketId     = pNumberList.LTL_Id;
            saleTicket.globalId     = pointSale.LPS_Id + "" + saleTicket.ticketId;
            saleTicket.customerName = pNumberList.LTL_CustomerName;
            // Obtener detalle de la lista procesada
            this.listRepo = new LotteryListRepository();
            saleTicket.listNumberDetail = listRepo.getTupleListDetail(pNumberList.LTL_Id);
            // Crear instancia de impresora y asignar el ticket
            TicketPrinter ticketPrinter = new TicketPrinter();

            ticketPrinter.saleTicket = saleTicket;
            // Obtener nombre de impresora y enviar impresión
            string printerName = UtilityService.getTicketPrinterName();

            ticketPrinter.printLotterySaleTicket(printerName);
        }
Exemple #2
0
        public bool AddSale(string from_station, string to_station, int route_id, int traveller_id, short amount, string ticket_name)
        {
            conn.Open();

            NpgsqlTransaction transaction = conn.BeginTransaction();

            try
            {
                RouteSubrouteRepository routeSubrouteRepository = new RouteSubrouteRepository();
                List <RouteSubroute>    routeParts = routeSubrouteRepository.GetRoutePart(route_id, from_station, to_station);

                foreach (var routePart in routeParts)
                {
                    if (routePart.seats_amount <= 0)
                    {
                        throw new Exception();
                    }
                }

                int saleId = NextId();

                Sale sale = new Sale();
                sale.id             = saleId;
                sale.payment_status = true;
                sale.sale_date      = DateTime.Now;
                sale.to_station     = to_station;
                sale.from_station   = from_station;
                sale.route_id       = route_id;
                sale.traveller_id   = traveller_id;

                NpgsqlCommand addSale = new NpgsqlCommand(" insert into sale " +
                                                          "(id, payment_status, from_station, to_station, route_id, traveller_id) " +
                                                          "values(:id,:payment_status, :from_station, :to_station, :route_id, :traveller_id); ", conn);

                var id_db_sale = new NpgsqlParameter(":id", DbType.Int32);
                id_db_sale.Value = sale.id;
                addSale.Parameters.Add(id_db_sale);

                var payment_status_db = new NpgsqlParameter(":payment_status", DbType.Boolean);
                payment_status_db.Value = sale.payment_status;
                addSale.Parameters.Add(payment_status_db);

                var to_station_db = new NpgsqlParameter(":to_station", DbType.String);
                to_station_db.Value = sale.to_station;
                addSale.Parameters.Add(to_station_db);

                var from_station_db = new NpgsqlParameter(":from_station", DbType.String);
                from_station_db.Value = sale.from_station;
                addSale.Parameters.Add(from_station_db);

                var route_id_db = new NpgsqlParameter(":route_id", DbType.Int32);
                route_id_db.Value = sale.route_id;
                addSale.Parameters.Add(route_id_db);

                var traveller_id_db = new NpgsqlParameter(":traveller_id", DbType.Int32);
                traveller_id_db.Value = sale.traveller_id;
                addSale.Parameters.Add(traveller_id_db);

                addSale.Prepare();

                //throw new Exception(); <-- TEST

                NpgsqlCommand selectTicket = new NpgsqlCommand("SELECT id FROM ticket" +
                                                               " WHERE name=:ticket_name", conn);

                var ticket_name_db = new NpgsqlParameter(":ticket_name", DbType.String);
                ticket_name_db.Value = ticket_name;
                selectTicket.Parameters.Add(ticket_name_db);

                selectTicket.Prepare();

                int ticketId = (int)selectTicket.ExecuteScalar();

                SaleTicket saleTicket = new SaleTicket
                {
                    sale_id   = saleId,
                    ticket_id = ticketId,
                    amount    = amount
                };

                NpgsqlCommand addSaleTicket = new NpgsqlCommand("insert into sale_ticket (amount,sale_id,ticket_id) " +
                                                                " values(:amount, :sale_id, :ticket_id); ", conn);
                var amount_db = new NpgsqlParameter(":amount", DbType.Int32);
                amount_db.Value = saleTicket.amount;
                addSaleTicket.Parameters.Add(amount_db);

                var sale_id_db = new NpgsqlParameter(":sale_id", DbType.Int32);
                sale_id_db.Value = saleTicket.sale_id;
                addSaleTicket.Parameters.Add(sale_id_db);

                var ticket_id_db = new NpgsqlParameter(":ticket_id", DbType.Int32);
                ticket_id_db.Value = saleTicket.ticket_id;
                addSaleTicket.Parameters.Add(ticket_id_db);

                addSaleTicket.Prepare();

                int rowsAddedToSale       = addSale.ExecuteNonQuery();
                int rowsAddedToTicketSale = addSaleTicket.ExecuteNonQuery();


                for (int i = 0; i < routeParts.Count; i++)
                {
                    routeParts[i].seats_amount -= 1;
                    NpgsqlCommand updateRouteSubroute = new NpgsqlCommand("update route_subroute set seats_amount = :seats_amount " +
                                                                          "where id = :id;", conn);

                    var seats_amount_db = new NpgsqlParameter(":seats_amount", DbType.Int32);
                    seats_amount_db.Value = routeParts[i].seats_amount;
                    updateRouteSubroute.Parameters.Add(seats_amount_db);

                    var id_db = new NpgsqlParameter(":id", DbType.Int32);
                    id_db.Value = routeParts[i].id;
                    updateRouteSubroute.Parameters.Add(id_db);

                    updateRouteSubroute.Prepare();

                    int rowsUpdated = updateRouteSubroute.ExecuteNonQuery();
                }
            }
            catch (Exception ex)
            {
                transaction.Rollback();
                conn.Close();
                return(false);
            }
            transaction.Commit();
            conn.Close();
            return(true);
        }