private void buttonDodajExcelDoBazy_Click(object sender, EventArgs e)
 {
     if (dataTable != null)
     {
         try
         {
             String deliveryNumberString = dataTable.Columns[4].ToString();
             var    isAdded = context.DeliveryNote.FirstOrDefault(d => d.deliveryNumber == deliveryNumberString);
             if (isAdded == null)
             {
                 LoadDeliveryNote loadDeliveryNote = new LoadDeliveryNote();
                 loadDeliveryNote.addDeliveryNote(comboBoxWidok, dataTable);
                 LoadProduct loadProduct = new LoadProduct();
                 loadProduct.addProduct(dataTable, productBindingSource);
                 FormZalogowany_Load(sender, e);
             }
             else
             {
                 MessageBox.Show("Wybrana faktura została już dodana");
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
     }
 }
Esempio n. 2
0
        public async Task <IActionResult> Load(LoadProduct lp)
        {
            if (ModelState.IsValid)
            {
                string produktet = "Produktet: ";
                foreach (var Load in lp.Loads)
                {
                    //Loaded Product
                    var Produkti = await _context.Products.SingleOrDefaultAsync(p => p.Id == Load.ProductId);

                    produktet += Produkti.Name + "-" + Load.Quantity + " cope, ";
                    //Source Stock
                    var SourceStock = await _context.Stock.Include(s => s.StockLocation).SingleOrDefaultAsync(s => s.ProductId == Load.ProductId && s.StockLocationId == lp.SourceId);

                    if (SourceStock.StockLocation.InHouse)
                    {
                        if (SourceStock.Quantity - Load.Quantity < 0)
                        {
                            ModelState.AddModelError(string.Empty, "Nuk ke sasi te " + Produkti.Name + " mjaftueshem ne " + SourceStock.StockLocation.Name);
                            return(View(lp));
                        }
                        SourceStock.Quantity -= Load.Quantity;
                    }
                    //Destination Stock
                    var DestinationStock = await _context.Stock.SingleOrDefaultAsync(s => s.ProductId == Load.ProductId && s.StockLocationId == lp.DestinationId);

                    DestinationStock.Quantity += Load.Quantity;
                }

                var SourceLocation = await _context.StockLocation.Where(s => s.Id == lp.SourceId).SingleOrDefaultAsync();

                var DestiantionLocation = await _context.StockLocation.Where(s => s.Id == lp.DestinationId).SingleOrDefaultAsync();

                Activity activity = new Activity
                {
                    Date    = DateTime.Now,
                    Comment = User.Identity.Name + " ka bere aranzhim te ketyre produkteve nga " + SourceLocation.Name + " ne " + DestiantionLocation.Name + "." + produktet + ".Komenti:" + lp.Coment
                };
                _context.Activities.Add(activity);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Home"));
            }

            ViewData["Products"] = new SelectList(_context.Set <Product>().OrderBy(p => p.Name), "Id", "Name");

            if (User.IsInRole("ADMIN") || User.IsInRole("PUNETOR BAZE"))
            {
                ViewData["StockLocations"] = new SelectList(_context.Set <StockLocation>().OrderBy(p => p.Name), "Id", "Name");
            }

            else if (User.IsInRole("PUNETOR TERENI"))
            {
                ViewData["StockLocations"] = new SelectList(_context.Set <StockLocation>().Where(s => s.InBase == false && s.InHouse == true).OrderBy(p => p.Name), "Id", "Name");
            }

            return(View(lp));
        }