예제 #1
0
 public static async Task <bool> warningParts(string partname, int assetID)
 {
     using (var db = new Session2Entities())
     {
         List <Part> returnlist = new List <Part>();
         try
         {
             var h = (from e in db.EmergencyMaintenances
                      where e.AssetID == assetID
                      select e).First();
             var p = (from part in h.ChangedParts
                      where part.Part.Name == partname
                      select part).First();
             if (h.EMStartDate - DateTime.Now < TimeSpan.FromDays((double)p.Part.EffectiveLife))
             {
                 return(true);
             }
         }
         catch (Exception)
         {
             return(false);
         }
         return(false);
     }
 }
예제 #2
0
 public static async Task <List <Employee> > GetEmployees()
 {
     //get list of all employees
     using (var db = new Session2Entities())
     {
         return((from e in db.Employees
                 select e).ToList());
     }
 }
예제 #3
0
 public static async Task <Part> getPartfromName(string partname)
 {
     using (var db = new Session2Entities())
     {
         var part = (from p in db.Parts
                     where p.Name == partname
                     select p).FirstOrDefault();
         return(part);
     }
 }
예제 #4
0
 public static async Task <AssetEMPageInfo> GetAssetInfo(int assetID)
 {
     //get information on the asset from database
     using (var db = new Session2Entities())
     {
         AssetEMPageInfo AssetPage  = new AssetEMPageInfo();
         var             priorities = (from p in db.Priorities
                                       select p.Name).ToList();
         var asset = (from e in db.EmergencyMaintenances
                      where e.ID == assetID
                      select e).First();
         AssetPage.AssetSN    = asset.Asset.AssetSN;
         AssetPage.AssetID    = (int)asset.AssetID;
         AssetPage.AssetName  = asset.Asset.AssetName;
         AssetPage.Department = asset.Asset.DepartmentLocation.Department.Name;
         AssetPage.Priorities = priorities;
         return(AssetPage);
     }
 }
예제 #5
0
 public static async Task <ManageRequestInfo> getEMInfo(int emID)
 {
     //get information on the selected EM
     using (var db = new Session2Entities())
     {
         ManageRequestInfo info = new ManageRequestInfo();
         var query = (from em in db.EmergencyMaintenances
                      where em.ID == emID
                      select em).First();
         var parts = (from p in db.Parts
                      select p.Name).ToList();
         info.EMID           = emID;
         info.AssetID        = (int)query.AssetID;
         info.AssetSN        = query.Asset.AssetSN;
         info.AssetName      = query.Asset.AssetName;
         info.Department     = query.Asset.DepartmentLocation.Department.Name;
         info.EndDate        = query.EMEndDate;
         info.StartDate      = query.EMStartDate;
         info.listOfParts    = parts;
         info.TechnicianNote = query.EMTechnicianNote;
         return(info);
     }
 }
예제 #6
0
 public static async Task <List <AssetInfo> > getAssets(int empID)
 {
     //get all assets for the datagridview
     using (var db = new Session2Entities())
     {
         List <AssetInfo> returnlist = new List <AssetInfo>();
         var query = (from a in db.Assets
                      where a.EmployeeID == empID
                      select a);
         foreach (var item in query)
         {
             AssetInfo availableAssets = new AssetInfo();
             availableAssets.AssetID   = (int)item.ID;
             availableAssets.AssetSN   = item.AssetSN;
             availableAssets.AssetName = item.AssetName;
             DateTime?dt         = null;
             int      numberOfEM = 0;
             var      EMs        = (from e in db.EmergencyMaintenances
                                    where e.AssetID == item.ID
                                    where e.EMEndDate != null
                                    orderby e.EMEndDate descending
                                    select e).ToList();
             try
             {
                 dt         = EMs.First().EMEndDate;
                 numberOfEM = EMs.Count();
             }
             catch (Exception e)
             {
             }
             availableAssets.LastClosedEM = dt;
             availableAssets.NumberOfEM   = numberOfEM;
             returnlist.Add(availableAssets);
         }
         return(returnlist);
     }
 }
예제 #7
0
        public static async Task updateEMData(ManageRequestInfo info)
        {
            using (var db = new Session2Entities())
            {
                var query = (from em in db.EmergencyMaintenances
                             where em.ID == info.EMID
                             select em).First();
                query.EMStartDate      = info.StartDate;
                query.EMEndDate        = info.EndDate;
                query.EMTechnicianNote = info.TechnicianNote;
                foreach (var item in info.AddedParts)
                {
                    bool beforeExpire = await warningParts(item.PartName, info.AssetID);

                    //pass by default
                    DialogResult result = DialogResult.OK;
                    if (beforeExpire)
                    {
                        result = MessageBox.Show($"Are you sure you want to replace { item.PartName} before the end of its effective life?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    }
                    if (result == DialogResult.OK)
                    {
                        var addpart = (await getPartfromName(item.PartName)).ID;
                        var cpid    = (from c in db.ChangedParts
                                       orderby c.ID descending
                                       select c.ID).First() + 1;
                        ChangedPart cp = new ChangedPart();
                        cp.EmergencyMaintenanceID = info.EMID;
                        cp.PartID = addpart;
                        cp.Amount = item.Amount;
                        cp.ID     = cpid;
                        db.ChangedParts.Add(cp);
                    }
                }
                await db.SaveChangesAsync();
            }
        }
예제 #8
0
 public static async Task addEmergencyMaintenance(AssetEMPageInfo info)
 {
     //insert maintenance request
     using (var db = new Session2Entities())
     {
         var ID = (from em in db.EmergencyMaintenances
                   orderby em.ID descending
                   select em.ID).First() + 1;
         var priorityID = (from p in db.Priorities
                           where p.Name == info.SelectedPriorities
                           select p.ID).First();
         EmergencyMaintenance EM = new EmergencyMaintenance();
         EM.ID                   = ID;
         EM.PriorityID           = priorityID;
         EM.AssetID              = info.AssetID;
         EM.DescriptionEmergency = info.Description;
         EM.OtherConsiderations  = info.Considerations;
         EM.EMTechnicianNote     = null;
         EM.EMReportDate         = DateTime.Now;
         EM.EMStartDate          = DateTime.Now;
         db.EmergencyMaintenances.Add(EM);
         await db.SaveChangesAsync();
     }
 }
예제 #9
0
 public static async Task <List <EMRequests> > getOpenRequests()
 {
     //get requests that are currently open, eg, no end date
     using (var db = new Session2Entities())
     {
         List <EMRequests> returnlist = new List <EMRequests>();
         var query = (from em in db.EmergencyMaintenances
                      where em.EMEndDate == null
                      orderby em.PriorityID descending
                      select em).ToList();
         foreach (var item in query)
         {
             EMRequests em = new EMRequests();
             em.EMID         = (int)item.ID;
             em.AssetSN      = item.Asset.AssetSN;
             em.AssetName    = item.Asset.AssetName;
             em.Department   = item.Asset.DepartmentLocation.Department.Name;
             em.RequestDate  = item.EMReportDate;
             em.EmployeeName = $"{item.Asset.Employee.FirstName} {item.Asset.Employee.LastName}";
             returnlist.Add(em);
         }
         return(returnlist);
     }
 }