Exemplo n.º 1
0
        public static Secretary GetSecretaryByPerson(int personId)
        {
            Secretary secretary     = null;
            string    sqlExpression = "SELECT * FROM Secretary 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"];
                        secretary = new Secretary
                        {
                            EmployeeId = id,
                            InitState  = InitializationState.INITIALIZATION_NEEDED
                        };
                    }
                }
            }
            return(secretary);
        }
Exemplo n.º 2
0
 private void PersistSecretaryChanges(Secretary secretary)
 {
     SqlSecretary.UpdateSecretary(secretary);
     if (secretary.Company != null && secretary.Company.UpdateState == UpdateState.UPDATE_NEEDED)
     {
         secretary.Company.UpdateState = UpdateState.IN_UPDATE;
         PersistCompanyChanges(secretary.Company);
         secretary.Company.UpdateState = UpdateState.UPDATE_UNNECESSARY;
     }
     foreach (Document document in secretary.CreatedDocuments)
     {
         if (document.UpdateState == UpdateState.UPDATE_NEEDED)
         {
             document.UpdateState = UpdateState.IN_UPDATE;
             PersistDocumentChanges(document);
             document.UpdateState = UpdateState.UPDATE_UNNECESSARY;
         }
     }
     foreach (Document document in secretary.PendingDocuments)
     {
         if (document.UpdateState == UpdateState.UPDATE_NEEDED)
         {
             document.UpdateState = UpdateState.IN_UPDATE;
             PersistDocumentChanges(document);
             document.UpdateState = UpdateState.UPDATE_UNNECESSARY;
         }
     }
 }
Exemplo n.º 3
0
        public static void UpdateSecretary(Secretary secretary)
        {
            string sqlExpression = "UPDATE Secretary SET PersonId = @personId, CompanyId = @companyId, MarkerId = @markerId, 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("@markerId", SqlDbType.Int);
                command.Parameters.Add("@salary", SqlDbType.Int);
                command.Parameters.Add("@id", SqlDbType.Int);
                command.Parameters["@personId"].Value = secretary.Id;
                if (secretary.Company == null)
                {
                    command.Parameters["@companyId"].Value = DBNull.Value;
                }
                else
                {
                    command.Parameters["@companyId"].Value = secretary.Company.Id;
                }
                if (secretary.Marker == null)
                {
                    command.Parameters["@markerId"].Value = DBNull.Value;
                }
                else
                {
                    command.Parameters["@markerId"].Value = secretary.Marker.Id;
                }
                command.Parameters["@salary"].Value = secretary.Salary;
                command.Parameters["@id"].Value     = secretary.EmployeeId;
                command.ExecuteNonQuery();
            }
        }
Exemplo n.º 4
0
        public static List <Secretary> GetCompanySecretaries(int companyId)
        {
            List <Secretary> secretaries   = new List <Secretary>();
            string           sqlExpression = "SELECT * FROM Secretary WHERE CompanyId = @companyId AND Deleted = 0";

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand(sqlExpression, connection);
                command.Parameters.Add("@companyId", SqlDbType.Int);
                command.Parameters["@companyId"].Value = companyId;
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        int       id        = (int)reader["Id"];
                        Secretary secretary = new Secretary
                        {
                            EmployeeId = id,
                            InitState  = InitializationState.INITIALIZATION_NEEDED
                        };
                        secretaries.Add(secretary);
                    }
                }
            }
            return(secretaries);
        }
        public void RedirectPendingDocument(Secretary secretary, Document document)
        {
            Chancery chancery = Company.Chancery;

            chancery.PendingDocuments.Remove(document);
            secretary.PendingDocuments.Add(document);
        }
Exemplo n.º 6
0
        public static void AddSecretary(Secretary secretary)
        {
            string sqlExpression = "INSERT INTO Secretary(Id, PersonId, CompanyId, MarkerId, Salary) VALUES (@id, @personId, @companyId, @markerId, @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("@markerId", SqlDbType.Int);
                command.Parameters.Add("@salary", SqlDbType.Int);
                command.Parameters["@id"].Value       = secretary.EmployeeId;
                command.Parameters["@personId"].Value = secretary.Id;
                if (secretary.Company == null)
                {
                    command.Parameters["@companyId"].Value = DBNull.Value;
                }
                else
                {
                    command.Parameters["@companyId"].Value = secretary.Company.Id;
                }
                if (secretary.Marker == null)
                {
                    command.Parameters["@markerId"].Value = DBNull.Value;
                }
                else
                {
                    command.Parameters["@markerId"].Value = secretary.Marker.Id;
                }
                command.Parameters["@salary"].Value = secretary.Salary;
                command.ExecuteNonQuery();
            }
        }
