コード例 #1
0
 public static int GeneratePersonId()
 {
     if (_lastIdDictionary[PersistedClass.Person] == 0)
     {
         _lastIdDictionary[PersistedClass.Person] = SqlPerson.GetMaxId();
     }
     _lastIdDictionary[PersistedClass.Person]++;
     return(_lastIdDictionary[PersistedClass.Person]);
 }
コード例 #2
0
        public static List <Secretary> GetAllSecretaries()
        {
            List <Secretary> secretaries   = new List <Secretary>();
            string           sqlExpression = "SELECT * FROM Secretary WHERE Deleted = 0";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand    command = new SqlCommand(sqlExpression, connection);
                SqlDataReader reader  = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Person  person  = null;
                        Company company = null;
                        int     id      = (int)reader["Id"];
                        if (reader["PersonId"] != null)
                        {
                            int personId = (int)reader["PersonId"];
                            person = SqlPerson.GetPerson(personId);
                        }
                        if (reader["CompanyId"] != null)
                        {
                            int companyId = (int)reader["CompanyId"];
                            company = new Company()
                            {
                                Id        = companyId,
                                InitState = InitializationState.INITIALIZATION_NEEDED
                            };
                        }
                        int             markerId         = (int)reader["MarkerId"];
                        int             salary           = (int)reader["Salary"];
                        Marker          marker           = SqlMarker.GetMarker(markerId);
                        List <Document> pendingDocuments = SqlSecretaryPendingDocuments.GetPendingDocuments(id);
                        List <Document> createdDocuments = SqlSecretaryCreatedDocuments.GetCurrentDocuments(id);

                        Secretary secretary = new Secretary(person, company, salary)
                        {
                            EmployeeId       = id,
                            Marker           = marker,
                            PendingDocuments = pendingDocuments,
                            CreatedDocuments = createdDocuments
                        };

                        secretaries.Add(secretary);
                    }
                }
            }
            return(secretaries);
        }
コード例 #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 static MainSecretary GetMainSecretary(int id)
        {
            MainSecretary mainSecretary = null;
            string        sqlExpression = "SELECT * FROM MainSecretary 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;
                        Company company = null;
                        int     salary  = (int)reader["Salary"];
                        if (reader["PersonId"] != DBNull.Value)
                        {
                            int personId = (int)reader["PersonId"];
                            person = SqlPerson.GetPerson(personId);
                        }
                        if (reader["CompanyId"] != DBNull.Value)
                        {
                            int companyId = (int)reader["CompanyId"];
                            company = new Company()
                            {
                                Id        = companyId,
                                InitState = InitializationState.INITIALIZATION_NEEDED
                            };
                        }
                        mainSecretary = new MainSecretary(person, company, salary)
                        {
                            EmployeeId = id
                        };
                    }
                }
            }
            return(mainSecretary);
        }
コード例 #5
0
        public static List <MainSecretary> GetAllMainSecretaries()
        {
            List <MainSecretary> mainSecretaries = new List <MainSecretary>();
            string sqlExpression = "SELECT * FROM MainSecretary WHERE Deleted = 0";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand    command = new SqlCommand(sqlExpression, connection);
                SqlDataReader reader  = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        Person  person  = null;
                        Company company = null;
                        int     id      = (int)reader["Id"];
                        int     salary  = (int)reader["Salary"];
                        if (reader["PersonId"] != DBNull.Value)
                        {
                            int personId = (int)reader["PersonId"];
                            person = SqlPerson.GetPerson(personId);
                        }
                        if (reader["CompanyId"] != DBNull.Value)
                        {
                            int companyId = (int)reader["CompanyId"];
                            company = new Company()
                            {
                                Id        = companyId,
                                InitState = InitializationState.INITIALIZATION_NEEDED
                            };
                        }
                        MainSecretary mainSecretary = new MainSecretary(person, company, salary)
                        {
                            EmployeeId = id
                        };
                        mainSecretaries.Add(mainSecretary);
                    }
                }
            }
            return(mainSecretaries);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 private void PersistPersonChanges(Person person)
 {
     SqlPerson.UpdatePerson(person);
 }
コード例 #8
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);
                }
            }
        }