Ejemplo n.º 1
0
        /// <summary>
        /// Данные работы обновляются по введенным значениям
        /// </summary>
        private void SaveData()
        {
            foreach (WorkPackageClosingDataGridViewRow row in dataGridViewItems.Rows.OfType <WorkPackageClosingDataGridViewRow>())
            {
                if ((bool)row.Cells[ColumnClosed.Index].Value == false)
                {
                    continue;
                }
                try
                {
                    DateTime performDate = (DateTime)row.Cells[ColumnDate.Index].Value;
                    if (row.ClosingItem is Procedure)
                    {
                        Procedure       dir             = (Procedure)row.ClosingItem;
                        DirectiveRecord directiveRecord = (DirectiveRecord)row.Record;

                        if (directiveRecord.ItemId <= 0)
                        {
                            directiveRecord.Completed    = true;
                            directiveRecord.RecordType   = DirectiveRecordType.Perfromed;
                            directiveRecord.RecordTypeId = DirectiveRecordType.Perfromed.ItemId;
                            directiveRecord.Remarks      = "Audit " + _currentAudit.Title + " Close " + dir.ProcedureType.CommonName + " Procedure";
                        }
                        directiveRecord.RecordDate = performDate;
                        Lifelength performanceSource;
                        directiveRecord.OnLifelength = Lifelength.TryParse((string)row.Cells[ColumnHours.Index].Value,
                                                                           (string)row.Cells[ColumnCycles.Index].Value,
                                                                           (string)row.Cells[ColumnDays.Index].Value,
                                                                           out performanceSource) ? performanceSource : Lifelength.Zero;

                        GlobalObjects.PerformanceCore.RegisterPerformance(dir, directiveRecord, _currentAudit);
                    }
                }
                catch (Exception ex)
                {
                    Program.Provider.Logger.Log("Error while saving performance for directive", ex);
                }
            }
            //_closingItems.All(item => item.SaveData());

            IEnumerable <MaintenanceCheck> closedChecks =
                dataGridViewItems.Rows.OfType <WorkPackageClosingDataGridViewRow>()
                .Where(ci => ci.ClosingItem is MaintenanceCheck)
                .Select(ci => ci.ClosingItem as MaintenanceCheck);

            foreach (MaintenanceCheck mc in closedChecks)
            {
                MaintenanceCheckRecord mcRecord =
                    mc.PerformanceRecords.FirstOrDefault(pr => pr.DirectivePackageId == _currentAudit.ItemId);
                if (mcRecord == null)
                {
                    continue;
                }
                IEnumerable <DirectiveRecord> bindedMpdsRecords =
                    dataGridViewItems.Rows.OfType <WorkPackageClosingDataGridViewRow>()
                    .Where(ci => ci.ClosingItem is MaintenanceDirective)
                    .Select(ci => ci.ClosingItem as MaintenanceDirective)
                    .Where(mpd => mpd.MaintenanceCheck != null &&
                           mpd.MaintenanceCheck.ItemId == mc.ItemId &&
                           mpd.PerformanceRecords.FirstOrDefault(pr => pr.DirectivePackageId == _currentAudit.ItemId) != null)
                    .Select(mpd => mpd.PerformanceRecords.FirstOrDefault(pr => pr.DirectivePackageId == _currentAudit.ItemId));
                foreach (DirectiveRecord mpdsRecord in bindedMpdsRecords)
                {
                    mpdsRecord.MaintenanceCheckRecordId = mcRecord.ItemId;
                    GlobalObjects.NewKeeper.Save(mpdsRecord, false);
                }
            }
        }