public FrmVirtualBidder(VirtualBidder role, ChildMainVirtualBidders father)
 {
     InitializeComponent();
     _father             = father;
     this._virtualBidder = role;
     _edit = true;
 }
Exemplo n.º 2
0
        public static List <VirtualBidder> GetAllVirtualBidders(string query)
        {
            if (string.IsNullOrEmpty(query))
            {
                query = "SELECT * FROM virtual_bidders_view";
            }
            var virtualBidders   = new List <VirtualBidder>();
            var virtualBiddersDt = DbConnection.consultar_datos(query);

            if (virtualBiddersDt == null)
            {
                return(null);
            }
            foreach (DataRow row in virtualBiddersDt.Rows)
            {
                var virtualBidder = new VirtualBidder()
                {
                    IdVirtualBidder   = (int)row[0],
                    IdBidder          = (int)row[1],
                    NameBidder        = (string)row[2],
                    DescriptionBidder = (string)row[3],
                    Wallet            = (decimal)row[4],
                    Role = new Role((int)row[5])
                };
                virtualBidders.Add(virtualBidder);
            }
            return(virtualBidders);
        }
Exemplo n.º 3
0
        public List <VirtualBidder> GetAvailableVirtualBidders()
        {
            var virtualBidders = new List <VirtualBidder>();
            var query          = "SELECT virtual_bidders_view.* FROM virtual_bidders_view " +
                                 "LEFT JOIN " +
                                 "routine_has_virtual_bidder ON routine_has_virtual_bidder.VIRTUAL_BIDDER_idVIrtualBidder = virtual_bidders_view.idVirtualBidder " +
                                 $"WHERE routine_has_virtual_bidder.ROUTINE_idRoutine IS NULL OR routine_has_virtual_bidder.ROUTINE_idRoutine != {IdRoutine}";
            var consult = DbConnection.consultar_datos(query);

            if (consult == null)
            {
                return(virtualBidders);
            }
            for (var index = 0; index < consult.Rows.Count; index++)
            {
                var row           = consult.Rows[index];
                var virtualBidder = new VirtualBidder()
                {
                    IdVirtualBidder   = (int)row[0],
                    IdBidder          = (int)row[1],
                    NameBidder        = (string)row[2],
                    DescriptionBidder = (string)row[3],
                    Wallet            = (decimal)row[4],
                    Role = new Role((int)row[5]),
                };
                virtualBidders.Add(virtualBidder);
            }

            return(virtualBidders);
        }
Exemplo n.º 4
0
        public List <VirtualBidder> GetVirtualBidders()
        {
            var virtualBidders = new List <VirtualBidder>();
            var query          = "SELECT * FROM virtual_bidders_per_routine " +
                                 $"WHERE ROUTINE_idRoutine = {IdRoutine}";
            var virtualBiddersDt = DbConnection.consultar_datos(query);

            if (virtualBiddersDt == null)
            {
                return(virtualBidders);
            }
            for (var index = 0; index < virtualBiddersDt.Rows.Count; index++)
            {
                var row           = virtualBiddersDt.Rows[index];
                var virtualBidder = new VirtualBidder()
                {
                    IdVirtualBidder   = (int)row[0],
                    IdBidder          = (int)row[1],
                    NameBidder        = (string)row[2],
                    DescriptionBidder = (string)row[3],
                    Wallet            = (decimal)row[4],
                    Role = new Role((int)row[5]),
                };
                virtualBidders.Add(virtualBidder);
            }

            return(virtualBidders);
        }
Exemplo n.º 5
0
        public void UpdateVirtualBidders(string query)
        {
            dgvVirtualBidders.Rows.Clear();
            var virtualBidders = VirtualBidder.GetAllVirtualBidders(query);

            if (virtualBidders == null)
            {
                return;
            }
            foreach (var vb in virtualBidders)
            {
                dgvVirtualBidders.Rows.Add(vb.IdVirtualBidder, vb.IdBidder, vb.NameBidder, vb.DescriptionBidder, vb.Role.NameRole,
                                           vb.Wallet);
            }
        }
