FormAddEdit.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. namespace СУБД_Альфапол
  11. {
  12. public partial class FormAddEdit : Form
  13. {
  14. public FormAddEdit()
  15. {
  16. InitializeComponent();
  17. }
  18. private void FormAddEdit_Load(object sender, EventArgs e)
  19. {
  20. // TODO: This line of code loads data into the 'dbAlphapolAGDataSet.Street' table. You can move, or remove it, as needed.
  21. this.streetTableAdapter.Fill(this.dbAlphapolAGDataSet.Street);
  22. // TODO: This line of code loads data into the 'dbAlphapolAGDataSet.IndexPartner' table. You can move, or remove it, as needed.
  23. this.indexPartnerTableAdapter.Fill(this.dbAlphapolAGDataSet.IndexPartner);
  24. // TODO: This line of code loads data into the 'dbAlphapolAGDataSet.City' table. You can move, or remove it, as needed.
  25. this.cityTableAdapter.Fill(this.dbAlphapolAGDataSet.City);
  26. // TODO: This line of code loads data into the 'dbAlphapolAGDataSet.Region' table. You can move, or remove it, as needed.
  27. this.regionTableAdapter.Fill(this.dbAlphapolAGDataSet.Region);
  28. // TODO: This line of code loads data into the 'dbAlphapolAGDataSet.TypePartner' table. You can move, or remove it, as needed.
  29. this.typePartnerTableAdapter.Fill(this.dbAlphapolAGDataSet.TypePartner);
  30. // TODO: This line of code loads data into the 'dbAlphapolAGDataSet.Partner' table. You can move, or remove it, as needed.
  31. this.partnerTableAdapter.Fill(this.dbAlphapolAGDataSet.Partner);
  32. if(lblTitle.Text == "Добавление партнера")
  33. {
  34. bsPartner.AddNew();
  35. }
  36. }
  37. private void btnSave_Click(object sender, EventArgs e)
  38. {
  39. if(tbxNamePartner.Text == "" || tbxEmail.Text == "" || tbxHouse.Text == "" || tbxName.Text == "" || tbxPatronymic.Text == "" || tbxPhone.Text == "" || tbxRating.Text == "" || tbxSurname.Text == "" || cbxCity.SelectedIndex == -1 || cbxIndex.SelectedIndex == -1 || cbxRegion.SelectedIndex == -1 || cbxStreet.SelectedIndex == -1 || cbxTypePartner.SelectedIndex == -1)
  40. {
  41. MessageBox.Show("Поля не должны быть пустыми!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  42. return;
  43. }
  44. if (int.Parse(tbxRating.Text) < 0)
  45. {
  46. MessageBox.Show("Рейтинг не может быть отрицательным!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  47. return;
  48. }
  49. bsPartner.EndEdit();
  50. this.partnerTableAdapter.Update(this.dbAlphapolAGDataSet.Partner);
  51. Close();
  52. }
  53. // если текстовое поле связано с БД, то при попытке сохранить изменения наступает событие Validating, в обработчике этого события можно выводить сообщения об ошибке
  54. private void tbxRating_Validating(object sender, CancelEventArgs e)
  55. {
  56. try
  57. {
  58. int r = int.Parse(tbxRating.Text);
  59. }
  60. catch
  61. {
  62. MessageBox.Show("Рейтинг должен быть целым не отрицательным числом!", "Внимание!", MessageBoxButtons.OK, MessageBoxIcon.Information);
  63. }
  64. }
  65. }
  66. }