Esempio n. 1
0
 protected async void gvCategories_RowCommand(object sender, GridViewCommandEventArgs e)
 {
     serviceDAO service = new serviceDAO();
     try
     {
         List<Category> category = await service.GetCategory(Convert.ToInt32(gvCategories.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text));
         if (category != null && category.Count > 0)
         {
             if (e.CommandName == "editar")
             {
                 txtCategory.Text = category[0].Name;
                 btnUpdate.Text = "Update";
                 lblIDHidden.Text = category[0].Id.ToString();
             }
             else if (e.CommandName == "eliminar")
             {
                 List<Book> bookAssignments = await service.GetAssignmentsCategories(Convert.ToInt32(gvCategories.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text));
                 if (bookAssignments != null && bookAssignments.Count > 1)
                     ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('Invalid operation, The item is assigned to one or more books');", true);
                 else
                 {
                     service.DeleteCategory(category[0]);
                     await loadCategories(service, 0, 0);
                 }
             }
         }
     }
     catch (Exception Ex)
     {
         ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('An error has ocurred, please contact with your software provider');", true);
     }
 }
Esempio n. 2
0
    protected async void btnUpdate_Click(object sender, EventArgs e)
    {
        serviceDAO service = new serviceDAO();
        try
        {
            if (btnUpdate.Text == "Add")
            {
                Category category = new Category();
                category.Name = txtCategory.Text;
                service.AddCategory(category);

                await loadCategories(service, 0, 0);
                txtCategory.Text = string.Empty;
            }
            else
            {
                List<Category> category = await service.GetCategory(Convert.ToInt32(lblIDHidden.Text));
                category[0].Name = txtCategory.Text;
                service.UpdateCategory(category[0]);

                await loadCategories(service, 0, 0);
                txtCategory.Text = string.Empty;
                btnUpdate.Text = "Add";
            }
        }
        catch (Exception Ex)
        {
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('An error has ocurred, please contact with your software provider');", true);
        }
    }
Esempio n. 3
0
    private async Task loadAuthors(serviceDAO service)
    {
        List<Author> authors = await service.GetAllAuthors();
        ddlAuthor.DataSource = authors;
        ddlAuthor.DataValueField = "Id";
        ddlAuthor.DataTextField = "Name";
        ListItem selec = new ListItem("Select...", "0");

        ddlAuthor.DataBind();
        selec.Selected = true;
        ddlAuthor.Items.Insert(0, selec);
    }
Esempio n. 4
0
    private async Task loadCategories(serviceDAO service)
    {
        List<Category> category = await service.GetAllCategories();
        ddlCategory.DataSource = category;
        ddlCategory.DataValueField = "Id";
        ddlCategory.DataTextField = "Name";
        ListItem selec = new ListItem("Select...", "0");

        ddlCategory.DataBind();
        selec.Selected = true;
        ddlCategory.Items.Insert(0, selec);
    }
Esempio n. 5
0
 protected async void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         serviceDAO service = new serviceDAO();
         try
         {
             await loadCategories(service, 0, 0);
         }
         catch (Exception Ex)
         {
             ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('An error has ocurred, please contact with your software provider');", true);
         }
     }
 }
Esempio n. 6
0
    private async Task loadAuthors(serviceDAO service, int init, int currentPage)
    {
        List<Author> authors = await service.GetAllAuthors();
        int fin = init + gvAuthors.PageSize;
        if (authors != null && fin > authors.Count)
            fin = authors.Count;
        gvAuthors.PageIndex = currentPage;

        gvAuthors.DataSource = authors;
        gvAuthors.DataBind();
        for (int i = init; i < fin; i++)
        {
            List<Country> countries = await service.GetCountry(authors[i].IdCountry);
            if (countries != null && countries.Count > 0)
                ((ImageButton)gvAuthors.Rows[i].Cells[3].Controls[0]).ImageUrl = "images/flags/" + countries[0].Code + ".png";
            ((ImageButton)gvAuthors.Rows[i].Cells[5].Controls[0]).Attributes.Add("OnClick", "if(!confirm('The entry will be deleted, are you sure?'))return false;");
        }
    }
