Exemplo n.º 1
0
        public static List <Chancery> GetAllChanceries()
        {
            List <Chancery> chanceries    = new List <Chancery>();
            string          sqlExpression = "SELECT * FROM Chancery 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())
                    {
                        int     id      = (int)reader["Id"];
                        Company company = new Company
                        {
                            Id        = SqlCompany_Chancery.GetCompanyByChancery(id),
                            InitState = InitializationState.INITIALIZATION_NEEDED
                        };
                        List <Document>  archive          = SqlArchive.GetArchivedDocuments(id);
                        List <Document>  pendingDocuments = SqlPendingDocuments.GetPendingDocuments(id);
                        List <Secretary> secretaries      = SqlSecretary.GetCompanySecretaries(company.Id);
                        MainSecretary    mainSecretary    = null;
                        if (SqlMainSecretary.GetCompanyMainSecretary(company.Id) != null)
                        {
                            mainSecretary = new MainSecretary
                            {
                                EmployeeId = SqlMainSecretary.GetCompanyMainSecretary(company.Id).EmployeeId,
                                InitState  = InitializationState.INITIALIZATION_NEEDED
                            };
                        }
                        Chancery chancery = new Chancery(company)
                        {
                            Id               = id,
                            Archive          = archive,
                            PendingDocuments = pendingDocuments,
                            Secretaries      = secretaries,
                            MainSecretary    = mainSecretary
                        };
                        chanceries.Add(chancery);
                    }
                }
            }
            return(chanceries);
        }
Exemplo n.º 2
0
        public static Chancery GetChancery(int id)
        {
            Chancery chancery      = null;
            string   sqlExpression = "SELECT * FROM Chancery 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())
                    {
                        Company company = new Company
                        {
                            Id        = SqlCompany_Chancery.GetCompanyByChancery(id),
                            InitState = InitializationState.INITIALIZATION_NEEDED
                        };
                        List <Document>  archive          = SqlArchive.GetArchivedDocuments(id);
                        List <Document>  pendingDocuments = SqlPendingDocuments.GetPendingDocuments(id);
                        List <Secretary> secretaries      = SqlSecretary.GetCompanySecretaries(company.Id);
                        MainSecretary    mainSecretary    = SqlMainSecretary.GetCompanyMainSecretary(company.Id);
                        chancery = new Chancery(company)
                        {
                            Id               = id,
                            Archive          = archive,
                            PendingDocuments = pendingDocuments,
                            Secretaries      = secretaries,
                            MainSecretary    = mainSecretary
                        };
                    }
                }
            }
            return(chancery);
        }