Ejemplo n.º 1
0
        public ActionResult FormCreate(string html, string tag)
        {
            AuleaseEntities db    = new AuleaseEntities();
            Component       comp  = db.Components.Where(n => n.LeaseTag == tag).Single();
            SystemGroup     group = comp.Leases.OrderByDescending(n => n.EndDate).FirstOrDefault().SystemGroup;

            Form form = new Form();

            form.HTML = html;

            group.Forms.Add(form);
            db.SaveChanges();

            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult EditorChanged(string html)
        {
            html = HttpUtility.HtmlDecode(html);

            AuleaseEntities db   = new AuleaseEntities();
            FormTemplate    form = new FormTemplate();

            form.HTML = html;
            form.Id   = db.FormTemplates.OrderByDescending(n => n.Id).First().Id + 1;

            db.FormTemplates.Add(form);
            db.SaveChanges();
            @ViewBag.HTML = html;
            return(View());
        }
        public JsonResult GroupContractNumber(string SR, string ContractNumber)
        {
            AuleaseEntities db = new AuleaseEntities();
            PO SRGroup         = db.POes.Where(n => n.PONumber == SR).Single();

            foreach (var group in SRGroup.SystemGroups)
            {
                foreach (var lease in group.Leases)
                {
                    lease.ContractNumber = ContractNumber.Trim();
                }
            }

            db.SaveChanges();
            return(Json(true));
        }
Ejemplo n.º 4
0
        public ActionResult SendBillingStatements(string Month)
        {
            string   Errors     = "Statements have been sent!";
            DateTime date       = DateTime.ParseExact(Month, "MMMM", CultureInfo.CurrentCulture);
            DateTime createDate = new DateTime(date.Year, date.Month, 1).AddMonths(1).AddSeconds(-1);

            Statement stat = new Statement {
                Date = createDate
            };
            AuleaseEntities db = new AuleaseEntities();

            db.Statements.Add(stat);
            db.SaveChanges();

            DateTime billingDate = createDate.AddMonths(-1); // Send statements for 1 month past last lease so customer can check that there are no more billings

            List <Department>  activeDepts = db.Leases.Where(n => n.EndDate >= billingDate).Select(n => n.Department).Distinct().ToList();
            List <Coordinator> people      = activeDepts.SelectMany(n => n.Coordinators).Where(n => n.BillingAccess == true).Distinct().ToList();

            foreach (var person in people)
            {
                // uncomment for production
                Email email = new Email();
                email.From("*****@*****.**");
                email.AddTo(person.GID + "@auburn.edu");
                email.AddCC("*****@*****.**");
                email.Subject = "AU Lease Billing Statement";
                email.Body    = "<html><body><p>Your " + Month + " statement(s) is now ready. Please visit <a href=\"https://cws.auburn.edu/oit/aulease/statements\">https://cws.auburn.edu/oit/aulease/statements</a> to view your billing statement(s).</p><br /><p>Sincerely,</p><p>AU Lease</p></body></html>";
                email.HTML    = true;
                try
                {
                    email.Send();
                }
                catch
                {
                    Errors += "\n Email failed for:" + person.GID;
                }
            }

            ViewBag.error = Errors;
            return(View());
        }
        public JsonResult Extend(string SerialNumber, string EndDate)
        {
            AuleaseEntities db        = new AuleaseEntities();
            Component       comp      = db.Components.Where(n => n.SerialNumber == SerialNumber).Single();
            Lease           lastLease = comp.Leases.OrderByDescending(n => n.EndDate).First();
            DateTime        d         = lastLease.EndDate.Value;

            DateTime begDate = new DateTime(d.AddMonths(1).Year, d.AddMonths(1).Month, 1);
            DateTime endDate = UnixTimeStampToDateTime(Convert.ToDouble(EndDate));

            Lease newLease = new Lease();

            newLease.Charges        = lastLease.Charges;
            newLease.Component      = lastLease.Component;
            newLease.ComponentId    = lastLease.ComponentId;
            newLease.ContractNumber = lastLease.ContractNumber;
            newLease.Department     = lastLease.Department;
            newLease.DepartmentId   = lastLease.DepartmentId;
            newLease.MonthlyCharge  = lastLease.MonthlyCharge;
            newLease.Overhead       = lastLease.Overhead;
            newLease.OverheadId     = lastLease.OverheadId;
            newLease.StatementName  = lastLease.StatementName;
            newLease.SystemGroup    = lastLease.SystemGroup;
            newLease.SystemGroupId  = lastLease.SystemGroupId;
            newLease.Timestamp      = DateTime.Now;

            newLease.BeginDate = begDate;
            newLease.EndDate   = endDate;

            comp.Leases.Add(newLease);
            comp.ReturnDate = endDate.AddMonths(1);

            db.SaveChanges();

            var output = new
            {
                success = true
            };

            return(Json(output));
        }
        public ActionResult UnFinalizePage(string SR)
        {
            AuleaseEntities db   = new AuleaseEntities();
            PO           po      = db.POes.Where(n => n.PONumber == SR).Single();
            List <Lease> leases  = po.SystemGroups.SelectMany(n => n.Leases).ToList();
            string       message = "";

            foreach (var lease in leases)
            {
                lease.MonthlyCharge  = null;
                lease.BeginDate      = null;
                lease.EndDate        = null;
                lease.ContractNumber = null;
                message += lease.Component.SerialNumber + " has been unfinalized from the database. <br /> ";
            }

            db.SaveChanges();

            ViewBag.message = message;
            return(View());
        }
Ejemplo n.º 7
0
        // POST api/repairs
        public void Post([FromBody] dynamic repair)
        {
            string SerialNumber = repair.SerialNumber;
            string Assignee     = repair.Assignee;
            string Note         = repair.Note;

            AuleaseEntities db = new AuleaseEntities();

            if (db.Components.Any(n => n.SerialNumber == SerialNumber))
            {
                Component comp            = db.Components.Where(n => n.SerialNumber == SerialNumber).Single();
                Status    NewRepairStatus = db.Status.Where(n => n.Id == Status.NewRepair).Single();
                Repair    NewRepair       = new Repair {
                    Assignee = Assignee, Timestamp = DateTime.Now, Note = Note, Component = comp, Status = NewRepairStatus
                };
                db.Repairs.Add(NewRepair);
                db.SaveChanges();

                sendRepairEmail(Assignee, comp, Note);
            }
        }
Ejemplo n.º 8
0
        // POST api/scan
        public void Post([FromBody] IEnumerable <ScanSystem> value)
        {
            AuleaseEntities db = new AuleaseEntities();

            foreach (ScanSystem system in value)
            {
                foreach (var comp in system.Components)
                {
                    Component Component = db.Components.Where(n => n.Id == comp.ComponentId).Single();

                    if (!String.IsNullOrWhiteSpace(comp.SerialNumber))
                    {
                        Component.SerialNumber = comp.SerialNumber.Trim().ToUpper();
                    }
                    if (!String.IsNullOrWhiteSpace(comp.LeaseTag))
                    {
                        Component.LeaseTag = comp.LeaseTag.Trim().ToUpper();
                    }
                }
            }

            db.SaveChanges();
        }
Ejemplo n.º 9
0
        public ActionResult EditRows()
        {
            var gridModel = new LeasingDatabase.Models.Grid.OrdersJqGridModel();
            var db        = new AuleaseEntities();

            var e = gridModel.OrdersGrid.GetEditData();             // Edit Row

            if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                int   id    = Convert.ToInt32(e.RowData["Id"].ToString());
                Lease lease = db.Leases.Where(n => n.Id == id).Single();

                string validationMessage = ValidationEditRow(e);

                if (!String.IsNullOrWhiteSpace(validationMessage))
                {
                    return(gridModel.OrdersGrid.ShowEditValidationMessage(validationMessage));
                }

                string _Fund    = e.RowData["Fund"].ToString().Trim();
                string _Org     = e.RowData["Org"].ToString().Trim();
                string _Program = e.RowData["Program"].ToString().Trim();

                string   _ContractNumber = e.RowData["ContractNumber"].ToString().Trim();
                DateTime _BeginDate      = Convert.ToDateTime(e.RowData["BeginDate"].ToString());
                DateTime _EndDate        = Convert.ToDateTime(e.RowData["EndDate"].ToString());
                string   _StatementName  = e.RowData["StatementName"].ToString();

                decimal _MonthlyCharge = Convert.ToDecimal(e.RowData["MonthlyCharge"].ToString());


                Department dept = db.Departments.Where(n => n.Fund == _Fund && n.Org == _Org && n.Program == _Program).Single();
                lease.Department     = dept;
                lease.BeginDate      = _BeginDate;
                lease.EndDate        = _EndDate;
                lease.StatementName  = _StatementName;
                lease.ContractNumber = _ContractNumber;
                lease.MonthlyCharge  = _MonthlyCharge;

                db.SaveChanges();
            }
            if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow)
            {
                // Add Row
            }
            if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                int   id    = Convert.ToInt32(e.RowData["Id"].ToString());
                Lease lease = db.Leases.Where(n => n.Id == id).Single();

                Session["SN"] = lease.Component.SerialNumber;

                foreach (var charge in lease.Charges)
                {
                    charge.Leases.Remove(lease);
                }

                Component comp = lease.Component;
                comp.Leases.Remove(lease);
                SystemGroup group = lease.SystemGroup;
                group.Leases.Remove(lease);

                Department dept = lease.Department;
                dept.Leases.Remove(lease);

                db.Entry(lease).State = EntityState.Deleted;
                db.SaveChanges();
            }

            return(new RedirectResult(Url.Action("DataRequested", "Billing")));
        }
