Ejemplo n.º 1
0
        private async void btnCreateCustomer_Click(object sender, EventArgs e)
        {
            string name    = txtCustomerName.Text.Trim();
            string surname = txtCustomerSurname.Text.Trim();
            string idcard  = txtCustomerIdCard.Text.Trim();

            if (!this.CheckInput())
            {
                MessageBox.Show("Fill all input", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (!idcard.IsNumber())
            {
                MessageBox.Show("Please enter the number", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (db.Customers.Any(c => idcard == c.IdCard))
            {
                MessageBox.Show("This IDCard already used", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            ct = new Customer {
                Name = name, Surname = surname, IdCard = idcard
            };
            db.Customers.Add(ct);
            await db.SaveChangesAsync();

            MessageBox.Show("Success added", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            UpdateDataGridView();
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> PutPrestamo(int id, Prestamo prestamo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != prestamo.IdLector)
            {
                return(BadRequest());
            }

            db.Entry(prestamo).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PrestamoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public async Task <IHttpActionResult> EditLivros(int id, Livros livros)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != livros.Id)
            {
                return(BadRequest());
            }

            db.Entry(livros).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!LivrosExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 4
0
        private async void btnCreateBook_Click(object sender, EventArgs e)
        {
            string name  = txtBookName.Text.Trim();
            string price = txtPrice.Text.Trim();
            string count = txtCount.Text.Trim();
            string genre = cmbGenres.Text.Trim();

            if (!this.CheckInput() || genre == "")
            {
                MessageBox.Show("Fill all input", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            this.cmbGenres.DropDownStyle = ComboBoxStyle.DropDownList;
            if (!txtPrice.Text.IsNumber() || !txtCount.Text.IsNumber())
            {
                MessageBox.Show("Please enter the number", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            int id = (cmbGenres.SelectedItem as CB_class).Id;

            bk = new Book {
                Name = name, Price = decimal.Parse(price), Count = int.Parse(count), GenresId = id
            };
            db.Books.Add(bk);
            await db.SaveChangesAsync();

            MessageBox.Show("Success added", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
            UpdateDataGridView();
        }
Ejemplo n.º 5
0
        public async Task <IHttpActionResult> PostAutor_Livro(Autor_Livro autor_Livro)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.Autor_Livro.Add(autor_Livro);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = autor_Livro.Id }, autor_Livro));
        }
Ejemplo n.º 6
0
        public async Task <HttpResponseMessage> PutEstudiante(int id, Estudiante estudiante)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }

            if (id != estudiante.IdLector)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BaseResult()
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Message = string.Format("El campo clave de la entidad debe ser igual a {0}", id)
                }));
            }

            if (EstudianteExists(id))
            {
                //    Estudiante record = await db.Estudiante.FindAsync(id);
                //    record.Nombre = estudiante.Nombre;
                //    record.Direccion = estudiante.Direccion;
                //    record.CI = estudiante.CI;
                //    record.Carrera = estudiante.Carrera;
                //    record.Edad = estudiante.Edad;

                db.Entry(estudiante).State = EntityState.Modified;
                try
                {
                    await db.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, new BaseResult()
                    {
                        ExceptionDetail = ex,
                        StatusCode = HttpStatusCode.InternalServerError,
                        Message = "Ocurrió un error en la operación"
                    }));
                }
            }
            else
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new BaseResult()
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Message = string.Format("No se encontró registro con el id {0}", id)
                }));
            }

            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
Ejemplo n.º 7
0
        private async void btnRegister_Click(object sender, EventArgs e)
        {
            string name       = txtrgsName.Text.Trim();
            string surname    = txtrgssurname.Text.Trim();
            string password   = txtpaswwordRegister.Text.Trim();
            string email      = txtRgsEmail.Text.Trim();
            string repeatpass = txtRgsRptPassword.Text.Trim();

            if (CheckRegistration(name, surname, password, email, repeatpass))
            {
                string hashPassword = Helpers.HashCode(password);
                Users  user         = new Users()
                {
                    Name     = name,
                    Surname  = surname,
                    Password = hashPassword,
                    Email    = email
                };
                db.Users.Add(user);
                await db.SaveChangesAsync();

                MessageBox.Show("You Registered");
                txtpaswwordRegister.Text = "";
                txtRgsEmail.Text         = "";
                txtrgsName.Text          = "";
                txtRgsRptPassword.Text   = "";
                txtrgssurname.Text       = "";
            }
        }
