75c01c08e9
x selezione magazzino SX/DX da select
175 lines
5.7 KiB
C#
175 lines
5.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data;
|
|
using System.Data.Entity;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
using StockManMVC.Models;
|
|
|
|
namespace StockManMVC.Controllers
|
|
{
|
|
public class ItemStocksController : Controller
|
|
{
|
|
private StockManEntities db = new StockManEntities();
|
|
|
|
|
|
/// <summary>
|
|
/// Selezione
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
/// <returns></returns>
|
|
public static IEnumerable<ItemStock> Select(int? ItemID)
|
|
{
|
|
StockManEntities db = new StockManEntities();
|
|
if (ItemID == null)
|
|
{
|
|
ItemID = 0;
|
|
}
|
|
var answ = db.ItemStock.Where(s => s.ItemID == ItemID);
|
|
return answ;
|
|
}
|
|
/// <summary>
|
|
/// calcolo num risultati
|
|
/// </summary>
|
|
/// <param name="ItemID"></param>
|
|
/// <returns></returns>
|
|
public static int SelectCount(int? ItemID)
|
|
{
|
|
return Select(ItemID).Count();
|
|
}
|
|
|
|
// GET: ItemStocks
|
|
public ActionResult Index()
|
|
{
|
|
var itemStock = db.ItemStock.Include(i => i.Item).Include(i => i.Location);
|
|
return View(itemStock.ToList());
|
|
}
|
|
|
|
/// <summary>
|
|
/// Elenco x famiglia ordine qta desc
|
|
/// </summary>
|
|
/// <param name="LocationID"></param>
|
|
/// <returns></returns>
|
|
public ActionResult ListByLocation(string LocationID)
|
|
{
|
|
if (LocationID == null) LocationID = "";
|
|
var itemStock = db.ItemStock.Where(s => s.LocationID == LocationID && s.QtyConf > 0).OrderByDescending(x => x.QtyConf);
|
|
return PartialView("ListByLocation", itemStock);
|
|
}
|
|
|
|
// GET: ItemStocks/Details/5
|
|
public ActionResult Details(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
ItemStock itemStock = db.ItemStock.Find(id);
|
|
if (itemStock == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(itemStock);
|
|
}
|
|
|
|
// GET: ItemStocks/Create
|
|
public ActionResult Create()
|
|
{
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr");
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr");
|
|
return View();
|
|
}
|
|
|
|
// POST: ItemStocks/Create
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Create([Bind(Include = "ID,ItemID,LocationID,QtyConf,Note,dtLastUpd")] ItemStock itemStock)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.ItemStock.Add(itemStock);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr", itemStock.ItemID);
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", itemStock.LocationID);
|
|
return View(itemStock);
|
|
}
|
|
|
|
// GET: ItemStocks/Edit/5
|
|
public ActionResult Edit(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
ItemStock itemStock = db.ItemStock.Find(id);
|
|
if (itemStock == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr", itemStock.ItemID);
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", itemStock.LocationID);
|
|
return View(itemStock);
|
|
}
|
|
|
|
// POST: ItemStocks/Edit/5
|
|
// To protect from overposting attacks, please enable the specific properties you want to bind to, for
|
|
// more details see http://go.microsoft.com/fwlink/?LinkId=317598.
|
|
[HttpPost]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult Edit([Bind(Include = "ID,ItemID,LocationID,QtyConf,Note,dtLastUpd")] ItemStock itemStock)
|
|
{
|
|
if (ModelState.IsValid)
|
|
{
|
|
db.Entry(itemStock).State = EntityState.Modified;
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
ViewBag.ItemID = new SelectList(db.Item, "ID", "Descr", itemStock.ItemID);
|
|
ViewBag.LocationID = new SelectList(db.Location, "ID", "Descr", itemStock.LocationID);
|
|
return View(itemStock);
|
|
}
|
|
|
|
// GET: ItemStocks/Delete/5
|
|
public ActionResult Delete(int? id)
|
|
{
|
|
if (id == null)
|
|
{
|
|
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
|
|
}
|
|
ItemStock itemStock = db.ItemStock.Find(id);
|
|
if (itemStock == null)
|
|
{
|
|
return HttpNotFound();
|
|
}
|
|
return View(itemStock);
|
|
}
|
|
|
|
// POST: ItemStocks/Delete/5
|
|
[HttpPost, ActionName("Delete")]
|
|
[ValidateAntiForgeryToken]
|
|
public ActionResult DeleteConfirmed(int id)
|
|
{
|
|
ItemStock itemStock = db.ItemStock.Find(id);
|
|
db.ItemStock.Remove(itemStock);
|
|
db.SaveChanges();
|
|
return RedirectToAction("Index");
|
|
}
|
|
|
|
protected override void Dispose(bool disposing)
|
|
{
|
|
if (disposing)
|
|
{
|
|
db.Dispose();
|
|
}
|
|
base.Dispose(disposing);
|
|
}
|
|
}
|
|
}
|