コード例 #1
0
        private void DeleteProductButton_Click(object sender, EventArgs e)
        {
            string productname = ExistingProductsList.GetItemText(ExistingProductsList.SelectedItem);

            using (var dbCtx = new POSApplication.Model.posdbEntities())
            {
                var itemToRemove = dbCtx.products.SingleOrDefault(x => x.ProductName == productname);
                if (itemToRemove != null)
                {
                    dbCtx.products.Remove(itemToRemove);
                    dbCtx.SaveChanges();
                    ExistingProductsList.Items.Remove(ExistingProductsList.SelectedItem);
                    clearFields();
                    MessageBox.Show("Product Deleted.");
                }
            }
        }
コード例 #2
0
 private void ExistingProductsList_DoubleClick(object sender, EventArgs e)
 {
     clearFields();
     using (var db = new POSApplication.Model.posdbEntities())
     {
         var ExistingProduct = ExistingProductsList.GetItemText(ExistingProductsList.SelectedItem);
         selectedProductName = ExistingProduct;
         var query = (from d in db.products
                      //join  s in db.suppliers on
                      //d.SupplierID equals s.SupplierID
                      where d.ProductName == ExistingProduct
                      select new
         {
             ProductName = d.ProductName,
             ProductDescription = d.ProductDescription,
             //SupplierName = s == null ? "No Supplier" : s.SupplierName,
             Barcode = d.Barcode,
             WarrantyYears = d.WarrantyPeriodYears,
             GuaranteeYears = d.GuaranteePeriodYears,
             ProductCode = d.ProductCode,
             Size = d.ProductSize,
             Width = d.ProductWidth,
             Height = d.ProductHeight,
             Weight = d.ProductWeight,
             Color = d.ProductColor,
             Image = d.ImageFileName
         }).SingleOrDefault();
         var supplierQuery = (from d in db.products
                              join s in db.suppliers on
                              d.SupplierID equals s.SupplierID
                              where d.ProductName == ExistingProduct
                              select new
         {
             SupplierName = s == null ? "No Supplier" : s.SupplierName
         }).SingleOrDefault();
         CategoryList.Text            = ExistingCategoryList.GetItemText(ExistingCategoryList.SelectedItem);
         ProductNameField.Text        = query.ProductName;
         ProductDescriptionField.Text = query.ProductDescription;
         ProductCodeField.Text        = query.ProductCode;
         if (supplierQuery != null)
         {
             SuppliersList.Text = supplierQuery.SupplierName;
         }
         else
         {
             SuppliersList.Text = "No Supplier";
         }
         ProductBarcodeField.Text = query.Barcode;
         WarrantyField.Text       = query.WarrantyYears;
         GuaranteeField.Text      = query.GuaranteeYears;
         SizeField.Text           = query.Size;
         WidthField.Text          = query.Width;
         WeightField.Text         = query.Weight;
         HeightField.Text         = query.Height;
         ColorField.Text          = query.Color;
         if (query.Image != null)
         {
             try
             {
                 string ImagesDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images");
                 //Console.WriteLine(ImagesDirectory + "\\" + query.Image);
                 filename = ImagesDirectory + "\\" + query.Image;
                 FileStream fs = new FileStream(filename, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                 ProductImage.Image = Image.FromStream(fs);
                 fs.Close();
             }
             catch
             {
             }
         }
     }
 }
コード例 #3
0
        private void ExistingProductsList_DoubleClick(object sender, EventArgs e)
        {
            if (ExistingProductsList.SelectedItem != null)
            {
                clearFields();
                using (var db = new POSApplication.Model.posdbEntities())
                {
                    var ExistingProduct = ExistingProductsList.GetItemText(ExistingProductsList.SelectedItem);
                    int productid       = getProductID(ExistingProduct);
                    selectedProductName = ExistingProduct;
                    DateTime lowdate = DateTime.Parse("1111/11/11");
                    var      query   = (from d in db.inventories
                                        join p in db.products on
                                        d.ProductID equals p.ProductID
                                        join c in db.categories on
                                        p.CategoryID equals c.CategoryID
                                        where d.ProductID == productid && d.UpdateDt == null
                                        orderby d.PurchasePrice descending
                                        select new
                    {
                        CategoryName = c.CategoryName,
                        ProductName = p.ProductName,
                        Barcode = p.Barcode,
                        Quantity = d.SumQuantity,
                        //ReorderLevel = d.ReorderValue,
                        LastCostPrice = d.PurchasePrice,
                        SalePrice = d.SalePrice,
                        LastPurchaseDate = d.PurchaseDate,
                        Imagepath = p.ImageFileName
                    }).FirstOrDefault();
                    CategoryList.Text     = ExistingCategoryList.GetItemText(ExistingCategoryList.SelectedItem);
                    ProductNameField.Text = query.ProductName;
                    BarCodeField.Text     = query.Barcode;

                    var results =
                        (from item in db.inventories
                         where item.ProductID == productid && item.UpdateDt == null
                         group item by item.ProductID into g
                         select new { totalQuantity = g.Sum(item => item.SumQuantity) }).SingleOrDefault();

                    //QuantityField.Text = query.Quantity.ToString();
                    QuantityField.Text = results.totalQuantity.ToString();
                    //ReOrderLevelField.Text = query.ReorderLevel.ToString();
                    CostPriceField.Text    = query.LastCostPrice.ToString();
                    SalePriceField.Text    = query.SalePrice.ToString();
                    PurchaseDateField.Text = query.LastPurchaseDate.ToString();

                    if (query.Imagepath != null)
                    {
                        try
                        {
                            string ImagesDirectory = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Images");
                            Console.WriteLine(ImagesDirectory + "\\" + query.Imagepath);
                            FileStream fs = new FileStream(ImagesDirectory + "\\" + query.Imagepath, System.IO.FileMode.Open, System.IO.FileAccess.Read);

                            ProductImage.Image = Image.FromStream(fs);
                            fs.Close();
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }