Esempio n. 1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            int productid = (int)dataGridViewNorthWind.CurrentRow.Cells["ProductID"].Value;

            KuzeyYeliDataContext ctx = new KuzeyYeliDataContext();
            // Lambda expression
            Product product = ctx.Products.SingleOrDefault(Lproduct => Lproduct.ProductID == productid);

            ctx.Products.DeleteOnSubmit(product);
            ctx.SubmitChanges();
            dataGridViewNorthWind.DataSource = ctx.Products;
        }
Esempio n. 2
0
        private void Form1_Load(object sender, EventArgs e)
        {
            KuzeyYeliDataContext ctx = new KuzeyYeliDataContext();

            dataGridViewNorthWind.DataSource = ctx.Products;

            cBoxCategory.DataSource    = ctx.Categories;
            cBoxCategory.DisplayMember = "CategoryName";
            cBoxCategory.ValueMember   = "CategoryID";

            cBoxSupplier.DataSource    = ctx.Suppliers;
            cBoxSupplier.DisplayMember = "CompanyName";
            cBoxSupplier.ValueMember   = "SupplierID";
        }
Esempio n. 3
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            int productid            = (int)txtProductName.Tag;
            KuzeyYeliDataContext ctx = new KuzeyYeliDataContext();
            Product product          = ctx.Products.SingleOrDefault(Lproduct => Lproduct.ProductID == productid);

            product.ProductName  = txtProductName.Text;
            product.UnitPrice    = numericUnitPrice.Value;
            product.UnitsInStock = (short)numericUnitsInStock.Value;
            product.SupplierID   = (int)cBoxSupplier.SelectedValue;
            product.CategoryID   = (int)cBoxCategory.SelectedValue;

            ctx.SubmitChanges();
            dataGridViewNorthWind.DataSource = ctx.Products;
        }
Esempio n. 4
0
        private void rdbProductName_CheckedChanged(object sender, EventArgs e)
        {
            KuzeyYeliDataContext ctx = new KuzeyYeliDataContext();

            if (rdbProductName.Checked)
            {
                dataGridViewNorthWind.DataSource = ctx.Products.OrderBy(x => x.ProductName);
            }
            else if (rdbUnitPrice.Checked)
            {
                dataGridViewNorthWind.DataSource = ctx.Products.OrderByDescending(x => x.UnitPrice);
            }
            else if (rdbUnitsInStcok.Checked)
            {
                dataGridViewNorthWind.DataSource = ctx.Products.OrderByDescending(x => x.UnitsInStock);
            }
        }
Esempio n. 5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            KuzeyYeliDataContext ctx = new KuzeyYeliDataContext();

            Product product = new Product();

            product.ProductName  = txtProductName.Text;
            product.UnitPrice    = numericUnitPrice.Value;
            product.UnitsInStock = (short)numericUnitsInStock.Value;

            product.CategoryID = (int)cBoxCategory.SelectedValue;
            product.SupplierID = (int)cBoxSupplier.SelectedValue;

            ctx.Products.InsertOnSubmit(product);

            ctx.SubmitChanges();

            dataGridViewNorthWind.DataSource = ctx.Products;
        }
Esempio n. 6
0
        private void txtFilter_TextChanged(object sender, EventArgs e)
        {
            KuzeyYeliDataContext ctx = new KuzeyYeliDataContext();

            dataGridViewNorthWind.DataSource = ctx.Products.Where(x => x.ProductName.Contains(txtFilter.Text));
        }