Пример #1
0
        private async void Initialize()
        {
            var dbTask = DBController.getEMInfo(EmergencyInfoID);

            InitializeComponent();
            //fill up the ui after waiting
            CurrentInfo           = await dbTask;
            asset_sn_label.Text   = CurrentInfo.AssetSN;
            asset_name_label.Text = CurrentInfo.AssetName;
            department_label.Text = CurrentInfo.Department;
            if (CurrentInfo.StartDate != null)
            {
                StartDatePicker.Value = (DateTime)CurrentInfo.StartDate;
            }
            if (CurrentInfo.EndDate != null)
            {
                EndDatePicker.Value = (DateTime)CurrentInfo.EndDate;
            }
            tech_note_richbox.Text = CurrentInfo.TechnicianNote;
            parts_combo.DataSource = CurrentInfo.listOfParts;
            CurrentInfo.AddedParts = new List <PartsDGV>();
        }
Пример #2
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);
     }
 }
Пример #3
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();
            }
        }