מחיקת מוצר

הסרטון

הקוד

Delete Product Win

image

 

using System;

using
System.Collections.Generic;

using
System.ComponentModel;

using
System.Data;

using
System.Drawing;

using
System.Linq;

using
System.Text;

using
System.Threading.Tasks;

using
System.Windows.Forms;

 

namespace exampleProj.Forms

{

    public partial class DeleteProductWin : Form

    {

        dbEntities db = new dbEntities();

        List<productView> prodList;

        public DeleteProductWin()

        {

            InitializeComponent();

        }

        private void
DeleteProductWin_Load(
object sender,
EventArgs e)

        {

            prodList = new List<productView>();

            updateAll();

        }

        private void
updateAll()

        {

            prodList = (from s in db.productView orderby s.productName select s).ToList();

            dgvProduct.DataSource =
cbxProduct.DataSource = prodList;

            cbxProduct.DisplayMember = "productName";

            cbxProduct.ValueMember = "Id";

            lblCountProd.Text = "מס המוצרים הוא : " + prodList.Count;

            btnDeleteProduct.Enabled =
prodList.Count > 0;

        }

        private void
btnDeleteProduct_Click(
object sender,
EventArgs e)

        {

            productView p1 =
(productView)cbxProduct.SelectedItem;

            if (p1 == null)

                return;

            if (MessageBox.Show("האם אתה בטוח במחיקה?","מחיקת מוצר", MessageBoxButtons.OKCancel) == DialogResult.OK)

            {

                productTBL prodToDelete = (from s in db.productTBL where s.Id == p1.Id select s).FirstOrDefault();

                db.productTBL.Remove(prodToDelete);

                db.SaveChanges();

                updateAll();

            }          

        }

        private void
DeleteProductWin_FormClosing(
object sender, FormClosingEventArgs e)

        {

            db.Dispose();

        }

    }

}