Example #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        XMLAccess xmlAccess = new XMLAccess();
        DataSet   data      = xmlAccess.GetBookNodes();

        BooksGridView.DataSource = data.Tables[0];
        BooksGridView.DataBind();
    }
 private void exitEditToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Height = Screen.FromControl(this).Bounds.Height - 250;
     updateBox.Hide();
     BookSearchGroupBox.Show();
     BooksGridView.Show();
     BookSearchFormPanel.Show();
     exitEditToolStripMenuItem.Enabled         = false;
     editBookDetailsToolStripMenuItem1.Enabled = true;
     _selectedId = 0;
 }
        private void BindBookData()
        {
            string        connectionString = ConfigurationManager.ConnectionStrings["Comp229-TeamAssign"].ConnectionString;
            SqlConnection conn             = new SqlConnection(connectionString);
            SqlCommand    comm             = new SqlCommand("select * from MyBooks", conn);

            try
            {
                // Opening database connection
                conn.Open();
                SqlDataReader reader = comm.ExecuteReader();
                BooksGridView.DataSource = reader;
                BooksGridView.DataBind();
                reader.Close();
            }
            finally
            {
                //Closing database connection
                conn.Close();
            }
        }
        private void editBookDetailsToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if (_selectedId > 0)
            {
                BooksGridView.Hide();
                BookSearchFormPanel.Hide();
                BookSearchGroupBox.Hide();
                this.Height = Screen.FromControl(this).Bounds.Height - 450;
                GetUpdatableData();
                updateBox.Show();

                _bookDeleIdList = _emptyList;

                editBookDetailsToolStripMenuItem1.Enabled = false;
                exitEditToolStripMenuItem.Enabled         = true;
            }
            else
            {
                var objDialogWindow = new DialogWindow("Please select a row to update/Edit", "Warning Dialog", DialogWindow.DialogBoxIconType.Exclamation);
                objDialogWindow.ShowDialog();
            }
        }