Ejemplo n.º 8
0
        private async void dgvUser_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int          Id       = (int)dgvUser.Rows[e.RowIndex].Cells[0].Value;
            User         usr      = db.Users.Find(Id);
            DialogResult responce = MessageBox.Show("Are you sure confirm ?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (responce == DialogResult.Yes)
            {
                usr.Status = true;
            }
            else
            {
                usr.Deleted = true;
            }

            await db.SaveChangesAsync();

            int count = db.Users.Where(u => u.Deleted == false).Where(u => u.Status == false).Count();

            btnNewUser.Text      = "New User:"******" " + count;
            btnNewUser.BackColor = System.Drawing.Color.Gray;
            dgvUser.DataSource   = null;
            dgvUser.DataSource   = db.Users.Where(u => u.Deleted == false).Where(u => u.Status == false).Select(u => new
            {
                u.Id,
                Fullname = u.Name + " " + u.Surname,
                u.Level,
                u.Status
            }).OrderByDescending(u => u.Id).ToList();
        }
Ejemplo n.º 9
0
        private async void BtnCreateBook_Click(object sender, EventArgs e)
        {
            int     id        = (cmbGenreList.SelectedItem as CMBBookClass).Id;
            string  bookName  = txbBookForm.Text.Trim();
            decimal bookPrice = decimal.Parse(txbBookPrice.Text.Trim());
            int     bookCount = int.Parse(txbBookCount.Text.Trim());

            if (!this.CheckInput())
            {
                MessageBox.Show("Please filled the all inputs !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Book book = new Book()
            {
                Name = bookName, Price = bookPrice, Count = bookCount, GenresID = id
            };

            _db.Books.Add(book);
            await _db.SaveChangesAsync();

            txbBookForm.Text        = null;
            txbBookCount.Text       = null;
            txbBookPrice.Text       = null;
            cmbGenreList.DataSource = null;
            RefreshDGV();
        }
Ejemplo n.º 10
0
        private async void btn_Created(object sender, RoutedEventArgs e)
        {
            string genre = txt_Create_Genre.Text.Trim();

            if (genre == "")
            {
                MessageBox.Show("Запоните это поле!!!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            if (_libdb.Book_Genres.Any(bg => bg.Genre_Name == genre))
            {
                MessageBox.Show("Такое тип уже имеется!!!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            Book_Genres book_Genre = new Book_Genres
            {
                Genre_Name = genre
            };

            _libdb.Book_Genres.Add(book_Genre);
            await _libdb.SaveChangesAsync();

            MessageBox.Show("Данный тип успешно добавлен!!!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);

            txt_Create_Genre.Text = "";
        }
Ejemplo n.º 11
0
        private async void BtnRegister_Click(object sender, EventArgs e)
        {
            string name            = txbRgsName.Text.Trim();
            string surname         = txbRgsSurname.Text.Trim();
            string phone           = txbRgsPhone.Text.Trim();
            string email           = txbRgsEmail.Text.Trim();
            string password        = txbRgsPassw.Text.Trim();
            string passwordConfirm = txbRgsConfirmPassw.Text.Trim();
            string age             = txbRgsAge.Text.Trim();

            if (!this.CheckInput())
            {
                MessageBox.Show("Please filled the all inputs !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!age.IsNumber())
            {
                MessageBox.Show("Please enter number for age !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!email.IsEmail())
            {
                MessageBox.Show("Please enter correct email !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (password != passwordConfirm)
            {
                MessageBox.Show("Please enter same password to confirm Input!!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (_db.Employees.Any(em => em.Email == email))
            {
                MessageBox.Show("This email already exist", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            string hashPassword = Helpers.HashPassword(password);

            Employee employee = new Employee()
            {
                Name     = name,
                Surname  = surname,
                Email    = email,
                Age      = int.Parse(age),
                Phone    = phone,
                Password = hashPassword
            };

            _db.Employees.Add(employee);
            await _db.SaveChangesAsync();

            MessageBox.Show("Your registration are succesfully", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            RefreshInputs();
            this.Close();
        }
Ejemplo n.º 12
0
        public async Task <HttpResponseMessage> PutLibro(int id, Libro libro)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
            }


            if (id != libro.IdLibro)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new BaseResult()
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Message = string.Format("El campo clave de la entidad debe ser igual a {0}", id)
                }));
            }

            db.Entry(libro).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException ex)
            {
                if (!LibroExists(id))
                {
                    return(Request.CreateResponse(HttpStatusCode.NotFound, new BaseResult()
                    {
                        StatusCode = HttpStatusCode.BadRequest,
                        Message = string.Format("No se encontró registro con el id {0}", id)
                    }));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, new BaseResult()
                    {
                        ExceptionDetail = ex,
                        StatusCode = HttpStatusCode.InternalServerError,
                        Message = "Ocurrió un error en la operación"
                    }));
                }
            }

            return(Request.CreateResponse(HttpStatusCode.NoContent));
        }
Ejemplo n.º 13
0
        private async void BtnCreateClient_Click(object sender, EventArgs e)
        {
            string name     = txbClientName.Text.Trim();
            string surname  = txbClientSurname.Text.Trim();
            string phone    = txbClientPhone.Text.Trim();
            string email    = txbClientEmail.Text.Trim();
            string passport = txbClientPassport.Text.Trim();

            if (!this.CheckInput())
            {
                MessageBox.Show("Please filled the all inputs !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!email.IsEmail())
            {
                MessageBox.Show("Please enter correct email !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (_db.Clients.Any(c => c.PassportSeriaNumber == txbClientPassport.Text))
            {
                MessageBox.Show("This passport series exist already", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            Client client = new Client()
            {
                Name                = name,
                Surname             = surname,
                Phone               = phone,
                Email               = email,
                PassportSeriaNumber = passport
            };

            _db.Clients.Add(client);
            await _db.SaveChangesAsync();

            RefreshTexbox();
            RefreshDGV();
            MessageBox.Show("This Person Resgistration is succesfully");
        }
Ejemplo n.º 14
0
        private async void btn_Delete_Click(object sender, RoutedEventArgs e)
        {
            int id = ((Cb_Genres)cb_Delete.SelectedItem).ID;

            Book_Genres genre = _libdb.Book_Genres.Find(id);

            genre.Is_Deleted = true;
            await _libdb.SaveChangesAsync();

            MessageBox.Show("Данный тип успешно удален!!!", "Deleted", MessageBoxButton.OK, MessageBoxImage.Information);
            cb_Delete.Text = "";
        }
Ejemplo n.º 15
0
        private async void btnGive_Click(object sender, EventArgs e)
        {
            if (!this.CheckInput())
            {
                MessageBox.Show("Fill all input", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            DateTime date       = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
            DateTime date1      = dateTimeReturn.Value;
            int      count      = cmbOrderBookName.Items.Count;
            int      customerId = (cmbOrderCustomerIDCard.SelectedItem as CB_CustomerID_class).Id;

            Order order = new Order()
            {
                GiveDate    = date,
                ReturnDate  = date1,
                CustomersId = customerId,
                UsersId     = _user.Id,
            };

            db.Orders.Add(order);
            await db.SaveChangesAsync();

            foreach (ListClass item in listGiveBook.Items)
            {
                order.OrderBooks.Add(new OrderBook
                {
                    BooksId  = item.Id,
                    OrdersId = order.Id
                });
            }
            foreach (ListClass item in listGiveBook.Items)
            {
                DecrementBook(item);
            }
            MessageBox.Show("Order successfully completed");
            listGiveBook.Items.Clear();
            lblBookCount.Text = "0";
            DGV_Refresh();
        }
Ejemplo n.º 16
0
        private async void Button1_Click(object sender, EventArgs e)
        {
            if (!this.CheckInput())
            {
                MessageBox.Show("Please filled the all inputs !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (lbOrderBook.Text == "")
            {
                MessageBox.Show("Please filled the  Listbox !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            DateTime date  = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);
            DateTime date1 = dtpReturnTime.Value;

            int count    = cmbClientBook.Items.Count;
            int clientId = (cmbClientPassport.SelectedItem as CMBForOrder).Id;

            Order order = new Order()
            {
                GiveTime    = date,
                ReturnTime  = date1,
                BookCount   = count,
                ClientsID   = clientId,
                EmployeesID = employ.Id
            };

            _db.Orders.Add(order);
            await _db.SaveChangesAsync();

            foreach (ListBookClass item in lbOrderBook.Items)
            {
                order.OrderBooks.Add(new OrderBook
                {
                    BooksID  = item.Id,
                    OrdersID = order.Id,
                });
            }

            foreach (ListBookClass item in lbOrderBook.Items)
            {
                DecrementBook(item);
            }

            MessageBox.Show("Order succesfully generated !");
            lbOrderBook.Items.Clear();
            lbCountBook.Text = "0";


            RefreshDGV();
        }
Ejemplo n.º 17
0
        private async void BtnCreateGenre_Click(object sender, EventArgs e)
        {
            string GenreName = txbGenre.Text.Trim();

            if (!this.CheckInput())
            {
                MessageBox.Show("Please filled the input !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            Genre genre = new Genre()
            {
                Name = GenreName
            };

            _db.Genres.Add(genre);
            await _db.SaveChangesAsync();

            txbGenre.Text = null;
            RefreshDgv();
            MessageBox.Show("Create genre is Succesfully");
        }
Ejemplo n.º 18
0
        private async void BtnCreateBook_Click(object sender, EventArgs e)
        {
            string bookName  = txbBookForm.Text.Trim();
            string bookPrice = txbBookPrice.Text.Trim();
            string bookCount = txbBookCount.Text.Trim();

            if (!this.CheckInput())
            {
                MessageBox.Show("Please filled the all inputs !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (!txbBookCount.Text.IsNumber() || !txbBookPrice.Text.IsNumber())
            {
                MessageBox.Show("Please enter the number to price and count inpust", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (cmbGenreList.Text == "")
            {
                MessageBox.Show("Please filled the all inputs !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            int id = (cmbGenreList.SelectedItem as CMBBookClass).Id;

            Book book = new Book()
            {
                Name = bookName, Price = decimal.Parse(bookPrice), Count = int.Parse(bookCount), GenresID = id
            };

            _db.Books.Add(book);
            await _db.SaveChangesAsync();

            cmbGenreList.Text = null;
            RefreshInputs();
            RefreshDGV();
        }
Ejemplo n.º 19
0
        private async void DgvEmployeeList_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            var id = (int)dgvEmployeeList.Rows[e.RowIndex].Cells[0].Value;

            Employee employee = _db.Employees.Find(id);

            DialogResult result = MessageBox.Show($"Are you sure confirm {employee.Name} {employee.Surname} ?", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (result == DialogResult.Yes)
            {
                employee.Status = true;
            }
            else
            {
                employee.Deleted = true;
            }

            await _db.SaveChangesAsync();

            ConfirmNewUser();
            DgvNewUser();
        }
Ejemplo n.º 20
0
        private async void btnRgsRegister_Click_1(object sender, EventArgs e)
        {
            string name            = txtRgsName.Text.Trim();
            string surname         = txtRgsSurname.Text.Trim();
            string email           = txtRgsEmail.Text.Trim();
            string password        = txtRgsPassword.Text.Trim();
            string repeat_password = txtRgsRepeatPassword.Text.Trim();

            if (CheckRegistration(name, surname, email, password, repeat_password))
            {
                string hashPassword = Extension.HashPassword(password);
                User   user         = new User()
                {
                    Name     = name,
                    Surname  = surname,
                    Password = hashPassword,
                    Email    = email
                };
                db.Users.Add(user);
                await db.SaveChangesAsync();

                MessageBox.Show("Registration is successfully,please wait confirmation", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Ejemplo n.º 21
0
        private async void BtnReturnBook_Click(object sender, EventArgs e)
        {
            DateTime lateDate = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day);

            if (order.Order.ReturnTime > lateDate)
            {
                order.Order.LateMoney = order.Book.Price * 5 / 1000;
                txbLateMoney.Text     = (order.Order.LateMoney).ToString();
            }
            else
            {
                txbLateMoney.Text = 0.ToString();
            }
            DialogResult result = MessageBox.Show($"Are you want to return {order.Book.Name}", "Information", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (result == DialogResult.Yes)
            {
                order.Order.DeleteOrder = true;
                await _db.SaveChangesAsync();

                dgvReturnOrder.DataSource = null;
                RefreshDGV();
            }
        }
Ejemplo n.º 22
0
 public void Save()
 {
     context.SaveChangesAsync();
 }