コード例 #1
0
ファイル: MainForm.cs プロジェクト: animtel/CourseProject
        private void ButEditBook_Click(object sender, EventArgs e)
        {
            int idOfBook = Int32.Parse(DataGrid.CurrentRow.Cells[0].Value.ToString());

            EditBook _bookform = new EditBook(this, _db.Books.Single(item => item.Id == idOfBook));

            _bookform.ShowDialog();
            if (_bookform.flag)
            {
                try
                {
                    using (IDbConnection db = new SqlConnection(_connectionString))
                    {
                        var sqlQuery = "UPDATE dbo.Books SET Name = @Name, Author = @Author, Publishing = @Publishing, Year = @Year, Amount = @Amount, Price = @Price, SeriesId = @SeriesId WHERE Id = @Id";
                        db.Execute(sqlQuery, new Books
                        {
                            Name       = _bookform.Name,
                            Author     = Int32.Parse(_bookform.Author),
                            Amount     = _bookform.Amount,
                            Price      = _bookform.Price,
                            SeriesId   = Int32.Parse(_bookform.Serieses),
                            Publishing = _bookform.Publishing,
                            Year       = Int32.Parse(_bookform.Year)
                        });
                    }

                    _db.SaveChanges();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #2
0
        private void sbtnSuaDS_Click(object sender, EventArgs e)
        {
            Sach sach = new Sach();

            sach.ma      = grvSach.GetFocusedRowCellValue("ma").ToString();
            sach.ten     = grvSach.GetFocusedRowCellValue("ten").ToString();
            sach.sotrang = int.Parse(grvSach.GetFocusedRowCellValue("sotrang").ToString());
            sach.gia     = int.Parse(grvSach.GetFocusedRowCellValue("gia").ToString());
            sach.soluong = int.Parse(grvSach.GetFocusedRowCellValue("soluong").ToString());
            // sach.ngaynhap = DateTime.Parse(grvSach.GetFocusedRowCellValue("ngaynhap").ToString());
            sach.nhaxuatbanma = grvSach.GetFocusedRowCellValue("nhaxuatbanma").ToString();
            sach.tacgiama     = grvSach.GetFocusedRowCellValue("tacgiama").ToString();
            sach.theloaima    = grvSach.GetFocusedRowCellValue("theloaima").ToString();
            if (bool.Parse(grvSach.GetFocusedRowCellValue("tinhtrang").ToString()) == true)
            {
                sach.tinhtrang = true;
            }
            //sach.tinhtrang = true;
            else
            {
                sach.tinhtrang = false;
            }
            sach.noidungtomtat = grvSach.GetFocusedRowCellValue("noidungtomtat").ToString();
            EditBook edit = new EditBook(sach);

            edit.ShowDialog();
            listSach = controller.getListSach();
            grcDSDauSach.DataSource = listSach;
        }
コード例 #3
0
        private void editBookbtn_Click(object sender, EventArgs e)
        {
            try
            {
                EditBook editBook = new EditBook();
                editBook.bookID = Int32.Parse(booksDataGridView.Rows[booksDataGridView.SelectedRows[0].Index].Cells[0].Value.ToString());
                editBook.ShowDialog();

                InformationForm information = new InformationForm("Selected book is edited.", "Info");
                information.Show();
            }
            catch (ArgumentOutOfRangeException)
            {
                MessageBox.Show("Please select a row first!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.ViewBooks_Load(sender, e);
            }
        }
コード例 #4
0
 private void button3_Click(object sender, EventArgs e)
 {
     LibrarianAssistant.EditBook edit = new EditBook();
     edit.ShowDialog();
 }