コード例 #1
0
        public static MainSecretary GetMainSecretaryByPerson(int personId)
        {
            MainSecretary mainSecretary = null;
            string        sqlExpression = "SELECT * FROM MainSecretary WHERE PersonId = @personId AND Deleted = 0";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);
                command.Parameters.Add("@personId", SqlDbType.Int);
                command.Parameters["@personId"].Value = personId;
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        int id = (int)reader["Id"];
                        mainSecretary = new MainSecretary
                        {
                            EmployeeId = id,
                            InitState  = InitializationState.INITIALIZATION_NEEDED
                        };
                    }
                }
            }
            return(mainSecretary);
        }
コード例 #2
0
        public static void UpdateMainSecretary(MainSecretary mainSecretary)
        {
            string sqlExpression = "UPDATE MainSecretary SET PersonId = @personId, CompanyId = @companyId, Salary = @salary WHERE Id = @id";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);
                command.Parameters.Add("@personId", SqlDbType.Int);
                command.Parameters.Add("@companyId", SqlDbType.Int);
                command.Parameters.Add("@salary", SqlDbType.Int);
                command.Parameters.Add("@id", SqlDbType.Int);
                command.Parameters["@personId"].Value = mainSecretary.Id;
                if (mainSecretary.Company == null)
                {
                    command.Parameters["@companyId"].Value = DBNull.Value;
                }
                else
                {
                    command.Parameters["@companyId"].Value = mainSecretary.Company.Id;
                }
                command.Parameters["@salary"].Value = mainSecretary.Salary;
                command.Parameters["@id"].Value     = mainSecretary.EmployeeId;
                command.ExecuteNonQuery();
            }
        }
コード例 #3
0
        public static void AddMainSecretary(MainSecretary mainSecretary)
        {
            string sqlExpression = "INSERT INTO MainSecretary(Id, PersonId, CompanyId, Salary) VALUES(@id, @personId, @companyId, @salary)";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);
                command.Parameters.Add("@id", SqlDbType.Int);
                command.Parameters.Add("@personId", SqlDbType.Int);
                command.Parameters.Add("@companyId", SqlDbType.Int);
                command.Parameters.Add("@salary", SqlDbType.Int);
                command.Parameters["@id"].Value       = mainSecretary.EmployeeId;
                command.Parameters["@personId"].Value = mainSecretary.Id;
                if (mainSecretary.Company == null)
                {
                    command.Parameters["@companyId"].Value = DBNull.Value;
                }
                else
                {
                    command.Parameters["@companyId"].Value = mainSecretary.Company.Id;
                }
                command.Parameters["@salary"].Value = mainSecretary.Salary;
                command.ExecuteNonQuery();
            }
        }
コード例 #4
0
        public void Delete()
        {
            DataLists dataLists = DataStorage.GetInstance().DataLists;

            //Удаляем всех секретарей из секретариата
            foreach (Secretary secretary in Secretaries)
            {
                secretary.Quit();
            }
            Secretaries = null;
            //Удаляем главного секретаря
            if (MainSecretary != null)
            {
                MainSecretary.Quit();
                MainSecretary = null;
            }
            //Удаляем необработанные документы
            foreach (Document document in PendingDocuments)
            {
                document.Delete();
            }
            PendingDocuments = null;
            //Удаляем архив
            foreach (Document document in Archive)
            {
                document.Delete();
            }
            Archive = null;
            dataLists.Chanceries.Remove(this);
        }
コード例 #5
0
 private void InitializeMainSecretary(MainSecretary mainSecretary, DataLists lists)
 {
     if (mainSecretary.Company != null && mainSecretary.Company.InitState == InitializationState.INITIALIZATION_NEEDED)
     {
         mainSecretary.Company.InitState = InitializationState.IN_INITIALIZATION;
         mainSecretary.Company           = lists.Companies.Find((c) => c.Id == mainSecretary.Company.Id);
         InitializeCompany(mainSecretary.Company, lists);
         mainSecretary.Company.InitState = InitializationState.INITIALIZED;
     }
 }
コード例 #6
0
 private void PersistMainSecretaryChanges(MainSecretary mainSecretary)
 {
     SqlMainSecretary.UpdateMainSecretary(mainSecretary);
     if (mainSecretary.Company != null && mainSecretary.Company.UpdateState == UpdateState.UPDATE_NEEDED)
     {
         mainSecretary.Company.UpdateState = UpdateState.IN_UPDATE;
         PersistCompanyChanges(mainSecretary.Company);
         mainSecretary.Company.UpdateState = UpdateState.UPDATE_UNNECESSARY;
     }
 }
コード例 #7
0
        private void ChangeMainSecretaryDisposeEvent(object sender, EventArgs e)
        {
            SecretaryForm form = (SecretaryForm)sender;

            if (form.CorrectOnClose)
            {
                Person person = form.Person;
                mainSecretary        = new MainSecretary(person, chancery.Company, form.Salary);
                mainSecretaryChanged = true;
            }
        }
コード例 #8
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);
        }
コード例 #9
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);
        }
コード例 #10
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);
        }
コード例 #11
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);
        }
コード例 #12
0
        private void AddMainSecretaryDisposeEvent(object sender, EventArgs e)
        {
            Control addMainSecretaryButton    = Utils.FindControl(this, "addMainSecretaryButton");
            Control personsToMainSecretaryBox = Utils.FindControl(this, "personsToMainSecretaryBox");
            //Создаем управляющего секретариатом
            SecretaryForm form = (SecretaryForm)sender;

            if (form.CorrectOnClose)
            {
                Person        person        = form.Person;
                MainSecretary mainSecretary = new MainSecretary(person, chancery.Company, form.Salary);
                mainSecretary.Persist();
                //Добавляем управляющего в секретариат
                chancery.MainSecretary = mainSecretary;

                Controls.Remove(addMainSecretaryButton);
                Controls.Remove(personsToMainSecretaryBox);
                Controls.Remove((Control)sender);
                UpdateSecretariesBox();
                UpdatePersonsToSecretaryBox();
                AddMainSecretaryInfoForms();
            }
        }
コード例 #13
0
        public void Delete()
        {
            DataLists     dataLists     = DataStorage.GetInstance().DataLists;
            Secretary     secretary     = dataLists.Secretaries.Find((s) => s.Id == Id);
            MainSecretary mainSecretary = dataLists.MainSecretaries.Find((ms) => ms.Id == Id);
            Director      director      = dataLists.Directors.Find((d) => d.Id == Id);

            if (secretary != null)
            {
                secretary.Quit();
                secretary = null;
            }
            if (mainSecretary != null)
            {
                mainSecretary.Quit();
                mainSecretary = null;
            }
            if (director != null)
            {
                // С компанией удаляется и директор
                director.Company.Delete();
            }
            dataLists.Persons.Remove(this);
        }
コード例 #14
0
 public MainSecretaryInfoForm(MainSecretary mainSecretary)
 {
     this.mainSecretary = mainSecretary;
     InitializeForm();
 }