Форма frmEmployee
В программе предусмотрена возможность извлечения, добавления и изменения информации о сотрудниках центра. Для этого используется форма frmEmployee, добавляем элементы управления в соответствии с рис. 11.41.
увеличить изображение
Рис. 11.41. Форма frmEmployee
Класс формы frmEmployee наследуем от интерфейса ISelectingForm.
Листинг формы frmEmployee:
Листинг 11.9.
(html, txt)
this.DesignDatagrid(); } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }
private void miExit_Click(object sender, System.EventArgs e) { this.Close(); }
private void btnNext_Click( object sender, EventArgs e) { if (cmEmployees.Position < mainDataSet.employees.Rows.Count) cmEmployees.Position++;
}
private void btnPrev_Click(object sender, EventArgs e) { if (cmEmployees.Position > 0) cmEmployees.Position--; }
private void SetSelectedRow(DataGrid dataGrid, DataGrid.HitTestInfo hti) { try { int rowIndex = hti.Row; DataTable table = (DataTable)dataGrid.DataSource;
if (rowIndex == table.Rows.Count) return;
DataRow selectedRow = table.Rows[rowIndex];
this.SelectedRow = selectedRow; } catch (Exception ex) { MessageBox.Show(ex.Message, ex.Source); } }
private void dgEmployees_MouseUp(object sender, MouseEventArgs e) { DataGrid.HitTestInfo hti = dgEmployees.HitTest(e.X, e.Y); if ((hti.Row != -1) && (hti.Column != -1)) SetSelectedRow(dgEmployees, hti); }
private void DesignDatagrid() { DataGridTableStyle employeesTableStyle = new DataGridTableStyle(); employeesTableStyle.MappingName = "employees";
DataGridTextBoxColumn employeeIDStyle = new DataGridTextBoxColumn(); employeeIDStyle.MappingName = "employeeID"; employeeIDStyle.Width = 50; employeeIDStyle.HeaderText = "ID";
DataGridTextBoxColumn lastNameStyle = new DataGridTextBoxColumn(); lastNameStyle.MappingName = "LastName"; lastNameStyle.Width = 120; lastNameStyle.HeaderText = "Фамилия";
DataGridTextBoxColumn firstNameStyle = new DataGridTextBoxColumn(); firstNameStyle.MappingName = "FirstName"; firstNameStyle.Width = 150; firstNameStyle.HeaderText = "Имя";
DataGridTextBoxColumn fatherNameStyle = new DataGridTextBoxColumn(); fatherNameStyle.MappingName = "amountToday"; fatherNameStyle.Width = 150; fatherNameStyle.HeaderText = "Отчество";
DataGridTextBoxColumn linkDataStyle = new DataGridTextBoxColumn(); linkDataStyle.MappingName = "linkData"; linkDataStyle.Width = 150; linkDataStyle.HeaderText = "Контакты";
DataGridTextBoxColumn birthDayStyle = new DataGridTextBoxColumn(); birthDayStyle.MappingName = "birthDay"; birthDayStyle.Width = 100; birthDayStyle.HeaderText = "День рождения";
DataGridTextBoxColumn directionIDStyle = new DataGridTextBoxColumn(); directionIDStyle.MappingName = "directionID"; directionIDStyle.Width = 60; directionIDStyle.HeaderText = "directionID";
DataGridTextBoxColumn addressStyle = new DataGridTextBoxColumn(); addressStyle.MappingName = "Address"; addressStyle.Width = 300; addressStyle.HeaderText = "Адрес";
DataGridTextBoxColumn notesStyle = new DataGridTextBoxColumn(); notesStyle.MappingName = "Notes"; notesStyle.Width = 100; notesStyle.HeaderText = "Notes";
DataGridTextBoxColumn passportSerialNumberStyle = new DataGridTextBoxColumn(); passportSerialNumberStyle.MappingName = "PassportSerialNumber"; passportSerialNumberStyle.Width = 100; passportSerialNumberStyle.HeaderText = "Серия паспорта";
DataGridTextBoxColumn dataPrinyatiyaStyle = new DataGridTextBoxColumn(); dataPrinyatiyaStyle.MappingName = "DataP"; dataPrinyatiyaStyle.Width = 100; dataPrinyatiyaStyle.HeaderText = "DataP";
DataGridTextBoxColumn kStyle = new DataGridTextBoxColumn(); kStyle.MappingName = "K"; kStyle.Width = 100; kStyle.HeaderText = "K";
DataGridTextBoxColumn postStyle = new DataGridTextBoxColumn(); postStyle.MappingName = "Post"; postStyle.Width = 100; postStyle.HeaderText = "Post";
employeesTableStyle.GridColumnStyles.AddRange(new DataGridTextBoxColumn[] { employeeIDStyle, lastNameStyle, firstNameStyle, fatherNameStyle, linkDataStyle, birthDayStyle, directionIDStyle, addressStyle, notesStyle, passportSerialNumberStyle, dataPrinyatiyaStyle, kStyle, postStyle});
dgEmployees.TableStyles.Add(employeesTableStyle); } } }
Листинг 11.9.