Пример #1
0
        /// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="serviceId">serviceId</param>
        /// <param name="serviceType">serviceType</param>
        /// <param name="companyId">companyId</param>
        public void DeleteDirect(int serviceId, string unitType, int companyId)
        {
            ServicesGateway servicesGeteway = new ServicesGateway();
            servicesGeteway.LoadByServiceId(serviceId, companyId);

            if (servicesGeteway.Table.Rows.Count > 0)
            {
                // Delete vehicle info
                if (unitType == "Vehicle")
                {
                   ServicesVehicle servicesVehicle = new ServicesVehicle(null);
                   servicesVehicle.DeleteDirect(serviceId, companyId);
                }

                // Delete notes
                ServicesNote servicesNote = new ServicesNote(null);
                servicesNote.DeleteAllDirect(serviceId, companyId);

                // Delete costs
                ServicesCost servicesCost = new ServicesCost(null);
                servicesCost.DeleteAllDirect(serviceId, companyId);

                // Delete service
                servicesGeteway.Delete(serviceId, companyId);
            }
        }
        /// <summary>
        /// Save all notes to database (direct)
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            ServiceInformationTDS serviceInformationChanges = (ServiceInformationTDS)Data.GetChanges();

            if (serviceInformationChanges != null)
            {
                if (serviceInformationChanges.NoteInformation.Rows.Count > 0)
                {
                    ServiceInformationServiceNoteGateway serviceInformationServiceNoteGateway = new ServiceInformationServiceNoteGateway(serviceInformationChanges);

                    foreach (ServiceInformationTDS.NoteInformationRow row in (ServiceInformationTDS.NoteInformationDataTable)serviceInformationChanges.NoteInformation)
                    {
                        // Insert new notes
                        if ((!row.Deleted) && (!row.InServiceNoteDatabase))
                        {
                            int? libraryFilesId = null; if (!row.IsLIBRARY_FILES_IDNull()) libraryFilesId = row.LIBRARY_FILES_ID;
                            ServicesNote servicesNote = new ServicesNote(null);
                            servicesNote.InsertDirect(row.ServiceID, row.RefID, row.Subject, row.UserID, row.DateTime_, row.Note, libraryFilesId, row.Deleted, row.COMPANY_ID);
                        }

                        // Update notes
                        if ((!row.Deleted) && (row.InServiceNoteDatabase))
                        {
                            int serviceId = row.ServiceID;
                            int refId = row.RefID;
                            bool originalDeleted = false;
                            int originalCompanyId = companyId;

                            // original values
                            string originalSubject = serviceInformationServiceNoteGateway.GetSubjectOriginal(serviceId, refId);
                            int originalUserId = serviceInformationServiceNoteGateway.GetUserIdOriginal(serviceId, refId);
                            DateTime originalDateTime_ = serviceInformationServiceNoteGateway.GetDateTime_Original(serviceId, refId);
                            string originalNote = serviceInformationServiceNoteGateway.GetNoteOriginal(serviceId, refId);
                            int? originalLibraryFilesId = null; if (serviceInformationServiceNoteGateway.GetLibraryFilesIdOriginal(serviceId, refId).HasValue) originalLibraryFilesId = serviceInformationServiceNoteGateway.GetLibraryFilesIdOriginal(serviceId, refId);

                            // new values
                            string newSubject = serviceInformationServiceNoteGateway.GetSubject(serviceId, refId);
                            string newNote = serviceInformationServiceNoteGateway.GetNote(serviceId, refId);
                            int? newLibraryFilesId = null; if (serviceInformationServiceNoteGateway.GetLibraryFilesId(serviceId, refId).HasValue) newLibraryFilesId = serviceInformationServiceNoteGateway.GetLibraryFilesId(serviceId, refId);

                            ServicesNote servicesNote = new ServicesNote(null);
                            servicesNote.UpdateDirect(serviceId, refId, originalSubject, originalUserId, originalDateTime_, originalNote, originalLibraryFilesId, originalDeleted, originalCompanyId, serviceId, refId, newSubject, originalUserId, originalDateTime_, newNote, newLibraryFilesId, originalDeleted, originalCompanyId);
                        }

                        // Deleted notes
                        if ((row.Deleted) && (row.InServiceNoteDatabase))
                        {
                            ServicesNote servicesNote = new ServicesNote(null);
                            servicesNote.DeleteDirect(row.ServiceID, row.RefID, row.COMPANY_ID);
                        }
                    }
                }
            }
        }