با سلام استاد, حدس میزنم یک چیزی پیدا کردم که دنبالش میگشتین. منظورم اینه:
Barnamenevis.Net.RtlMessageBox.WindowsForms;
using Barnamenevis.Net.RtlMessageBox.WindowsForms;
using DataLayer.Context;
using DataLayer.Models;
using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows;
using System.Windows.Forms;
using Tools.Convertor;
namespace BookKeeper.Books
{
public partial class frmBookManagement : Form
{
BookKeeper_DB_Context bookKeeper = new();
public frmBookManagement()
{
InitializeComponent();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void frmBookManagement_Load(object sender, EventArgs e)
{
BindGrid();
}
#region Data Grid View Books
void BindGrid()
{
dgvBooks.Rows.Clear();
var book = bookKeeper.Books.ToList();
foreach (var item in book)
{
dgvBooks.Rows.Add(item.Id,
item.Title,
item.Subject,
item.AuthorName,
item.Description,
item.Rating,
item.IsAvailable ? "موجود" : "ناموجود",
item.IsFavorite ? "⭐" : "-",
item.IsWishlist ? "📌" : "-",
item.AddedDate.ToShamsiDateOnly()
);
}
}
#endregion
private void btnAdd_Click(object sender, EventArgs e)
{
frmAddBook frmAddBook = new frmAddBook();
frmAddBook.ShowDialog();
if (frmAddBook.DialogResult == DialogResult.Yes)
{
BindGrid();
}
}
private void btnDelete_Click(object sender, EventArgs e)
{
if (dgvBooks.CurrentRow != null)
{
string id = dgvBooks.CurrentRow.Cells[0].Value.ToString();
string bookName = dgvBooks.CurrentRow.Cells[1].Value.ToString();
string authotName = dgvBooks.CurrentRow.Cells[3].Value.ToString();
if (bookName == "CAN'T HURT ME")
{
RtlMessageBox.Show("نمیتوانید از خط را پاک کنید", "خطا", System.Windows.MessageBoxButton.OK, System.Windows.MessageBoxImage.Stop);
}
else
{
int bookId = Convert.ToInt32(id);
string message = $"آیا مطمئنی میخوای کتاب : '{bookName}' از نویسنده : {authotName} را پاک کنی؟ ";
var result = RtlMessageBox.Show(message, "سوال", System.Windows.MessageBoxButton.YesNo, System.Windows.MessageBoxImage.Question);
if (result == MessageBoxResult.Yes)
{
var bookDelete = bookKeeper.Books.Single(b => b.Id == bookId);
bookKeeper.Books.Remove(bookDelete);
bookKeeper.SaveChanges();
BindGrid();
}
}
}
}
}
}
بله خودشه ، ممنون