Beispiel #1
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            String Name = txtSearch.Text.Trim();

            if (Name.Length == 0)
            {
                MessageBox.Show("Please input an ID to search!!!");
            }
            else
            {
                if (manage.FindProduct(int.Parse(Name)).Count == 0)
                {
                    MessageBox.Show("Your Id cannot be found");
                }
                else
                {
                    // dataView.DataSource = manage.FindProduct(int.Parse(Name));
                    List <Product> list   = manage.FindProduct(int.Parse(Name));
                    SearchDetail   detail = new SearchDetail();
                    detail.Show();
                    detail.txtName.Text  = list[0].ProductName.ToString();
                    detail.txtUnit.Text  = list[0].Quantity.ToString();
                    detail.txtPrice.Text = list[0].UnitPrice.ToString();
                    detail.txtTotal.Text = list[0].SubTotal.ToString();
                }
            }
        }
        static void Main2()
        {
            ProductOption prod = new ProductOption
            {
                Name     = "mobile",
                Price    = 300,
                Quantity = 5,
            };

            using CrmDbContext db = new CrmDbContext();
            ProductManagement prodMangr = new ProductManagement(db);


            // product tries
            Product prodFind = prodMangr.FindProduct(2);

            Console.WriteLine(
                $"Id= {prodFind.Id} Name= {prodFind.Name} Price= {prodFind.Price}" +
                $" Quantity= {prodFind.Quantity}");


            //testing reading a customer
            Product pd3 = prod.FindProductById(2);

            Console.WriteLine(
                $"Id= {pd3.Id} Name= {pd3.Name} Price= {pd3.Price} Quantity={pd3.Quantity}");


            //testing updating
            ProductOption prodUpdateName = new ProductOption
            {
                Name = "laptop"
            };
            Product product = prodMangr.Update(prodChangingName, 2);

            pd3 = product;
            Console.WriteLine(
                $"Id= {pd3.Id} Name= {pd3.Name} Price= {pd3.Price} Quantity= {pd3.Quantity}");


            //testing deletion

            bool result = prodMangr.DeleteProductById(3);

            Console.WriteLine($"Result = {result}");
            pd3 = prodMangr.FindProductById(3);
            if (pd3 != null)
            {
                Console.WriteLine(
                    $"Id= {pd3.Id} Name= {pd3.Name} Price= {pd3.Price} Quantity= {pd3.Quantity}");
            }
            else
            {
                Console.WriteLine("The product does not exist");
            }
        }