// // GET: /Component/ public ActionResult Index() { var gridModel = new LeasingDatabase.Models.Grid.ComponentJqGridModel(); var ordersGrid = gridModel.OrdersGrid; SetUpGrid(ordersGrid); return(View(gridModel)); }
public ActionResult ExportToExcel() { var gridModel = new LeasingDatabase.Models.Grid.ComponentJqGridModel(); var ordersGrid = gridModel.OrdersGrid; AuleaseEntities db = new AuleaseEntities(); SetUpGrid(gridModel.OrdersGrid); var comps = db.Components.Where(n => n.Leases.OrderByDescending(o => o.Timestamp).FirstOrDefault().MonthlyCharge != null && n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().ContractNumber == null); // Performance increase if taken from first lease perspective??? var model = comps.OrderByDescending(n => n.SystemGroupId).Select(n => new ComponentModel { ComponentID = n.Id, SerialNumber = n.SerialNumber, LeaseTag = n.LeaseTag, Note = n.Note, Make = n.Make.Name, ComponentType = n.Type.Name, Model = n.Model.Name, BeginDate = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().BeginDate.Value, EndDate = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().EndDate.Value, StatementName = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().StatementName, ContractNumber = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().ContractNumber, DepartmentName = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().Department.Name, Fund = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().Department.Fund, Org = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().Department.Org, Program = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().Department.Program, MonthlyCharge = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().MonthlyCharge.Value, RateLevel = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().Overhead.RateLevel, Term = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().Overhead.Term, SRNumber = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().SystemGroup.PO.PONumber, GID = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().SystemGroup.User.GID, Phone = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().SystemGroup.User.Phone, Building = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().SystemGroup.Location.Building, Room = n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().SystemGroup.Location.Room }); ordersGrid.ExportToExcel(model, "grid.xls"); return(View()); }
public JsonResult DataRequested() { var gridModel = new LeasingDatabase.Models.Grid.ComponentJqGridModel(); var db = new AuleaseEntities(); SetUpGrid(gridModel.OrdersGrid); var CutOffDate = DateTime.Now.AddMonths(-6); var comps = db.Components.Where(n => n.Leases.OrderByDescending(o => o.EndDate).FirstOrDefault().MonthlyCharge != null); // Performance increase if taken from first lease perspective??? var model = comps.Select(x => new { activeLease = x.Leases.OrderByDescending(p => p.EndDate).FirstOrDefault(), comp = x }).Select(n => new ComponentModel { ComponentID = n.comp.Id, SerialNumber = n.comp.SerialNumber, LeaseTag = n.comp.LeaseTag, Note = n.comp.Note, Make = n.comp.Make.Name, ComponentType = n.comp.Type.Name, Model = n.comp.Model.Name, BeginDate = n.activeLease.BeginDate.Value, EndDate = n.activeLease.EndDate.Value, StatementName = n.activeLease.StatementName, ContractNumber = n.activeLease.ContractNumber, DepartmentName = n.activeLease.Department.Name, Fund = n.activeLease.Department.Fund, Org = n.activeLease.Department.Org, Program = n.activeLease.Department.Program, MonthlyCharge = n.activeLease.MonthlyCharge.Value, RateLevel = n.activeLease.Overhead.RateLevel, Term = n.activeLease.Overhead.Term, SRNumber = n.activeLease.SystemGroup.PO.PONumber, GID = n.activeLease.SystemGroup.User.GID, Phone = n.activeLease.SystemGroup.User.Phone, Building = n.activeLease.SystemGroup.Location.Building, Room = n.activeLease.SystemGroup.Location.Room }); return(gridModel.OrdersGrid.DataBind(model.AsQueryable())); }
public void EditRows() { var gridModel = new LeasingDatabase.Models.Grid.ComponentJqGridModel(); var db = new AuleaseEntities(); var e = gridModel.OrdersGrid.GetEditData(); // Edit Row if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow) { int ComponentID = Convert.ToInt32(e.RowData["ComponentID"]); string _SerialNumber = e.RowData["SerialNumber"].ToString().Trim(); string _LeaseTag = e.RowData["LeaseTag"].ToString().Trim(); string _Note = e.RowData["Note"].ToString().Trim(); string _Make = e.RowData["Make"].ToString().Trim(); string _ComponentType = e.RowData["ComponentType"].ToString().Trim(); string _Model = e.RowData["Model"].ToString().Trim(); // Update Component Component comp = db.Components.Where(n => n.Id == ComponentID).Single(); comp.SerialNumber = _SerialNumber; comp.LeaseTag = _LeaseTag; comp.Note = _Note; comp.Make = db.Makes.Where(n => n.Name == _Make).Single(); comp.Type = db.Types.Where(n => n.Name == _ComponentType).Single(); Model model; if (db.Models.Any(n => n.Name == _Model)) { model = db.Models.Where(n => n.Name == _Model).FirstOrDefault(); } else { model = new Model() { Name = _Model, Make = db.Makes.Where(n => n.Name == _Make).Single() }; } comp.Model = model; // Update Leases DateTime _BeginDate = Convert.ToDateTime(e.RowData["BeginDate"]); DateTime _EndDate = Convert.ToDateTime(e.RowData["EndDate"]); string _StatementName = e.RowData["StatementName"].ToString().Trim(); string _ContractNumber = e.RowData["ContractNumber"].ToString().Trim(); string _Fund = e.RowData["Fund"].ToString().Trim(); string _Org = e.RowData["Org"].ToString().Trim(); string _Program = e.RowData["Program"].ToString().Trim(); string _RateLevel = e.RowData["RateLevel"].ToString().Trim(); int _Term = Convert.ToInt32(e.RowData["Term"]); string _GID = e.RowData["GID"].ToString().Trim(); Lease currentLease = comp.Leases.OrderByDescending(n => n.EndDate).First(); Department department; if (db.Departments.Any(n => n.Fund == _Fund && n.Org == _Org && n.Program == _Program)) { department = db.Departments.Where(n => n.Fund == _Fund && n.Org == _Org && n.Program == _Program).FirstOrDefault(); } else { department = new Department { Fund = _Fund, Org = _Org, Program = _Program }; } Overhead Overhead = db.Overheads.Where(n => n.RateLevel == _RateLevel && n.Term == _Term).OrderByDescending(n => n.BeginDate).FirstOrDefault(); User newUser; if (db.Users.Any(n => n.GID == _GID)) { newUser = db.Users.Where(n => n.GID == _GID).Single(); } else { newUser = new User(); newUser.GID = _GID; newUser.Location = new Location(); } currentLease.BeginDate = _BeginDate; currentLease.EndDate = _EndDate; currentLease.StatementName = _StatementName; currentLease.Timestamp = DateTime.Now; currentLease.ContractNumber = _ContractNumber; currentLease.Department = department; currentLease.Overhead = Overhead; currentLease.SystemGroup.User = newUser; db.SaveChanges(); } if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow) { // No Adding through this table! throw new NotImplementedException(); } if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow) { int ComponentID = Convert.ToInt32(e.RowData["ComponentID"]); Component comp = db.Components.Where(n => n.Id == ComponentID).Single(); List <Lease> leases = comp.Leases.ToList(); List <Charge> Charges = leases.SelectMany(n => n.Charges).ToList(); int SystemGroupID = leases.Select(n => n.SystemGroupId).Single(); int OrderID = leases.Select(n => n.SystemGroup).SingleOrDefault().OrderId; int? POID = leases.Select(n => n.SystemGroup).SingleOrDefault().POId.HasValue ? (int?)leases.Select(n => n.SystemGroup).Single().POId.Value : null; foreach (var charge in Charges) { db.Entry(charge).State = EntityState.Deleted; } foreach (var lease in leases) { db.Entry(lease).State = EntityState.Deleted; } List <Property> props = comp.Properties.ToList(); foreach (var prop in props) { comp.Properties.Remove(prop); } db.Entry(comp).State = EntityState.Deleted; db.SaveChanges(); if (db.SystemGroups.Where(n => n.Id == SystemGroupID).SingleOrDefault().Leases.Count == 0) { db.Entry(db.SystemGroups.Where(n => n.Id == SystemGroupID).SingleOrDefault()).State = EntityState.Deleted; } if (db.Orders.Where(n => n.Id == OrderID).Single().SystemGroups.Count == 0) { db.Entry(db.Orders.Where(n => n.Id == OrderID).Single()).State = EntityState.Deleted; } if (POID != null && db.POes.Where(n => n.Id == POID).Single().SystemGroups.Count == 0) { db.Entry(db.POes.Where(n => n.Id == POID).Single()).State = EntityState.Deleted; } db.SaveChanges(); } }