예제 #1
0
        private void JO_Tool_ReadAuthors_Click(object sender, EventArgs e)
        {
            //If setup for grid has already been done, just refresh the grid.
            if (_gridSetupDone == true)
            {
                RefreshGrid();
                return;
            }
            JO_DataGrid_Authors.AutoGenerateColumns = false;
            JO_DataGrid_Authors.ColumnCount         = 3;
            JO_DataGrid_Authors.DataSource          = BiblioQueries.GetAuthors(connection);

            //Hide author id row for later to use.
            JO_DataGrid_Authors.Columns[0].Name             = "AuthorID";
            JO_DataGrid_Authors.Columns[0].DataPropertyName = "AuthorID";
            JO_DataGrid_Authors.Columns[0].Visible          = false;

            JO_DataGrid_Authors.Columns[1].Name             = "Name";
            JO_DataGrid_Authors.Columns[1].DataPropertyName = "Name";

            JO_DataGrid_Authors.Columns[2].Name             = "Year Born";
            JO_DataGrid_Authors.Columns[2].DataPropertyName = "YearBorn";


            _gridSetupDone = true;
        }
예제 #2
0
파일: JO_YL1.cs 프로젝트: Dzeikob/Praktika3
        private void JO_Btn_Insert_Click(object sender, EventArgs e)
        {
            Author author = new Author();

            author.Name     = JO_TextBox_Author.Text;
            author.YearBorn = JO_TxtBoxYearBorn.Text;

            BiblioQueries.InsertToDatabase(author, connection);
            SyncAuthors();
        }
예제 #3
0
파일: JO_YL1.cs 프로젝트: Dzeikob/Praktika3
        private void JO_Btn_Delete_Click(object sender, EventArgs e)
        {
            Author author = (Author)JO_ListBox_Authors.SelectedItem;

            //Sync authors list only when DeleteAuthor successfully deleted a record
            if (BiblioQueries.DeleteAuthor(author.AuthorID, connection) == true)
            {
                SyncAuthors();
            }
        }
예제 #4
0
        private void JO_Btn_Titles_Click(object sender, EventArgs e)
        {
            int rowIndex = JO_DataGrid_Authors.SelectedCells[0].RowIndex;
            int authorID = (int)JO_DataGrid_Authors.Rows[rowIndex].Cells["AuthorID"].Value;

            JO_DataGrid_Titles.Rows.Clear();
            foreach (string item in BiblioQueries.GetTitles(authorID, connection))
            {
                JO_DataGrid_Titles.Rows.Add(item);
            }
        }
예제 #5
0
파일: JO_YL1.cs 프로젝트: Dzeikob/Praktika3
        private void JO_Btn_Update_Click(object sender, EventArgs e)
        {
            Author oldAuthor = (Author)JO_ListBox_Authors.SelectedItem;
            Author newAuthor = new Author();

            newAuthor.Name     = JO_TextBox_Author.Text;
            newAuthor.YearBorn = JO_TxtBoxYearBorn.Text;

            BiblioQueries.UpdateAuthor(oldAuthor.AuthorID, newAuthor, connection);
            SyncAuthors();
        }
예제 #6
0
파일: JO_YL1.cs 프로젝트: Dzeikob/Praktika3
        private void SyncAuthors()
        {
            var watch = System.Diagnostics.Stopwatch.StartNew();

            JO_ListBox_Authors.DataSource = BiblioQueries.GetAuthors(connection);
            JO_Lbl_AuthorsCount.Text      = JO_ListBox_Authors.Items.Count.ToString();

            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            JO_Lbl_AuthorsTimeTaken.Text = elapsedMs.ToString() + " ms";
        }
예제 #7
0
        private void JO_DataGrid_Authors_CellValueChanged(object sender, DataGridViewCellEventArgs e)
        {
            int rowIndex = e.RowIndex;

            Author author = new Author();

            author.AuthorID = (int)JO_DataGrid_Authors.Rows[rowIndex].Cells["AuthorID"].Value;

            if (JO_DataGrid_Authors.Rows[rowIndex].Cells["Name"].Value == null)
            {
                BiblioQueries.DeleteAuthor(author.AuthorID, connection);
                RefreshGrid();
            }
            else
            {
                author.Name     = JO_DataGrid_Authors.Rows[rowIndex].Cells["Name"].Value.ToString();
                author.YearBorn = JO_DataGrid_Authors.Rows[rowIndex].Cells["Year Born"].Value.ToString();
                BiblioQueries.UpdateAuthor(author.AuthorID, author, connection);
            }
        }
예제 #8
0
파일: JO_YL1.cs 프로젝트: Dzeikob/Praktika3
        private void JO_Btn_Titles_Click(object sender, EventArgs e)
        {
            if (JO_ListBox_Authors.SelectedIndex == -1)
            {
                return;
            }

            var watch = System.Diagnostics.Stopwatch.StartNew();

            Author author = (Author)JO_ListBox_Authors.SelectedItem;

            JO_ListBox_Titles.DataSource = BiblioQueries.GetTitles(author.AuthorID, connection);

            var elapsedMs = watch.ElapsedMilliseconds;

            JO_Lbl_TitlesTimeTaken.Text = elapsedMs.ToString() + " ms";
            JO_Lbl_TitlesCount.Text     = JO_ListBox_Titles.Items.Count.ToString();

            JO_ListBox_Titles.SelectedIndex = -1;
        }
예제 #9
0
 private void RefreshGrid()
 {
     JO_DataGrid_Authors.DataSource = BiblioQueries.GetAuthors(connection);
 }