//Function Key F11
        private void PrintVoucher()
        {
            Sale sale = new Sale();
                int totalQuantity = 0;
                List<SaleProduct> saleProducts = new List<SaleProduct>();

                if(txtBarcode.Text.Length > 0)
                    AddSaleProducts(int.Parse(spnQty.Text.ToString()));

                sale.VoucherNumber = lblVoucherNo.Text;
                sale.SellerID = ZuluContext.Current.CurrentUser.UserID;
                sale.CounterNumber = int.Parse(ApplicationSetting.ClientID);
                sale.SaleTotal = int.Parse(lblTotalAmount.Text.Replace(",", ""));
                sale.GiftVoucherAmount = 0;

                foreach (var loopSaleProductSupport in ZuluContext.Current.SaleProductSupports)
                {
                    totalQuantity = totalQuantity + loopSaleProductSupport.Quantity;
                }

                sale.SaleTotalQuantity = totalQuantity;
                sale.SaleStatus = 2;

                SaleService.SaveSaleVoucher(sale);

                foreach (var loopSaleProductSupport in ZuluContext.Current.SaleProductSupports)
                {
                    SaleProduct saleProduct = new SaleProduct();
                    saleProduct.SaleID = sale.SaleID;
                    saleProduct.ProductBarcode = loopSaleProductSupport.ProductBarcode;
                    saleProduct.ProductName = loopSaleProductSupport.ProductName;
                    saleProduct.Quantity = loopSaleProductSupport.Quantity;
                    saleProduct.UnitPrice = loopSaleProductSupport.UnitPrice;
                    saleProduct.TotalCost = loopSaleProductSupport.TotalCost;

                    saleProducts.Add(saleProduct);
                }

                SaleService.SaveSaleDetails(sale.SaleID, saleProducts);

            frmSaleReceived ReceivedForm = new frmSaleReceived(sale, lblNetAmount.Text);

            NewVoucher();
            ReceivedForm.ShowDialog();
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the SaleProducts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToSaleProducts(SaleProduct saleProduct)
 {
     base.AddObject("SaleProducts", saleProduct);
 }
 /// <summary>
 /// Create a new SaleProduct object.
 /// </summary>
 /// <param name="saleProductID">Initial value of the SaleProductID property.</param>
 public static SaleProduct CreateSaleProduct(global::System.Int32 saleProductID)
 {
     SaleProduct saleProduct = new SaleProduct();
     saleProduct.SaleProductID = saleProductID;
     return saleProduct;
 }
        ///<summary>
        ///Save Sale Voucher
        ///</summary>
        ///<param name="saleID">The Sale Identifier.</param>
        ///<param name="saleProducts">The Sale Products.</param>
        public void SaveSaleDetails(SaleProduct saleproduct)
        {
            SaleProduct existingData = GetSaleProductByID(saleproduct.SaleProductID);

            if (existingData == null)
            {
                //saleproduct.CreatedOn = DateTime.Now;
                _context.SaleProducts.AddObject(saleproduct);
            }
            else
            {
                existingData.SaleID = saleproduct.SaleID;
                existingData.ProductBarcode = saleproduct.ProductBarcode;
                existingData.ProductName = saleproduct.ProductName;
                existingData.Quantity = saleproduct.Quantity;
                existingData.UnitPrice = saleproduct.UnitPrice;
                existingData.TotalCost = saleproduct.TotalCost;

                if (!_context.IsAttached(existingData))
                    _context.SaleProducts.Attach(existingData);
            }
            _context.SaveChanges();
        }