הוספת קטגוריה והוספת מוצר

הסרטון

הקוד

 

 

Add Category Win

תמונת החלון

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 AddCategoryWin : Form

    {

        dbEntities db = new dbEntities();       

        List<categoryTBL> catList;

        public AddCategoryWin()

        {

            InitializeComponent();

        }

 

        private void
AddCategoryWin_Load(
object sender,
EventArgs e)

        {

            updateAll();

        }

        private void
updateAll()

        {

           

            catList = (from s in db.categoryTBL orderby s.name select
s).ToList();           

            dgvCategory.DataSource = catList;

            lblCountCat.Text = "מספר הקטגוריות הוא : " + catList.Count;           

        }

        private void
btnAddCat_Click(
object sender,
EventArgs e)

        {

            // need to
implement validation

            categoryTBL c1 = new categoryTBL();

            c1.name = txbCatName.Text.Trim();

            c1.description =
txbCatDesc.Text.Trim();

            db.categoryTBL.Add(c1);

            db.SaveChanges();

            txbCatDesc.Text = "";

            txbCatName.Text = "";

            updateAll();

        }

 

        private void
AddCategoryWin_FormClosing(
object sender, FormClosingEventArgs e)

        {

            db.Dispose();

        }

    }

}

 

Add Product Winclip_image004

 

using System;

using
System.Collections.Generic;

using
System.ComponentModel;

using
System.Data;

using
System.Drawing;

using
System.Linq;

using
System.Text;

using
System.Threading;

using
System.Threading.Tasks;

using
System.Windows.Forms;

 

namespace exampleProj.Forms

{

    public partial class AddProductWin : Form

    {

        dbEntities db = new dbEntities();

        List<productView> prodList;

        List<categoryTBL> catList;

      

        public AddProductWin()

        {

            InitializeComponent();

        }

 

        private void AddProductWin_Load(object sender, EventArgs e)

        {          

            updateAll();           

        }

      

        private void
updateAll()

        {

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

            catList = (from s in db.categoryTBL select s).ToList();

            dgvProduct.DataSource = prodList;

            cbxCategory.DataSource = catList;

            cbxCategory.DisplayMember = "name";

            cbxCategory.ValueMember = "Id";

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

        }

        private void
btnAddProduct_Click(
object sender,
EventArgs e)

        {

            productTBL p1 = new productTBL();

            p1.name = txbProdName.Text.Trim();

            string priceStr =
txbProdPrice.Text.Trim();

            p1.price =
Convert.ToInt32(priceStr);

            categoryTBL c1 =
(categoryTBL)cbxCategory.SelectedItem;

            p1.catID = c1.Id;

            db.productTBL.Add(p1);

            db.SaveChanges();

            txbProdName.Text = "";

            txbProdPrice.Text = "";

            updateAll();

        }

        private void
AddProductWin_FormClosing(
object sender,
FormClosingEventArgs e)

        {

            db.Dispose();

        }

 

    }

}