Ejemplo n.º 1
0
        /// <summary>
        /// Данные работы обновляются по введенным значениям
        /// </summary>
        private bool SaveData()
        {
            TimeSpan hours;
            int      cycles;

            if (!UsefulMethods.ParseTime(textBoxHours.Text, out hours))
            {
                SimpleBalloon.Show(textBoxHours, ToolTipIcon.Warning, "Incorrect time format", "Please enter the time period in the following format:\nHH:MM");
                return(false);
            }
            if (!int.TryParse(textBoxCycles.Text, out cycles))
            {
                SimpleBalloon.Show(textBoxCycles, ToolTipIcon.Warning, "Incorrect value", "Please enter integer value");
                return(false);
            }
            if (currentRecord.RecordDate != Date)
            {
                currentRecord.RecordDate = Date;
            }
            if (currentRecord.Description != Remarks)
            {
                currentRecord.Description = Remarks;
            }
            if (currentRecord.AttachedFile != AttachedFile)
            {
                currentRecord.AttachedFile.FileName = AttachedFile.FileName;
                currentRecord.AttachedFile.FileData = AttachedFile.FileData;
            }
            if (currentRecord.MaintenanceOrganization != MaintenanceOrganization)
            {
                currentRecord.MaintenanceOrganization = MaintenanceOrganization;
            }
            if (currentRecord.Reference != Reference)
            {
                currentRecord.Reference = Reference;
            }
            if (currentRecord.OfficialDocumentsReceived != OfficialRecordsReceived)
            {
                currentRecord.OfficialDocumentsReceived = OfficialRecordsReceived;
            }

            try
            {
                if (mode == ScreenMode.Add)
                {
                    currentRecord.Completed = true;
                    if (currentDetail != null)
                    {
                        currentRecord = new DetailDirectiveRecord(currentRecord);
                        ((DetailDirective)comboBoxWorkType.SelectedItem).AddPerformance((DetailDirectiveRecord)currentRecord);
                    }
                    else
                    {
                        if (currentRecord.RecordType != RecordType)
                        {
                            currentRecord.RecordType = RecordType;
                        }
                        if (currentRecord.RecordType == RecordTypesCollection.Instance.DirectivePerformanceRecordType &&
                            !currentDirective.RepeatedlyPerform)
                        {
                            currentRecord.RecordType = RecordTypesCollection.Instance.DirectiveClosingRecordType;
                        }
                        currentDirective.AddRecord(currentRecord);
                    }
                    if (AttachedFile != null)
                    {
                        currentRecord.AttachedFile.FileName = AttachedFile.FileName;
                        currentRecord.AttachedFile.FileData = AttachedFile.FileData;
                    }
                    mode = ScreenMode.Edit;
                }
                currentRecord.Save(true);
                if (actualStateChanged)
                {
                    bool exist = false;
                    int  index = -1;
                    for (int i = actualStateRecords.Length - 1; i >= 0; i--)
                    {
                        if (UsefulMethods.CompareDates(actualStateRecords[i].RecordDate, dateTimePickerDate.Value))
                        {
                            exist = true;
                            index = i;
                            break;
                        }
                    }
                    if (exist)
                    {
                        if (MessageBox.Show("There is another actual state record for this date.\nExisting data will be updated.\nContinue?", new GlobalTermsProvider()["SystemName"].ToString(), MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation) == DialogResult.Yes)
                        {
                            actualStateRecords[index].Lifelength = new Lifelength(new TimeSpan(0), cycles, hours);
                            actualStateRecords[index].Save();
                        }
                    }
                    else
                    {
                        ActualStateRecord record = new ActualStateRecord(new Lifelength(new TimeSpan(0), cycles, hours));
                        record.RecordDate = dateTimePickerDate.Value;
                        if (currentRecord.Parent.Parent is BaseDetail)
                        {
                            ((BaseDetail)currentRecord.Parent.Parent).AddRecord(record);
                        }
                        else
                        {
                            ((BaseDetail)currentRecord.Parent.Parent.Parent).AddRecord(record);
                        }
                    }
                }
                if (RecordChanged != null)
                {
                    RecordChanged(this, EventArgs.Empty);
                }
            }
            catch (Exception ex)
            {
                Program.Provider.Logger.Log("Error while saving data", ex);
                return(false);
            }
            return(true);
        }