Esempio n. 1
0
 private void ok_button_Click(object sender, EventArgs e)
 {
     using (var db = new Session2Entities())
     {
         var aaaaa = (from ee in db.Employees
                      where ee.Username == name_box.Text
                      where ee.Password == password_box.Text
                      select ee);
         if (aaaaa.Any())
         {
             if (aaaaa.First().isAdmin == true)
             {
                 var form = new EmergencyMaintainenece(aaaaa.First());
                 this.Hide();
                 form.Closed += (s, args) => this.Close();
                 form.Show();
             }
         }
     }
 }
        public async Task <List <MaintaineneceEmergency> > GetData()
        {
            var returnlist = new List <MaintaineneceEmergency>();

            using (var db = new Session2Entities())
            {
                var listofassets = (from a in db.Assets
                                    where a.EmployeeID == a.EmployeeID
                                    select a).ToList();
                Parallel.ForEach(listofassets, item => {
                    if ((from e in db.EmergencyMaintenances where e.AssetID == item.ID select e).Any())
                    {
                        var me       = new MaintaineneceEmergency();
                        me.AssetName = item.AssetName;
                        returnlist.Add(new MaintaineneceEmergency()
                        {
                            AssetName    = item.AssetName,
                            AssetSN      = item.AssetSN,
                            NumberOfEMs  = (from e in db.EmergencyMaintenances where e.ID == item.ID orderby e.EMEndDate descending select e.EMEndDate).Count(),
                            LastClosedEM = (from e in db.EmergencyMaintenances where e.ID == item.ID orderby e.EMEndDate descending select e.EMEndDate).First().ToString()
                        }
                                       );
                    }
                    else
                    {
                        returnlist.Add(new MaintaineneceEmergency()
                        {
                            AssetName    = item.AssetName,
                            AssetSN      = item.AssetSN,
                            NumberOfEMs  = (from e in db.EmergencyMaintenances where e.ID == item.ID orderby e.EMEndDate descending select e.EMEndDate).Count(),
                            LastClosedEM = "---"
                        }
                                       );
                    }
                });
            }
            return(returnlist);
        }