Exemplo n.º 6
0
        private void dgvVirtualBidders_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            var row = dgvVirtualBidders.CurrentRow; //Obtiene la fila seleccionada

            if (row == null || row.Index == -1 || e.RowIndex == -1)
            {
                return;
            }

            //Obtiene los datos de la fila seleccioanda y la convierte a objeto de PRODUCTO
            var idVirtualBidder = int.Parse(row.Cells[0].Value.ToString());

            var virtualBidder = VirtualBidder.GetVirtualBidderById(idVirtualBidder);

            var form = new FrmVirtualBidder(virtualBidder, this); //Instancia un nuevo formulario para agregar productos

            form.Show();                                          //Abre el formulario
        }
Exemplo n.º 7
0
        public static VirtualBidder GetVirtualBidderById(int idVirtualBidder)
        {
            var query            = $"SELECT * FROM virtual_bidders_view WHERE idVirtualBidder = {idVirtualBidder}";
            var virtualBiddersDt = DbConnection.consultar_datos(query);

            if (virtualBiddersDt == null)
            {
                return(null);
            }
            var row           = virtualBiddersDt.Rows[0];
            var virtualBidder = new VirtualBidder()
            {
                IdVirtualBidder   = (int)row[0],
                IdBidder          = (int)row[1],
                NameBidder        = (string)row[2],
                DescriptionBidder = (string)row[3],
                Wallet            = (decimal)row[4],
                Role = new Role((int)row[5])
            };

            return(virtualBidder);
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (ValidaData())
            {
                var newNameVirtualBidder        = txbNameVirtualBidder.Text;
                var newDescriptionVirtualBidder = txbDescriptionVirtuaBidder.Text;
                var newWalletVirtualBidder      = txbWalletVirtualBidder.Text;
                var newIdRoleVirtualBidder      = ((Role)cboRole.SelectedItem).IdRole;

                if (!_edit)
                {
                    var query =
                        $"SELECT insert_virtual_bidder(" +
                        $"'{newNameVirtualBidder}', " +
                        $"'{newDescriptionVirtualBidder}', " +
                        $"{newWalletVirtualBidder}, " +
                        $"{newIdRoleVirtualBidder})";
                    var idVirtualBidderDt = DbConnection.consultar_datos(query);
                    if (idVirtualBidderDt != null)
                    {
                        _virtualBidder = VirtualBidder.GetVirtualBidderById(int.Parse(idVirtualBidderDt.Rows[0][0].ToString()));
                        _father?.UpdateVirtualBidders(null);
                        if (Question(@"¡Se ha registrado el jugador virtual exitosamente! ¿Desea agregar otro?", @"Jugador Virtual Agregado"))
                        {
                            txbDescriptionVirtuaBidder.Clear();
                            txbNameVirtualBidder.Clear();
                            txbWalletVirtualBidder.Clear();
                        }
                        else
                        {
                            _edit = true;
                        }
                    }
                    else
                    {
                        MessageBox.Show(@"Ocurrió un problema al registrar el jugador virtual.");
                    }
                }
                else if (_edit) //Si va a editar un producto ya existente
                {
                    var query =
                        $"CALL update_virtual_bidder (" +
                        $"{_virtualBidder.IdVirtualBidder}, " +
                        $"'{newNameVirtualBidder}', " +
                        $"'{newDescriptionVirtualBidder}', " +
                        $"{newWalletVirtualBidder}, " +
                        $"{newIdRoleVirtualBidder})";
                    if (DbConnection.ejecutar(query)) //Si se ejecuta la consulta en la base de datos correctamente
                    {
                        _father?.UpdateVirtualBidders(null);
                        if (Question($"¡Se ha modificado el jugador virtual exitosamente! ¿Desea Salir?",
                                     @"Jugador Virtual Modificado"))
                        {
                            this.Close();
                        }
                    }
                    else
                    {
                        MessageBox.Show(@"Ocurrió un problema modificando el jugador virtual.");
                    }
                }
            }
            else
            {
                MessageBox.Show(@"Existe un error en el formulario.");
            }
        }