Esempio n. 7
0
    private async Task loadAuthorsActives(serviceDAO service)
    {
        List<BookFull> books = await service.GetAllBooksFull(0);


        foreach (BookFull bf in books)
        {
            ListItem item = new ListItem();
            item.Text = bf.Author;
            item.Value = bf.IdAuthor.ToString();
            if(ddlAuthorsActives.Items.FindByValue(item.Value)==null)
                ddlAuthorsActives.Items.Add(item);
        }
        ListItem selec = new ListItem("All", "0");
        ddlAuthorsActives.DataBind();


        selec.Selected = true;
        ddlAuthorsActives.Items.Insert(0, selec);
    }
Esempio n. 8
0
    private async Task loadBooks(serviceDAO service, int init, int currentPage)
    {
        List<BookFull> books;
        if (ddlAuthorsActives.SelectedValue=="0")
            books = await service.GetAllBooksFull(0);
        else        
            books = await service.GetAllBooksFull(Int32.Parse(ddlAuthorsActives.SelectedValue));        
        int fin = init + gvBooks.PageSize;
        if (books != null && fin > books.Count)
            fin = books.Count;
        gvBooks.PageIndex = currentPage;

        gvBooks.DataSource = books;
        gvBooks.DataBind();
        for (int i = init; i < fin; i++)
        {
            ((ImageButton)gvBooks.Rows[i].Cells[6].Controls[0]).ImageUrl = "images/flags/" + books[i].Country + ".png";
            ((ImageButton)gvBooks.Rows[i].Cells[7].Controls[0]).Attributes.Add("OnClick", "if(!confirm('The entry will be deleted, are you sure?'))return false;");
        }
    }
Esempio n. 9
0
    protected async void gvAuthors_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        serviceDAO service = new serviceDAO();
        try
        {
            List<Author> author = await service.GetAuthor(Convert.ToInt32(gvAuthors.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text));
            if (author != null && author.Count > 0)
            {
                if (e.CommandName == "editar")
                {
                    ModalPopupExtender1.Show();
                    List<Author> authors = await service.GetAuthor(author[0].Id);
                    lblIDAuthor.Text = authors[0].Id.ToString();
                    txtAuthorName.Text = authors[0].Name;
                    txtAuthorLastName.Text = authors[0].LastName;
                    ddlCountry.SelectedValue = authors[0].IdCountry.ToString();
                    btnAddAuthor.Text = "Update";

                }
                else if (e.CommandName == "eliminar")
                {
                    List<Book> bookAssignments = await service.GetAssignmentsAuthors(Convert.ToInt32(gvAuthors.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text));
                    if (bookAssignments != null && bookAssignments.Count > 1)
                        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('Invalid operation, The item is assigned to one or more books');", true);
                    else
                    {
                        service.DeleteAuthor(author[0]);
                        await loadAuthors(service, 0, 0);
                    }
                }
            }
        }
        catch (Exception Ex)
        {
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('An error has ocurred, please contact with your software provider');", true);
        }
    }
Esempio n. 10
0
    protected async void gvBooks_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "eliminar")
        {

            serviceDAO service = new serviceDAO();
            try
            {
                List<Book> book = await service.GetBook(Convert.ToInt32(gvBooks.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text));
                service.DeleteBook(book[0]);
                await loadBooks(service, 0, 0);
            }
            catch (Exception Ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('An error has ocurred, please contact with your software provider');", true);
            }
        }
    }
Esempio n. 11
0
    protected async void ddlAuthorsActives_SelectedIndexChanged(object sender, EventArgs e)
    {
        serviceDAO service = new serviceDAO();
        List<BookFull> books;
        if (ddlAuthorsActives.SelectedValue == "0")
            books = await service.GetAllBooksFull(0);
        else
            books = await service.GetAllBooksFull(Int32.Parse(ddlAuthorsActives.SelectedValue));


        gvBooks.DataSource = books;
        gvBooks.DataBind();
        for (int i = 0; i < gvBooks.Rows.Count; i++)
        {
            ((ImageButton)gvBooks.Rows[i].Cells[6].Controls[0]).ImageUrl = "images/flags/" + books[i].Country + ".png";
            ((ImageButton)gvBooks.Rows[i].Cells[7].Controls[0]).Attributes.Add("OnClick", "if(!confirm('The entry will be deleted, are you sure?'))return false;");
        }
    }
