示例#1
0
 private void InitializeCompany(Company company, DataLists lists)
 {
     if (company.Director != null)
     {
         if (company.Director.InitState == InitializationState.INITIALIZATION_NEEDED)
         {
             int      directorId = SqlCompany_Director.GetDirectorFromCompany(company.Id);
             Director director   = lists.Directors.Find((d) => d.EmployeeId == directorId);
             if (director != null && director.InitState == InitializationState.INITIALIZATION_NEEDED)
             {
                 director.InitState = InitializationState.IN_INITIALIZATION;
                 company.Director   = director;
                 director.Company   = company;
                 InitializeDirector(director, lists);
                 company.Director.InitState = InitializationState.INITIALIZED;
             }
         }
     }
     if (company.Chancery != null && company.Chancery.InitState == InitializationState.INITIALIZATION_NEEDED)
     {
         int      chanceryId = SqlCompany_Chancery.GetChanceryFromCompany(company.Id);
         Chancery chancery   = lists.Chanceries.Find((c) => c.Id == chanceryId);
         if (chancery != null && chancery.InitState == InitializationState.INITIALIZATION_NEEDED)
         {
             chancery.InitState = InitializationState.IN_INITIALIZATION;
             company.Chancery   = chancery;
             chancery.Company   = company;
             InitializeChancery(chancery, lists);
             company.Chancery.InitState = InitializationState.INITIALIZED;
         }
     }
 }
示例#2
0
 private void AddCompanyDirectorRecord(Company company, Director director)
 {
     if (director.Id != 0)
     {
         SqlCompany_Director.AddRecord(company.Id, director.EmployeeId);
     }
     else
     {
         SqlCompany_Director.AddRecord(company.Id, null);
     }
 }
        public static void DeleteDirector(int id)
        {
            string sqlExpression = "UPDATE Director SET Deleted = 1 WHERE Id = @id";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);
                command.Parameters.Add("@id", SqlDbType.Int);
                command.Parameters["@id"].Value = id;
                SqlCompany_Director.DeleteFromDirector(id);
                command.ExecuteNonQuery();
            }
        }
        public static Director GetDirector(int id)
        {
            Director director      = null;
            string   sqlExpression = "SELECT * FROM Director WHERE Id = @id AND Deleted = 0";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);
                command.Parameters.Add("@id", SqlDbType.Int);
                command.Parameters["@id"].Value = id;
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Person person    = null;
                        byte[] signature = (byte[])reader["DirectorSignature"];
                        int    salary    = (int)reader["Salary"];
                        if (reader["PersonId"] != DBNull.Value)
                        {
                            int personId = (int)reader["PersonId"];
                            person = SqlPerson.GetPerson(personId);
                        }
                        Company company = new Company
                        {
                            Id        = SqlCompany_Director.GetCompanyByDirector(id),
                            InitState = InitializationState.INITIALIZATION_NEEDED
                        };
                        List <Document> pendingDocuments = SqlDirectorPendingDocuments.GetPendingDocuments(id);
                        director = new Director(person, company, signature, salary)
                        {
                            EmployeeId       = id,
                            PendingDocuments = pendingDocuments
                        };
                    }
                }
            }
            return(director);
        }
示例#5
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);
                }
            }
        }