Ejemplo n.º 10
0
        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();
            }
        }
Ejemplo n.º 11
0
        public JsonResult ChangeFOP(string SerialNumber, string StatementName, string Fund, string Org, string Program, string changeDate)
        {
            DateTime        ChangeDate = UnixTimeStampToDateTime(Convert.ToDouble(changeDate));
            AuleaseEntities db         = new AuleaseEntities();
            Department      newDept;

            if (db.Departments.Any(n => n.Fund == Fund && n.Org == Org && n.Program == Program))
            {
                newDept = db.Departments.Where(n => n.Fund == Fund && n.Org == Org && n.Program == Program).Single();
            }
            else
            {
                newDept         = new Department();
                newDept.Fund    = Fund;
                newDept.Org     = Org;
                newDept.Program = Program;

                db.Departments.Add(newDept);
                db.SaveChanges();
            }

            Component comp      = db.Components.Where(n => n.SerialNumber == SerialNumber).Single();
            Lease     lastLease = comp.Leases.OrderByDescending(n => n.EndDate).First();

            DateTime begDate = new DateTime(ChangeDate.Year, ChangeDate.Month, 1);
            DateTime endDate = lastLease.EndDate.Value;

            lastLease.EndDate = new DateTime(ChangeDate.AddMonths(-1).Year, ChangeDate.AddMonths(-1).Month, DateTime.DaysInMonth(ChangeDate.AddMonths(-1).Year, ChangeDate.AddMonths(-1).Month));

            Lease newLease = new Lease();

            newLease.StatementName  = StatementName;
            newLease.Charges        = lastLease.Charges;
            newLease.Component      = lastLease.Component;
            newLease.ComponentId    = lastLease.ComponentId;
            newLease.ContractNumber = lastLease.ContractNumber;
            newLease.Department     = newDept;
            newLease.MonthlyCharge  = lastLease.MonthlyCharge;
            newLease.Overhead       = lastLease.Overhead;
            newLease.OverheadId     = lastLease.OverheadId;
            newLease.Timestamp      = DateTime.Now;

            SystemGroup oldSystemGroup = lastLease.SystemGroup;
            SystemGroup newSystemGroup = new SystemGroup();

            newSystemGroup.Location = oldSystemGroup.Location;
            newSystemGroup.PO       = oldSystemGroup.PO;
            newSystemGroup.Order    = oldSystemGroup.Order;
            newSystemGroup.User     = oldSystemGroup.User;

            newLease.SystemGroup = newSystemGroup;

            newLease.BeginDate = begDate;
            newLease.EndDate   = endDate;

            comp.Leases.Add(newLease);

            db.SaveChanges();

            var output = new { success = true };

            return(Json(output));
        }
