public static int GenerateCompanyTypeId() { if (_lastIdDictionary[PersistedClass.CompanyType] == 0) { _lastIdDictionary[PersistedClass.CompanyType] = SqlCompanyType.GetMaxId(); } _lastIdDictionary[PersistedClass.CompanyType]++; return(_lastIdDictionary[PersistedClass.CompanyType]); }
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(); }
public static Company GetCompany(int id) { Company company = null; string sqlExpression = "SELECT * FROM Company 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()) { int companyTypeId = (int)reader["CompanyTypeId"]; string name = (string)reader["CompanyName"]; string address = (string)reader["CompanyAddress"]; Director director = new Director() { InitState = InitializationState.INITIALIZATION_NEEDED }; Chancery chancery = new Chancery() { InitState = InitializationState.INITIALIZATION_NEEDED }; CompanyType companyType = SqlCompanyType.GetCompanyType(companyTypeId); company = new Company(director, companyType, chancery, name, address) { Id = id }; } } } return(company); }
public static List <Company> GetAllCompanies() { List <Company> companies = new List <Company>(); string sqlExpression = "SELECT * FROM Company WHERE Deleted = 0"; using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand expression = new SqlCommand(sqlExpression, connection); SqlDataReader reader = expression.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { int id = (int)reader["Id"]; int companyTypeId = (int)reader["CompanyTypeId"]; string name = (string)reader["CompanyName"]; string address = (string)reader["CompanyAddress"]; Director director = new Director() { InitState = InitializationState.INITIALIZATION_NEEDED }; Chancery chancery = new Chancery() { InitState = InitializationState.INITIALIZATION_NEEDED }; CompanyType companyType = SqlCompanyType.GetCompanyType(companyTypeId); Company company = new Company(director, companyType, chancery, name, address) { Id = id }; companies.Add(company); } } } return(companies); }