Example #1
0
        private void btnDeleteSection_Click(object sender, EventArgs e)
        {
            string sectionCode           = ((Section)cmbSections.SelectedValue).Code;
            OrganizationalLevel orgLevel = ((Section)cmbSections.SelectedValue).OrganizationalLevel;

            if (_logic.DeleteSection(sectionCode, orgLevel))
            {
                Close();
            }
        }
Example #2
0
        private void cmbSectionType_DropDownClosed(object sender, EventArgs e)
        {
            OrganizationalLevel selectedLevel = (OrganizationalLevel)cmbSectionType.SelectedValue;

            if (selectedLevel > 0)
            {
                FillCmbSuperiorSection(selectedLevel - 1);
            }
            else
            {
                cmbSuperiorSection.DataSource = null;
            }
        }
Example #3
0
 public bool DeleteSection(string sectionCode, OrganizationalLevel orgLevel)
 {
     using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.ConnectionString))
     {
         string sqlQueryDelete = @"DELETE FROM Sections WHERE Code LIKE '' + @sectionCode + '%' AND OrganizationalLevel = @counter";
         string sqlQueryUpdate = @"UPDATE Employees SET DepartmentCode = NULL WHERE DepartmentCode LIKE '' + @sectionCode + '%'";
         try
         {
             connection.Open();
             SqlTransaction transaction = connection.BeginTransaction();
             SqlCommand     command     = new SqlCommand();
             command.Connection  = connection;
             command.Transaction = transaction;
             command.Parameters.Add("@sectionCode", SqlDbType.NVarChar).Value = sectionCode;
             command.Parameters.Add("@counter", SqlDbType.Int).Value          = 0;
             try
             {
                 command.CommandText = sqlQueryUpdate;
                 command.ExecuteNonQuery();
                 for (int i = (int)OrganizationalLevel.Department; i >= (int)orgLevel; i--)
                 {
                     command.Parameters["@counter"].Value = i;
                     command.CommandText = sqlQueryDelete;
                     command.ExecuteNonQuery();
                 }
                 transaction.Commit();
                 return(true);
             }
             catch (Exception e)
             {
                 Debug.WriteLine(e.StackTrace);
                 Debug.WriteLine(e.Message);
                 transaction.Rollback();
                 return(false);
             }
         }
         catch (Exception e)
         {
             Debug.WriteLine(e.StackTrace);
             Debug.WriteLine(e.Message);
             return(false);
         }
     }
 }
Example #4
0
 private void FillDtGrdSection(DataGridView dataGridView, OrganizationalLevel level, int?superiorSectionId)
 {
     if (level.Equals(OrganizationalLevel.Company))
     {
         dataGridView.DataSource = _logic.GetSectionsByLevel(level);
     }
     else
     {
         dataGridView.DataSource = _logic.GetSections(level, superiorSectionId);
     }
     dataGridView.Columns["ID"].Visible = false;
     dataGridView.Columns["OrganizationalLevel"].Visible = false;
     dataGridView.Columns["ManagerID"].Visible           = false;
     dataGridView.Columns["SuperiorSectionID"].Visible   = false;
     dataGridView.Columns["Code"].HeaderText             = "Kód";
     dataGridView.Columns["Code"].AutoSizeMode           = DataGridViewAutoSizeColumnMode.AllCells;
     dataGridView.Columns["Name"].HeaderText             = "Názov";
     dataGridView.Columns["Name"].AutoSizeMode           = DataGridViewAutoSizeColumnMode.Fill;
     EnablingBtns();
 }
Example #5
0
        private void FillLblSectionManager(OrganizationalLevel orgLevel)
        {
            switch (orgLevel)
            {
            case OrganizationalLevel.Company:
                lblSectionManager.Text = "Riaditeľ:";
                break;

            case OrganizationalLevel.Division:
                lblSectionManager.Text = "Vedúci divízie:";
                break;

            case OrganizationalLevel.Project:
                lblSectionManager.Text = "Vedúci projektu:";
                break;

            case OrganizationalLevel.Department:
                lblSectionManager.Text = "Vedúci oddelenia:";
                break;
            }
        }
Example #6
0
        public List <Section> GetSections(OrganizationalLevel level, int?superiorSectionId)
        {
            List <Section> sections = new List <Section>();

            using (SqlConnection connection = new SqlConnection(Properties.Settings.Default.ConnectionString))
            {
                try
                {
                    connection.Open();
                    string     sqlQuery = @"SELECT ID, Name, Code, OrganizationalLevel, ManagerID, SuperiorSectionID
                                    FROM Sections WHERE OrganizationalLevel = @level AND SuperiorSectionID = @superiorSectionId";
                    SqlCommand command  = new SqlCommand(sqlQuery, connection);
                    command.Parameters.Add("@level", SqlDbType.Int).Value             = level;
                    command.Parameters.Add("@superiorSectionId", SqlDbType.Int).Value = superiorSectionId;
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            Section section = new Section();
                            section.ID   = reader.GetInt32(0);
                            section.Name = reader.GetString(1);
                            section.Code = reader.GetString(2);
                            section.OrganizationalLevel = (OrganizationalLevel)reader.GetInt32(3);
                            section.ManagerID           = reader.IsDBNull(4) ? (int?)null : reader.GetInt32(4);
                            section.SuperiorSectionID   = reader.IsDBNull(5) ? (int?)null : reader.GetInt32(5);
                            sections.Add(section);
                        }
                    }
                }
                catch (SqlException e)
                {
                    Debug.WriteLine(e.StackTrace);
                    Debug.WriteLine(e.Message);
                }
                return(sections);
            }
        }
Example #7
0
 public bool DeleteSection(string sectionCode, OrganizationalLevel orglevel)
 {
     return(_sectionRepository.DeleteSection(sectionCode, orglevel));
 }
Example #8
0
 public List <Section> GetSections(OrganizationalLevel level, int?superiorSectionId)
 {
     return(_sectionRepository.GetSections(level, superiorSectionId));
 }
Example #9
0
 public List <Section> GetSectionsByLevel(OrganizationalLevel level)
 {
     return(_sectionRepository.GetSectionsByLevel(level));
 }
Example #10
0
 private void FillCmbSuperiorSection(OrganizationalLevel level)
 {
     cmbSuperiorSection.DataSource    = _logic.GetSectionsByLevel(level);
     cmbSuperiorSection.DisplayMember = "Name";
 }