Ejemplo n.º 12
0
        public static void FillLeasingInfo(int SystemGroupID, string BegBillDate, string EndBillDate,
                                           string CPUCost, string MonitorCost, string Monitor2Cost,
                                           string InsuranceCost, string WarrantyCost, string ShippingCost)
        {
            AuleaseEntities db = new AuleaseEntities();

            SystemGroup system = db.SystemGroups.Where(n => n.Id == SystemGroupID).Single();

            //Remove existing charges before adding new ones
            foreach (var lease in system.Leases)
            {
                List <Charge> charges = lease.Charges.ToList();
                foreach (var charge in charges)
                {
                    lease.Charges.Remove(charge);
                }

                foreach (var charge in db.Charges.Where(n => n.Leases.FirstOrDefault().Id == lease.Id))
                {
                    db.Entry(charge).State = EntityState.Deleted;
                }
            }

            db.SaveChanges();


            //Add new charges
            int compCount = system.Leases.Count;
            List <Component> MainComps = system.Components.Where(n => n.Type.Name != "Monitor").ToList();
            List <Component> Monitors  = system.Components.Where(n => n.Type.Name == "Monitor").ToList();

            foreach (var comp in MainComps)
            {
                Lease currentLease = comp.CurrentLease;
                currentLease.BeginDate = Convert.ToDateTime(BegBillDate);
                currentLease.EndDate   = Convert.ToDateTime(EndBillDate);

                int Term = comp.Leases.FirstOrDefault().Overhead.Term + 1;                 // Add 1 for vendor rates

                VendorRate VendorRate = db.VendorRates.Where(n => n.Term == Term && n.Type.Name == comp.Type.Name).OrderByDescending(n => n.BeginDate).FirstOrDefault();
                Charge     MainCharge = new Charge {
                    Price = Convert.ToDecimal(CPUCost), VendorRate = VendorRate, Type = comp.Type, Tax = db.Taxes.OrderByDescending(n => n.Timestamp).First()
                };
                currentLease.Charges.Add(MainCharge);

                if (!String.IsNullOrWhiteSpace(InsuranceCost))
                {
                    VendorRate InsuranceVendorRate = db.VendorRates.Where(n => n.Term == Term && n.Type.Name == "Insurance").OrderByDescending(n => n.BeginDate).FirstOrDefault();
                    Charge     InsuranceCharge     = new Charge {
                        Price = Convert.ToDecimal(InsuranceCost), VendorRate = InsuranceVendorRate, Type = db.TypesInsurance
                    };
                    currentLease.Charges.Add(InsuranceCharge);
                }

                if (!String.IsNullOrWhiteSpace(WarrantyCost))
                {
                    VendorRate WarrantyVendorRate = db.VendorRates.Where(n => n.Term == Term && n.Type.Name == "Insurance").OrderByDescending(n => n.BeginDate).FirstOrDefault();
                    Charge     WarrantyCharge     = new Charge {
                        Price = Convert.ToDecimal(WarrantyCost) / compCount, VendorRate = WarrantyVendorRate, Type = db.TypesWarranty
                    };
                    currentLease.Charges.Add(WarrantyCharge);
                }

                if (!String.IsNullOrWhiteSpace(ShippingCost))
                {
                    VendorRate ShippingVendorRate = db.VendorRates.Where(n => n.Term == Term && n.Type.Name == "Insurance").OrderByDescending(n => n.BeginDate).FirstOrDefault();
                    Charge     ShippingCharge     = new Charge {
                        Price = Convert.ToDecimal(ShippingCost) / compCount, VendorRate = ShippingVendorRate, Type = db.TypesShipping
                    };
                    currentLease.Charges.Add(ShippingCharge);
                }
            }
            int i = 0;

            foreach (var comp in Monitors)
            {
                Lease currentLease = comp.CurrentLease;
                currentLease.BeginDate = Convert.ToDateTime(BegBillDate);
                currentLease.EndDate   = Convert.ToDateTime(EndBillDate);

                int Term = comp.Leases.FirstOrDefault().Overhead.Term + 1;                 // Add 1 for vendor rates

                VendorRate VendorRate = db.VendorRates.Where(n => n.Term == Term && n.Type.Name == comp.Type.Name).OrderByDescending(n => n.BeginDate).FirstOrDefault();

                Charge MainCharge;
                if (i == 0)
                {
                    MainCharge = new Charge {
                        Price = Convert.ToDecimal(MonitorCost), VendorRate = VendorRate, Type = comp.Type, Tax = db.Taxes.OrderByDescending(n => n.Timestamp).First()
                    };
                }
                else
                {
                    MainCharge = new Charge {
                        Price = Convert.ToDecimal(Monitor2Cost), VendorRate = VendorRate, Type = comp.Type, Tax = db.Taxes.OrderByDescending(n => n.Timestamp).First()
                    };
                }
                i++;
                currentLease.Charges.Add(MainCharge);

                if (!String.IsNullOrWhiteSpace(InsuranceCost) && MainComps.Count == 0)
                {
                    VendorRate InsuranceVendorRate = db.VendorRates.Where(n => n.Term == Term && n.Type.Name == "Insurance").OrderByDescending(n => n.BeginDate).FirstOrDefault();
                    Charge     InsuranceCharge     = new Charge {
                        Price = Convert.ToDecimal(InsuranceCost), VendorRate = InsuranceVendorRate, Type = db.TypesInsurance
                    };
                    currentLease.Charges.Add(InsuranceCharge);
                }

                if (!String.IsNullOrWhiteSpace(WarrantyCost))
                {
                    VendorRate WarrantyVendorRate = db.VendorRates.Where(n => n.Term == Term && n.Type.Name == "Insurance").OrderByDescending(n => n.BeginDate).FirstOrDefault();
                    Charge     WarrantyCharge     = new Charge {
                        Price = Convert.ToDecimal(WarrantyCost) / compCount, VendorRate = WarrantyVendorRate, Type = db.TypesWarranty
                    };
                    currentLease.Charges.Add(WarrantyCharge);
                }

                if (!String.IsNullOrWhiteSpace(ShippingCost))
                {
                    VendorRate ShippingVendorRate = db.VendorRates.Where(n => n.Term == Term && n.Type.Name == "Insurance").OrderByDescending(n => n.BeginDate).FirstOrDefault();
                    Charge     ShippingCharge     = new Charge {
                        Price = Convert.ToDecimal(ShippingCost) / compCount, VendorRate = ShippingVendorRate, Type = db.TypesShipping
                    };
                    currentLease.Charges.Add(ShippingCharge);
                }
            }

            db.SaveChanges();
        }
