Загрузка данных


using System;

namespace Lab9WindowsForms
{
    public class CSotrudnik
    {
        // Закрытые поля по ТЗ
        private string family;
        private string name;
        private string otch;
        private float cost_day;
        private float count_days;
        
        // Поле для хранения типа (0 - Фиксированная, 1 - Объем продаж, 2 - Процент)
        private int empType;

        // Конструктор
        public CSotrudnik()
        {
            this.count_days = 0; // По условию
            this.cost_day = 0;   // По условию
            this.family = "";
            this.name = "";
            this.otch = "";
            this.empType = 0;
        }

        // Установка и получение ФИО
        public bool SetFIO(string f, string n, string o)
        {
            if (string.IsNullOrWhiteSpace(f) || string.IsNullOrWhiteSpace(n) || string.IsNullOrWhiteSpace(o))
                return false;
            family = f;
            name = n;
            otch = o;
            return true;
        }

        public string GetFamily() => family;
        public string GetName() => name;
        public string GetOtch() => otch;

        // Установка рабочих дней
        public bool SetCountDays(int count)
        {
            if (count < 0) return false;
            count_days = count;
            return true;
        }

        // Установка стоимости дня
        public bool SetDayCost(float cost)
        {
            if (cost < 0) return false;
            cost_day = cost;
            return true;
        }

        // Тип сотрудника
        public void SetEmpType(int type) => empType = type;
        public int GetEmpType() => empType;

        // Расчет зарплаты
        public float GetSumma()
        {
            return count_days * cost_day;
        }

        // Сравнение ФИО для поиска
        public bool IsThisSotrudnik(string searchFIO)
        {
            if (string.IsNullOrWhiteSpace(searchFIO)) return false;
            string currentFIO = $"{family} {name} {otch}".Trim().ToLower();
            return currentFIO == searchFIO.Trim().ToLower();
        }
    }
}


форма

using System;
using System.Windows.Forms;

namespace Lab9WindowsForms
{
    public partial class Form1 : Form
    {
        // Массив объектов по ТЗ (пункт 11)
        private CSotrudnik[] m_Sotrudniks = new CSotrudnik[30];
        private int m_iCount = 0; // Количество введенных сотрудников (пункт 10)

        public Form1()
        {
            InitializeComponent();
            txtCount.Text = "0"; // Начальные значения (пункт 12)
            txtTotalSalary.Text = "0,00";
            txtTotalFixed.Text = "0,00";
            txtTotalVolume.Text = "0,00";
            txtTotalPercent.Text = "0,00";
            rbFixed.Checked = true; 
        }

        // КНОПКА "ДОБАВИТЬ" (Пункт 13)
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (m_iCount >= m_Sotrudniks.Length)
            {
                MessageBox.Show("Массив сотрудников заполнен!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            m_Sotrudniks[m_iCount] = new CSotrudnik();

            // Проверка ФИО
            if (!m_Sotrudniks[m_iCount].SetFIO(txtFamily.Text, txtName.Text, txtOtch.Text))
            {
                MessageBox.Show("Заполните поля: Фамилия, Имя, Отчество!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Проверка дней
            if (!int.TryParse(txtDays.Text, out int days) || !m_Sotrudniks[m_iCount].SetCountDays(days))
            {
                MessageBox.Show("Не корректные данные о количестве дней", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Проверка стоимости дня
            if (!float.TryParse(txtCost.Text, out float cost) || !m_Sotrudniks[m_iCount].SetDayCost(cost))
            {
                MessageBox.Show("Не корректные данные о стоимости одного дня", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return; 
            }

            // Сохраняем тип в зависимости от выбранного переключателя
            if (rbFixed.Checked) m_Sotrudniks[m_iCount].SetEmpType(0);
            else if (rbVolume.Checked) m_Sotrudniks[m_iCount].SetEmpType(1);
            else if (rbPercent.Checked) m_Sotrudniks[m_iCount].SetEmpType(2);

            m_iCount++;
            txtCount.Text = m_iCount.ToString(); // Обновляем "Количество сотрудников"

            // Очищаем поля ввода
            txtFamily.Clear(); txtName.Clear(); txtOtch.Clear(); txtDays.Clear(); txtCost.Clear();
            MessageBox.Show("Сотрудник успешно добавлен!", "Успех", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        // КНОПКА "ПОДСЧИТАТЬ" (Пункт 14)
        private void btnCalc_Click(object sender, EventArgs e)
        {
            float allSumma = 0;     // Общая сумма затрат
            float fixedSumma = 0;   // Для Фиксированной оплаты
            float volumeSumma = 0;  // Для Объема продаж
            float percentSumma = 0; // Для Процента от продаж

            // Цикл подсчета сумм по категориям
            for (int i = 0; i < m_iCount; i++)
            {
                float currentSalary = m_Sotrudniks[i].GetSumma();
                allSumma += currentSalary;

                if (m_Sotrudniks[i].GetEmpType() == 0)
                    fixedSumma += currentSalary;
                else if (m_Sotrudniks[i].GetEmpType() == 1)
                    volumeSumma += currentSalary;
                else if (m_Sotrudniks[i].GetEmpType() == 2)
                    percentSumma += currentSalary;
            }

            // Выводим результаты во ВСЕ текстовые поля по лейблам
            txtTotalSalary.Text = allSumma.ToString("F2");
            txtTotalFixed.Text = fixedSumma.ToString("F2");
            txtTotalVolume.Text = volumeSumma.ToString("F2");
            txtTotalPercent.Text = percentSumma.ToString("F2");
        }

        // КНОПКА "ПОИСК" (Пункт 19)
        private void btnSearch_Click(object sender, EventArgs e)
        {
            string searchInput = Microsoft.VisualBasic.Interaction.InputBox(
                "Введите Фамилию, Имя и Отчество сотрудника через пробел для поиска:", 
                "Поиск по ФИО");

            if (string.IsNullOrWhiteSpace(searchInput)) return;

            bool found = false;

            for (int i = 0; i < m_iCount; i++)
            {
                if (m_Sotrudniks[i].IsThisSotrudnik(searchInput))
                {
                    found = true;
                    string info = $"Сотрудник найден!\n\n" +
                                  $"Фамилия: {m_Sotrudniks[i].GetFamily()}\n" +
                                  $"Имя: {m_Sotrudniks[i].GetName()}\n" +
                                  $"Отчество: {m_Sotrudniks[i].GetOtch()}\n" +
                                  $"Заработная плата: {m_Sotrudniks[i].GetSumma():F2} руб.";
                    
                    MessageBox.Show(info, "Результаты поиска", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
                }
            }

            if (!found)
            {
                MessageBox.Show("Сотрудник с таким ФИО не найден.", "Поиск", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }
    }
}