Exemplo n.º 7
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);
        }
        private void RemoveSecretaryEvent(object sender, EventArgs e)
        {
            ComboBox  secretariesBox = (ComboBox)Utils.FindControl(this, "secretariesBox");
            Secretary secretary      = (Secretary)secretariesBox.SelectedValue;

            if (secretary == null)
            {
                MessageBox.Show("Персона не выбрана!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                chancery.Secretaries.Remove(secretary);
                secretary.Delete();
                secretary = null;
            }
        }
        private void SelectSecretaryEvent(object sender, EventArgs e)
        {
            ComboBox secretariesBox = (ComboBox)Utils.FindControl(this, "secretariesBox");

            if (secretariesBox.SelectedItem == null)
            {
                MessageBox.Show("Персона не выбрана!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                Secretary         secretary         = (Secretary)secretariesBox.SelectedValue;
                SecretaryInfoForm secretaryInfoForm = new SecretaryInfoForm(secretary);
                secretaryInfoForm.Activate();
                secretaryInfoForm.Show();
            }
        }
Exemplo n.º 10
0
        public void RedirectDocumentToSecretaryButton_Click(object sender, EventArgs e)
        {
            ComboBox  pendingDocumentsBox = (ComboBox)Utils.FindControl(this, "pendingDocumentsBox");
            ComboBox  secretariesBox      = (ComboBox)Utils.FindControl(this, "secretariesBox");
            Document  document            = (Document)pendingDocumentsBox.SelectedItem;
            Secretary secretary           = (Secretary)secretariesBox.SelectedItem;

            if (document == null || secretary == null)
            {
                MessageBox.Show("Документ или секретарь не выбран!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                mainSecretary.RedirectPendingDocument(secretary, document);
                UpdatePendingDocumentsBox();
            }
        }
Exemplo n.º 11
0
        private void InitializeSecretary(Secretary secretary, DataLists lists)
        {
            if (secretary.Company != null && secretary.Company.InitState == InitializationState.INITIALIZATION_NEEDED)
            {
                secretary.Company.InitState = InitializationState.IN_INITIALIZATION;
                secretary.Company           = lists.Companies.Find((c) => c.Id == secretary.Company.Id);
                InitializeCompany(secretary.Company, lists);
                secretary.Company.InitState = InitializationState.INITIALIZED;
            }
            List <Document> pendingDocumentsTemporal = new List <Document>();

            foreach (Document document in secretary.PendingDocuments)
            {
                pendingDocumentsTemporal.Add(lists.Documents.Find((d) => d.Id == document.Id));
            }
            secretary.PendingDocuments = pendingDocumentsTemporal;
            foreach (Document document in secretary.PendingDocuments)
            {
                if (document.InitState == InitializationState.INITIALIZATION_NEEDED)
                {
                    document.InitState = InitializationState.IN_INITIALIZATION;
                    InitializeDocument(document, lists);
                    document.InitState = InitializationState.INITIALIZED;
                }
            }
            List <Document> createdDocumentsTemporal = new List <Document>();

            foreach (Document document in secretary.CreatedDocuments)
            {
                createdDocumentsTemporal.Add(lists.Documents.Find((d) => d.Id == document.Id));
            }
            secretary.CreatedDocuments = createdDocumentsTemporal;
            foreach (Document document in secretary.CreatedDocuments)
            {
                if (document.InitState == InitializationState.INITIALIZATION_NEEDED)
                {
                    document.InitState = InitializationState.IN_INITIALIZATION;
                    InitializeDocument(document, lists);
                    document.InitState = InitializationState.INITIALIZED;
                }
            }
        }
Exemplo n.º 12
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);
        }
        private void AddSecretaryDisposeEvent(object sender, EventArgs e)
        {
            //Создаем секретаря
            SecretaryForm form = (SecretaryForm)sender;

            if (form.CorrectOnClose)
            {
                Person    person    = form.Person;
                Marker    marker    = new Marker(Marker.Color.BLUE);
                Secretary secretary = new Secretary(person, chancery.Company, form.Salary)
                {
                    Marker           = marker,
                    PendingDocuments = new List <Document>(),
                    CreatedDocuments = new List <Document>()
                };
                secretary.Persist();
                //Добавляем секретаря в секретариат
                chancery.Secretaries.Add(secretary);

                UpdateSecretariesBox();
                UpdatePersonsToSecretaryBox();
                UpdatePersonsToMainSecretaryBox();
            }
        }
Exemplo n.º 14
0
 public DocumentEditForm(Secretary secretary, Document document)
 {
     this.secretary = secretary;
     this.document  = document;
     InitializeForm();
 }
Exemplo n.º 15
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);
                }
            }
        }
Exemplo n.º 16
0
 public SecretaryInfoForm(Secretary secretary)
 {
     this.secretary = secretary;
     InitializeForm();
 }
Exemplo n.º 17
0
 public DocumentForm(Secretary secretary)
 {
     this.secretary = secretary;
     InitializeForm();
 }