Ejemplo n.º 13
0
        public void GIDEditRows()
        {
            var gridModel = new LeasingDatabase.Models.Grid.BillingCoordinatorJqGridModel();
            var db        = new AuleaseEntities();

            var e = gridModel.OrdersGrid.GetEditData(); // Edit Row

            if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.EditRow)
            {
                // Not gonna allow editing, just adding and deleting
                throw new NotImplementedException();
            }
            if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.AddRow)
            {
                string Fund    = e.RowData["Fund"].ToString().Trim();
                string Org     = e.RowData["Org"].ToString().Trim();
                string Program = e.RowData["Program"].ToString().Trim();
                string GID     = e.RowData["GID"].ToString().Trim();
                Session["GID"] = GID;
                bool BillingAccess = Convert.ToBoolean(e.RowData["BillingAccess"]);

                if (!db.Departments.Any(n => n.Fund == Fund && n.Org == Org && n.Program == Program))
                {
                    Department newDept = new Department();
                    newDept.Fund    = Fund;
                    newDept.Org     = Org;
                    newDept.Program = Program;
                    newDept.Name    = "New Department";
                    db.Departments.Add(newDept);
                    db.SaveChanges();
                }

                if (!db.Coordinators.Any(n => n.GID == GID))
                {
                    Coordinator newCoordinator = new Coordinator();
                    newCoordinator.BillingAccess = BillingAccess;
                    newCoordinator.GID           = GID;
                    db.Coordinators.Add(newCoordinator);
                    db.SaveChanges();
                }

                Coordinator user = db.Coordinators.Where(n => n.GID == GID).Single();

                var dept = db.Departments.Where(n => n.Fund == Fund && n.Org == Org && n.Program == Program).Single();

                dept.Coordinators.Add(user);
                db.SaveChanges();
            }
            if (gridModel.OrdersGrid.AjaxCallBackMode == AjaxCallBackMode.DeleteRow)
            {
                string[] array = e.RowData["Id"].ToString().Split('-');
                string   GID   = array[0];
                Session["GID"] = GID;
                string Fund    = array[1];
                string Org     = array[2];
                string Program = array[3];

                var         dept = db.Departments.Where(n => n.Fund == Fund && n.Org == Org && n.Program == Program).Single();
                Coordinator user = db.Coordinators.Where(n => n.GID == GID).Single();

                dept.Coordinators.Remove(user);
                db.SaveChanges();
            }
        }
