コード例 #1
0
        private void Load()
        {
            try
            {
                Employees = new List <Employee_monthly>();


                using (var sr = new StreamReader(FileEmployees))
                {
                    while (!sr.EndOfStream)
                    {
                        var line  = sr.ReadLine();
                        var parts = line.Split(':');
                        if (parts.Length == 6)
                        {
                            var employee = new Employee_monthly(parts[0], parts[1], parts[2], parts[3], parts[4], int.Parse(parts[5]));
                            Employees.Add(employee);
                        }
                    }
                }
            }

            catch
            {
                MessageBox.Show("Ошибка чтения из файла");
            }
            listView_Employees.Items.Refresh();
        }
コード例 #2
0
        private void button_save_Click(object sender, RoutedEventArgs e)
        {
            Load();
            int missed;



            if (string.IsNullOrWhiteSpace(textBox_name.Text))
            {
                MessageBox.Show("Введите имя и фамилию сотрудника.");
                textBox_name.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(textBox_position.Text))
            {
                MessageBox.Show("Введите должность сотрудника.");
                textBox_position.Focus();
                return;
            }

            if (comboBox_department.SelectedItem == null)
            {
                MessageBox.Show("Укажите отдел, где работает сотрудник");
                textBox_missed.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(textBox_arrival.Text))
            {
                MessageBox.Show("Введите среднее время прибытия сотрудника.");
                textBox_arrival.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(textBox_leaving.Text))
            {
                MessageBox.Show("Введите среднее время ухода сотрудника.");
                textBox_leaving.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(textBox_missed.Text))
            {
                MessageBox.Show("Введите количество пропущенных сотрудником рабочих дней.");
                textBox_missed.Focus();
                return;
            }

            if (!int.TryParse(textBox_missed.Text, out missed))
            {
                MessageBox.Show("Некорректное значение! Введите целое число от 0 до 31.");
                textBox_missed.Focus();
                return;
            }

            if (missed < 0 || missed > 31)
            {
                MessageBox.Show("Некорректное значение! Введите целое число от 0 до 31.");
                textBox_missed.Focus();
                return;
            }

            Employee_monthly EmployeeEdited = new Employee_monthly(textBox_name.Text, textBox_position.Text, comboBox_department.Text, textBox_arrival.Text, textBox_leaving.Text, missed);
            Employee_monthly tempEmployee   = null;

            foreach (var item in Employees)
            {
                if ((item.Name == EmployeeEdit.Name) && (item.Position == EmployeeEdit.Position) && (item.Department == EmployeeEdit.Department) && (item.Arrival == EmployeeEdit.Arrival) && (item.Leaving == EmployeeEdit.Leaving) && (item.Missed == EmployeeEdit.Missed))
                {
                    tempEmployee = item;
                }
            }
            if (tempEmployee != null)
            {
                Employees.Remove(tempEmployee);
            }
            Employees.Add(EmployeeEdited);
            Save();
            NavigationService.Navigate(Pages.MainPage);
        }
コード例 #3
0
        private void button_add_Click(object sender, RoutedEventArgs e)
        {
            int missed;



            if (string.IsNullOrWhiteSpace(textBox_name.Text))
            {
                MessageBox.Show("Введите имя и фамилию сотрудника.");
                textBox_name.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(textBox_position.Text))
            {
                MessageBox.Show("Введите должность сотрудника.");
                textBox_position.Focus();
                return;
            }

            if (comboBox_department.SelectedItem == null)
            {
                MessageBox.Show("Укажите отдел, где работает сотрудник");
                textBox_missed.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(textBox_arrival.Text))
            {
                MessageBox.Show("Введите среднее время прибытия сотрудника.");
                textBox_arrival.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(textBox_leaving.Text))
            {
                MessageBox.Show("Введите среднее время ухода сотрудника.");
                textBox_leaving.Focus();
                return;
            }

            if (string.IsNullOrWhiteSpace(textBox_missed.Text))
            {
                MessageBox.Show("Введите количество пропущенных сотрудником рабочих дней.");
                textBox_missed.Focus();
                return;
            }

            if (!int.TryParse(textBox_missed.Text, out missed))
            {
                MessageBox.Show("Некорректное значение! Введите целое число от 0 до 31.");
                textBox_missed.Focus();
                return;
            }

            if (missed < 0 || missed > 31)
            {
                MessageBox.Show("Некорректное значение! Введите целое число от 0 до 31.");
                textBox_missed.Focus();
                return;
            }

            _newEmployee_monthly = new Employee_monthly(textBox_name.Text, textBox_position.Text, comboBox_department.Text, textBox_arrival.Text, textBox_leaving.Text, missed);
            Employees.Add(_newEmployee_monthly);
            //Save();
            Pages.Employee_addPage.textBox_arrival.Text             = "";
            Pages.Employee_addPage.textBox_name.Text                = "";
            Pages.Employee_addPage.textBox_missed.Text              = "";
            Pages.Employee_addPage.textBox_leaving.Text             = "";
            Pages.Employee_addPage.textBox_position.Text            = "";
            Pages.Employee_addPage.comboBox_department.SelectedItem = null;

            Save();
            Pages.MainPage.listView_Employees.Items.Refresh();
            NavigationService.Navigate(Pages.MainPage);
        }