Example #5
0
 private void HandleNewBook(object sender, EventArgs e)
 {
     bookClassTableAdapter.Fill(BooksDataSet.BookClass);
     BooksGridView.Refresh();
 }
        private void UpdateSaveButton_Click(object sender, EventArgs e)
        {
            if (_selectedId > 0)
            {
                var numRegex = new Regex("[0-9]");

                if (SubjectTextBox.Text == "")
                {
                    label11.Show();
                }
                if (TitleTextBox.Text == "")
                {
                    label12.Show();
                }
                if (AuthorTextBox.Text == "")
                {
                    label13.Show();
                }
                if (PublisherTextBox.Text == "")
                {
                    label14.Show();
                }
                if (EditionTextBox.Text == "")
                {
                    label15.Show();
                }

                if (PageTextBox.Text == "")
                {
                    label21.Hide();
                    label16.Show();
                }
                if (PageTextBox.Text != "")
                {
                    if (!numRegex.IsMatch(PageTextBox.Text))
                    {
                        label16.Hide();
                        label21.Show();
                    }
                    if (numRegex.IsMatch(PageTextBox.Text))
                    {
                        label16.Hide();
                        label16.Hide();
                    }
                }
                if (IsbnTextBox.Text == "")
                {
                    label17.Show();
                }

                if (AmountTextBox.Text == "")
                {
                    label22.Hide();
                    label18.Show();
                }
                if (AmountTextBox.Text != "")
                {
                    if (!numRegex.IsMatch(AmountTextBox.Text))
                    {
                        label18.Hide();
                        label22.Show();
                    }
                    if (numRegex.IsMatch(AmountTextBox.Text))
                    {
                        label18.Hide();
                        label22.Hide();
                    }
                }
                if (LibraryTextBox.Text == "")
                {
                    label19.Show();
                }
                if (SelfTextBox.Text == "")
                {
                    label20.Show();
                }

                if (SubjectTextBox.Text == "" || TitleTextBox.Text == "" || AuthorTextBox.Text == "" ||
                    PublisherTextBox.Text == "" || EditionTextBox.Text == "" || PageTextBox.Text == "" ||
                    IsbnTextBox.Text == "" ||
                    AmountTextBox.Text == "" || LibraryTextBox.Text == "" || SelfTextBox.Text == "")
                {
                    return;
                }
                if (!numRegex.IsMatch(PageTextBox.Text) || !numRegex.IsMatch(AmountTextBox.Text) ||
                    !numRegex.IsMatch(EditionTextBox.Text) || !numRegex.IsMatch(SelfTextBox.Text))
                {
                    return;
                }

                try
                {
                    var bookKUpdateClass = new BookUpdateClass()
                    {
                        Subject     = SubjectTextBox.Text,
                        Title       = TitleTextBox.Text,
                        Author      = AuthorTextBox.Text,
                        Publisher   = PublisherTextBox.Text,
                        Edition     = Convert.ToInt32(EditionTextBox.Text),
                        Pages       = Convert.ToInt32(PageTextBox.Text),
                        TotalNumber = Convert.ToInt32(AmountTextBox.Text),
                        Library     = LibraryTextBox.Text,
                        SelfNumber  = Convert.ToInt32(SelfTextBox.Text),
                        Isbn        = IsbnTextBox.Text
                    };

                    _connection.Open();

                    var sqlCommand =
                        new SqlCommand(
                            "update  Book set Subject=@Subject,Title=@Title,Author=@Author,Publisher=@Publisher,Edition=@Edition,Pages=@Pages,Isbn=@Isbn,NumberOfBooks=@TotalNumber,Library=@Library,ShelfNo=@SelfNumber where BookId=@Id",
                            _connection);

                    sqlCommand.Parameters.AddWithValue("@Subject", bookKUpdateClass.Subject);
                    sqlCommand.Parameters.AddWithValue("@Title", bookKUpdateClass.Title);
                    sqlCommand.Parameters.AddWithValue("@Author", bookKUpdateClass.Author);
                    sqlCommand.Parameters.AddWithValue("@Publisher", bookKUpdateClass.Publisher);


                    sqlCommand.Parameters.AddWithValue("@Edition", bookKUpdateClass.Edition);
                    sqlCommand.Parameters.AddWithValue("@Pages", bookKUpdateClass.Pages);
                    sqlCommand.Parameters.AddWithValue("@Isbn", bookKUpdateClass.Isbn);
                    sqlCommand.Parameters.AddWithValue("@TotalNumber", bookKUpdateClass.TotalNumber);
                    sqlCommand.Parameters.AddWithValue("@Library", bookKUpdateClass.Library);
                    sqlCommand.Parameters.AddWithValue("@SelfNumber", bookKUpdateClass.SelfNumber);
                    sqlCommand.Parameters.AddWithValue("@Id", _selectedId);
                    sqlCommand.ExecuteNonQuery();

                    _connection.Close();
                    SubjectTextBox.Text   = "";
                    TitleTextBox.Text     = "";
                    AuthorTextBox.Text    = "";
                    PublisherTextBox.Text = "";
                    EditionTextBox.Text   = "";
                    PageTextBox.Text      = "";
                    AmountTextBox.Text    = "";
                    LibraryTextBox.Text   = "";
                    SelfTextBox.Text      = "";
                    IsbnTextBox.Text      = "";
                    MessageBox.Show(@"Updated successfully", "", MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    updateBox.Hide();
                    BooksGridView.Show();
                    LoadBookGridView();
                    UpdateSaveButton.Hide();

                    BookSearchFormPanel.Show();
                    _selectedId = 0;
                    editBookDetailsToolStripMenuItem1.Enabled = true;
                    exitEditToolStripMenuItem.Enabled         = false;
                    Height = Screen.FromControl(this).Bounds.Height - 250;
                }
                catch (Exception)
                {
                    MessageBox.Show(
                        @"Something may be wrong.Please make sure that all data fields are valid.Specially make  sure that all integer fields have valid value!",
                        "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show(@"Unable to update.Something wrong ", "",
                                MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #7
0
 protected void Page_Load(object sender, EventArgs e)
 {
     _dataSet = CreateDataSet();
     BooksGridView.DataSource = _dataSet.Tables["Books"];
     BooksGridView.DataBind();
 }