Ejemplo n.º 14
0
        public static string[] Parse(string file, ref List <string> errors)
        {
            string[] words = file.Split(' ', '\t', '\n');

            string[]         Array = new string[words.Count()];
            HashSet <string> SR    = new HashSet <string>();

            int e = 0;

            foreach (string word in words)
            {
                Array[e] = word.Trim().TrimEnd('\r', '\n').ToUpper();
                e++;
            }

            int num1;
            int LastIdx = -1;
            int length  = Array.Length;

            for (int i = 0; i < length; i++)
            {
                AuleaseEntities  db         = new AuleaseEntities();
                List <Component> components = db.Components.Where(n => n.SerialNumber == null || n.SerialNumber.Length < 2).ToList();
                bool             res;
                try
                { res = int.TryParse((Array[i].Substring(2, 5)), out num1); }
                catch
                { res = false; }

                bool res2;
                try
                { res2 = Array[i].StartsWith("AU"); }
                catch
                { res2 = false; }

                bool res3;
                bool res4;
                if (res == true & res2 == true)
                {
                    if ((i + 2) < length)
                    {
                        res3 = Array[i + 2].StartsWith("AU");
                        try
                        { res4 = Int32.TryParse(Array[i + 2].Substring(2, 5), out num1); }
                        catch
                        { res4 = false; }
                    }
                    else
                    {
                        res3 = false;
                        res4 = false;
                    }


                    if (res3 == true & res4 == true)
                    {
                        continue;
                    }
                    else
                    {
                        if (i - LastIdx == 3)
                        {
                            List <Component> Order = components.Where(n => n.OrderNumber == Array[i - 2]).ToList();
                            if (Order.Count == 0)
                            {
                                LastIdx = i; db.SaveChanges(); errors.Add("No order number found"); continue;
                            }
                            SystemGroup SystemGroup = Order.First().SystemGroup;

                            if (SystemGroup.ComponentCount == 1)
                            {
                                string Serial1 = Array[i - 1];
                                if (db.Components.Any(n => n.SerialNumber.Contains(Serial1)))
                                {
                                    LastIdx = i;
                                    db.SaveChanges();
                                    errors.Add("Serial Number already exists");
                                    continue;
                                }

                                Component comp = SystemGroup.ActiveLeases.First().Component;
                                comp.SerialNumber = Array[i - 1];
                                comp.LeaseTag     = Array[i];

                                SR.Add(comp.PO.PONumber);
                            }
                            LastIdx = i;
                        }

                        else if (i - LastIdx == 5)
                        {
                            List <Component> Order = components.Where(n => n.OrderNumber == Array[i - 4]).ToList();
                            if (Order.Count == 0)
                            {
                                LastIdx = i; db.SaveChanges(); errors.Add("No order number found"); continue;
                            }
                            SystemGroup SystemGroup = Order.First().SystemGroup;

                            if (SystemGroup.ComponentCount == 2)
                            {
                                string Serial1 = Array[i - 3];
                                string Serial2 = Array[i - 1];

                                if (db.Components.Any(n => n.SerialNumber.Contains(Serial1) || n.SerialNumber.Contains(Serial2)))
                                {
                                    LastIdx = i;
                                    db.SaveChanges();
                                    errors.Add("Serial Number already exists");
                                    continue;
                                }

                                if (!ContainsTwoMonitors(SystemGroup))
                                {
                                    Component comp = SystemGroup.Components.Where(n => n.Type.Name != "Monitor").Single();
                                    comp.SerialNumber = Array[i - 3];
                                    comp.LeaseTag     = Array[i - 2];
                                    Component mon = SystemGroup.Components.Where(n => n.Type.Name == "Monitor").First();
                                    mon.SerialNumber = Array[i - 1];
                                    mon.LeaseTag     = Array[i];
                                }
                                else
                                {
                                    List <Component> mon = SystemGroup.Components.Where(n => n.Type.Name == "Monitor").ToList();
                                    mon[0].SerialNumber = Array[i - 3];
                                    mon[0].LeaseTag     = Array[i - 2];
                                    mon[1].SerialNumber = Array[i - 1];
                                    mon[1].LeaseTag     = Array[i];
                                }

                                SR.Add(SystemGroup.PO.PONumber);
                            }
                            LastIdx = i;
                        }

                        else if (i - LastIdx == 7)
                        {
                            List <Component> Order = components.Where(n => n.OrderNumber == Array[i - 6]).ToList();
                            if (Order.Count == 0)
                            {
                                LastIdx = i; db.SaveChanges(); errors.Add("No order number found"); continue;
                            }
                            SystemGroup SystemGroup = Order.First().SystemGroup;

                            if (SystemGroup.ComponentCount == 3)
                            {
                                string Serial1 = Array[i - 5];
                                string Serial2 = Array[i - 3];
                                string Serial3 = Array[i - 1];

                                if (db.Components.Any(n => n.SerialNumber.Contains(Serial1) || n.SerialNumber.Contains(Serial2) || n.SerialNumber.Contains(Serial3)))
                                {
                                    LastIdx = i;
                                    db.SaveChanges();
                                    errors.Add("Serial Number already exists");
                                    continue;
                                }

                                Component comp = SystemGroup.Components.Where(n => n.Type.Name != "Monitor").Single();
                                comp.SerialNumber = Array[i - 5];
                                comp.LeaseTag     = Array[i - 4];
                                List <Component> mon = SystemGroup.Components.Where(n => n.Type.Name == "Monitor").ToList();
                                mon[0].SerialNumber = Array[i - 3];
                                mon[0].LeaseTag     = Array[i - 2];
                                mon[1].SerialNumber = Array[i - 1];
                                mon[1].LeaseTag     = Array[i];



                                SR.Add(comp.PO.PONumber);
                            }
                            LastIdx = i;
                        }
                    }
                }

                else
                {
                }

                db.SaveChanges();
            }



            string[] SRs   = new string[SR.Count];
            int      count = 0;

            foreach (string item in SR)
            {
                SRs[count] = item;
                count++;
            }
            return(SRs);
        }