Пример #1
0
 public static int GenerateCompanyId()
 {
     if (_lastIdDictionary[PersistedClass.Company] == 0)
     {
         _lastIdDictionary[PersistedClass.Company] = SqlCompany.GetMaxId();
     }
     _lastIdDictionary[PersistedClass.Company]++;
     return(_lastIdDictionary[PersistedClass.Company]);
 }
Пример #2
0
 private void PersistCompanyChanges(Company company)
 {
     SqlCompany.UpdateCompany(company);
     if (company.Director != null && company.Director.UpdateState == UpdateState.UPDATE_NEEDED)
     {
         company.Director.UpdateState = UpdateState.IN_UPDATE;
         PersistDirectorChanges(company.Director);
         company.Director.UpdateState = UpdateState.UPDATE_UNNECESSARY;
     }
     if (company.Chancery != null && company.Chancery.UpdateState == UpdateState.UPDATE_NEEDED)
     {
         company.Chancery.UpdateState = UpdateState.IN_UPDATE;
         PersistChanceryChanges(company.Chancery);
         company.Chancery.UpdateState = UpdateState.UPDATE_UNNECESSARY;
     }
 }
Пример #3
0
 public void Initialize()
 {
     Persons   = SqlPerson.GetAllPersons();
     Companies = SqlCompany.GetAllCompanies();
     Companies.ForEach((c) => c.InitState = InitializationState.INITIALIZATION_NEEDED);
     Chanceries = SqlChancery.GetAllChanceries();
     Chanceries.ForEach((c) => c.InitState = InitializationState.INITIALIZATION_NEEDED);
     Directors = SqlDirector.GetAllDirectors();
     Directors.ForEach((d) => d.InitState = InitializationState.INITIALIZATION_NEEDED);
     Secretaries = SqlSecretary.GetAllSecretaries();
     Secretaries.ForEach((s) => s.InitState = InitializationState.INITIALIZATION_NEEDED);
     MainSecretaries = SqlMainSecretary.GetAllMainSecretaries();
     MainSecretaries.ForEach((ms) => ms.InitState = InitializationState.INITIALIZATION_NEEDED);
     Documents = SqlDocument.GetAllDocuments();
     Documents.ForEach((d) => d.InitState = InitializationState.INITIALIZATION_NEEDED);
     CompanyTypes  = SqlCompanyType.GetAllCompanyTypes();
     DocumentTypes = SqlDocumentType.GetAllDocumentTypes();
     Markers       = SqlMarker.GetAllMarkers();
 }
