FormAddRecord.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Forms;
  11. namespace InfoTrack
  12. {
  13. public partial class FormAddRecord : Form
  14. {
  15. DataBase dataBase = new DataBase();
  16. public FormAddRecord()
  17. {
  18. InitializeComponent();
  19. panelAddAlbum.Visible = false;
  20. panelAddGroup.Visible = false;
  21. panelAddTrack.Visible = false;
  22. panelAddMusician.Visible = false;
  23. switch(GlobalValues.nameOfOpenedTable)
  24. {
  25. case "Albums":
  26. panelAddAlbum.Visible = true;
  27. break;
  28. case "Groups":
  29. panelAddGroup.Visible = true;
  30. break;
  31. case "Tracks":
  32. panelAddTrack.Visible = true;
  33. break;
  34. case "Musicians":
  35. panelAddMusician.Visible = true;
  36. break;
  37. }
  38. }
  39. private void buttonAdd_Click(object sender, EventArgs e)
  40. {
  41. int index = GlobalValues.lastIndex;
  42. index++;
  43. dataBase.openConnection();
  44. switch(GlobalValues.nameOfOpenedTable)
  45. {
  46. case "Albums":
  47. var NameAlbum = textBoxAddNameAlbum.Text;
  48. var CodeGroup = textBoxAddCodeGroup.Text;
  49. var DurAlbum = textBoxAddDurAlbum.Text;
  50. var Year = textBoxAddYear.Text;
  51. var TracksCount = textBoxAddTracksCount.Text;
  52. var addQuery = $"insert into Albums (Kod_Album, NameAlbum, Kod_Group, DurationAlbum, YearAlbum, TracksNumbers) values('{index}','{NameAlbum}','{CodeGroup}','{DurAlbum}','{Year}','{TracksCount}')";
  53. var command = new SqlCommand(addQuery, dataBase.getConnection());
  54. command.ExecuteNonQuery();
  55. break;
  56. case "Groups":
  57. var NameGroup = textBoxAddNameGroup.Text;
  58. var YearCreation = textBoxAddYearCreation.Text;
  59. var DescriptionGroup = textBoxAddDiscription.Text;
  60. var Direction = textBoxAddDirection.Text;
  61. var addQuery2 = $"insert into Groups (Kod_Group, NameGroup, YearCreation, DescriptionGroup, Direction) values('{index}','{NameGroup}','{YearCreation}','{DescriptionGroup}','{Direction}')";
  62. var command2 = new SqlCommand(addQuery2, dataBase.getConnection());
  63. command2.ExecuteNonQuery();
  64. break;
  65. case "Tracks":
  66. var NameTrack = textBoxAddTrackName.Text;
  67. var Kod_Album = textBoxAddCodeAlbum_t.Text;
  68. var Kod_Group = textBoxAddCodeGroup_t.Text;
  69. var TrackDurationTrack = textBoxAddTimeTrack.Text;
  70. var addQuery3 = $"insert into Tracks (Kod_Track, NameTrack, Kod_Album, Kod_Group, TrackDurationTrack) values('{index}','{NameTrack}','{Kod_Album}','{Kod_Group}','{TrackDurationTrack}')";
  71. var command3 = new SqlCommand(addQuery3, dataBase.getConnection());
  72. command3.ExecuteNonQuery();
  73. break;
  74. case "Musicians":
  75. var Kod_Group_m = textBoxAddCodeGroup_m.Text;
  76. var NameMusician = textBoxAddNameMus.Text;
  77. var Role = textBoxAddRole.Text;
  78. var Birthday = textBoxAddbday.Text;
  79. var addQuery4 = $"insert into Musicians (Kod_Musician, Kod_Group, NameMusician, Role, Birthday) values('{index}','{Kod_Group_m}','{NameMusician}','{Role}','{Birthday}')";
  80. var command4 = new SqlCommand(addQuery4, dataBase.getConnection());
  81. command4.ExecuteNonQuery();
  82. break;
  83. }
  84. dataBase.closeConnection();
  85. MessageBox.Show("Запись успешно добавлена!");
  86. }
  87. private void buttonBack_Click(object sender, EventArgs e)
  88. {
  89. this.Hide();
  90. FormMenu form = new FormMenu();
  91. form.Show();
  92. }
  93. }
  94. }