Exemplo n.º 1
0
        private void Employees_Table_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
        {
            int selectedRow = e.RowIndex;

            if (e.RowIndex != -1)
            {
                employee_menu.Enabled = true;
                this.employees_table.ClearSelection();
                this.employees_table.Rows[selectedRow].Selected = true;
                selected_employee = db.Empoyee.Find(employees_table.Rows[selectedRow].Cells[0].Value);
            }
            else
            {
                employee_menu.Enabled = false;
            }
        }
Exemplo n.º 2
0
 public Employee_Form(TestDBContext db, Empoyee selected_employee)
 {
     InitializeComponent();
     this.db = db;
     this.selected_employee  = selected_employee;
     comboBox1.DataSource    = db.Department.ToList();
     comboBox1.DisplayMember = "Name";
     comboBox1.ValueMember   = "Id";
     comboBox1.SelectedItem  = selected_employee.Department;
     groupBox1.Text          = "Редактирование сотрудника";
     textBox1.Text           = selected_employee.FirstName;
     textBox2.Text           = selected_employee.SurName;
     textBox3.Text           = selected_employee.Patronymic;
     maskedTextBox1.Text     = selected_employee.DateOfBirth.ToShortDateString();
     maskedTextBox2.Text     = selected_employee.DocSeries + selected_employee.DocNumber;
     textBox4.Text           = selected_employee.Position;
     button1.Text            = "Сохранить";
     this.button1.Click     += new EventHandler(Employee_Save);
     this.button3.Click     += (sender, e) => { this.Close(); };
 }
Exemplo n.º 3
0
        private void Employee_Create(object sender, EventArgs e)
        {
            Empoyee new_employee = new Empoyee()
            {
                Patronymic = textBox3.Text
            };

            if (textBox1.Text != "")
            {
                new_employee.FirstName = textBox1.Text;
                data_error.SetError(textBox1, "");
            }
            else
            {
                data_error.SetError(textBox1, "Поле пустое");
                return;
            }
            if (textBox2.Text != "")
            {
                new_employee.SurName = textBox2.Text;
                data_error.SetError(textBox2, "");
            }
            else
            {
                data_error.SetError(textBox2, "Поле пустое");
                return;
            }
            if (textBox4.Text != "")
            {
                new_employee.Position = textBox4.Text;
                data_error.SetError(textBox4, "");
            }
            else
            {
                data_error.SetError(textBox4, "Поле пустое");
                return;
            }
            DateTime dt;

            if (DateTime.TryParse(maskedTextBox1.Text, out dt))
            {
                if (dt.Year >= 1950 && dt <= DateTime.Now)
                {
                    new_employee.DateOfBirth = dt;
                    data_error.SetError(maskedTextBox1, "");
                }
                else
                {
                    data_error.SetError(maskedTextBox1, "Некорректная запись.");
                    maskedTextBox1.Focus();
                    return;
                }
            }
            else
            {
                data_error.SetError(maskedTextBox1, "Формат даты должен иметь вид ДД.ММ.ГГГГ");
                maskedTextBox1.Focus();
                return;
            }
            if (maskedTextBox2.Text.Length == 11)
            {
                new_employee.DocSeries = maskedTextBox2.Text.Substring(0, 4);
                new_employee.DocNumber = maskedTextBox2.Text.Substring(5, 6);
            }
            else
            {
                data_error.SetError(maskedTextBox2, "Строка должна иметь вид СЕРИЯ НОМЕР");
                maskedTextBox2.Focus();
                return;
            }
            new_employee.Department = db.Department.Find(comboBox1.SelectedValue);
            db.Empoyee.Add(new_employee);
            db.SaveChanges();
            this.Close();
        }