Пример #4
0
        public void UpdateCollections(DataLists oldDataLists, DataLists dataLists)
        {
            List <Person> oldPersons = oldDataLists.Persons;
            List <Person> persons    = dataLists.Persons;

            foreach (Person person in persons)
            {
                //Если не было этой персоны то добавить
                if (oldPersons.Contains(person) == false)
                {
                    SqlPerson.AddPerson(person);
                }
            }
            foreach (Person oldPerson in oldPersons)
            {
                //Если персона была удалена то удалить
                if (persons.Contains(oldPerson) == false)
                {
                    SqlPerson.DeletePerson(oldPerson.Id);
                }
            }

            List <Company> oldCompanies = oldDataLists.Companies;
            List <Company> companies    = dataLists.Companies;

            foreach (Company company in companies)
            {
                if (oldCompanies.Contains(company) == false)
                {
                    SqlCompany.AddCompany(company);
                }
            }
            foreach (Company oldCompany in oldCompanies)
            {
                if (companies.Contains(oldCompany) == false)
                {
                    SqlCompany_Director.DeleteFromCompany(oldCompany.Id);
                    SqlCompany_Chancery.DeleteFromCompany(oldCompany.Id);
                    SqlCompany.DeleteCompany(oldCompany.Id);
                }
            }

            List <Chancery> oldChanceries = oldDataLists.Chanceries;
            List <Chancery> chanceries    = dataLists.Chanceries;

            foreach (Chancery chancery in chanceries)
            {
                if (oldChanceries.Contains(chancery) == false)
                {
                    SqlChancery.AddChancery(chancery);
                    AddCompanyChanceryRecord(chancery.Company, chancery);
                    foreach (Document document in chancery.PendingDocuments)
                    {
                        SqlPendingDocuments.AddPendingDocument(chancery.Id, document.Id);
                    }
                    foreach (Document document in chancery.Archive)
                    {
                        SqlArchive.AddArchivedDocument(chancery.Id, document.Id);
                    }
                }
                else
                {
                    Chancery oldChancery = oldChanceries.Find((oc) => oc.Id == chancery.Id);
                    foreach (Document document in chancery.PendingDocuments)
                    {
                        if (oldChancery.PendingDocuments.Contains(document) == false)
                        {
                            SqlPendingDocuments.AddPendingDocument(chancery.Id, document.Id);
                        }
                    }
                    foreach (Document oldDocument in oldChancery.PendingDocuments)
                    {
                        if (chancery.PendingDocuments.Contains(oldDocument) == false)
                        {
                            SqlPendingDocuments.DeletePendingDocument(chancery.Id, oldDocument.Id);
                        }
                    }
                    foreach (Document document in chancery.Archive)
                    {
                        if (oldChancery.Archive.Contains(document) == false)
                        {
                            SqlArchive.AddArchivedDocument(chancery.Id, document.Id);
                        }
                    }
                    foreach (Document oldDocument in oldChancery.Archive)
                    {
                        if (chancery.Archive.Contains(oldDocument) == false)
                        {
                            SqlArchive.DeleteArchivedDocument(chancery.Id, oldDocument.Id);
                        }
                    }
                }
            }
            foreach (Chancery oldChancery in oldChanceries)
            {
                if (chanceries.Contains(oldChancery) == false)
                {
                    SqlCompany_Chancery.GetCompanyByChancery(oldChancery.Id);
                    SqlChancery.DeleteChancery(oldChancery.Id);
                }
            }
            List <Director> oldDirectors = oldDataLists.Directors;
            List <Director> directors    = dataLists.Directors;

            foreach (Director director in directors)
            {
                if (oldDirectors.Contains(director) == false)
                {
                    SqlDirector.AddDirector(director);
                    AddCompanyDirectorRecord(director.Company, director);
                    foreach (Document document in director.PendingDocuments)
                    {
                        SqlDirectorPendingDocuments.AddPendingDocument(director.EmployeeId, document.Id);
                    }
                }
                else
                {
                    Director oldDirector = oldDirectors.Find((od) => od.EmployeeId == director.EmployeeId);
                    foreach (Document document in director.PendingDocuments)
                    {
                        if (oldDirector.PendingDocuments.Contains(document) == false)
                        {
                            SqlDirectorPendingDocuments.AddPendingDocument(director.EmployeeId, document.Id);
                        }
                    }
                    foreach (Document oldDocument in oldDirector.PendingDocuments)
                    {
                        if (director.PendingDocuments.Contains(oldDocument) == false)
                        {
                            SqlDirectorPendingDocuments.DeletePendingDocument(director.EmployeeId, oldDocument.Id);
                        }
                    }
                }
            }
            foreach (Director oldDirector in oldDirectors)
            {
                if (directors.Contains(oldDirector) == false)
                {
                    foreach (Document oldDocument in oldDirector.PendingDocuments)
                    {
                        SqlDirectorPendingDocuments.DeletePendingDocument(oldDirector.EmployeeId, oldDocument.Id);
                    }
                    SqlCompany_Director.GetCompanyByDirector(oldDirector.EmployeeId);
                    SqlDirector.DeleteDirector(oldDirector.EmployeeId);
                }
            }
            List <Secretary> oldSecretaries = oldDataLists.Secretaries;
            List <Secretary> secretaries    = dataLists.Secretaries;

            //документи не додаються
            foreach (Secretary secretary in secretaries)
            {
                if (oldSecretaries.Contains(secretary) == false)
                {
                    SqlSecretary.AddSecretary(secretary);
                    foreach (Document document in secretary.PendingDocuments)
                    {
                        SqlSecretaryPendingDocuments.AddPendingDocument(secretary.EmployeeId, document.Id);
                    }
                    foreach (Document document in secretary.CreatedDocuments)
                    {
                        SqlSecretaryCreatedDocuments.AddCreatedDocument(secretary.EmployeeId, document.Id);
                    }
                }
                else
                {
                    Secretary oldSecretary = oldSecretaries.Find((os) => os.EmployeeId == secretary.EmployeeId);
                    foreach (Document document in secretary.PendingDocuments)
                    {
                        if (oldSecretary.PendingDocuments.Contains(document) == false)
                        {
                            SqlSecretaryPendingDocuments.AddPendingDocument(secretary.EmployeeId, document.Id);
                        }
                    }
                    foreach (Document oldDocument in oldSecretary.PendingDocuments)
                    {
                        if (secretary.PendingDocuments.Contains(oldDocument) == false)
                        {
                            SqlSecretaryPendingDocuments.DeletePendingDocument(secretary.EmployeeId, oldDocument.Id);
                        }
                    }
                    foreach (Document document in secretary.CreatedDocuments)
                    {
                        if (oldSecretary.CreatedDocuments.Contains(document) == false)
                        {
                            SqlSecretaryCreatedDocuments.AddCreatedDocument(secretary.EmployeeId, document.Id);
                        }
                    }
                    foreach (Document oldDocument in oldSecretary.CreatedDocuments)
                    {
                        if (secretary.PendingDocuments.Contains(oldDocument) == false)
                        {
                            SqlSecretaryCreatedDocuments.DeleteCreatedDocument(secretary.EmployeeId, oldDocument.Id);
                        }
                    }
                }
            }
            foreach (Secretary oldSecretary in oldSecretaries)
            {
                if (secretaries.Contains(oldSecretary) == false)
                {
                    foreach (Document oldDocument in oldSecretary.PendingDocuments)
                    {
                        SqlSecretaryPendingDocuments.DeletePendingDocument(oldSecretary.EmployeeId, oldDocument.Id);
                    }
                    foreach (Document oldDocument in oldSecretary.CreatedDocuments)
                    {
                        SqlSecretaryCreatedDocuments.DeleteCreatedDocument(oldSecretary.EmployeeId, oldDocument.Id);
                    }
                    SqlSecretary.DeleteSecretary(oldSecretary.EmployeeId);
                }
            }
            List <MainSecretary> oldMainSecretaries = oldDataLists.MainSecretaries;
            List <MainSecretary> mainSecretaries    = dataLists.MainSecretaries;

            foreach (MainSecretary mainSecretary in mainSecretaries)
            {
                if (oldMainSecretaries.Contains(mainSecretary) == false)
                {
                    SqlMainSecretary.AddMainSecretary(mainSecretary);
                }
            }
            foreach (MainSecretary oldMainSecretary in oldMainSecretaries)
            {
                if (mainSecretaries.Contains(oldMainSecretary) == false)
                {
                    SqlMainSecretary.DeleteMainSecretary(oldMainSecretary.EmployeeId);
                }
            }
            List <Document> oldDocuments = oldDataLists.Documents;
            List <Document> documents    = dataLists.Documents;

            foreach (Document document in documents)
            {
                if (oldDocuments.Contains(document) == false)
                {
                    SqlDocument.AddDocument(document);
                }
            }
            foreach (Document oldDocument in oldDocuments)
            {
                if (documents.Contains(oldDocument) == false)
                {
                    SqlDocument.DeleteDocument(oldDocument.Id);
                }
            }
            List <Marker> oldMarkers = oldDataLists.Markers;
            List <Marker> markers    = dataLists.Markers;

            foreach (Marker marker in markers)
            {
                if (oldMarkers.Contains(marker) == false)
                {
                    SqlMarker.AddMarker(marker);
                }
            }
            foreach (Marker oldMarker in oldMarkers)
            {
                if (markers.Contains(oldMarker) == false)
                {
                    SqlMarker.DeleteMarker(oldMarker.Id);
                }
            }
        }