Esempio n. 12
0
    protected async void btnAddBookAcept_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {
            try
            {
                lblError.Text = string.Empty;
                serviceDAO service = new serviceDAO();
                Book book = new Book();
                book.IdAuthor = Int32.Parse(ddlAuthor.SelectedValue);
                book.IdCategory = Int32.Parse(ddlCategory.SelectedValue);
                book.ISBN = txtISBN.Text;
                book.Title = txtTitle.Text;
                book.Publisher = txtPublisher.Text;
                service.AddBook(book);

                ddlAuthor.SelectedValue = "0";
                ddlCategory.SelectedValue = "0";
                txtISBN.Text = txtTitle.Text = txtPublisher.Text = string.Empty;
                await loadBooks(service, 0, 0);
                ModalPopupExtender1.Hide();
            }
            catch (Exception Ex)
            {
                ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('An error has ocurred, please contact with your software provider');", true);
            }
        }
        else
        {
            lblError.Text = "*All information is required";
            ModalPopupExtender1.Show();
        }
    }
Esempio n. 13
0
    private async Task loadCategories(serviceDAO service, int init, int currentPage)
    {
        List<Category> categorias = await service.GetAllCategories();
        int fin = init + gvCategories.PageSize;
        if (categorias != null && fin > categorias.Count)
            fin = categorias.Count;
        gvCategories.PageIndex = currentPage;

        gvCategories.DataSource = categorias;
        gvCategories.DataBind();
        for (int i = init; i < fin; i++)
            ((ImageButton)gvCategories.Rows[i].Cells[3].Controls[0]).Attributes.Add("OnClick", "if(!confirm('The entry will be deleted, are you sure?'))return false;");
    }
Esempio n. 14
0
 protected async void gvCategories_PageIndexChanging(object sender, GridViewPageEventArgs e)
 {
     serviceDAO service = new serviceDAO();
     try
     {
         await loadCategories(service, (gvCategories.PageSize * e.NewPageIndex), e.NewPageIndex);
     }
     catch (Exception Ex)
     {
         ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('An error has ocurred, please contact with your software provider');", true);
     }
 }
Esempio n. 15
0
    protected async void btnAddAuthor_Click(object sender, EventArgs e)
    {
        try
        {
            serviceDAO service = new serviceDAO();
            if (Page.IsValid)
            {
                lblError.Text = string.Empty;

                if (btnAddAuthor.Text == "Add")
                {
                    Author author = new Author();
                    author.Name = txtAuthorName.Text;
                    author.LastName = txtAuthorLastName.Text;
                    author.IdCountry = Int32.Parse(ddlCountry.SelectedValue);
                    service.AddAuthor(author);
                }
                else
                {
                    List<Author> author = await service.GetAuthor(Int32.Parse(lblIDAuthor.Text));
                    author[0].Name = txtAuthorName.Text;
                    author[0].LastName = txtAuthorLastName.Text;
                    author[0].IdCountry = Int32.Parse(ddlCountry.SelectedValue);
                    service.UpdateAuthor(author[0]);

                    await loadAuthors(service, 0, 0);
                }

                await loadAuthors(service, 0, 0);
                txtAuthorName.Text = txtAuthorLastName.Text = string.Empty;
                ddlCountry.SelectedValue = "0";
                btnAddAuthor.Text = "Add";

            }
            else
            {
                lblError.Text = "*All information is required";
                ModalPopupExtender1.Show();
            }
        }
        catch (Exception Ex)
        {
            ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), Guid.NewGuid().ToString(), "alert('An error has ocurred, please contact with your software provider');", true);
        }
    }